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

Side by Side Diff: chrome/browser/extensions/installed_loader.cc

Issue 273253002: Add UMA to track the extensions (and friends) which have been allowed in (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: nit Created 6 years, 7 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 | Annotate | Revision Log
« no previous file with comments | « no previous file | tools/metrics/histograms/histograms.xml » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 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/extensions/installed_loader.h" 5 #include "chrome/browser/extensions/installed_loader.h"
6 6
7 #include "base/files/file_path.h" 7 #include "base/files/file_path.h"
8 #include "base/metrics/histogram.h" 8 #include "base/metrics/histogram.h"
9 #include "base/strings/stringprintf.h" 9 #include "base/strings/stringprintf.h"
10 #include "base/strings/utf_string_conversions.h" 10 #include "base/strings/utf_string_conversions.h"
11 #include "base/threading/thread_restrictions.h" 11 #include "base/threading/thread_restrictions.h"
12 #include "base/values.h" 12 #include "base/values.h"
13 #include "chrome/browser/browser_process.h" 13 #include "chrome/browser/browser_process.h"
14 #include "chrome/browser/extensions/extension_action_manager.h" 14 #include "chrome/browser/extensions/extension_action_manager.h"
15 #include "chrome/browser/extensions/extension_error_reporter.h" 15 #include "chrome/browser/extensions/extension_error_reporter.h"
16 #include "chrome/browser/extensions/extension_service.h" 16 #include "chrome/browser/extensions/extension_service.h"
17 #include "chrome/browser/extensions/extension_util.h"
17 #include "chrome/browser/profiles/profile_manager.h" 18 #include "chrome/browser/profiles/profile_manager.h"
18 #include "chrome/common/chrome_switches.h" 19 #include "chrome/common/chrome_switches.h"
19 #include "chrome/common/extensions/api/managed_mode_private/managed_mode_handler .h" 20 #include "chrome/common/extensions/api/managed_mode_private/managed_mode_handler .h"
20 #include "chrome/common/extensions/manifest_url_handler.h" 21 #include "chrome/common/extensions/manifest_url_handler.h"
21 #include "chrome/common/pref_names.h" 22 #include "chrome/common/pref_names.h"
22 #include "content/public/browser/notification_service.h" 23 #include "content/public/browser/notification_service.h"
23 #include "content/public/browser/user_metrics.h" 24 #include "content/public/browser/user_metrics.h"
24 #include "extensions/browser/api/runtime/runtime_api.h" 25 #include "extensions/browser/api/runtime/runtime_api.h"
25 #include "extensions/browser/extension_prefs.h" 26 #include "extensions/browser/extension_prefs.h"
26 #include "extensions/browser/extension_registry.h" 27 #include "extensions/browser/extension_registry.h"
27 #include "extensions/browser/extension_system.h" 28 #include "extensions/browser/extension_system.h"
28 #include "extensions/browser/management_policy.h" 29 #include "extensions/browser/management_policy.h"
29 #include "extensions/common/extension.h" 30 #include "extensions/common/extension.h"
Devlin 2014/05/09 22:45:25 extension_set.h
not at google - send to devlin 2014/05/09 22:58:56 Done.
30 #include "extensions/common/extension_l10n_util.h" 31 #include "extensions/common/extension_l10n_util.h"
31 #include "extensions/common/file_util.h" 32 #include "extensions/common/file_util.h"
32 #include "extensions/common/manifest.h" 33 #include "extensions/common/manifest.h"
33 #include "extensions/common/manifest_constants.h" 34 #include "extensions/common/manifest_constants.h"
34 #include "extensions/common/manifest_handlers/background_info.h" 35 #include "extensions/common/manifest_handlers/background_info.h"
35 36
36 using base::UserMetricsAction; 37 using base::UserMetricsAction;
37 using content::BrowserThread; 38 using content::BrowserThread;
38 39
39 namespace extensions { 40 namespace extensions {
(...skipping 144 matching lines...) Expand 10 before | Expand all | Expand 10 after
184 extension_prefs_->UpdateManifest(extension.get()); 185 extension_prefs_->UpdateManifest(extension.get());
185 186
186 extension_service_->AddExtension(extension.get()); 187 extension_service_->AddExtension(extension.get());
187 } 188 }
188 189
189 void InstalledLoader::LoadAllExtensions() { 190 void InstalledLoader::LoadAllExtensions() {
190 CHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 191 CHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
191 192
192 base::TimeTicks start_time = base::TimeTicks::Now(); 193 base::TimeTicks start_time = base::TimeTicks::Now();
193 194
195 Profile* profile = extension_service_->profile();
194 scoped_ptr<ExtensionPrefs::ExtensionsInfo> extensions_info( 196 scoped_ptr<ExtensionPrefs::ExtensionsInfo> extensions_info(
195 extension_prefs_->GetInstalledExtensionsInfo()); 197 extension_prefs_->GetInstalledExtensionsInfo());
196 198
197 std::vector<int> reload_reason_counts(NUM_MANIFEST_RELOAD_REASONS, 0); 199 std::vector<int> reload_reason_counts(NUM_MANIFEST_RELOAD_REASONS, 0);
198 bool should_write_prefs = false; 200 bool should_write_prefs = false;
199 201
200 for (size_t i = 0; i < extensions_info->size(); ++i) { 202 for (size_t i = 0; i < extensions_info->size(); ++i) {
201 ExtensionInfo* info = extensions_info->at(i).get(); 203 ExtensionInfo* info = extensions_info->at(i).get();
202 204
203 // Skip extensions that were loaded from the command-line because we don't 205 // Skip extensions that were loaded from the command-line because we don't
(...skipping 19 matching lines...) Expand all
223 scoped_refptr<const Extension> extension( 225 scoped_refptr<const Extension> extension(
224 file_util::LoadExtension(info->extension_path, 226 file_util::LoadExtension(info->extension_path,
225 info->extension_location, 227 info->extension_location,
226 GetCreationFlags(info), 228 GetCreationFlags(info),
227 &error)); 229 &error));
228 230
229 if (!extension.get()) { 231 if (!extension.get()) {
230 ExtensionErrorReporter::GetInstance()->ReportLoadError( 232 ExtensionErrorReporter::GetInstance()->ReportLoadError(
231 info->extension_path, 233 info->extension_path,
232 error, 234 error,
233 extension_service_->profile(), 235 profile,
234 false); // Be quiet. 236 false); // Be quiet.
235 continue; 237 continue;
236 } 238 }
237 239
238 extensions_info->at(i)->extension_manifest.reset( 240 extensions_info->at(i)->extension_manifest.reset(
239 static_cast<base::DictionaryValue*>( 241 static_cast<base::DictionaryValue*>(
240 extension->manifest()->value()->DeepCopy())); 242 extension->manifest()->value()->DeepCopy()));
241 should_write_prefs = true; 243 should_write_prefs = true;
242 } 244 }
243 } 245 }
244 246
245 for (size_t i = 0; i < extensions_info->size(); ++i) { 247 for (size_t i = 0; i < extensions_info->size(); ++i) {
246 if (extensions_info->at(i)->extension_location == Manifest::COMMAND_LINE) 248 if (extensions_info->at(i)->extension_location == Manifest::COMMAND_LINE)
247 continue; 249 continue;
248 Load(*extensions_info->at(i), should_write_prefs); 250 Load(*extensions_info->at(i), should_write_prefs);
249 } 251 }
250 252
251 extension_service_->OnLoadedInstalledExtensions(); 253 extension_service_->OnLoadedInstalledExtensions();
252 254
253 // The histograms Extensions.ManifestReload* allow us to validate 255 // The histograms Extensions.ManifestReload* allow us to validate
254 // the assumption that reloading manifest is a rare event. 256 // the assumption that reloading manifest is a rare event.
255 UMA_HISTOGRAM_COUNTS_100("Extensions.ManifestReloadNotNeeded", 257 UMA_HISTOGRAM_COUNTS_100("Extensions.ManifestReloadNotNeeded",
256 reload_reason_counts[NOT_NEEDED]); 258 reload_reason_counts[NOT_NEEDED]);
257 UMA_HISTOGRAM_COUNTS_100("Extensions.ManifestReloadUnpackedDir", 259 UMA_HISTOGRAM_COUNTS_100("Extensions.ManifestReloadUnpackedDir",
258 reload_reason_counts[UNPACKED_DIR]); 260 reload_reason_counts[UNPACKED_DIR]);
259 UMA_HISTOGRAM_COUNTS_100("Extensions.ManifestReloadNeedsRelocalization", 261 UMA_HISTOGRAM_COUNTS_100("Extensions.ManifestReloadNeedsRelocalization",
260 reload_reason_counts[NEEDS_RELOCALIZATION]); 262 reload_reason_counts[NEEDS_RELOCALIZATION]);
261 263
262 UMA_HISTOGRAM_COUNTS_100("Extensions.LoadAll", 264 const ExtensionSet& enabled = extension_registry_->enabled_extensions();
263 extension_registry_->enabled_extensions().size()); 265 const ExtensionSet& disabled = extension_registry_->disabled_extensions();
Devlin 2014/05/09 22:45:25 why store disabled? Only used on line 268, right?
not at google - send to devlin 2014/05/09 22:58:56 harmony. but I can revert.
264 UMA_HISTOGRAM_COUNTS_100("Extensions.Disabled", 266
265 extension_registry_->disabled_extensions().size()); 267 UMA_HISTOGRAM_COUNTS_100("Extensions.LoadAll", enabled.size());
268 UMA_HISTOGRAM_COUNTS_100("Extensions.Disabled", disabled.size());
269
270 // Gather stats about the extensions which have/have-not been enabled for
271 // incognito and file access in chrome://extensions.
272 int incognito = 0, not_incognito = 0, file_access = 0, not_file_access = 0;
Devlin 2014/05/09 22:45:25 chrome style: one variable per line.
Devlin 2014/05/09 22:45:25 nit: seems like these are conceptually a size_t.
not at google - send to devlin 2014/05/09 22:58:56 Done, though I'm not totally sure about this one.
273
274 for (ExtensionSet::const_iterator it = enabled.begin();
Devlin 2014/05/09 22:45:25 Do we only care about enabled extensions?
not at google - send to devlin 2014/05/09 22:58:56 Yeah I was thinking about this. I wasn't entirely
275 it != enabled.end();
276 ++it) {
277 const Extension& e = **it;
278
279 // Skip unpacked extensions because they get file access up-front, and
280 // the data isn't useful. Skip anything that doesn't appear in settings.
281 if (e.location() == Manifest::UNPACKED ||
282 !e.ShouldDisplayInExtensionSettings()) {
283 continue;
284 }
285
286 if (e.can_be_incognito_enabled()) {
287 if (util::IsIncognitoEnabled(e.id(), profile)) {
288 ++incognito;
289 } else {
Devlin 2014/05/09 22:45:25 nit: no braces around single-line ifs/elses
not at google - send to devlin 2014/05/09 22:58:56 haha If you insist.
290 ++not_incognito;
291 }
292 }
293
294 if (e.wants_file_access()) {
295 if (util::AllowFileAccess(e.id(), profile)) {
296 ++file_access;
297 } else {
298 ++not_file_access;
299 }
300 }
301 }
302
303 UMA_HISTOGRAM_COUNTS_100("Extensions.IncognitoAllowed", incognito);
304 UMA_HISTOGRAM_COUNTS_100("Extensions.IncognitoNotAllowed", not_incognito);
305 UMA_HISTOGRAM_COUNTS_100("Extensions.FileAccessAllowed", file_access);
306 UMA_HISTOGRAM_COUNTS_100("Extensions.FileAccessNotAllowed", not_file_access);
266 307
267 UMA_HISTOGRAM_TIMES("Extensions.LoadAllTime", 308 UMA_HISTOGRAM_TIMES("Extensions.LoadAllTime",
268 base::TimeTicks::Now() - start_time); 309 base::TimeTicks::Now() - start_time);
269 310
270 int app_user_count = 0; 311 int app_user_count = 0;
271 int app_external_count = 0; 312 int app_external_count = 0;
272 int hosted_app_count = 0; 313 int hosted_app_count = 0;
273 int legacy_packaged_app_count = 0; 314 int legacy_packaged_app_count = 0;
274 int platform_app_count = 0; 315 int platform_app_count = 0;
275 int user_script_count = 0; 316 int user_script_count = 0;
(...skipping 208 matching lines...) Expand 10 before | Expand all | Expand 10 after
484 int InstalledLoader::GetCreationFlags(const ExtensionInfo* info) { 525 int InstalledLoader::GetCreationFlags(const ExtensionInfo* info) {
485 int flags = extension_prefs_->GetCreationFlags(info->extension_id); 526 int flags = extension_prefs_->GetCreationFlags(info->extension_id);
486 if (!Manifest::IsUnpackedLocation(info->extension_location)) 527 if (!Manifest::IsUnpackedLocation(info->extension_location))
487 flags |= Extension::REQUIRE_KEY; 528 flags |= Extension::REQUIRE_KEY;
488 if (extension_prefs_->AllowFileAccess(info->extension_id)) 529 if (extension_prefs_->AllowFileAccess(info->extension_id))
489 flags |= Extension::ALLOW_FILE_ACCESS; 530 flags |= Extension::ALLOW_FILE_ACCESS;
490 return flags; 531 return flags;
491 } 532 }
492 533
493 } // namespace extensions 534 } // namespace extensions
OLDNEW
« no previous file with comments | « no previous file | tools/metrics/histograms/histograms.xml » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698