| 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( |
| 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 // Retrieves the set of extensions installed in the current profile. The |
| 37 // default implementation should be fine, but this can be overridden for | 43 // default implementation should be fine, but this can be overridden for |
| 38 // testing. | 44 // testing. |
| 39 // | 45 // |
| 40 // TODO(mvrable): If metrics are ever converted to being per-profile, then | 46 // TODO(mvrable): If metrics are ever converted to being per-profile, then |
| 41 // this should be updated to return extensions installed in a specified | 47 // this should be updated to return extensions installed in a specified |
| 42 // profile. | 48 // profile. |
| 43 virtual scoped_ptr<extensions::ExtensionSet> GetInstalledExtensions(); | 49 virtual scoped_ptr<extensions::ExtensionSet> GetInstalledExtensions(); |
| 44 | 50 |
| 51 // Retrieves the client ID. |
| 52 virtual uint64 GetClientID(); |
| 53 |
| 45 // Hashes the extension extension ID using the provided client key (which | 54 // Hashes the extension extension ID using the provided client key (which |
| 46 // must be less than kExtensionListClientKeys) and to produce an output value | 55 // must be less than kExtensionListClientKeys) and to produce an output value |
| 47 // between 0 and kExtensionListBuckets-1. | 56 // between 0 and kExtensionListBuckets-1. |
| 48 static int HashExtension(const std::string& extension_id, uint32 client_key); | 57 static int HashExtension(const std::string& extension_id, uint32 client_key); |
| 49 | 58 |
| 50 private: | 59 private: |
| 51 // Returns the profile for which extensions will be gathered. Once a | 60 // Returns the profile for which extensions will be gathered. Once a |
| 52 // suitable profile has been found, future calls will continue to return the | 61 // suitable profile has been found, future calls will continue to return the |
| 53 // same value so that reported extensions are consistent. | 62 // same value so that reported extensions are consistent. |
| 54 Profile* GetMetricsProfile(); | 63 Profile* GetMetricsProfile(); |
| 55 | 64 |
| 56 // The key used when hashing extension identifiers, derived from client_id. | 65 // The MetricsStateManager from which the client ID is obtained. |
| 57 const int client_key_; | 66 metrics::MetricsStateManager* metrics_state_manager_; |
| 58 | 67 |
| 59 // The profile for which extensions are gathered. Once a profile is found | 68 // The profile for which extensions are gathered. Once a profile is found |
| 60 // its value is cached here so that GetMetricsProfile() can return a | 69 // its value is cached here so that GetMetricsProfile() can return a |
| 61 // consistent value. | 70 // consistent value. |
| 62 Profile* cached_profile_; | 71 Profile* cached_profile_; |
| 63 | 72 |
| 64 DISALLOW_COPY_AND_ASSIGN(HashedExtensionMetrics); | 73 DISALLOW_COPY_AND_ASSIGN(ExtensionsMetricsProvider); |
| 65 }; | 74 }; |
| 66 | 75 |
| 67 #endif // CHROME_BROWSER_METRICS_EXTENSION_METRICS_H_ | 76 #endif // CHROME_BROWSER_METRICS_EXTENSIONS_METRICS_PROVIDER_H_ |
| OLD | NEW |