| 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 <stddef.h> |
| 8 |
| 7 #include <algorithm> | 9 #include <algorithm> |
| 8 #include <set> | 10 #include <set> |
| 9 #include <vector> | 11 #include <vector> |
| 10 | 12 |
| 11 #include "base/logging.h" | 13 #include "base/logging.h" |
| 12 #include "base/memory/scoped_ptr.h" | 14 #include "base/memory/scoped_ptr.h" |
| 13 #include "base/strings/stringprintf.h" | 15 #include "base/strings/stringprintf.h" |
| 14 #include "chrome/browser/browser_process.h" | 16 #include "chrome/browser/browser_process.h" |
| 15 #include "chrome/browser/extensions/install_verifier.h" | 17 #include "chrome/browser/extensions/install_verifier.h" |
| 16 #include "chrome/browser/profiles/profile_manager.h" | 18 #include "chrome/browser/profiles/profile_manager.h" |
| (...skipping 101 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 118 metrics::MetricsStateManager* metrics_state_manager) | 120 metrics::MetricsStateManager* metrics_state_manager) |
| 119 : metrics_state_manager_(metrics_state_manager), cached_profile_(NULL) { | 121 : metrics_state_manager_(metrics_state_manager), cached_profile_(NULL) { |
| 120 DCHECK(metrics_state_manager_); | 122 DCHECK(metrics_state_manager_); |
| 121 } | 123 } |
| 122 | 124 |
| 123 ExtensionsMetricsProvider::~ExtensionsMetricsProvider() { | 125 ExtensionsMetricsProvider::~ExtensionsMetricsProvider() { |
| 124 } | 126 } |
| 125 | 127 |
| 126 // static | 128 // static |
| 127 int ExtensionsMetricsProvider::HashExtension(const std::string& extension_id, | 129 int ExtensionsMetricsProvider::HashExtension(const std::string& extension_id, |
| 128 uint32 client_key) { | 130 uint32_t client_key) { |
| 129 DCHECK_LE(client_key, kExtensionListClientKeys); | 131 DCHECK_LE(client_key, kExtensionListClientKeys); |
| 130 std::string message = | 132 std::string message = |
| 131 base::StringPrintf("%u:%s", client_key, extension_id.c_str()); | 133 base::StringPrintf("%u:%s", client_key, extension_id.c_str()); |
| 132 uint64 output = CityHash64(message.data(), message.size()); | 134 uint64_t output = CityHash64(message.data(), message.size()); |
| 133 return output % kExtensionListBuckets; | 135 return output % kExtensionListBuckets; |
| 134 } | 136 } |
| 135 | 137 |
| 136 Profile* ExtensionsMetricsProvider::GetMetricsProfile() { | 138 Profile* ExtensionsMetricsProvider::GetMetricsProfile() { |
| 137 ProfileManager* profile_manager = g_browser_process->profile_manager(); | 139 ProfileManager* profile_manager = g_browser_process->profile_manager(); |
| 138 if (!profile_manager) | 140 if (!profile_manager) |
| 139 return NULL; | 141 return NULL; |
| 140 | 142 |
| 141 // If there is a cached profile, reuse that. However, check that it is still | 143 // If there is a cached profile, reuse that. However, check that it is still |
| 142 // valid first. | 144 // valid first. |
| (...skipping 15 matching lines...) Expand all Loading... |
| 158 | 160 |
| 159 scoped_ptr<extensions::ExtensionSet> | 161 scoped_ptr<extensions::ExtensionSet> |
| 160 ExtensionsMetricsProvider::GetInstalledExtensions(Profile* profile) { | 162 ExtensionsMetricsProvider::GetInstalledExtensions(Profile* profile) { |
| 161 if (profile) { | 163 if (profile) { |
| 162 return extensions::ExtensionRegistry::Get(profile) | 164 return extensions::ExtensionRegistry::Get(profile) |
| 163 ->GenerateInstalledExtensionsSet(); | 165 ->GenerateInstalledExtensionsSet(); |
| 164 } | 166 } |
| 165 return scoped_ptr<extensions::ExtensionSet>(); | 167 return scoped_ptr<extensions::ExtensionSet>(); |
| 166 } | 168 } |
| 167 | 169 |
| 168 uint64 ExtensionsMetricsProvider::GetClientID() { | 170 uint64_t ExtensionsMetricsProvider::GetClientID() { |
| 169 // TODO(blundell): Create a MetricsLog::ClientIDAsInt() API and call it | 171 // TODO(blundell): Create a MetricsLog::ClientIDAsInt() API and call it |
| 170 // here as well as in MetricsLog's population of the client_id field of | 172 // here as well as in MetricsLog's population of the client_id field of |
| 171 // the uma_proto. | 173 // the uma_proto. |
| 172 return metrics::MetricsLog::Hash(metrics_state_manager_->client_id()); | 174 return metrics::MetricsLog::Hash(metrics_state_manager_->client_id()); |
| 173 } | 175 } |
| 174 | 176 |
| 175 void ExtensionsMetricsProvider::ProvideSystemProfileMetrics( | 177 void ExtensionsMetricsProvider::ProvideSystemProfileMetrics( |
| 176 metrics::SystemProfileProto* system_profile) { | 178 metrics::SystemProfileProto* system_profile) { |
| 177 ProvideOffStoreMetric(system_profile); | 179 ProvideOffStoreMetric(system_profile); |
| 178 ProvideOccupiedBucketMetric(system_profile); | 180 ProvideOccupiedBucketMetric(system_profile); |
| (...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 226 it != extensions->end(); | 228 it != extensions->end(); |
| 227 ++it) { | 229 ++it) { |
| 228 buckets.insert(HashExtension((*it)->id(), client_key)); | 230 buckets.insert(HashExtension((*it)->id(), client_key)); |
| 229 } | 231 } |
| 230 | 232 |
| 231 for (std::set<int>::const_iterator it = buckets.begin(); it != buckets.end(); | 233 for (std::set<int>::const_iterator it = buckets.begin(); it != buckets.end(); |
| 232 ++it) { | 234 ++it) { |
| 233 system_profile->add_occupied_extension_bucket(*it); | 235 system_profile->add_occupied_extension_bucket(*it); |
| 234 } | 236 } |
| 235 } | 237 } |
| OLD | NEW |