зеркало из https://github.com/mozilla/gecko-dev.git
Bug 1138503 - Add the default search engine to the Telemetry Environment. r=gfritzsche
This commit is contained in:
Родитель
d71257a4ce
Коммит
b5230985ee
|
@ -154,6 +154,8 @@ const PREF_UPDATE_AUTODOWNLOAD = "app.update.auto";
|
|||
const MILLISECONDS_PER_DAY = 24 * 60 * 60 * 1000;
|
||||
|
||||
const EXPERIMENTS_CHANGED_TOPIC = "experiments-changed";
|
||||
const SEARCH_ENGINE_MODIFIED_TOPIC = "browser-search-engine-modified";
|
||||
const SEARCH_SERVICE_TOPIC = "browser-search-service";
|
||||
|
||||
/**
|
||||
* Turn a millisecond timestamp into a day timestamp.
|
||||
|
@ -651,6 +653,8 @@ function EnvironmentCache() {
|
|||
};
|
||||
|
||||
this._updateSettings();
|
||||
// Fill in the default search engine, if the search provider is already initialized.
|
||||
this._updateSearchEngine();
|
||||
|
||||
// Build the remaining asynchronous parts of the environment. Don't register change listeners
|
||||
// until the initial environment has been built.
|
||||
|
@ -663,21 +667,21 @@ function EnvironmentCache() {
|
|||
p.push(this._updateProfile());
|
||||
#endif
|
||||
|
||||
let setup = () => {
|
||||
this._initTask = null;
|
||||
this._startWatchingPrefs();
|
||||
this._addonBuilder.watchForChanges();
|
||||
this._addObservers();
|
||||
return this.currentEnvironment;
|
||||
};
|
||||
|
||||
this._initTask = Promise.all(p)
|
||||
.then(
|
||||
() => {
|
||||
this._initTask = null;
|
||||
this._startWatchingPrefs();
|
||||
this._addonBuilder.watchForChanges();
|
||||
return this.currentEnvironment;
|
||||
},
|
||||
() => setup(),
|
||||
(err) => {
|
||||
// log errors but eat them for consumers
|
||||
this._log.error("EnvironmentCache - error while initializing", err);
|
||||
this._initTask = null;
|
||||
this._startWatchingPrefs();
|
||||
this._addonBuilder.watchForChanges();
|
||||
return this.currentEnvironment;
|
||||
return setup();
|
||||
});
|
||||
}
|
||||
EnvironmentCache.prototype = {
|
||||
|
@ -799,6 +803,90 @@ EnvironmentCache.prototype = {
|
|||
}
|
||||
},
|
||||
|
||||
_addObservers: function () {
|
||||
// Watch the search engine change and service topics.
|
||||
Services.obs.addObserver(this, SEARCH_ENGINE_MODIFIED_TOPIC, false);
|
||||
Services.obs.addObserver(this, SEARCH_SERVICE_TOPIC, false);
|
||||
},
|
||||
|
||||
_removeObservers: function () {
|
||||
// Remove the search engine change and service observers.
|
||||
Services.obs.removeObserver(this, SEARCH_ENGINE_MODIFIED_TOPIC);
|
||||
Services.obs.removeObserver(this, SEARCH_SERVICE_TOPIC);
|
||||
},
|
||||
|
||||
observe: function (aSubject, aTopic, aData) {
|
||||
this._log.trace("observe - aTopic: " + aTopic + ", aData: " + aData);
|
||||
switch (aTopic) {
|
||||
case SEARCH_ENGINE_MODIFIED_TOPIC:
|
||||
if (aData != "engine-default" && aData != "engine-current") {
|
||||
return;
|
||||
}
|
||||
// Record the new default search choice and send the change notification.
|
||||
this._onSearchEngineChange();
|
||||
break;
|
||||
case SEARCH_SERVICE_TOPIC:
|
||||
if (aData != "init-complete") {
|
||||
return;
|
||||
}
|
||||
// Now that the search engine init is complete, record the default search choice.
|
||||
this._updateSearchEngine();
|
||||
break;
|
||||
}
|
||||
},
|
||||
|
||||
/**
|
||||
* Get the default search engine.
|
||||
* @return {String} Returns the search engine identifier, "NONE" if no default search
|
||||
* engine is defined or "UNDEFINED" if no engine identifier or name can be found.
|
||||
*/
|
||||
_getDefaultSearchEngine: function () {
|
||||
let engine;
|
||||
try {
|
||||
engine = Services.search.defaultEngine;
|
||||
} catch (e) {}
|
||||
|
||||
let name;
|
||||
if (!engine) {
|
||||
name = "NONE";
|
||||
} else if (engine.identifier) {
|
||||
name = engine.identifier;
|
||||
} else if (engine.name) {
|
||||
name = "other-" + engine.name;
|
||||
} else {
|
||||
name = "UNDEFINED";
|
||||
}
|
||||
|
||||
return name;
|
||||
},
|
||||
|
||||
/**
|
||||
* Update the default search engine value.
|
||||
*/
|
||||
_updateSearchEngine: function () {
|
||||
this._log.trace("_updateSearchEngine - isInitialized: " + Services.search.isInitialized);
|
||||
if (!Services.search.isInitialized) {
|
||||
return;
|
||||
}
|
||||
|
||||
// Make sure we have a settings section.
|
||||
this._currentEnvironment.settings = this._currentEnvironment.settings || {};
|
||||
// Update the search engine entry in the current environment.
|
||||
this._currentEnvironment.settings.defaultSearchEngine = this._getDefaultSearchEngine();
|
||||
},
|
||||
|
||||
/**
|
||||
* Update the default search engine value and trigger the environment change.
|
||||
*/
|
||||
_onSearchEngineChange: function () {
|
||||
this._log.trace("_onSearchEngineChange");
|
||||
|
||||
// Finally trigger the environment change notification.
|
||||
let oldEnvironment = Cu.cloneInto(this._currentEnvironment, myScope);
|
||||
this._updateSearchEngine();
|
||||
this._onEnvironmentChange("search-engine-changed", oldEnvironment);
|
||||
},
|
||||
|
||||
/**
|
||||
* Get the build data in object form.
|
||||
* @return Object containing the build data.
|
||||
|
|
|
@ -34,6 +34,7 @@ Structure::
|
|||
settings: {
|
||||
blocklistEnabled: <bool>, // true on failure
|
||||
isDefaultBrowser: <bool>, // null on failure, not available on Android
|
||||
defaultSearchEngine: <string>, // e.g. "yahoo"
|
||||
e10sEnabled: <bool>, // false on failure
|
||||
telemetryEnabled: <bool>, // false on failure
|
||||
locale: <string>, // e.g. "it", null on failure
|
||||
|
@ -189,3 +190,16 @@ Structure::
|
|||
persona: <string>, // id of the current persona, null on GONK
|
||||
},
|
||||
}
|
||||
|
||||
Settings
|
||||
--------
|
||||
|
||||
defaultSearchEngine
|
||||
~~~~~~~~~~~~~~~~~~~
|
||||
Contains the string identifier or name of the default search engine provider. This will not be present in environment data collected before the Search Service initialization.
|
||||
|
||||
The special value ``NONE`` could occur if there is no default search engine.
|
||||
|
||||
The special value ``UNDEFINED`` could occur if a default search engine exists but its identifier could not be determined.
|
||||
|
||||
This field's contents are ``Services.search.defaultEngine.identifier`` (if defined) or ``"other-"`` + ``Services.search.defaultEngine.name`` if not. In other words, search engines without an ``.identifier`` are prefixed with ``other-``.
|
||||
|
|
Загрузка…
Ссылка в новой задаче