Bug 855604 - SearchCountMeasurement2 should wait for nsSearchService to initialize asynchronously. r=gps

This commit is contained in:
Richard Newman 2013-03-29 09:23:02 -07:00
parent e1a86c81cf
commit 64e918ba98
3 changed files with 44 additions and 17 deletions

View File

@ -189,11 +189,11 @@ AppInfoProvider.prototype = Object.freeze({
xpcomabi: "XPCOMABI",
},
onInit: function () {
return Task.spawn(this._onInit.bind(this));
postInit: function () {
return Task.spawn(this._postInit.bind(this));
},
_onInit: function () {
_postInit: function () {
let recordEmptyAppInfo = function () {
this._setCurrentAppVersion("");
this._setCurrentPlatformVersion("");
@ -728,7 +728,7 @@ AddonsProvider.prototype = Object.freeze({
AddonCountsMeasurement,
],
onInit: function () {
postInit: function () {
let listener = {};
for (let method of this.ADDON_LISTENER_CALLBACKS) {
@ -1196,7 +1196,7 @@ SearchCountMeasurement2.prototype = Object.freeze({
* data.
*/
shouldIncludeField: function (name) {
return name.indexOf(".") != -1;
return name.contains(".");
},
/**
@ -1328,6 +1328,18 @@ this.SearchesProvider.prototype = Object.freeze({
SearchCountMeasurement2,
],
/**
* Initialize the search service before our measurements are touched.
*/
preInit: function (storage) {
// Initialize search service.
let deferred = Promise.defer();
Services.search.init(function onInitComplete () {
deferred.resolve();
});
return deferred.promise;
},
/**
* Record that a search occurred.
*

View File

@ -170,7 +170,6 @@ add_task(function test_record_telemetry() {
setTelemetry(true);
provider = new AppInfoProvider();
yield provider.init(storage);
yield provider.onInit();
yield provider.collectConstantData();
let m = provider.getMeasurement("appinfo", 2);
@ -182,7 +181,6 @@ add_task(function test_record_telemetry() {
setTelemetry(false);
provider = new AppInfoProvider();
yield provider.init(storage);
yield provider.onInit();
yield provider.collectConstantData();
m = provider.getMeasurement("appinfo", 2);
@ -202,7 +200,6 @@ add_task(function test_record_blocklist() {
Services.prefs.setBoolPref("extensions.blocklist.enabled", true);
let provider = new AppInfoProvider();
yield provider.init(storage);
yield provider.onInit();
yield provider.collectConstantData();
let m = provider.getMeasurement("appinfo", 2);
@ -214,7 +211,6 @@ add_task(function test_record_blocklist() {
Services.prefs.setBoolPref("extensions.blocklist.enabled", false);
provider = new AppInfoProvider();
yield provider.init(storage);
yield provider.onInit();
yield provider.collectConstantData();
m = provider.getMeasurement("appinfo", 2);

View File

@ -556,6 +556,12 @@ Provider.prototype = Object.freeze({
let self = this;
return Task.spawn(function init() {
let pre = self.preInit();
if (!pre || typeof(pre.then) != "function") {
throw new Error("preInit() does not return a promise.");
}
yield pre;
for (let measurementType of self.measurementTypes) {
let measurement = new measurementType();
@ -573,13 +579,11 @@ Provider.prototype = Object.freeze({
measurement);
}
let promise = self.onInit();
if (!promise || typeof(promise.then) != "function") {
throw new Error("onInit() does not return a promise.");
let post = self.postInit();
if (!post || typeof(post.then) != "function") {
throw new Error("postInit() does not return a promise.");
}
yield promise;
yield post;
});
},
@ -594,7 +598,22 @@ Provider.prototype = Object.freeze({
},
/**
* Hook point for implementations to perform initialization activity.
* Hook point for implementations to perform pre-initialization activity.
*
* This method will be called before measurement registration.
*
* Implementations should return a promise which is resolved when
* initialization activities have completed.
*/
preInit: function () {
return CommonUtils.laterTickResolvingPromise();
},
/**
* Hook point for implementations to perform post-initialization activity.
*
* This method will be called after `preInit` and measurement registration,
* but before initialization is finished.
*
* If a `Provider` instance needs to register observers, etc, it should
* implement this function.
@ -602,7 +621,7 @@ Provider.prototype = Object.freeze({
* Implementations should return a promise which is resolved when
* initialization activities have completed.
*/
onInit: function () {
postInit: function () {
return CommonUtils.laterTickResolvingPromise();
},