2010-10-19 03:44:03 -07:00
|
|
|
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*-
|
|
|
|
* vim: sw=2 ts=2 sts=2 expandtab
|
2012-05-21 04:12:37 -07:00
|
|
|
* This Source Code Form is subject to the terms of the Mozilla Public
|
|
|
|
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
|
|
|
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
2010-10-19 03:44:03 -07:00
|
|
|
|
|
|
|
////////////////////////////////////////////////////////////////////////////////
|
|
|
|
//// Constants
|
|
|
|
|
|
|
|
const Cc = Components.classes;
|
|
|
|
const Ci = Components.interfaces;
|
2012-01-26 13:19:14 -08:00
|
|
|
const Cu = Components.utils;
|
2010-10-19 03:44:03 -07:00
|
|
|
|
2011-10-07 12:10:42 -07:00
|
|
|
// Fired by TelemetryPing when async telemetry data should be collected.
|
|
|
|
const TOPIC_GATHER_TELEMETRY = "gather-telemetry";
|
|
|
|
|
2011-01-10 10:54:49 -08:00
|
|
|
// Seconds between maintenance runs.
|
|
|
|
const MAINTENANCE_INTERVAL_SECONDS = 7 * 86400;
|
|
|
|
|
2011-10-07 12:10:42 -07:00
|
|
|
////////////////////////////////////////////////////////////////////////////////
|
|
|
|
//// Imports
|
|
|
|
|
2010-10-19 03:44:03 -07:00
|
|
|
Components.utils.import("resource://gre/modules/XPCOMUtils.jsm");
|
2011-10-07 12:10:42 -07:00
|
|
|
Components.utils.import("resource://gre/modules/Services.jsm");
|
|
|
|
Components.utils.import("resource://gre/modules/PlacesUtils.jsm");
|
|
|
|
XPCOMUtils.defineLazyModuleGetter(this, "PlacesDBUtils",
|
|
|
|
"resource://gre/modules/PlacesDBUtils.jsm");
|
2010-10-19 03:44:03 -07:00
|
|
|
|
|
|
|
/**
|
|
|
|
* This component can be used as a starter for modules that have to run when
|
|
|
|
* certain categories are invoked.
|
|
|
|
*/
|
|
|
|
function PlacesCategoriesStarter()
|
|
|
|
{
|
2011-10-07 12:10:42 -07:00
|
|
|
Services.obs.addObserver(this, TOPIC_GATHER_TELEMETRY, false);
|
|
|
|
Services.obs.addObserver(this, PlacesUtils.TOPIC_SHUTDOWN, false);
|
2011-10-27 02:11:45 -07:00
|
|
|
|
|
|
|
// nsINavBookmarkObserver implementation.
|
|
|
|
let notify = (function () {
|
|
|
|
if (!this._notifiedBookmarksSvcReady) {
|
|
|
|
// For perf reasons unregister from the category, since no further
|
|
|
|
// notifications are needed.
|
|
|
|
Cc["@mozilla.org/categorymanager;1"]
|
|
|
|
.getService(Ci.nsICategoryManager)
|
|
|
|
.deleteCategoryEntry("bookmarks-observer", this, false);
|
2012-02-24 02:10:38 -08:00
|
|
|
// Directly notify PlacesUtils, to ensure it catches the notification.
|
|
|
|
PlacesUtils.observe(null, "bookmarks-service-ready", null);
|
2011-10-27 02:11:45 -07:00
|
|
|
}
|
|
|
|
}).bind(this);
|
|
|
|
[ "onItemAdded", "onItemRemoved", "onItemChanged", "onBeginUpdateBatch",
|
2013-02-06 11:48:56 -08:00
|
|
|
"onEndUpdateBatch", "onItemVisited",
|
2011-10-27 02:11:45 -07:00
|
|
|
"onItemMoved" ].forEach(function(aMethod) {
|
|
|
|
this[aMethod] = notify;
|
|
|
|
}, this);
|
2010-10-19 03:44:03 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
PlacesCategoriesStarter.prototype = {
|
|
|
|
//////////////////////////////////////////////////////////////////////////////
|
|
|
|
//// nsIObserver
|
|
|
|
|
|
|
|
observe: function PCS_observe(aSubject, aTopic, aData)
|
|
|
|
{
|
|
|
|
switch (aTopic) {
|
2011-10-07 12:10:42 -07:00
|
|
|
case PlacesUtils.TOPIC_SHUTDOWN:
|
|
|
|
Services.obs.removeObserver(this, PlacesUtils.TOPIC_SHUTDOWN);
|
|
|
|
Services.obs.removeObserver(this, TOPIC_GATHER_TELEMETRY);
|
2012-01-26 13:19:14 -08:00
|
|
|
let globalObj =
|
|
|
|
Cu.getGlobalForObject(PlacesCategoriesStarter.prototype);
|
|
|
|
let descriptor =
|
|
|
|
Object.getOwnPropertyDescriptor(globalObj, "PlacesDBUtils");
|
|
|
|
if (descriptor.value !== undefined) {
|
|
|
|
PlacesDBUtils.shutdown();
|
|
|
|
}
|
2011-10-07 12:10:42 -07:00
|
|
|
break;
|
|
|
|
case TOPIC_GATHER_TELEMETRY:
|
|
|
|
PlacesDBUtils.telemetry();
|
|
|
|
break;
|
2010-10-19 03:44:03 -07:00
|
|
|
case "idle-daily":
|
2011-01-10 10:54:49 -08:00
|
|
|
// Once a week run places.sqlite maintenance tasks.
|
|
|
|
let lastMaintenance = 0;
|
|
|
|
try {
|
2011-10-07 12:10:42 -07:00
|
|
|
lastMaintenance =
|
|
|
|
Services.prefs.getIntPref("places.database.lastMaintenance");
|
2011-01-10 10:54:49 -08:00
|
|
|
} catch (ex) {}
|
|
|
|
let nowSeconds = parseInt(Date.now() / 1000);
|
|
|
|
if (lastMaintenance < nowSeconds - MAINTENANCE_INTERVAL_SECONDS) {
|
|
|
|
PlacesDBUtils.maintenanceOnIdle();
|
|
|
|
}
|
2010-10-19 03:44:03 -07:00
|
|
|
break;
|
|
|
|
default:
|
|
|
|
throw new Error("Trying to handle an unknown category.");
|
|
|
|
}
|
|
|
|
},
|
|
|
|
|
|
|
|
//////////////////////////////////////////////////////////////////////////////
|
|
|
|
//// nsISupports
|
|
|
|
|
|
|
|
classID: Components.ID("803938d5-e26d-4453-bf46-ad4b26e41114"),
|
|
|
|
|
2012-02-07 01:17:42 -08:00
|
|
|
_xpcom_factory: XPCOMUtils.generateSingletonFactory(PlacesCategoriesStarter),
|
|
|
|
|
2010-10-19 03:44:03 -07:00
|
|
|
QueryInterface: XPCOMUtils.generateQI([
|
|
|
|
Ci.nsIObserver
|
2011-10-27 02:11:45 -07:00
|
|
|
, Ci.nsINavBookmarkObserver
|
2010-10-19 03:44:03 -07:00
|
|
|
])
|
|
|
|
};
|
|
|
|
|
|
|
|
////////////////////////////////////////////////////////////////////////////////
|
|
|
|
//// Module Registration
|
|
|
|
|
|
|
|
let components = [PlacesCategoriesStarter];
|
2012-10-31 09:13:28 -07:00
|
|
|
this.NSGetFactory = XPCOMUtils.generateNSGetFactory(components);
|