Source code

Revision control

Other Tools

1
/* -*- indent-tabs-mode: nil; js-indent-level: 2 -*-
2
* vim: sw=2 ts=2 sts=2 expandtab
3
* This Source Code Form is subject to the terms of the Mozilla Public
4
* License, v. 2.0. If a copy of the MPL was not distributed with this
5
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
6
7
// Fired by TelemetryController when async telemetry data should be collected.
8
const TOPIC_GATHER_TELEMETRY = "gather-telemetry";
9
10
// Seconds between maintenance runs.
11
const MAINTENANCE_INTERVAL_SECONDS = 7 * 86400;
12
13
const { Services } = ChromeUtils.import("resource://gre/modules/Services.jsm");
14
ChromeUtils.defineModuleGetter(
15
this,
16
"PlacesUtils",
18
);
19
ChromeUtils.defineModuleGetter(
20
this,
21
"PlacesDBUtils",
23
);
24
25
/**
26
* This component can be used as a starter for modules that have to run when
27
* certain categories are invoked.
28
*/
29
function PlacesCategoriesStarter() {
30
Services.obs.addObserver(this, TOPIC_GATHER_TELEMETRY);
31
Services.obs.addObserver(this, PlacesUtils.TOPIC_SHUTDOWN);
32
}
33
34
PlacesCategoriesStarter.prototype = {
35
observe: function PCS_observe(aSubject, aTopic, aData) {
36
switch (aTopic) {
37
case PlacesUtils.TOPIC_SHUTDOWN:
38
Services.obs.removeObserver(this, PlacesUtils.TOPIC_SHUTDOWN);
39
Services.obs.removeObserver(this, TOPIC_GATHER_TELEMETRY);
40
if (Cu.isModuleLoaded("resource://gre/modules/PlacesDBUtils.jsm")) {
41
PlacesDBUtils.shutdown();
42
}
43
break;
44
case TOPIC_GATHER_TELEMETRY:
45
PlacesDBUtils.telemetry();
46
break;
47
case "idle-daily":
48
// Once a week run places.sqlite maintenance tasks.
49
let lastMaintenance = Services.prefs.getIntPref(
50
"places.database.lastMaintenance",
51
0
52
);
53
let nowSeconds = parseInt(Date.now() / 1000);
54
if (lastMaintenance < nowSeconds - MAINTENANCE_INTERVAL_SECONDS) {
55
PlacesDBUtils.maintenanceOnIdle();
56
}
57
break;
58
default:
59
throw new Error("Trying to handle an unknown category.");
60
}
61
},
62
63
classID: Components.ID("803938d5-e26d-4453-bf46-ad4b26e41114"),
64
QueryInterface: ChromeUtils.generateQI([Ci.nsIObserver]),
65
};
66
67
var EXPORTED_SYMBOLS = ["PlacesCategoriesStarter"];