1 // Copyright 2014 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
5 #ifndef CHROME_BROWSER_METRICS_EXTENSIONS_METRICS_PROVIDER_H_
6 #define CHROME_BROWSER_METRICS_EXTENSIONS_METRICS_PROVIDER_H_
10 #include "base/basictypes.h"
11 #include "base/memory/scoped_ptr.h"
12 #include "components/metrics/metrics_provider.h"
16 namespace extensions
{
21 class MetricsStateManager
;
22 class SystemProfileProto
;
25 // ExtensionsMetricsProvider groups various constants and functions used for
26 // reporting extension IDs with UMA reports (after hashing the extension IDs
28 class ExtensionsMetricsProvider
: public metrics::MetricsProvider
{
30 // Holds on to |metrics_state_manager|, which must outlive this object, as a
32 explicit ExtensionsMetricsProvider(
33 metrics::MetricsStateManager
* metrics_state_manager
);
34 ~ExtensionsMetricsProvider() override
;
36 // metrics::MetricsProvider:
37 void ProvideSystemProfileMetrics(
38 metrics::SystemProfileProto
* system_profile
) override
;
41 // Exposed for the sake of mocking in test code.
43 // Retrieves the set of extensions installed in the given |profile|.
44 virtual scoped_ptr
<extensions::ExtensionSet
> GetInstalledExtensions(
47 // Retrieves the client ID.
48 virtual uint64
GetClientID();
50 // Hashes the extension extension ID using the provided client key (which
51 // must be less than kExtensionListClientKeys) and to produce an output value
52 // between 0 and kExtensionListBuckets-1.
53 static int HashExtension(const std::string
& extension_id
, uint32 client_key
);
56 // Returns the profile for which extensions will be gathered. Once a
57 // suitable profile has been found, future calls will continue to return the
58 // same value so that reported extensions are consistent.
59 Profile
* GetMetricsProfile();
61 // Writes whether any loaded profiles have extensions not from the webstore.
62 void ProvideOffStoreMetric(metrics::SystemProfileProto
* system_profile
);
64 // Writes the hashed list of installed extensions into the specified
65 // SystemProfileProto object.
66 void ProvideOccupiedBucketMetric(metrics::SystemProfileProto
* system_profile
);
68 // The MetricsStateManager from which the client ID is obtained.
69 metrics::MetricsStateManager
* metrics_state_manager_
;
71 // The profile for which extensions are gathered for the occupied bucket
72 // metric. Once a profile is found its value is cached here so that
73 // GetMetricsProfile() can return a consistent value.
74 Profile
* cached_profile_
;
76 DISALLOW_COPY_AND_ASSIGN(ExtensionsMetricsProvider
);
79 #endif // CHROME_BROWSER_METRICS_EXTENSIONS_METRICS_PROVIDER_H_