Bug 828540 - Part 2: APIs to retrieve a registered provider; r=rnewman

--HG--
extra : rebase_source : 0b91c4da3adc153ff102872ce88245bab2c7cf7c
This commit is contained in:
Gregory Szorc 2013-02-12 16:32:45 -08:00
parent b38fb3ce82
commit d23ad1c3e9
4 changed files with 28 additions and 0 deletions

View File

@ -508,6 +508,17 @@ HealthReporter.prototype = Object.freeze({
// Provider Management
//--------------------
/**
* Obtain a provider from its name.
*
* This will only return providers that are currently initialized. If
* a provider is lazy initialized (like constant-only providers) this
* will likely not return anything.
*/
getProvider: function (name) {
return this._collector.getProvider(name);
},
/**
* Register a `Metrics.Provider` with this instance.
*

View File

@ -191,6 +191,8 @@ add_task(function test_constant_only_providers() {
do_check_eq(reporter._collector._providers.size, 1);
do_check_true(reporter._storage.hasProvider("DummyProvider"));
do_check_false(reporter._storage.hasProvider("DummyConstantProvider"));
do_check_neq(reporter.getProvider("DummyProvider"), null);
do_check_null(reporter.getProvider("DummyConstantProvider"));
yield reporter.ensureConstantOnlyProvidersRegistered();
yield reporter.collectMeasurements();

View File

@ -45,6 +45,19 @@ Collector.prototype = Object.freeze({
return providers;
},
/**
* Obtain a provider from its name.
*/
getProvider: function (name) {
let provider = this._providers.get(name);
if (!provider) {
return null;
}
return provider.provider;
},
/**
* Registers a `MetricsProvider` with this collector.
*

View File

@ -30,6 +30,7 @@ add_task(function test_register_provider() {
yield collector.registerProvider(dummy);
do_check_eq(collector._providers.size, 1);
do_check_eq(collector.providerErrors.size, 1);
do_check_eq(collector.getProvider(dummy.name), dummy);
let failed = false;
try {
@ -44,6 +45,7 @@ add_task(function test_register_provider() {
collector.unregisterProvider(dummy.name);
do_check_eq(collector._providers.size, 0);
do_check_null(collector.getProvider(dummy.name));
yield storage.close();
});