зеркало из https://github.com/mozilla/gecko-dev.git
Bug 1191912 - Part 1 - Move client id caching to ClientID.jsm. r=rvitillo
This commit is contained in:
Родитель
32e0da13ce
Коммит
c04d10815f
|
@ -678,7 +678,7 @@ let Impl = {
|
|||
// id from disk.
|
||||
// We try to cache it in prefs to avoid this, even though this may
|
||||
// lead to some stale client ids.
|
||||
this._clientID = Preferences.get(PREF_CACHED_CLIENTID, null);
|
||||
this._clientID = ClientID.getCachedClientID();
|
||||
|
||||
// Delay full telemetry initialization to give the browser time to
|
||||
// run various late initializers. Otherwise our gathered memory
|
||||
|
@ -691,9 +691,8 @@ let Impl = {
|
|||
|
||||
yield TelemetrySend.setup(this._testMode);
|
||||
|
||||
// Load the ClientID and update the cache.
|
||||
// Load the ClientID.
|
||||
this._clientID = yield ClientID.getClientID();
|
||||
Preferences.set(PREF_CACHED_CLIENTID, this._clientID);
|
||||
|
||||
// Purge the pings archive by removing outdated pings. We don't wait for this
|
||||
// task to complete, but TelemetryStorage blocks on it during shutdown.
|
||||
|
|
|
@ -11,6 +11,7 @@ const {classes: Cc, interfaces: Ci, results: Cr, utils: Cu} = Components;
|
|||
Cu.import("resource://gre/modules/osfile.jsm");
|
||||
Cu.import("resource://gre/modules/Task.jsm");
|
||||
Cu.import("resource://gre/modules/XPCOMUtils.jsm");
|
||||
Cu.import("resource://gre/modules/Preferences.jsm");
|
||||
|
||||
XPCOMUtils.defineLazyModuleGetter(this, "CommonUtils",
|
||||
"resource://services-common/utils.js");
|
||||
|
@ -23,6 +24,8 @@ XPCOMUtils.defineLazyGetter(this, "gStateFilePath", () => {
|
|||
return OS.Path.join(gDatareportingPath, "state.json");
|
||||
});
|
||||
|
||||
const PREF_CACHED_CLIENTID = "toolkit.telemetry.cachedClientID";
|
||||
|
||||
this.ClientID = Object.freeze({
|
||||
/**
|
||||
* This returns a promise resolving to the the stable client ID we use for
|
||||
|
@ -35,6 +38,17 @@ this.ClientID = Object.freeze({
|
|||
return ClientIDImpl.getClientID();
|
||||
},
|
||||
|
||||
/**
|
||||
* Get the client id synchronously without hitting the disk.
|
||||
* This returns:
|
||||
* - the current on-disk client id if it was already loaded
|
||||
* - the client id that we cached into preferences (if any)
|
||||
* - null otherwise
|
||||
*/
|
||||
getCachedClientID: function() {
|
||||
return ClientIDImpl.getCachedClientID();
|
||||
},
|
||||
|
||||
/**
|
||||
* Only used for testing. Invalidates the client ID so that it gets read
|
||||
* again from file.
|
||||
|
@ -71,6 +85,7 @@ let ClientIDImpl = {
|
|||
let state = yield CommonUtils.readJSON(gStateFilePath);
|
||||
if (state && 'clientID' in state && typeof(state.clientID) == 'string') {
|
||||
this._clientID = state.clientID;
|
||||
Preferences.set(PREF_CACHED_CLIENTID, this._clientID);
|
||||
return this._clientID;
|
||||
}
|
||||
} catch (e) {
|
||||
|
@ -83,6 +98,7 @@ let ClientIDImpl = {
|
|||
let state = yield CommonUtils.readJSON(fhrStatePath);
|
||||
if (state && 'clientID' in state && typeof(state.clientID) == 'string') {
|
||||
this._clientID = state.clientID;
|
||||
Preferences.set(PREF_CACHED_CLIENTID, this._clientID);
|
||||
this._saveClientID();
|
||||
return this._clientID;
|
||||
}
|
||||
|
@ -92,6 +108,7 @@ let ClientIDImpl = {
|
|||
|
||||
// We dont have an id from FHR yet, generate a new ID.
|
||||
this._clientID = CommonUtils.generateUUID();
|
||||
Preferences.set(PREF_CACHED_CLIENTID, this._clientID);
|
||||
this._saveClientIdTask = this._saveClientID();
|
||||
|
||||
// Wait on persisting the id. Otherwise failure to save the ID would result in
|
||||
|
@ -130,6 +147,23 @@ let ClientIDImpl = {
|
|||
return Promise.resolve(this._clientID);
|
||||
},
|
||||
|
||||
/**
|
||||
* Get the client id synchronously without hitting the disk.
|
||||
* This returns:
|
||||
* - the current on-disk client id if it was already loaded
|
||||
* - the client id that we cached into preferences (if any)
|
||||
* - null otherwise
|
||||
*/
|
||||
getCachedClientID: function() {
|
||||
if (this._clientID) {
|
||||
// Already loaded the client id from disk.
|
||||
return this._clientID;
|
||||
}
|
||||
|
||||
// Not yet loaded, return the cached client id if we have one.
|
||||
return Preferences.get(PREF_CACHED_CLIENTID, null);
|
||||
},
|
||||
|
||||
/*
|
||||
* Resets the provider. This is for testing only.
|
||||
*/
|
||||
|
|
Загрузка…
Ссылка в новой задаче