2012-12-11 15:13:00 -08: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/. */
|
|
|
|
|
2013-01-27 11:26:48 -08:00
|
|
|
#ifndef MERGED_COMPARTMENT
|
|
|
|
|
2014-08-07 21:52:05 -07:00
|
|
|
"use strict";
|
|
|
|
|
2015-03-07 08:53:36 -08:00
|
|
|
this.EXPORTED_SYMBOLS = ["ProfileMetadataProvider"];
|
2012-12-11 15:13:00 -08:00
|
|
|
|
|
|
|
const {utils: Cu, classes: Cc, interfaces: Ci} = Components;
|
|
|
|
|
|
|
|
const MILLISECONDS_PER_DAY = 24 * 60 * 60 * 1000;
|
2013-01-27 11:26:48 -08:00
|
|
|
|
|
|
|
Cu.import("resource://gre/modules/Metrics.jsm");
|
|
|
|
|
|
|
|
#endif
|
|
|
|
|
|
|
|
const DEFAULT_PROFILE_MEASUREMENT_NAME = "age";
|
2014-10-22 21:00:23 -07:00
|
|
|
const DEFAULT_PROFILE_MEASUREMENT_VERSION = 2;
|
2012-12-11 15:13:00 -08:00
|
|
|
const REQUIRED_UINT32_TYPE = {type: "TYPE_UINT32"};
|
|
|
|
|
2013-06-13 18:36:21 -07:00
|
|
|
Cu.import("resource://gre/modules/Promise.jsm");
|
2012-12-11 15:13:00 -08:00
|
|
|
Cu.import("resource://gre/modules/osfile.jsm")
|
2013-01-06 12:13:27 -08:00
|
|
|
Cu.import("resource://gre/modules/Task.jsm");
|
2013-08-26 11:55:58 -07:00
|
|
|
Cu.import("resource://gre/modules/Log.jsm");
|
2015-03-07 08:53:36 -08:00
|
|
|
Cu.import("resource://gre/modules/ProfileAge.jsm");
|
2012-12-11 15:13:00 -08:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Measurements pertaining to the user's profile.
|
|
|
|
*/
|
2014-10-22 21:00:23 -07:00
|
|
|
// This is "version 1" of the metadata measurement - it must remain, but
|
|
|
|
// it's currently unused - see bug 1063714 comment 12 for why.
|
2013-01-06 12:13:27 -08:00
|
|
|
function ProfileMetadataMeasurement() {
|
|
|
|
Metrics.Measurement.call(this);
|
2012-12-11 15:13:00 -08:00
|
|
|
}
|
|
|
|
ProfileMetadataMeasurement.prototype = {
|
2013-01-06 12:13:27 -08:00
|
|
|
__proto__: Metrics.Measurement.prototype,
|
|
|
|
|
|
|
|
name: DEFAULT_PROFILE_MEASUREMENT_NAME,
|
|
|
|
version: 1,
|
2012-12-11 15:13:00 -08:00
|
|
|
|
2013-02-21 14:11:54 -08:00
|
|
|
fields: {
|
2012-12-11 15:13:00 -08:00
|
|
|
// Profile creation date. Number of days since Unix epoch.
|
2013-02-21 14:11:54 -08:00
|
|
|
profileCreation: {type: Metrics.Storage.FIELD_LAST_NUMERIC},
|
2012-12-11 15:13:00 -08:00
|
|
|
},
|
|
|
|
};
|
|
|
|
|
2014-10-22 21:00:23 -07:00
|
|
|
// This is the current measurement - it adds the profileReset value.
|
|
|
|
function ProfileMetadataMeasurement2() {
|
|
|
|
Metrics.Measurement.call(this);
|
|
|
|
}
|
|
|
|
ProfileMetadataMeasurement2.prototype = {
|
|
|
|
__proto__: Metrics.Measurement.prototype,
|
|
|
|
|
|
|
|
name: DEFAULT_PROFILE_MEASUREMENT_NAME,
|
|
|
|
version: DEFAULT_PROFILE_MEASUREMENT_VERSION,
|
|
|
|
|
|
|
|
fields: {
|
|
|
|
// Profile creation date. Number of days since Unix epoch.
|
|
|
|
profileCreation: {type: Metrics.Storage.FIELD_LAST_NUMERIC},
|
|
|
|
// Profile reset date. Number of days since Unix epoch.
|
|
|
|
profileReset: {type: Metrics.Storage.FIELD_LAST_NUMERIC},
|
|
|
|
},
|
|
|
|
};
|
|
|
|
|
2012-12-11 15:13:00 -08:00
|
|
|
/**
|
|
|
|
* Turn a millisecond timestamp into a day timestamp.
|
|
|
|
*
|
|
|
|
* @param msec a number of milliseconds since epoch.
|
|
|
|
* @return the number of whole days denoted by the input.
|
|
|
|
*/
|
|
|
|
function truncate(msec) {
|
|
|
|
return Math.floor(msec / MILLISECONDS_PER_DAY);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2014-10-22 21:00:23 -07:00
|
|
|
* A Metrics.Provider for profile metadata, such as profile creation and
|
|
|
|
* reset time.
|
2012-12-11 15:13:00 -08:00
|
|
|
*/
|
2013-06-26 17:01:45 -07:00
|
|
|
this.ProfileMetadataProvider = function() {
|
2013-01-06 12:13:27 -08:00
|
|
|
Metrics.Provider.call(this);
|
2012-12-11 15:13:00 -08:00
|
|
|
}
|
2013-06-26 17:01:45 -07:00
|
|
|
this.ProfileMetadataProvider.prototype = {
|
2013-01-06 12:13:27 -08:00
|
|
|
__proto__: Metrics.Provider.prototype,
|
|
|
|
|
|
|
|
name: "org.mozilla.profile",
|
|
|
|
|
2014-10-22 21:00:23 -07:00
|
|
|
measurementTypes: [ProfileMetadataMeasurement2],
|
2012-12-11 15:13:00 -08:00
|
|
|
|
2013-02-18 13:05:07 -08:00
|
|
|
pullOnly: true,
|
2013-01-31 08:58:19 -08:00
|
|
|
|
2014-10-22 21:00:23 -07:00
|
|
|
getProfileDays: Task.async(function* () {
|
|
|
|
let result = {};
|
2015-03-07 08:53:36 -08:00
|
|
|
let accessor = new ProfileAge(null, this._log);
|
2012-12-11 15:13:00 -08:00
|
|
|
|
2014-10-22 21:00:23 -07:00
|
|
|
let created = yield accessor.created;
|
|
|
|
result["profileCreation"] = truncate(created);
|
|
|
|
let reset = yield accessor.reset;
|
|
|
|
if (reset) {
|
|
|
|
result["profileReset"] = truncate(reset);
|
|
|
|
}
|
|
|
|
return result;
|
|
|
|
}),
|
2012-12-11 15:13:00 -08:00
|
|
|
|
2013-01-06 12:13:27 -08:00
|
|
|
collectConstantData: function () {
|
2014-10-22 21:00:23 -07:00
|
|
|
let m = this.getMeasurement(DEFAULT_PROFILE_MEASUREMENT_NAME,
|
|
|
|
DEFAULT_PROFILE_MEASUREMENT_VERSION);
|
2012-12-11 15:13:00 -08:00
|
|
|
|
2014-10-22 21:00:23 -07:00
|
|
|
return Task.spawn(function* collectConstants() {
|
|
|
|
let days = yield this.getProfileDays();
|
2013-01-06 12:13:27 -08:00
|
|
|
|
|
|
|
yield this.enqueueStorageOperation(function storeDays() {
|
2014-10-22 21:00:23 -07:00
|
|
|
return Task.spawn(function* () {
|
|
|
|
yield m.setLastNumeric("profileCreation", days["profileCreation"]);
|
|
|
|
if (days["profileReset"]) {
|
|
|
|
yield m.setLastNumeric("profileReset", days["profileReset"]);
|
|
|
|
}
|
|
|
|
});
|
2013-01-06 12:13:27 -08:00
|
|
|
});
|
|
|
|
}.bind(this));
|
2012-12-11 15:13:00 -08:00
|
|
|
},
|
|
|
|
};
|
|
|
|
|