Pin Chrome's shortcut to the Win10 Start menu on install and OS upgrade.
[chromium-blink-merge.git] / chrome / browser / metrics / extensions_metrics_provider.h
blob1e851b2613657bf3a75efc159459dfe65ab6b8b9
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_
8 #include <string>
10 #include "base/basictypes.h"
11 #include "base/memory/scoped_ptr.h"
12 #include "components/metrics/metrics_provider.h"
14 class Profile;
16 namespace extensions {
17 class ExtensionSet;
20 namespace metrics {
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
27 // for privacy).
28 class ExtensionsMetricsProvider : public metrics::MetricsProvider {
29 public:
30 // Holds on to |metrics_state_manager|, which must outlive this object, as a
31 // weak pointer.
32 explicit ExtensionsMetricsProvider(
33 metrics::MetricsStateManager* metrics_state_manager);
34 ~ExtensionsMetricsProvider() override;
36 // metrics::MetricsProvider:
37 void ProvideSystemProfileMetrics(
38 metrics::SystemProfileProto* system_profile) override;
40 protected:
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(
45 Profile* profile);
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);
55 private:
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_