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

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

Issue 16295026: Collect UMA data for extension manifest version and background page type. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: . Created 7 years, 6 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 | no next file » | 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/stringprintf.h" 9 #include "base/stringprintf.h"
10 #include "base/threading/thread_restrictions.h" 10 #include "base/threading/thread_restrictions.h"
11 #include "base/utf_string_conversions.h" 11 #include "base/utf_string_conversions.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/api/runtime/runtime_api.h" 14 #include "chrome/browser/extensions/api/runtime/runtime_api.h"
15 #include "chrome/browser/extensions/extension_action_manager.h" 15 #include "chrome/browser/extensions/extension_action_manager.h"
16 #include "chrome/browser/extensions/extension_prefs.h" 16 #include "chrome/browser/extensions/extension_prefs.h"
17 #include "chrome/browser/extensions/extension_service.h" 17 #include "chrome/browser/extensions/extension_service.h"
18 #include "chrome/browser/extensions/extension_system.h" 18 #include "chrome/browser/extensions/extension_system.h"
19 #include "chrome/browser/extensions/management_policy.h" 19 #include "chrome/browser/extensions/management_policy.h"
20 #include "chrome/browser/profiles/profile_manager.h" 20 #include "chrome/browser/profiles/profile_manager.h"
21 #include "chrome/common/chrome_switches.h" 21 #include "chrome/common/chrome_switches.h"
22 #include "chrome/common/extensions/api/managed_mode_private/managed_mode_handler .h" 22 #include "chrome/common/extensions/api/managed_mode_private/managed_mode_handler .h"
23 #include "chrome/common/extensions/background_info.h"
23 #include "chrome/common/extensions/extension.h" 24 #include "chrome/common/extensions/extension.h"
24 #include "chrome/common/extensions/extension_file_util.h" 25 #include "chrome/common/extensions/extension_file_util.h"
25 #include "chrome/common/extensions/extension_l10n_util.h" 26 #include "chrome/common/extensions/extension_l10n_util.h"
26 #include "chrome/common/extensions/extension_manifest_constants.h" 27 #include "chrome/common/extensions/extension_manifest_constants.h"
27 #include "chrome/common/extensions/manifest.h" 28 #include "chrome/common/extensions/manifest.h"
28 #include "chrome/common/pref_names.h" 29 #include "chrome/common/pref_names.h"
29 #include "content/public/browser/notification_service.h" 30 #include "content/public/browser/notification_service.h"
30 #include "content/public/browser/user_metrics.h" 31 #include "content/public/browser/user_metrics.h"
31 32
32 using content::BrowserThread; 33 using content::BrowserThread;
33 using content::UserMetricsAction; 34 using content::UserMetricsAction;
34 using extensions::Extension; 35 using extensions::Extension;
35 using extensions::ExtensionInfo; 36 using extensions::ExtensionInfo;
36 using extensions::Manifest; 37 using extensions::Manifest;
37 38
38 namespace errors = extension_manifest_errors; 39 namespace errors = extension_manifest_errors;
39 40
41 namespace extensions {
42
40 namespace { 43 namespace {
41 44
42 // The following enumeration is used in histograms matching 45 // The following enumeration is used in histograms matching
43 // Extensions.ManifestReload* . Values may be added, as long as existing 46 // Extensions.ManifestReload* . Values may be added, as long as existing
44 // values are not changed. 47 // values are not changed.
45 enum ManifestReloadReason { 48 enum ManifestReloadReason {
46 NOT_NEEDED = 0, // Reload not needed. 49 NOT_NEEDED = 0, // Reload not needed.
47 UNPACKED_DIR, // Unpacked directory. 50 UNPACKED_DIR, // Unpacked directory.
48 NEEDS_RELOCALIZATION, // The locale has changed since we read this extension. 51 NEEDS_RELOCALIZATION, // The locale has changed since we read this extension.
49 NUM_MANIFEST_RELOAD_REASONS 52 NUM_MANIFEST_RELOAD_REASONS
50 }; 53 };
51 54
55 // Used in histogram Extension.BackgroundPageType. Values may be added, as
56 // long as existing values are not changed.
57 enum BackgroundPageType {
58 NO_BACKGROUND_PAGE = 0,
59 BACKGROUND_PAGE_PERSISTENT = 1,
60 EVENT_PAGE = 2,
61 };
62
52 ManifestReloadReason ShouldReloadExtensionManifest(const ExtensionInfo& info) { 63 ManifestReloadReason ShouldReloadExtensionManifest(const ExtensionInfo& info) {
53 // Always reload manifests of unpacked extensions, because they can change 64 // Always reload manifests of unpacked extensions, because they can change
54 // on disk independent of the manifest in our prefs. 65 // on disk independent of the manifest in our prefs.
55 if (Manifest::IsUnpackedLocation(info.extension_location)) 66 if (Manifest::IsUnpackedLocation(info.extension_location))
56 return UNPACKED_DIR; 67 return UNPACKED_DIR;
57 68
58 // Reload the manifest if it needs to be relocalized. 69 // Reload the manifest if it needs to be relocalized.
59 if (extension_l10n_util::ShouldRelocalizeManifest( 70 if (extension_l10n_util::ShouldRelocalizeManifest(
60 info.extension_manifest.get())) 71 info.extension_manifest.get()))
61 return NEEDS_RELOCALIZATION; 72 return NEEDS_RELOCALIZATION;
62 73
63 return NOT_NEEDED; 74 return NOT_NEEDED;
64 } 75 }
65 76
77 BackgroundPageType GetBackgroundPageType(const Extension* extension) {
78 if (!BackgroundInfo::HasBackgroundPage(extension))
79 return NO_BACKGROUND_PAGE;
80 if (BackgroundInfo::HasPersistentBackgroundPage(extension))
81 return BACKGROUND_PAGE_PERSISTENT;
82 return EVENT_PAGE;
83 }
84
66 void DispatchOnInstalledEvent( 85 void DispatchOnInstalledEvent(
67 Profile* profile, 86 Profile* profile,
68 const std::string& extension_id, 87 const std::string& extension_id,
69 const Version& old_version, 88 const Version& old_version,
70 bool chrome_updated) { 89 bool chrome_updated) {
71 // profile manager can be NULL in unit tests. 90 // profile manager can be NULL in unit tests.
72 if (!g_browser_process->profile_manager()) 91 if (!g_browser_process->profile_manager())
73 return; 92 return;
74 if (!g_browser_process->profile_manager()->IsValidProfile(profile)) 93 if (!g_browser_process->profile_manager()->IsValidProfile(profile))
75 return; 94 return;
76 95
77 extensions::RuntimeEventRouter::DispatchOnInstalledEvent( 96 extensions::RuntimeEventRouter::DispatchOnInstalledEvent(
78 profile, extension_id, old_version, chrome_updated); 97 profile, extension_id, old_version, chrome_updated);
79 } 98 }
80 99
81 } // namespace 100 } // namespace
82 101
83 namespace extensions {
84
85 InstalledLoader::InstalledLoader(ExtensionService* extension_service) 102 InstalledLoader::InstalledLoader(ExtensionService* extension_service)
86 : extension_service_(extension_service), 103 : extension_service_(extension_service),
87 extension_prefs_(extension_service->extension_prefs()) { 104 extension_prefs_(extension_service->extension_prefs()) {
88 } 105 }
89 106
90 InstalledLoader::~InstalledLoader() { 107 InstalledLoader::~InstalledLoader() {
91 } 108 }
92 109
93 void InstalledLoader::Load(const ExtensionInfo& info, bool write_to_prefs) { 110 void InstalledLoader::Load(const ExtensionInfo& info, bool write_to_prefs) {
94 std::string error; 111 std::string error;
(...skipping 179 matching lines...) Expand 10 before | Expand all | Expand 10 after
274 // Don't count component extensions, since they are only extensions as an 291 // Don't count component extensions, since they are only extensions as an
275 // implementation detail. 292 // implementation detail.
276 if (location == Manifest::COMPONENT) 293 if (location == Manifest::COMPONENT)
277 continue; 294 continue;
278 295
279 // Don't count unpacked extensions, since they're a developer-specific 296 // Don't count unpacked extensions, since they're a developer-specific
280 // feature. 297 // feature.
281 if (Manifest::IsUnpackedLocation(location)) 298 if (Manifest::IsUnpackedLocation(location))
282 continue; 299 continue;
283 300
301 UMA_HISTOGRAM_ENUMERATION("Extensions.ManifestVersion",
302 (*ex)->manifest_version(), 10);
303
304 if (type == Manifest::TYPE_EXTENSION) {
305 BackgroundPageType background_page_type = GetBackgroundPageType(*ex);
306 UMA_HISTOGRAM_ENUMERATION("Extensions.BackgroundPageType",
307 background_page_type, 10);
308 }
309
284 // Using an enumeration shows us the total installed ratio across all users. 310 // Using an enumeration shows us the total installed ratio across all users.
285 // Using the totals per user at each startup tells us the distribution of 311 // Using the totals per user at each startup tells us the distribution of
286 // usage for each user (e.g. 40% of users have at least one app installed). 312 // usage for each user (e.g. 40% of users have at least one app installed).
287 UMA_HISTOGRAM_ENUMERATION("Extensions.LoadType", type, 100); 313 UMA_HISTOGRAM_ENUMERATION("Extensions.LoadType", type, 100);
288 switch (type) { 314 switch (type) {
289 case Manifest::TYPE_THEME: 315 case Manifest::TYPE_THEME:
290 ++theme_count; 316 ++theme_count;
291 break; 317 break;
292 case Manifest::TYPE_USER_SCRIPT: 318 case Manifest::TYPE_USER_SCRIPT:
293 ++user_script_count; 319 ++user_script_count;
(...skipping 84 matching lines...) Expand 10 before | Expand all | Expand 10 after
378 int InstalledLoader::GetCreationFlags(const ExtensionInfo* info) { 404 int InstalledLoader::GetCreationFlags(const ExtensionInfo* info) {
379 int flags = extension_prefs_->GetCreationFlags(info->extension_id); 405 int flags = extension_prefs_->GetCreationFlags(info->extension_id);
380 if (!Manifest::IsUnpackedLocation(info->extension_location)) 406 if (!Manifest::IsUnpackedLocation(info->extension_location))
381 flags |= Extension::REQUIRE_KEY; 407 flags |= Extension::REQUIRE_KEY;
382 if (extension_prefs_->AllowFileAccess(info->extension_id)) 408 if (extension_prefs_->AllowFileAccess(info->extension_id))
383 flags |= Extension::ALLOW_FILE_ACCESS; 409 flags |= Extension::ALLOW_FILE_ACCESS;
384 return flags; 410 return flags;
385 } 411 }
386 412
387 } // namespace extensions 413 } // namespace extensions
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698