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

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

Issue 299853002: Make installed_loader UMA less wasteful. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: fixes 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 | chrome/common/extensions/sync_helper.cc » ('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"
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after
52 UNPACKED_DIR, // Unpacked directory. 52 UNPACKED_DIR, // Unpacked directory.
53 NEEDS_RELOCALIZATION, // The locale has changed since we read this extension. 53 NEEDS_RELOCALIZATION, // The locale has changed since we read this extension.
54 CORRUPT_PREFERENCES, // The manifest in the preferences is corrupt. 54 CORRUPT_PREFERENCES, // The manifest in the preferences is corrupt.
55 NUM_MANIFEST_RELOAD_REASONS 55 NUM_MANIFEST_RELOAD_REASONS
56 }; 56 };
57 57
58 // Used in histogram Extension.BackgroundPageType. Values may be added, as 58 // Used in histogram Extension.BackgroundPageType. Values may be added, as
59 // long as existing values are not changed. 59 // long as existing values are not changed.
60 enum BackgroundPageType { 60 enum BackgroundPageType {
61 NO_BACKGROUND_PAGE = 0, 61 NO_BACKGROUND_PAGE = 0,
62 BACKGROUND_PAGE_PERSISTENT = 1, 62 BACKGROUND_PAGE_PERSISTENT,
63 EVENT_PAGE = 2, 63 EVENT_PAGE,
64 NUM_BACKGROUND_PAGE_TYPES
Devlin 2014/05/21 23:23:37 nit: New enum values must go above here.
not at google - send to devlin 2014/05/21 23:36:05 done and done and done
64 }; 65 };
65 66
66 // Used in histogram Extensions.ExternalItemState. Values may be added, as 67 // Used in histogram Extensions.ExternalItemState. Values may be added, as
67 // long as existing values are not changed. 68 // long as existing values are not changed.
68 enum ExternalItemState { 69 enum ExternalItemState {
69 DEPRECATED_EXTERNAL_ITEM_DISABLED = 0, 70 DEPRECATED_EXTERNAL_ITEM_DISABLED = 0,
70 DEPRECATED_EXTERNAL_ITEM_ENABLED = 1, 71 DEPRECATED_EXTERNAL_ITEM_ENABLED = 1,
71 EXTERNAL_ITEM_WEBSTORE_DISABLED = 2, 72 EXTERNAL_ITEM_WEBSTORE_DISABLED = 2,
72 EXTERNAL_ITEM_WEBSTORE_ENABLED = 3, 73 EXTERNAL_ITEM_WEBSTORE_ENABLED = 3,
73 EXTERNAL_ITEM_NONWEBSTORE_DISABLED = 4, 74 EXTERNAL_ITEM_NONWEBSTORE_DISABLED = 4,
(...skipping 75 matching lines...) Expand 10 before | Expand all | Expand 10 after
149 *info.extension_manifest, 150 *info.extension_manifest,
150 GetCreationFlags(&info), 151 GetCreationFlags(&info),
151 &error); 152 &error);
152 } else { 153 } else {
153 error = errors::kManifestUnreadable; 154 error = errors::kManifestUnreadable;
154 } 155 }
155 156
156 // Once installed, non-unpacked extensions cannot change their IDs (e.g., by 157 // Once installed, non-unpacked extensions cannot change their IDs (e.g., by
157 // updating the 'key' field in their manifest). 158 // updating the 'key' field in their manifest).
158 // TODO(jstritar): migrate preferences when unpacked extensions change IDs. 159 // TODO(jstritar): migrate preferences when unpacked extensions change IDs.
159 if (extension.get() && !Manifest::IsUnpackedLocation(extension->location()) && 160 if (extension.get() &&
161 !Manifest::IsUnpackedLocation(extension->location()) &&
160 info.extension_id != extension->id()) { 162 info.extension_id != extension->id()) {
161 error = errors::kCannotChangeExtensionID; 163 error = errors::kCannotChangeExtensionID;
162 extension = NULL; 164 extension = NULL;
163 content::RecordAction(UserMetricsAction("Extensions.IDChangedError"));
164 } 165 }
165 166
166 // Check policy on every load in case an extension was blacklisted while 167 // Check policy on every load in case an extension was blacklisted while
167 // Chrome was not running. 168 // Chrome was not running.
168 const ManagementPolicy* policy = extensions::ExtensionSystem::Get( 169 const ManagementPolicy* policy = extensions::ExtensionSystem::Get(
169 extension_service_->profile())->management_policy(); 170 extension_service_->profile())->management_policy();
170 if (extension.get()) { 171 if (extension.get()) {
171 Extension::DisableReason disable_reason = Extension::DISABLE_NONE; 172 Extension::DisableReason disable_reason = Extension::DISABLE_NONE;
172 bool force_disabled = false; 173 bool force_disabled = false;
173 if (!policy->UserMayLoad(extension.get(), NULL)) { 174 if (!policy->UserMayLoad(extension.get(), NULL)) {
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after
215 for (size_t i = 0; i < extensions_info->size(); ++i) { 216 for (size_t i = 0; i < extensions_info->size(); ++i) {
216 ExtensionInfo* info = extensions_info->at(i).get(); 217 ExtensionInfo* info = extensions_info->at(i).get();
217 218
218 // Skip extensions that were loaded from the command-line because we don't 219 // Skip extensions that were loaded from the command-line because we don't
219 // want those to persist across browser restart. 220 // want those to persist across browser restart.
220 if (info->extension_location == Manifest::COMMAND_LINE) 221 if (info->extension_location == Manifest::COMMAND_LINE)
221 continue; 222 continue;
222 223
223 ManifestReloadReason reload_reason = ShouldReloadExtensionManifest(*info); 224 ManifestReloadReason reload_reason = ShouldReloadExtensionManifest(*info);
224 ++reload_reason_counts[reload_reason]; 225 ++reload_reason_counts[reload_reason];
225 UMA_HISTOGRAM_ENUMERATION("Extensions.ManifestReloadEnumValue",
226 reload_reason, 100);
227 226
228 if (reload_reason != NOT_NEEDED) { 227 if (reload_reason != NOT_NEEDED) {
229 // Reloading an extension reads files from disk. We do this on the 228 // Reloading an extension reads files from disk. We do this on the
230 // UI thread because reloads should be very rare, and the complexity 229 // UI thread because reloads should be very rare, and the complexity
231 // added by delaying the time when the extensions service knows about 230 // added by delaying the time when the extensions service knows about
232 // all extensions is significant. See crbug.com/37548 for details. 231 // all extensions is significant. See crbug.com/37548 for details.
233 // |allow_io| disables tests that file operations run on the file 232 // |allow_io| disables tests that file operations run on the file
234 // thread. 233 // thread.
235 base::ThreadRestrictions::ScopedAllowIO allow_io; 234 base::ThreadRestrictions::ScopedAllowIO allow_io;
236 235
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after
287 int legacy_packaged_app_count = 0; 286 int legacy_packaged_app_count = 0;
288 int platform_app_count = 0; 287 int platform_app_count = 0;
289 int user_script_count = 0; 288 int user_script_count = 0;
290 int content_pack_count = 0; 289 int content_pack_count = 0;
291 int extension_user_count = 0; 290 int extension_user_count = 0;
292 int extension_external_count = 0; 291 int extension_external_count = 0;
293 int theme_count = 0; 292 int theme_count = 0;
294 int page_action_count = 0; 293 int page_action_count = 0;
295 int browser_action_count = 0; 294 int browser_action_count = 0;
296 int disabled_for_permissions_count = 0; 295 int disabled_for_permissions_count = 0;
297 int item_user_count = 0;
298 int non_webstore_ntp_override_count = 0; 296 int non_webstore_ntp_override_count = 0;
299 int incognito = 0; 297 int incognito = 0;
300 int not_incognito = 0; 298 int not_incognito = 0;
301 int file_access = 0; 299 int file_access = 0;
302 int not_file_access = 0; 300 int not_file_access = 0;
303 301
304 const ExtensionSet& extensions = extension_registry_->enabled_extensions(); 302 const ExtensionSet& extensions = extension_registry_->enabled_extensions();
305 ExtensionActionManager* extension_action_manager = 303 ExtensionActionManager* extension_action_manager =
306 ExtensionActionManager::Get(profile); 304 ExtensionActionManager::Get(profile);
307 for (ExtensionSet::const_iterator iter = extensions.begin(); 305 for (ExtensionSet::const_iterator iter = extensions.begin();
308 iter != extensions.end(); 306 iter != extensions.end();
309 ++iter) { 307 ++iter) {
310 const Extension* extension = *iter; 308 const Extension* extension = *iter;
311 Manifest::Location location = extension->location(); 309 Manifest::Location location = extension->location();
312 Manifest::Type type = extension->GetType(); 310 Manifest::Type type = extension->GetType();
313 311
314 // For the first few metrics, include all extensions and apps (component, 312 // For the first few metrics, include all extensions and apps (component,
315 // unpacked, etc). It's good to know these locations, and it doesn't 313 // unpacked, etc). It's good to know these locations, and it doesn't
316 // muck up any of the stats. Later, though, we want to omit component and 314 // muck up any of the stats. Later, though, we want to omit component and
317 // unpacked, as they are less interesting. 315 // unpacked, as they are less interesting.
318 if (extension->is_app()) 316 if (extension->is_app())
319 UMA_HISTOGRAM_ENUMERATION("Extensions.AppLocation", location, 100); 317 UMA_HISTOGRAM_ENUMERATION(
318 "Extensions.AppLocation", location, Manifest::NUM_LOCATIONS);
320 else if (extension->is_extension()) 319 else if (extension->is_extension())
321 UMA_HISTOGRAM_ENUMERATION("Extensions.ExtensionLocation", location, 100); 320 UMA_HISTOGRAM_ENUMERATION(
321 "Extensions.ExtensionLocation", location, Manifest::NUM_LOCATIONS);
322 322
323 if (!ManifestURL::UpdatesFromGallery(extension)) { 323 if (!ManifestURL::UpdatesFromGallery(extension)) {
324 UMA_HISTOGRAM_ENUMERATION( 324 UMA_HISTOGRAM_ENUMERATION(
325 "Extensions.NonWebstoreLocation", location, 100); 325 "Extensions.NonWebstoreLocation", location, Manifest::NUM_LOCATIONS);
326 326
327 // Check for inconsistencies if the extension was supposedly installed 327 // Check for inconsistencies if the extension was supposedly installed
328 // from the webstore. 328 // from the webstore.
329 enum { 329 enum {
330 BAD_UPDATE_URL = 0, 330 BAD_UPDATE_URL = 0,
331 // This value was a mistake. Turns out sideloaded extensions can 331 // This value was a mistake. Turns out sideloaded extensions can
332 // have the from_webstore bit if they update from the webstore. 332 // have the from_webstore bit if they update from the webstore.
333 DEPRECATED_IS_EXTERNAL = 1, 333 DEPRECATED_IS_EXTERNAL = 1,
334 }; 334 };
335 if (extension->from_webstore()) { 335 if (extension->from_webstore()) {
(...skipping 27 matching lines...) Expand all
363 URLOverrides::GetChromeURLOverrides(extension).count("newtab")) { 363 URLOverrides::GetChromeURLOverrides(extension).count("newtab")) {
364 ++non_webstore_ntp_override_count; 364 ++non_webstore_ntp_override_count;
365 } 365 }
366 366
367 // Don't count unpacked extensions anymore, either. 367 // Don't count unpacked extensions anymore, either.
368 if (Manifest::IsUnpackedLocation(location)) 368 if (Manifest::IsUnpackedLocation(location))
369 continue; 369 continue;
370 370
371 UMA_HISTOGRAM_ENUMERATION("Extensions.ManifestVersion", 371 UMA_HISTOGRAM_ENUMERATION("Extensions.ManifestVersion",
372 extension->manifest_version(), 372 extension->manifest_version(),
373 10); 373 10); // TODO(kalman): Why 10 manifest versions?
374 374
375 // We might have wanted to count legacy packaged apps here, too, since they 375 // We might have wanted to count legacy packaged apps here, too, since they
376 // are effectively extensions. Unfortunately, it's too late, as we don't 376 // are effectively extensions. Unfortunately, it's too late, as we don't
377 // want to mess up the existing stats. 377 // want to mess up the existing stats.
378 if (type == Manifest::TYPE_EXTENSION) { 378 if (type == Manifest::TYPE_EXTENSION) {
379 UMA_HISTOGRAM_ENUMERATION("Extensions.BackgroundPageType", 379 UMA_HISTOGRAM_ENUMERATION("Extensions.BackgroundPageType",
380 GetBackgroundPageType(extension), 380 GetBackgroundPageType(extension),
381 10); 381 NUM_BACKGROUND_PAGE_TYPES);
382 } 382 }
383 383
384 // Using an enumeration shows us the total installed ratio across all users. 384 // Using an enumeration shows us the total installed ratio across all users.
385 // Using the totals per user at each startup tells us the distribution of 385 // Using the totals per user at each startup tells us the distribution of
386 // usage for each user (e.g. 40% of users have at least one app installed). 386 // usage for each user (e.g. 40% of users have at least one app installed).
387 UMA_HISTOGRAM_ENUMERATION("Extensions.LoadType", type, 100); 387 UMA_HISTOGRAM_ENUMERATION(
388 "Extensions.LoadType", type, Manifest::NUM_LOAD_TYPES);
388 switch (type) { 389 switch (type) {
389 case Manifest::TYPE_THEME: 390 case Manifest::TYPE_THEME:
390 ++theme_count; 391 ++theme_count;
391 break; 392 break;
392 case Manifest::TYPE_USER_SCRIPT: 393 case Manifest::TYPE_USER_SCRIPT:
393 ++user_script_count; 394 ++user_script_count;
394 break; 395 break;
395 case Manifest::TYPE_HOSTED_APP: 396 case Manifest::TYPE_HOSTED_APP:
396 ++hosted_app_count; 397 ++hosted_app_count;
397 if (Manifest::IsExternalLocation(location)) { 398 if (Manifest::IsExternalLocation(location)) {
(...skipping 20 matching lines...) Expand all
418 break; 419 break;
419 case Manifest::TYPE_EXTENSION: 420 case Manifest::TYPE_EXTENSION:
420 default: 421 default:
421 if (Manifest::IsExternalLocation(location)) { 422 if (Manifest::IsExternalLocation(location)) {
422 ++extension_external_count; 423 ++extension_external_count;
423 } else { 424 } else {
424 ++extension_user_count; 425 ++extension_user_count;
425 } 426 }
426 break; 427 break;
427 } 428 }
428 if (!Manifest::IsExternalLocation(location))
429 ++item_user_count;
430 429
431 if (extension_action_manager->GetPageAction(*extension)) 430 if (extension_action_manager->GetPageAction(*extension))
432 ++page_action_count; 431 ++page_action_count;
433 432
434 if (extension_action_manager->GetBrowserAction(*extension)) 433 if (extension_action_manager->GetBrowserAction(*extension))
435 ++browser_action_count; 434 ++browser_action_count;
436 435
437 if (ManagedModeInfo::IsContentPack(extension)) 436 if (ManagedModeInfo::IsContentPack(extension))
438 ++content_pack_count; 437 ++content_pack_count;
439 438
(...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after
495 EXTERNAL_ITEM_WEBSTORE_UNINSTALLED, 494 EXTERNAL_ITEM_WEBSTORE_UNINSTALLED,
496 EXTERNAL_ITEM_MAX_ITEMS); 495 EXTERNAL_ITEM_MAX_ITEMS);
497 } else { 496 } else {
498 UMA_HISTOGRAM_ENUMERATION("Extensions.ExternalItemState", 497 UMA_HISTOGRAM_ENUMERATION("Extensions.ExternalItemState",
499 EXTERNAL_ITEM_NONWEBSTORE_UNINSTALLED, 498 EXTERNAL_ITEM_NONWEBSTORE_UNINSTALLED,
500 EXTERNAL_ITEM_MAX_ITEMS); 499 EXTERNAL_ITEM_MAX_ITEMS);
501 } 500 }
502 } 501 }
503 } 502 }
504 503
505 UMA_HISTOGRAM_COUNTS_100("Extensions.LoadAllUser", item_user_count);
506 UMA_HISTOGRAM_COUNTS_100("Extensions.LoadApp", 504 UMA_HISTOGRAM_COUNTS_100("Extensions.LoadApp",
507 app_user_count + app_external_count); 505 app_user_count + app_external_count);
508 UMA_HISTOGRAM_COUNTS_100("Extensions.LoadAppUser", app_user_count); 506 UMA_HISTOGRAM_COUNTS_100("Extensions.LoadAppUser", app_user_count);
509 UMA_HISTOGRAM_COUNTS_100("Extensions.LoadAppExternal", app_external_count); 507 UMA_HISTOGRAM_COUNTS_100("Extensions.LoadAppExternal", app_external_count);
510 UMA_HISTOGRAM_COUNTS_100("Extensions.LoadHostedApp", hosted_app_count); 508 UMA_HISTOGRAM_COUNTS_100("Extensions.LoadHostedApp", hosted_app_count);
511 UMA_HISTOGRAM_COUNTS_100("Extensions.LoadPackagedApp", 509 UMA_HISTOGRAM_COUNTS_100("Extensions.LoadPackagedApp",
512 legacy_packaged_app_count); 510 legacy_packaged_app_count);
513 UMA_HISTOGRAM_COUNTS_100("Extensions.LoadPlatformApp", platform_app_count); 511 UMA_HISTOGRAM_COUNTS_100("Extensions.LoadPlatformApp", platform_app_count);
514 UMA_HISTOGRAM_COUNTS_100("Extensions.LoadExtension", 512 UMA_HISTOGRAM_COUNTS_100("Extensions.LoadExtension",
515 extension_user_count + extension_external_count); 513 extension_user_count + extension_external_count);
(...skipping 20 matching lines...) Expand all
536 int InstalledLoader::GetCreationFlags(const ExtensionInfo* info) { 534 int InstalledLoader::GetCreationFlags(const ExtensionInfo* info) {
537 int flags = extension_prefs_->GetCreationFlags(info->extension_id); 535 int flags = extension_prefs_->GetCreationFlags(info->extension_id);
538 if (!Manifest::IsUnpackedLocation(info->extension_location)) 536 if (!Manifest::IsUnpackedLocation(info->extension_location))
539 flags |= Extension::REQUIRE_KEY; 537 flags |= Extension::REQUIRE_KEY;
540 if (extension_prefs_->AllowFileAccess(info->extension_id)) 538 if (extension_prefs_->AllowFileAccess(info->extension_id))
541 flags |= Extension::ALLOW_FILE_ACCESS; 539 flags |= Extension::ALLOW_FILE_ACCESS;
542 return flags; 540 return flags;
543 } 541 }
544 542
545 } // namespace extensions 543 } // namespace extensions
OLDNEW
« no previous file with comments | « no previous file | chrome/common/extensions/sync_helper.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698