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

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: 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
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
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 79 matching lines...) Expand 10 before | Expand all | Expand 10 after
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() && !Manifest::IsUnpackedLocation(extension->location()) &&
160 info.extension_id != extension->id()) { 161 info.extension_id != extension->id()) {
161 error = errors::kCannotChangeExtensionID; 162 error = errors::kCannotChangeExtensionID;
162 extension = NULL; 163 extension = NULL;
163 content::RecordAction(UserMetricsAction("Extensions.IDChangedError")); 164 content::RecordAction(UserMetricsAction("Extensions.IDChangedError"));
not at google - send to devlin 2014/05/21 22:31:07 (see below... what even is "content::RecordAction"
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 42 matching lines...) Expand 10 before | Expand all | Expand 10 after
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 UMA_HISTOGRAM_ENUMERATION("Extensions.ManifestReloadEnumValue",
226 reload_reason, 100); 227 reload_reason,
228 NUM_MANIFEST_RELOAD_REASONS);
227 229
228 if (reload_reason != NOT_NEEDED) { 230 if (reload_reason != NOT_NEEDED) {
229 // Reloading an extension reads files from disk. We do this on the 231 // Reloading an extension reads files from disk. We do this on the
230 // UI thread because reloads should be very rare, and the complexity 232 // UI thread because reloads should be very rare, and the complexity
231 // added by delaying the time when the extensions service knows about 233 // added by delaying the time when the extensions service knows about
232 // all extensions is significant. See crbug.com/37548 for details. 234 // all extensions is significant. See crbug.com/37548 for details.
233 // |allow_io| disables tests that file operations run on the file 235 // |allow_io| disables tests that file operations run on the file
234 // thread. 236 // thread.
235 base::ThreadRestrictions::ScopedAllowIO allow_io; 237 base::ThreadRestrictions::ScopedAllowIO allow_io;
236 238
(...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after
309 ++iter) { 311 ++iter) {
310 const Extension* extension = *iter; 312 const Extension* extension = *iter;
311 Manifest::Location location = extension->location(); 313 Manifest::Location location = extension->location();
312 Manifest::Type type = extension->GetType(); 314 Manifest::Type type = extension->GetType();
313 315
314 // For the first few metrics, include all extensions and apps (component, 316 // 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 317 // 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 318 // muck up any of the stats. Later, though, we want to omit component and
317 // unpacked, as they are less interesting. 319 // unpacked, as they are less interesting.
318 if (extension->is_app()) 320 if (extension->is_app())
319 UMA_HISTOGRAM_ENUMERATION("Extensions.AppLocation", location, 100); 321 UMA_HISTOGRAM_ENUMERATION(
322 "Extensions.AppLocation", location, Manifest::NUM_LOCATIONS);
320 else if (extension->is_extension()) 323 else if (extension->is_extension())
321 UMA_HISTOGRAM_ENUMERATION("Extensions.ExtensionLocation", location, 100); 324 UMA_HISTOGRAM_ENUMERATION(
325 "Extensions.ExtensionLocation", location, Manifest::NUM_LOCATIONS);
322 326
323 if (!ManifestURL::UpdatesFromGallery(extension)) { 327 if (!ManifestURL::UpdatesFromGallery(extension)) {
324 UMA_HISTOGRAM_ENUMERATION( 328 UMA_HISTOGRAM_ENUMERATION(
325 "Extensions.NonWebstoreLocation", location, 100); 329 "Extensions.NonWebstoreLocation", location, Manifest::NUM_LOCATIONS);
326 330
327 // Check for inconsistencies if the extension was supposedly installed 331 // Check for inconsistencies if the extension was supposedly installed
328 // from the webstore. 332 // from the webstore.
329 enum { 333 enum {
330 BAD_UPDATE_URL = 0, 334 BAD_UPDATE_URL = 0,
331 // This value was a mistake. Turns out sideloaded extensions can 335 // This value was a mistake. Turns out sideloaded extensions can
332 // have the from_webstore bit if they update from the webstore. 336 // have the from_webstore bit if they update from the webstore.
333 DEPRECATED_IS_EXTERNAL = 1, 337 DEPRECATED_IS_EXTERNAL = 1,
334 }; 338 };
335 if (extension->from_webstore()) { 339 if (extension->from_webstore()) {
(...skipping 27 matching lines...) Expand all
363 URLOverrides::GetChromeURLOverrides(extension).count("newtab")) { 367 URLOverrides::GetChromeURLOverrides(extension).count("newtab")) {
364 ++non_webstore_ntp_override_count; 368 ++non_webstore_ntp_override_count;
365 } 369 }
366 370
367 // Don't count unpacked extensions anymore, either. 371 // Don't count unpacked extensions anymore, either.
368 if (Manifest::IsUnpackedLocation(location)) 372 if (Manifest::IsUnpackedLocation(location))
369 continue; 373 continue;
370 374
371 UMA_HISTOGRAM_ENUMERATION("Extensions.ManifestVersion", 375 UMA_HISTOGRAM_ENUMERATION("Extensions.ManifestVersion",
372 extension->manifest_version(), 376 extension->manifest_version(),
373 10); 377 10);
jar (doing other things) 2014/05/21 22:12:45 nit: I was curious about this bound (10)... but I
not at google - send to devlin 2014/05/21 22:31:07 Looks like there are actually 4 values that are be
not at google - send to devlin 2014/05/21 23:17:22 Actually I'm going to delete (2). It's not very in
374 378
375 // We might have wanted to count legacy packaged apps here, too, since they 379 // 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 380 // are effectively extensions. Unfortunately, it's too late, as we don't
377 // want to mess up the existing stats. 381 // want to mess up the existing stats.
378 if (type == Manifest::TYPE_EXTENSION) { 382 if (type == Manifest::TYPE_EXTENSION) {
379 UMA_HISTOGRAM_ENUMERATION("Extensions.BackgroundPageType", 383 UMA_HISTOGRAM_ENUMERATION("Extensions.BackgroundPageType",
380 GetBackgroundPageType(extension), 384 GetBackgroundPageType(extension),
381 10); 385 NUM_BACKGROUND_PAGE_TYPES);
382 } 386 }
383 387
384 // Using an enumeration shows us the total installed ratio across all users. 388 // 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 389 // 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). 390 // usage for each user (e.g. 40% of users have at least one app installed).
387 UMA_HISTOGRAM_ENUMERATION("Extensions.LoadType", type, 100); 391 UMA_HISTOGRAM_ENUMERATION(
392 "Extensions.LoadType", type, Manifest::NUM_LOAD_TYPES);
388 switch (type) { 393 switch (type) {
389 case Manifest::TYPE_THEME: 394 case Manifest::TYPE_THEME:
390 ++theme_count; 395 ++theme_count;
391 break; 396 break;
392 case Manifest::TYPE_USER_SCRIPT: 397 case Manifest::TYPE_USER_SCRIPT:
393 ++user_script_count; 398 ++user_script_count;
394 break; 399 break;
395 case Manifest::TYPE_HOSTED_APP: 400 case Manifest::TYPE_HOSTED_APP:
396 ++hosted_app_count; 401 ++hosted_app_count;
397 if (Manifest::IsExternalLocation(location)) { 402 if (Manifest::IsExternalLocation(location)) {
(...skipping 138 matching lines...) Expand 10 before | Expand all | Expand 10 after
536 int InstalledLoader::GetCreationFlags(const ExtensionInfo* info) { 541 int InstalledLoader::GetCreationFlags(const ExtensionInfo* info) {
537 int flags = extension_prefs_->GetCreationFlags(info->extension_id); 542 int flags = extension_prefs_->GetCreationFlags(info->extension_id);
538 if (!Manifest::IsUnpackedLocation(info->extension_location)) 543 if (!Manifest::IsUnpackedLocation(info->extension_location))
539 flags |= Extension::REQUIRE_KEY; 544 flags |= Extension::REQUIRE_KEY;
540 if (extension_prefs_->AllowFileAccess(info->extension_id)) 545 if (extension_prefs_->AllowFileAccess(info->extension_id))
541 flags |= Extension::ALLOW_FILE_ACCESS; 546 flags |= Extension::ALLOW_FILE_ACCESS;
542 return flags; 547 return flags;
543 } 548 }
544 549
545 } // namespace extensions 550 } // namespace extensions
OLDNEW
« no previous file with comments | « no previous file | chrome/common/extensions/sync_helper.cc » ('j') | extensions/browser/admin_policy.cc » ('J')

Powered by Google App Engine
This is Rietveld 408576698