Bug 828546 - Part 2: Health Report probe for Places data; r=rnewman

This commit is contained in:
Gregory Szorc 2013-02-05 10:44:33 -08:00
parent 1920b6d833
commit ddafb6104e
5 changed files with 115 additions and 0 deletions

View File

@ -10,6 +10,7 @@ this.EXPORTED_SYMBOLS = [
"AppInfoProvider",
"CrashesProvider",
"Metrics",
"PlacesProvider",
"ProfileMetadataProvider",
"SessionsProvider",
"SysInfoProvider",

View File

@ -5,4 +5,5 @@ category healthreport-js-provider CrashesProvider resource://gre/modules/HealthR
category healthreport-js-provider SysInfoProvider resource://gre/modules/HealthReport.jsm
category healthreport-js-provider ProfileMetadataProvider resource://gre/modules/HealthReport.jsm
category healthreport-js-provider SessionsProvider resource://gre/modules/HealthReport.jsm
category healthreport-js-provider PlacesProvider resource://gre/modules/HealthReport.jsm

View File

@ -21,6 +21,7 @@ this.EXPORTED_SYMBOLS = [
"AppInfoProvider",
"CrashDirectoryService",
"CrashesProvider",
"PlacesProvider",
"SessionsProvider",
"SysInfoProvider",
];
@ -43,6 +44,9 @@ XPCOMUtils.defineLazyModuleGetter(this, "AddonManager",
"resource://gre/modules/AddonManager.jsm");
XPCOMUtils.defineLazyModuleGetter(this, "UpdateChannel",
"resource://gre/modules/UpdateChannel.jsm");
XPCOMUtils.defineLazyModuleGetter(this, "PlacesDBUtils",
"resource://gre/modules/PlacesDBUtils.jsm");
/**
* Represents basic application state.
@ -888,3 +892,65 @@ CrashDirectoryService.prototype = Object.freeze({
},
});
/**
* Holds basic statistics about the Places database.
*/
function PlacesMeasurement() {
Metrics.Measurement.call(this);
}
PlacesMeasurement.prototype = Object.freeze({
__proto__: Metrics.Measurement.prototype,
name: "places",
version: 1,
configureStorage: function () {
return Task.spawn(function registerFields() {
yield this.registerStorageField("pages", this.storage.FIELD_DAILY_LAST_NUMERIC);
yield this.registerStorageField("bookmarks", this.storage.FIELD_DAILY_LAST_NUMERIC);
}.bind(this));
},
});
/**
* Collects information about Places.
*/
this.PlacesProvider = function () {
Metrics.Provider.call(this);
};
PlacesProvider.prototype = Object.freeze({
__proto__: Metrics.Provider.prototype,
name: "org.mozilla.places",
measurementTypes: [PlacesMeasurement],
collectDailyData: function () {
return this.storage.enqueueTransaction(this._collectData.bind(this));
},
_collectData: function () {
let now = new Date();
let data = yield this._getDailyValues();
let m = this.getMeasurement("places", 1);
yield m.setDailyLastNumeric("pages", data.PLACES_PAGES_COUNT);
yield m.setDailyLastNumeric("bookmarks", data.PLACES_BOOKMARKS_COUNT);
},
_getDailyValues: function () {
let deferred = Promise.defer();
PlacesDBUtils.telemetry(null, function onResult(data) {
deferred.resolve(data);
});
return deferred.promise;
},
});

View File

@ -0,0 +1,46 @@
/* Any copyright is dedicated to the Public Domain.
* http://creativecommons.org/publicdomain/zero/1.0/ */
"use strict";
const {utils: Cu} = Components;
Cu.import("resource://gre/modules/Metrics.jsm");
Cu.import("resource://gre/modules/services/healthreport/providers.jsm");
function run_test() {
run_next_test();
}
add_test(function test_constructor() {
let provider = new PlacesProvider();
run_next_test();
});
add_task(function test_collect_smoketest() {
let storage = yield Metrics.Storage("collect_smoketest");
let provider = new PlacesProvider();
yield provider.init(storage);
let now = new Date();
yield provider.collectDailyData();
let m = provider.getMeasurement("places", 1);
let data = yield storage.getMeasurementValues(m.id);
do_check_eq(data.days.size, 1);
do_check_true(data.days.hasDay(now));
let serializer = m.serializer(m.SERIALIZE_JSON);
let day = serializer.daily(data.days.getDay(now));
do_check_eq(day._v, 1);
do_check_eq(Object.keys(day).length, 3);
do_check_eq(day.pages, 0);
do_check_eq(day.bookmarks, 0);
yield storage.close();
});

View File

@ -8,6 +8,7 @@ tail =
[test_provider_addons.js]
[test_provider_appinfo.js]
[test_provider_crashes.js]
[test_provider_places.js]
[test_provider_sysinfo.js]
[test_provider_sessions.js]