Bug 838072 - Part 2: Add collectDailyData API to providers; r=rnewman

This commit is contained in:
Gregory Szorc 2013-02-05 09:59:13 -08:00
parent 23ab086600
commit 2e58450766
4 changed files with 54 additions and 0 deletions

View File

@ -167,6 +167,14 @@ Collector.prototype = Object.freeze({
onCollect);
},
/**
* Calls collectDailyData on all providers.
*/
collectDailyData: function () {
return this._callCollectOnProviders(this._providers.values(),
"collectDailyData");
},
_callCollectOnProviders: function (entries, fnProperty, onCollect=null) {
let promises = [];

View File

@ -523,11 +523,29 @@ Provider.prototype = Object.freeze({
*
* Implementations should return a promise that resolves when all data has
* been collected and storage operations have been finished.
*
* @return Promise<>
*/
collectConstantData: function () {
return Promise.resolve();
},
/**
* Collects data approximately every day.
*
* For long-running applications, this is called approximately every day.
* It may or may not be called every time the application is run. It also may
* be called more than once per day.
*
* Implementations should return a promise that resolves when all data has
* been collected and storage operations have completed.
*
* @return Promise<>
*/
collectDailyData: function () {
return Promise.resolve();
},
/**
* Queue a deferred storage operation.
*

View File

@ -54,6 +54,8 @@ this.DummyProvider = function DummyProvider(name="DummyProvider") {
this.throwDuringCollectConstantData = null;
this.throwDuringConstantPopulate = null;
this.collectDailyCount = 0;
this.havePushedMeasurements = true;
}
@ -86,6 +88,11 @@ DummyProvider.prototype = {
}.bind(this));
},
collectDailyData: function () {
this.collectDailyCount++;
return Promise.resolve();
},
};

View File

@ -128,3 +128,24 @@ add_task(function test_collect_multiple() {
yield storage.close();
});
add_task(function test_collect_daily() {
let storage = yield Metrics.Storage("collect_daily");
let collector = new Metrics.Collector(storage);
let provider1 = new DummyProvider("DP1");
let provider2 = new DummyProvider("DP2");
yield collector.registerProvider(provider1);
yield collector.registerProvider(provider2);
yield collector.collectDailyData();
do_check_eq(provider1.collectDailyCount, 1);
do_check_eq(provider2.collectDailyCount, 1);
yield collector.collectDailyData();
do_check_eq(provider1.collectDailyCount, 2);
do_check_eq(provider2.collectDailyCount, 2);
yield storage.close();
});