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

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

Issue 12093036: Move Extension Location and Type enums to Manifest, and move InstallWarning to its own file. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 7 years, 10 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/file_path.h" 7 #include "base/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"
(...skipping 14 matching lines...) Expand all
25 #include "chrome/common/extensions/extension_manifest_constants.h" 25 #include "chrome/common/extensions/extension_manifest_constants.h"
26 #include "chrome/common/extensions/manifest.h" 26 #include "chrome/common/extensions/manifest.h"
27 #include "chrome/common/pref_names.h" 27 #include "chrome/common/pref_names.h"
28 #include "content/public/browser/notification_service.h" 28 #include "content/public/browser/notification_service.h"
29 #include "content/public/browser/user_metrics.h" 29 #include "content/public/browser/user_metrics.h"
30 30
31 using content::BrowserThread; 31 using content::BrowserThread;
32 using content::UserMetricsAction; 32 using content::UserMetricsAction;
33 using extensions::Extension; 33 using extensions::Extension;
34 using extensions::ExtensionInfo; 34 using extensions::ExtensionInfo;
35 using extensions::Manifest;
35 36
36 namespace errors = extension_manifest_errors; 37 namespace errors = extension_manifest_errors;
37 38
38 namespace { 39 namespace {
39 40
40 // The following enumeration is used in histograms matching 41 // The following enumeration is used in histograms matching
41 // Extensions.ManifestReload* . Values may be added, as long as existing 42 // Extensions.ManifestReload* . Values may be added, as long as existing
42 // values are not changed. 43 // values are not changed.
43 enum ManifestReloadReason { 44 enum ManifestReloadReason {
44 NOT_NEEDED = 0, // Reload not needed. 45 NOT_NEEDED = 0, // Reload not needed.
45 UNPACKED_DIR, // Unpacked directory. 46 UNPACKED_DIR, // Unpacked directory.
46 NEEDS_RELOCALIZATION, // The locale has changed since we read this extension. 47 NEEDS_RELOCALIZATION, // The locale has changed since we read this extension.
47 NUM_MANIFEST_RELOAD_REASONS 48 NUM_MANIFEST_RELOAD_REASONS
48 }; 49 };
49 50
50 ManifestReloadReason ShouldReloadExtensionManifest(const ExtensionInfo& info) { 51 ManifestReloadReason ShouldReloadExtensionManifest(const ExtensionInfo& info) {
51 // Always reload manifests of unpacked extensions, because they can change 52 // Always reload manifests of unpacked extensions, because they can change
52 // on disk independent of the manifest in our prefs. 53 // on disk independent of the manifest in our prefs.
53 if (info.extension_location == Extension::LOAD) 54 if (info.extension_location == Manifest::LOAD)
54 return UNPACKED_DIR; 55 return UNPACKED_DIR;
55 56
56 // Reload the manifest if it needs to be relocalized. 57 // Reload the manifest if it needs to be relocalized.
57 if (extension_l10n_util::ShouldRelocalizeManifest(info)) 58 if (extension_l10n_util::ShouldRelocalizeManifest(info))
58 return NEEDS_RELOCALIZATION; 59 return NEEDS_RELOCALIZATION;
59 60
60 return NOT_NEEDED; 61 return NOT_NEEDED;
61 } 62 }
62 63
63 void DispatchOnInstalledEvent( 64 void DispatchOnInstalledEvent(
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after
98 GetCreationFlags(&info), 99 GetCreationFlags(&info),
99 &error); 100 &error);
100 } else { 101 } else {
101 error = errors::kManifestUnreadable; 102 error = errors::kManifestUnreadable;
102 } 103 }
103 104
104 // Once installed, non-unpacked extensions cannot change their IDs (e.g., by 105 // Once installed, non-unpacked extensions cannot change their IDs (e.g., by
105 // updating the 'key' field in their manifest). 106 // updating the 'key' field in their manifest).
106 // TODO(jstritar): migrate preferences when unpacked extensions change IDs. 107 // TODO(jstritar): migrate preferences when unpacked extensions change IDs.
107 if (extension && 108 if (extension &&
108 extension->location() != Extension::LOAD && 109 extension->location() != Manifest::LOAD &&
109 info.extension_id != extension->id()) { 110 info.extension_id != extension->id()) {
110 error = errors::kCannotChangeExtensionID; 111 error = errors::kCannotChangeExtensionID;
111 extension = NULL; 112 extension = NULL;
112 content::RecordAction(UserMetricsAction("Extensions.IDChangedError")); 113 content::RecordAction(UserMetricsAction("Extensions.IDChangedError"));
113 } 114 }
114 115
115 // Check policy on every load in case an extension was blacklisted while 116 // Check policy on every load in case an extension was blacklisted while
116 // Chrome was not running. 117 // Chrome was not running.
117 const ManagementPolicy* policy = extensions::ExtensionSystem::Get( 118 const ManagementPolicy* policy = extensions::ExtensionSystem::Get(
118 extension_service_->profile())->management_policy(); 119 extension_service_->profile())->management_policy();
(...skipping 127 matching lines...) Expand 10 before | Expand all | Expand 10 after
246 int extension_user_count = 0; 247 int extension_user_count = 0;
247 int extension_external_count = 0; 248 int extension_external_count = 0;
248 int theme_count = 0; 249 int theme_count = 0;
249 int page_action_count = 0; 250 int page_action_count = 0;
250 int browser_action_count = 0; 251 int browser_action_count = 0;
251 int disabled_for_permissions_count = 0; 252 int disabled_for_permissions_count = 0;
252 int item_user_count = 0; 253 int item_user_count = 0;
253 const ExtensionSet* extensions = extension_service_->extensions(); 254 const ExtensionSet* extensions = extension_service_->extensions();
254 ExtensionSet::const_iterator ex; 255 ExtensionSet::const_iterator ex;
255 for (ex = extensions->begin(); ex != extensions->end(); ++ex) { 256 for (ex = extensions->begin(); ex != extensions->end(); ++ex) {
256 Extension::Location location = (*ex)->location(); 257 Manifest::Location location = (*ex)->location();
257 Extension::Type type = (*ex)->GetType(); 258 Manifest::Type type = (*ex)->GetType();
258 if ((*ex)->is_app()) { 259 if ((*ex)->is_app()) {
259 UMA_HISTOGRAM_ENUMERATION("Extensions.AppLocation", 260 UMA_HISTOGRAM_ENUMERATION("Extensions.AppLocation",
260 location, 100); 261 location, 100);
261 } else if (type == Extension::TYPE_EXTENSION) { 262 } else if (type == Manifest::TYPE_EXTENSION) {
262 UMA_HISTOGRAM_ENUMERATION("Extensions.ExtensionLocation", 263 UMA_HISTOGRAM_ENUMERATION("Extensions.ExtensionLocation",
263 location, 100); 264 location, 100);
264 } 265 }
265 266
266 // Don't count component extensions, since they are only extensions as an 267 // Don't count component extensions, since they are only extensions as an
267 // implementation detail. 268 // implementation detail.
268 if (location == Extension::COMPONENT) 269 if (location == Manifest::COMPONENT)
269 continue; 270 continue;
270 271
271 // Don't count unpacked extensions, since they're a developer-specific 272 // Don't count unpacked extensions, since they're a developer-specific
272 // feature. 273 // feature.
273 if (location == Extension::LOAD) 274 if (location == Manifest::LOAD)
274 continue; 275 continue;
275 276
276 // Using an enumeration shows us the total installed ratio across all users. 277 // Using an enumeration shows us the total installed ratio across all users.
277 // Using the totals per user at each startup tells us the distribution of 278 // Using the totals per user at each startup tells us the distribution of
278 // usage for each user (e.g. 40% of users have at least one app installed). 279 // usage for each user (e.g. 40% of users have at least one app installed).
279 UMA_HISTOGRAM_ENUMERATION("Extensions.LoadType", type, 100); 280 UMA_HISTOGRAM_ENUMERATION("Extensions.LoadType", type, 100);
280 switch (type) { 281 switch (type) {
281 case Extension::TYPE_THEME: 282 case Manifest::TYPE_THEME:
282 ++theme_count; 283 ++theme_count;
283 break; 284 break;
284 case Extension::TYPE_USER_SCRIPT: 285 case Manifest::TYPE_USER_SCRIPT:
285 ++user_script_count; 286 ++user_script_count;
286 break; 287 break;
287 case Extension::TYPE_HOSTED_APP: 288 case Manifest::TYPE_HOSTED_APP:
288 ++hosted_app_count; 289 ++hosted_app_count;
289 if (Extension::IsExternalLocation(location)) { 290 if (Manifest::IsExternalLocation(location)) {
290 ++app_external_count; 291 ++app_external_count;
291 } else { 292 } else {
292 ++app_user_count; 293 ++app_user_count;
293 } 294 }
294 break; 295 break;
295 case Extension::TYPE_LEGACY_PACKAGED_APP: 296 case Manifest::TYPE_LEGACY_PACKAGED_APP:
296 ++legacy_packaged_app_count; 297 ++legacy_packaged_app_count;
297 if (Extension::IsExternalLocation(location)) { 298 if (Manifest::IsExternalLocation(location)) {
298 ++app_external_count; 299 ++app_external_count;
299 } else { 300 } else {
300 ++app_user_count; 301 ++app_user_count;
301 } 302 }
302 break; 303 break;
303 case Extension::TYPE_PLATFORM_APP: 304 case Manifest::TYPE_PLATFORM_APP:
304 ++platform_app_count; 305 ++platform_app_count;
305 if (Extension::IsExternalLocation(location)) { 306 if (Manifest::IsExternalLocation(location)) {
306 ++app_external_count; 307 ++app_external_count;
307 } else { 308 } else {
308 ++app_user_count; 309 ++app_user_count;
309 } 310 }
310 break; 311 break;
311 case Extension::TYPE_EXTENSION: 312 case Manifest::TYPE_EXTENSION:
312 default: 313 default:
313 if (Extension::IsExternalLocation(location)) { 314 if (Manifest::IsExternalLocation(location)) {
314 ++extension_external_count; 315 ++extension_external_count;
315 } else { 316 } else {
316 ++extension_user_count; 317 ++extension_user_count;
317 } 318 }
318 break; 319 break;
319 } 320 }
320 if (!Extension::IsExternalLocation((*ex)->location())) 321 if (!Manifest::IsExternalLocation((*ex)->location()))
321 ++item_user_count; 322 ++item_user_count;
322 ExtensionActionManager* extension_action_manager = 323 ExtensionActionManager* extension_action_manager =
323 ExtensionActionManager::Get(extension_service_->profile()); 324 ExtensionActionManager::Get(extension_service_->profile());
324 if (extension_action_manager->GetPageAction(**ex)) 325 if (extension_action_manager->GetPageAction(**ex))
325 ++page_action_count; 326 ++page_action_count;
326 if (extension_action_manager->GetBrowserAction(**ex)) 327 if (extension_action_manager->GetBrowserAction(**ex))
327 ++browser_action_count; 328 ++browser_action_count;
328 329
329 if ((*ex)->is_content_pack()) 330 if ((*ex)->is_content_pack())
330 ++content_pack_count; 331 ++content_pack_count;
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after
362 UMA_HISTOGRAM_COUNTS_100("Extensions.LoadPageAction", page_action_count); 363 UMA_HISTOGRAM_COUNTS_100("Extensions.LoadPageAction", page_action_count);
363 UMA_HISTOGRAM_COUNTS_100("Extensions.LoadBrowserAction", 364 UMA_HISTOGRAM_COUNTS_100("Extensions.LoadBrowserAction",
364 browser_action_count); 365 browser_action_count);
365 UMA_HISTOGRAM_COUNTS_100("Extensions.LoadContentPack", content_pack_count); 366 UMA_HISTOGRAM_COUNTS_100("Extensions.LoadContentPack", content_pack_count);
366 UMA_HISTOGRAM_COUNTS_100("Extensions.DisabledForPermissions", 367 UMA_HISTOGRAM_COUNTS_100("Extensions.DisabledForPermissions",
367 disabled_for_permissions_count); 368 disabled_for_permissions_count);
368 } 369 }
369 370
370 int InstalledLoader::GetCreationFlags(const ExtensionInfo* info) { 371 int InstalledLoader::GetCreationFlags(const ExtensionInfo* info) {
371 int flags = extension_prefs_->GetCreationFlags(info->extension_id); 372 int flags = extension_prefs_->GetCreationFlags(info->extension_id);
372 if (info->extension_location != Extension::LOAD) 373 if (info->extension_location != Manifest::LOAD)
373 flags |= Extension::REQUIRE_KEY; 374 flags |= Extension::REQUIRE_KEY;
374 if (extension_prefs_->AllowFileAccess(info->extension_id)) 375 if (extension_prefs_->AllowFileAccess(info->extension_id))
375 flags |= Extension::ALLOW_FILE_ACCESS; 376 flags |= Extension::ALLOW_FILE_ACCESS;
376 return flags; 377 return flags;
377 } 378 }
378 379
379 } // namespace extensions 380 } // namespace extensions
OLDNEW
« no previous file with comments | « chrome/browser/extensions/image_loading_tracker_unittest.cc ('k') | chrome/browser/extensions/pending_extension_info.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698