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 #include "chrome/browser/metrics/extensions_metrics_provider.h" | 5 #include "chrome/browser/metrics/extensions_metrics_provider.h" |
6 | 6 |
7 #include <set> | 7 #include <set> |
8 | 8 |
9 #include "base/logging.h" | 9 #include "base/logging.h" |
10 #include "base/memory/scoped_ptr.h" | 10 #include "base/memory/scoped_ptr.h" |
11 #include "base/strings/stringprintf.h" | 11 #include "base/strings/stringprintf.h" |
12 #include "chrome/browser/browser_process.h" | 12 #include "chrome/browser/browser_process.h" |
13 #include "chrome/browser/profiles/profile_manager.h" | 13 #include "chrome/browser/profiles/profile_manager.h" |
14 #include "components/metrics/metrics_log_base.h" | 14 #include "components/metrics/metrics_log.h" |
15 #include "components/metrics/metrics_state_manager.h" | 15 #include "components/metrics/metrics_state_manager.h" |
16 #include "components/metrics/proto/system_profile.pb.h" | 16 #include "components/metrics/proto/system_profile.pb.h" |
17 #include "extensions/browser/extension_registry.h" | 17 #include "extensions/browser/extension_registry.h" |
18 #include "extensions/common/extension_set.h" | 18 #include "extensions/common/extension_set.h" |
19 #include "third_party/smhasher/src/City.h" | 19 #include "third_party/smhasher/src/City.h" |
20 | 20 |
21 namespace { | 21 namespace { |
22 | 22 |
23 // The number of possible hash keys that a client may use. The UMA client_id | 23 // The number of possible hash keys that a client may use. The UMA client_id |
24 // value is reduced modulo this value to produce the key used by that | 24 // value is reduced modulo this value to produce the key used by that |
(...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
83 Profile* profile = GetMetricsProfile(); | 83 Profile* profile = GetMetricsProfile(); |
84 if (profile) { | 84 if (profile) { |
85 return extensions::ExtensionRegistry::Get(profile) | 85 return extensions::ExtensionRegistry::Get(profile) |
86 ->GenerateInstalledExtensionsSet(); | 86 ->GenerateInstalledExtensionsSet(); |
87 } | 87 } |
88 #endif // defined(ENABLE_EXTENSIONS) | 88 #endif // defined(ENABLE_EXTENSIONS) |
89 return scoped_ptr<extensions::ExtensionSet>(); | 89 return scoped_ptr<extensions::ExtensionSet>(); |
90 } | 90 } |
91 | 91 |
92 uint64 ExtensionsMetricsProvider::GetClientID() { | 92 uint64 ExtensionsMetricsProvider::GetClientID() { |
93 // TODO(blundell): Create a MetricsLogBase::ClientIDAsInt() API and call it | 93 // TODO(blundell): Create a MetricsLog::ClientIDAsInt() API and call it |
94 // here as well as in MetricsLogBases's population of the client_id field of | 94 // here as well as in MetricsLog's population of the client_id field of |
95 // the uma_proto. | 95 // the uma_proto. |
96 return metrics::MetricsLogBase::Hash(metrics_state_manager_->client_id()); | 96 return MetricsLog::Hash(metrics_state_manager_->client_id()); |
97 } | 97 } |
98 | 98 |
99 void ExtensionsMetricsProvider::ProvideSystemProfileMetrics( | 99 void ExtensionsMetricsProvider::ProvideSystemProfileMetrics( |
100 metrics::SystemProfileProto* system_profile) { | 100 metrics::SystemProfileProto* system_profile) { |
101 scoped_ptr<extensions::ExtensionSet> extensions(GetInstalledExtensions()); | 101 scoped_ptr<extensions::ExtensionSet> extensions(GetInstalledExtensions()); |
102 if (!extensions) | 102 if (!extensions) |
103 return; | 103 return; |
104 | 104 |
105 const int client_key = GetClientID() % kExtensionListClientKeys; | 105 const int client_key = GetClientID() % kExtensionListClientKeys; |
106 | 106 |
107 std::set<int> buckets; | 107 std::set<int> buckets; |
108 for (extensions::ExtensionSet::const_iterator it = extensions->begin(); | 108 for (extensions::ExtensionSet::const_iterator it = extensions->begin(); |
109 it != extensions->end(); | 109 it != extensions->end(); |
110 ++it) { | 110 ++it) { |
111 buckets.insert(HashExtension((*it)->id(), client_key)); | 111 buckets.insert(HashExtension((*it)->id(), client_key)); |
112 } | 112 } |
113 | 113 |
114 for (std::set<int>::const_iterator it = buckets.begin(); it != buckets.end(); | 114 for (std::set<int>::const_iterator it = buckets.begin(); it != buckets.end(); |
115 ++it) { | 115 ++it) { |
116 system_profile->add_occupied_extension_bucket(*it); | 116 system_profile->add_occupied_extension_bucket(*it); |
117 } | 117 } |
118 } | 118 } |
OLD | NEW |