Chromium Code Reviews| 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 explicit ExtensionsMetricsProvider( |
|
Alexei Svitkine (slow)
2014/05/21 12:23:22
Nit: Add a comment about |metrics_state_manager| o
blundell
2014/05/21 13:03:29
Done.
| |
| 29 virtual ~HashedExtensionMetrics(); | 31 metrics::MetricsStateManager* metrics_state_manager); |
| 32 virtual ~ExtensionsMetricsProvider(); | |
| 33 | |
| 34 // metrics::MetricsProvider: | |
| 30 | 35 |
| 31 // Writes the hashed list of installed extensions into the specified | 36 // Writes the hashed list of installed extensions into the specified |
| 32 // SystemProfileProto object. | 37 // SystemProfileProto object. |
| 33 void WriteExtensionList(metrics::SystemProfileProto* system_profile); | 38 virtual void ProvideSystemProfileMetrics( |
| 39 metrics::SystemProfileProto* system_profile) OVERRIDE; | |
| 34 | 40 |
| 35 protected: | 41 protected: |
| 36 // Retrieves the set of extensions installed in the current profile. The | 42 // Exposed for the sake of mocking in test code. |
| 37 // default implementation should be fine, but this can be overridden for | 43 |
| 38 // testing. | 44 // Retrieves the set of extensions installed in the current profile. |
| 39 // | |
| 40 // TODO(mvrable): If metrics are ever converted to being per-profile, then | 45 // TODO(mvrable): If metrics are ever converted to being per-profile, then |
| 41 // this should be updated to return extensions installed in a specified | 46 // this should be updated to return extensions installed in a specified |
| 42 // profile. | 47 // profile. |
| 43 virtual scoped_ptr<extensions::ExtensionSet> GetInstalledExtensions(); | 48 virtual scoped_ptr<extensions::ExtensionSet> GetInstalledExtensions(); |
| 44 | 49 |
| 50 // Retrieves the client ID. | |
| 51 virtual uint64 GetClientID(); | |
| 52 | |
| 45 // Hashes the extension extension ID using the provided client key (which | 53 // Hashes the extension extension ID using the provided client key (which |
| 46 // must be less than kExtensionListClientKeys) and to produce an output value | 54 // must be less than kExtensionListClientKeys) and to produce an output value |
| 47 // between 0 and kExtensionListBuckets-1. | 55 // between 0 and kExtensionListBuckets-1. |
| 48 static int HashExtension(const std::string& extension_id, uint32 client_key); | 56 static int HashExtension(const std::string& extension_id, uint32 client_key); |
| 49 | 57 |
| 50 private: | 58 private: |
| 51 // Returns the profile for which extensions will be gathered. Once a | 59 // Returns the profile for which extensions will be gathered. Once a |
| 52 // suitable profile has been found, future calls will continue to return the | 60 // suitable profile has been found, future calls will continue to return the |
| 53 // same value so that reported extensions are consistent. | 61 // same value so that reported extensions are consistent. |
| 54 Profile* GetMetricsProfile(); | 62 Profile* GetMetricsProfile(); |
| 55 | 63 |
| 56 // The key used when hashing extension identifiers, derived from client_id. | 64 // The MetricsStateManager from which the client ID is obtained. |
| 57 const int client_key_; | 65 metrics::MetricsStateManager* metrics_state_manager_; |
| 58 | 66 |
| 59 // The profile for which extensions are gathered. Once a profile is found | 67 // The profile for which extensions are gathered. Once a profile is found |
| 60 // its value is cached here so that GetMetricsProfile() can return a | 68 // its value is cached here so that GetMetricsProfile() can return a |
| 61 // consistent value. | 69 // consistent value. |
| 62 Profile* cached_profile_; | 70 Profile* cached_profile_; |
| 63 | 71 |
| 64 DISALLOW_COPY_AND_ASSIGN(HashedExtensionMetrics); | 72 DISALLOW_COPY_AND_ASSIGN(ExtensionsMetricsProvider); |
| 65 }; | 73 }; |
| 66 | 74 |
| 67 #endif // CHROME_BROWSER_METRICS_EXTENSION_METRICS_H_ | 75 #endif // CHROME_BROWSER_METRICS_EXTENSIONS_METRICS_PROVIDER_H_ |
| OLD | NEW |