Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(197)

Side by Side Diff: chrome/browser/metrics/extensions_metrics_provider.cc

Issue 1886913002: Convert //chrome/browser/metrics from scoped_ptr to std::unique_ptr (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 4 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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> 7 #include <stddef.h>
8 8
9 #include <algorithm> 9 #include <algorithm>
10 #include <memory>
10 #include <set> 11 #include <set>
11 #include <vector> 12 #include <vector>
12 13
13 #include "base/logging.h" 14 #include "base/logging.h"
14 #include "base/memory/scoped_ptr.h"
15 #include "base/strings/stringprintf.h" 15 #include "base/strings/stringprintf.h"
16 #include "chrome/browser/browser_process.h" 16 #include "chrome/browser/browser_process.h"
17 #include "chrome/browser/extensions/install_verifier.h" 17 #include "chrome/browser/extensions/install_verifier.h"
18 #include "chrome/browser/profiles/profile_manager.h" 18 #include "chrome/browser/profiles/profile_manager.h"
19 #include "components/metrics/metrics_log.h" 19 #include "components/metrics/metrics_log.h"
20 #include "components/metrics/metrics_state_manager.h" 20 #include "components/metrics/metrics_state_manager.h"
21 #include "components/metrics/proto/system_profile.pb.h" 21 #include "components/metrics/proto/system_profile.pb.h"
22 #include "extensions/browser/extension_registry.h" 22 #include "extensions/browser/extension_registry.h"
23 #include "extensions/browser/extension_system.h" 23 #include "extensions/browser/extension_system.h"
24 #include "extensions/common/extension_set.h" 24 #include "extensions/common/extension_set.h"
(...skipping 126 matching lines...) Expand 10 before | Expand all | Expand 10 after
151 // of creating a profile if it does not yet exist. 151 // of creating a profile if it does not yet exist.
152 cached_profile_ = profile_manager->GetProfileByPath( 152 cached_profile_ = profile_manager->GetProfileByPath(
153 profile_manager->GetLastUsedProfileDir(profile_manager->user_data_dir())); 153 profile_manager->GetLastUsedProfileDir(profile_manager->user_data_dir()));
154 if (cached_profile_) { 154 if (cached_profile_) {
155 // Ensure that the returned profile is not an incognito profile. 155 // Ensure that the returned profile is not an incognito profile.
156 cached_profile_ = cached_profile_->GetOriginalProfile(); 156 cached_profile_ = cached_profile_->GetOriginalProfile();
157 } 157 }
158 return cached_profile_; 158 return cached_profile_;
159 } 159 }
160 160
161 scoped_ptr<extensions::ExtensionSet> 161 std::unique_ptr<extensions::ExtensionSet>
162 ExtensionsMetricsProvider::GetInstalledExtensions(Profile* profile) { 162 ExtensionsMetricsProvider::GetInstalledExtensions(Profile* profile) {
163 if (profile) { 163 if (profile) {
164 return extensions::ExtensionRegistry::Get(profile) 164 return extensions::ExtensionRegistry::Get(profile)
165 ->GenerateInstalledExtensionsSet(); 165 ->GenerateInstalledExtensionsSet();
166 } 166 }
167 return scoped_ptr<extensions::ExtensionSet>(); 167 return std::unique_ptr<extensions::ExtensionSet>();
168 } 168 }
169 169
170 uint64_t ExtensionsMetricsProvider::GetClientID() { 170 uint64_t ExtensionsMetricsProvider::GetClientID() {
171 // TODO(blundell): Create a MetricsLog::ClientIDAsInt() API and call it 171 // TODO(blundell): Create a MetricsLog::ClientIDAsInt() API and call it
172 // 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
173 // the uma_proto. 173 // the uma_proto.
174 return metrics::MetricsLog::Hash(metrics_state_manager_->client_id()); 174 return metrics::MetricsLog::Hash(metrics_state_manager_->client_id());
175 } 175 }
176 176
177 void ExtensionsMetricsProvider::ProvideSystemProfileMetrics( 177 void ExtensionsMetricsProvider::ProvideSystemProfileMetrics(
(...skipping 10 matching lines...) Expand all
188 188
189 ExtensionState state = NO_EXTENSIONS; 189 ExtensionState state = NO_EXTENSIONS;
190 190
191 // The off-store metric includes information from all loaded profiles at the 191 // The off-store metric includes information from all loaded profiles at the
192 // time when this metric is generated. 192 // time when this metric is generated.
193 std::vector<Profile*> profiles = profile_manager->GetLoadedProfiles(); 193 std::vector<Profile*> profiles = profile_manager->GetLoadedProfiles();
194 for (size_t i = 0u; i < profiles.size() && state < OFF_STORE; ++i) { 194 for (size_t i = 0u; i < profiles.size() && state < OFF_STORE; ++i) {
195 extensions::InstallVerifier* verifier = 195 extensions::InstallVerifier* verifier =
196 extensions::InstallVerifier::Get(profiles[i]); 196 extensions::InstallVerifier::Get(profiles[i]);
197 197
198 scoped_ptr<extensions::ExtensionSet> extensions( 198 std::unique_ptr<extensions::ExtensionSet> extensions(
199 GetInstalledExtensions(profiles[i])); 199 GetInstalledExtensions(profiles[i]));
200 if (!extensions) 200 if (!extensions)
201 continue; 201 continue;
202 202
203 // Combine the state from each profile, always favoring the higher state as 203 // Combine the state from each profile, always favoring the higher state as
204 // defined by the order of ExtensionState. 204 // defined by the order of ExtensionState.
205 state = std::max(state, CheckForOffStore(*extensions.get(), *verifier)); 205 state = std::max(state, CheckForOffStore(*extensions.get(), *verifier));
206 } 206 }
207 207
208 system_profile->set_offstore_extensions_state(ExtensionStateAsProto(state)); 208 system_profile->set_offstore_extensions_state(ExtensionStateAsProto(state));
209 } 209 }
210 210
211 void ExtensionsMetricsProvider::ProvideOccupiedBucketMetric( 211 void ExtensionsMetricsProvider::ProvideOccupiedBucketMetric(
212 metrics::SystemProfileProto* system_profile) { 212 metrics::SystemProfileProto* system_profile) {
213 // UMA reports do not support multiple profiles, but extensions are installed 213 // UMA reports do not support multiple profiles, but extensions are installed
214 // per-profile. We return the extensions installed in the primary profile. 214 // per-profile. We return the extensions installed in the primary profile.
215 // In the future, we might consider reporting data about extensions in all 215 // In the future, we might consider reporting data about extensions in all
216 // profiles. 216 // profiles.
217 Profile* profile = GetMetricsProfile(); 217 Profile* profile = GetMetricsProfile();
218 218
219 scoped_ptr<extensions::ExtensionSet> extensions( 219 std::unique_ptr<extensions::ExtensionSet> extensions(
220 GetInstalledExtensions(profile)); 220 GetInstalledExtensions(profile));
221 if (!extensions) 221 if (!extensions)
222 return; 222 return;
223 223
224 const int client_key = GetClientID() % kExtensionListClientKeys; 224 const int client_key = GetClientID() % kExtensionListClientKeys;
225 225
226 std::set<int> buckets; 226 std::set<int> buckets;
227 for (extensions::ExtensionSet::const_iterator it = extensions->begin(); 227 for (extensions::ExtensionSet::const_iterator it = extensions->begin();
228 it != extensions->end(); 228 it != extensions->end();
229 ++it) { 229 ++it) {
230 buckets.insert(HashExtension((*it)->id(), client_key)); 230 buckets.insert(HashExtension((*it)->id(), client_key));
231 } 231 }
232 232
233 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();
234 ++it) { 234 ++it) {
235 system_profile->add_occupied_extension_bucket(*it); 235 system_profile->add_occupied_extension_bucket(*it);
236 } 236 }
237 } 237 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698