OLD | NEW |
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #ifndef CHROME_BROWSER_METRICS_EXTENSION_METRICS_H_ | 5 #ifndef CHROME_BROWSER_METRICS_EXTENSIONS_METRICS_PROVIDER_H_ |
6 #define CHROME_BROWSER_METRICS_EXTENSION_METRICS_H_ | 6 #define CHROME_BROWSER_METRICS_EXTENSIONS_METRICS_PROVIDER_H_ |
7 | 7 |
8 #include <string> | 8 #include <string> |
9 | 9 |
10 #include "base/basictypes.h" | 10 #include "base/basictypes.h" |
11 #include "base/memory/scoped_ptr.h" | 11 #include "base/memory/scoped_ptr.h" |
| 12 #include "components/metrics/metrics_provider.h" |
12 | 13 |
13 class Profile; | 14 class Profile; |
14 | 15 |
15 namespace extensions { | 16 namespace extensions { |
16 class ExtensionSet; | 17 class ExtensionSet; |
17 } | 18 } |
18 | 19 |
19 namespace metrics { | 20 namespace metrics { |
| 21 class MetricsStateManager; |
20 class SystemProfileProto; | 22 class SystemProfileProto; |
21 } | 23 } |
22 | 24 |
23 // HashedExtensionMetrics groups various constants and functions used for | 25 // ExtensionsMetricsProvider groups various constants and functions used for |
24 // reporting extension IDs with UMA reports (after hashing the extension IDs | 26 // reporting extension IDs with UMA reports (after hashing the extension IDs |
25 // for privacy). | 27 // for privacy). |
26 class HashedExtensionMetrics { | 28 class ExtensionsMetricsProvider : public metrics::MetricsProvider { |
27 public: | 29 public: |
28 explicit HashedExtensionMetrics(uint64 client_id); | 30 // Holds on to |metrics_state_manager|, which must outlive this object, as a |
29 virtual ~HashedExtensionMetrics(); | 31 // weak pointer. |
| 32 explicit ExtensionsMetricsProvider( |
| 33 metrics::MetricsStateManager* metrics_state_manager); |
| 34 virtual ~ExtensionsMetricsProvider(); |
| 35 |
| 36 // metrics::MetricsProvider: |
30 | 37 |
31 // Writes the hashed list of installed extensions into the specified | 38 // Writes the hashed list of installed extensions into the specified |
32 // SystemProfileProto object. | 39 // SystemProfileProto object. |
33 void WriteExtensionList(metrics::SystemProfileProto* system_profile); | 40 virtual void ProvideSystemProfileMetrics( |
| 41 metrics::SystemProfileProto* system_profile) OVERRIDE; |
34 | 42 |
35 protected: | 43 protected: |
36 // Retrieves the set of extensions installed in the current profile. The | 44 // Exposed for the sake of mocking in test code. |
37 // default implementation should be fine, but this can be overridden for | 45 |
38 // testing. | 46 // Retrieves the set of extensions installed in the current profile. |
39 // | |
40 // TODO(mvrable): If metrics are ever converted to being per-profile, then | 47 // TODO(mvrable): If metrics are ever converted to being per-profile, then |
41 // this should be updated to return extensions installed in a specified | 48 // this should be updated to return extensions installed in a specified |
42 // profile. | 49 // profile. |
43 virtual scoped_ptr<extensions::ExtensionSet> GetInstalledExtensions(); | 50 virtual scoped_ptr<extensions::ExtensionSet> GetInstalledExtensions(); |
44 | 51 |
| 52 // Retrieves the client ID. |
| 53 virtual uint64 GetClientID(); |
| 54 |
45 // Hashes the extension extension ID using the provided client key (which | 55 // Hashes the extension extension ID using the provided client key (which |
46 // must be less than kExtensionListClientKeys) and to produce an output value | 56 // must be less than kExtensionListClientKeys) and to produce an output value |
47 // between 0 and kExtensionListBuckets-1. | 57 // between 0 and kExtensionListBuckets-1. |
48 static int HashExtension(const std::string& extension_id, uint32 client_key); | 58 static int HashExtension(const std::string& extension_id, uint32 client_key); |
49 | 59 |
50 private: | 60 private: |
51 // Returns the profile for which extensions will be gathered. Once a | 61 // Returns the profile for which extensions will be gathered. Once a |
52 // suitable profile has been found, future calls will continue to return the | 62 // suitable profile has been found, future calls will continue to return the |
53 // same value so that reported extensions are consistent. | 63 // same value so that reported extensions are consistent. |
54 Profile* GetMetricsProfile(); | 64 Profile* GetMetricsProfile(); |
55 | 65 |
56 // The key used when hashing extension identifiers, derived from client_id. | 66 // The MetricsStateManager from which the client ID is obtained. |
57 const int client_key_; | 67 metrics::MetricsStateManager* metrics_state_manager_; |
58 | 68 |
59 // The profile for which extensions are gathered. Once a profile is found | 69 // The profile for which extensions are gathered. Once a profile is found |
60 // its value is cached here so that GetMetricsProfile() can return a | 70 // its value is cached here so that GetMetricsProfile() can return a |
61 // consistent value. | 71 // consistent value. |
62 Profile* cached_profile_; | 72 Profile* cached_profile_; |
63 | 73 |
64 DISALLOW_COPY_AND_ASSIGN(HashedExtensionMetrics); | 74 DISALLOW_COPY_AND_ASSIGN(ExtensionsMetricsProvider); |
65 }; | 75 }; |
66 | 76 |
67 #endif // CHROME_BROWSER_METRICS_EXTENSION_METRICS_H_ | 77 #endif // CHROME_BROWSER_METRICS_EXTENSIONS_METRICS_PROVIDER_H_ |
OLD | NEW |