Chromium Code Reviews| OLD | NEW |
|---|---|
| 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" |
| 30 #include "extensions/common/extension_l10n_util.h" | 31 #include "extensions/common/extension_l10n_util.h" |
| 32 #include "extensions/common/extension_set.h" | |
| 31 #include "extensions/common/file_util.h" | 33 #include "extensions/common/file_util.h" |
| 32 #include "extensions/common/manifest.h" | 34 #include "extensions/common/manifest.h" |
| 33 #include "extensions/common/manifest_constants.h" | 35 #include "extensions/common/manifest_constants.h" |
| 34 #include "extensions/common/manifest_handlers/background_info.h" | 36 #include "extensions/common/manifest_handlers/background_info.h" |
| 35 | 37 |
| 36 using base::UserMetricsAction; | 38 using base::UserMetricsAction; |
| 37 using content::BrowserThread; | 39 using content::BrowserThread; |
| 38 | 40 |
| 39 namespace extensions { | 41 namespace extensions { |
| 40 | 42 |
| (...skipping 143 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 184 extension_prefs_->UpdateManifest(extension.get()); | 186 extension_prefs_->UpdateManifest(extension.get()); |
| 185 | 187 |
| 186 extension_service_->AddExtension(extension.get()); | 188 extension_service_->AddExtension(extension.get()); |
| 187 } | 189 } |
| 188 | 190 |
| 189 void InstalledLoader::LoadAllExtensions() { | 191 void InstalledLoader::LoadAllExtensions() { |
| 190 CHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 192 CHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| 191 | 193 |
| 192 base::TimeTicks start_time = base::TimeTicks::Now(); | 194 base::TimeTicks start_time = base::TimeTicks::Now(); |
| 193 | 195 |
| 196 Profile* profile = extension_service_->profile(); | |
| 194 scoped_ptr<ExtensionPrefs::ExtensionsInfo> extensions_info( | 197 scoped_ptr<ExtensionPrefs::ExtensionsInfo> extensions_info( |
| 195 extension_prefs_->GetInstalledExtensionsInfo()); | 198 extension_prefs_->GetInstalledExtensionsInfo()); |
| 196 | 199 |
| 197 std::vector<int> reload_reason_counts(NUM_MANIFEST_RELOAD_REASONS, 0); | 200 std::vector<int> reload_reason_counts(NUM_MANIFEST_RELOAD_REASONS, 0); |
| 198 bool should_write_prefs = false; | 201 bool should_write_prefs = false; |
| 199 | 202 |
| 200 for (size_t i = 0; i < extensions_info->size(); ++i) { | 203 for (size_t i = 0; i < extensions_info->size(); ++i) { |
| 201 ExtensionInfo* info = extensions_info->at(i).get(); | 204 ExtensionInfo* info = extensions_info->at(i).get(); |
| 202 | 205 |
| 203 // Skip extensions that were loaded from the command-line because we don't | 206 // Skip extensions that were loaded from the command-line because we don't |
| (...skipping 19 matching lines...) Expand all Loading... | |
| 223 scoped_refptr<const Extension> extension( | 226 scoped_refptr<const Extension> extension( |
| 224 file_util::LoadExtension(info->extension_path, | 227 file_util::LoadExtension(info->extension_path, |
| 225 info->extension_location, | 228 info->extension_location, |
| 226 GetCreationFlags(info), | 229 GetCreationFlags(info), |
| 227 &error)); | 230 &error)); |
| 228 | 231 |
| 229 if (!extension.get()) { | 232 if (!extension.get()) { |
| 230 ExtensionErrorReporter::GetInstance()->ReportLoadError( | 233 ExtensionErrorReporter::GetInstance()->ReportLoadError( |
| 231 info->extension_path, | 234 info->extension_path, |
| 232 error, | 235 error, |
| 233 extension_service_->profile(), | 236 profile, |
| 234 false); // Be quiet. | 237 false); // Be quiet. |
| 235 continue; | 238 continue; |
| 236 } | 239 } |
| 237 | 240 |
| 238 extensions_info->at(i)->extension_manifest.reset( | 241 extensions_info->at(i)->extension_manifest.reset( |
| 239 static_cast<base::DictionaryValue*>( | 242 static_cast<base::DictionaryValue*>( |
| 240 extension->manifest()->value()->DeepCopy())); | 243 extension->manifest()->value()->DeepCopy())); |
| 241 should_write_prefs = true; | 244 should_write_prefs = true; |
| 242 } | 245 } |
| 243 } | 246 } |
| 244 | 247 |
| 245 for (size_t i = 0; i < extensions_info->size(); ++i) { | 248 for (size_t i = 0; i < extensions_info->size(); ++i) { |
| 246 if (extensions_info->at(i)->extension_location == Manifest::COMMAND_LINE) | 249 if (extensions_info->at(i)->extension_location == Manifest::COMMAND_LINE) |
| 247 continue; | 250 continue; |
| 248 Load(*extensions_info->at(i), should_write_prefs); | 251 Load(*extensions_info->at(i), should_write_prefs); |
| 249 } | 252 } |
| 250 | 253 |
| 251 extension_service_->OnLoadedInstalledExtensions(); | 254 extension_service_->OnLoadedInstalledExtensions(); |
| 252 | 255 |
| 253 // The histograms Extensions.ManifestReload* allow us to validate | 256 // The histograms Extensions.ManifestReload* allow us to validate |
| 254 // the assumption that reloading manifest is a rare event. | 257 // the assumption that reloading manifest is a rare event. |
| 255 UMA_HISTOGRAM_COUNTS_100("Extensions.ManifestReloadNotNeeded", | 258 UMA_HISTOGRAM_COUNTS_100("Extensions.ManifestReloadNotNeeded", |
| 256 reload_reason_counts[NOT_NEEDED]); | 259 reload_reason_counts[NOT_NEEDED]); |
| 257 UMA_HISTOGRAM_COUNTS_100("Extensions.ManifestReloadUnpackedDir", | 260 UMA_HISTOGRAM_COUNTS_100("Extensions.ManifestReloadUnpackedDir", |
| 258 reload_reason_counts[UNPACKED_DIR]); | 261 reload_reason_counts[UNPACKED_DIR]); |
| 259 UMA_HISTOGRAM_COUNTS_100("Extensions.ManifestReloadNeedsRelocalization", | 262 UMA_HISTOGRAM_COUNTS_100("Extensions.ManifestReloadNeedsRelocalization", |
| 260 reload_reason_counts[NEEDS_RELOCALIZATION]); | 263 reload_reason_counts[NEEDS_RELOCALIZATION]); |
| 261 | 264 |
| 262 UMA_HISTOGRAM_COUNTS_100("Extensions.LoadAll", | 265 const ExtensionSet& enabled = extension_registry_->enabled_extensions(); |
| 263 extension_registry_->enabled_extensions().size()); | 266 |
| 267 UMA_HISTOGRAM_COUNTS_100("Extensions.LoadAll", enabled.size()); | |
| 264 UMA_HISTOGRAM_COUNTS_100("Extensions.Disabled", | 268 UMA_HISTOGRAM_COUNTS_100("Extensions.Disabled", |
| 265 extension_registry_->disabled_extensions().size()); | 269 extension_registry_->disabled_extensions().size()); |
| 266 | 270 |
| 271 // Gather stats about the extensions which have/have-not been enabled for | |
| 272 // incognito and file access in chrome://extensions. | |
| 273 size_t incognito = 0; | |
| 274 size_t not_incognito = 0; | |
|
Devlin
2014/05/09 23:01:12
nit of all nits: 0u, not 0, to avoid an implicit c
not at google - send to devlin
2014/05/09 23:18:58
Done. sort of. you're right, but right below there
| |
| 275 size_t file_access = 0; | |
| 276 size_t not_file_access = 0; | |
| 277 | |
| 278 for (ExtensionSet::const_iterator it = enabled.begin(); | |
| 279 it != enabled.end(); | |
| 280 ++it) { | |
| 281 const Extension& e = **it; | |
| 282 | |
| 283 // Skip unpacked extensions because they get file access up-front, and | |
| 284 // the data isn't useful. Skip anything that doesn't appear in settings. | |
| 285 if (e.location() == Manifest::UNPACKED || | |
| 286 !e.ShouldDisplayInExtensionSettings()) { | |
| 287 continue; | |
| 288 } | |
| 289 | |
| 290 if (e.can_be_incognito_enabled()) { | |
| 291 if (util::IsIncognitoEnabled(e.id(), profile)) | |
| 292 ++incognito; | |
| 293 else | |
| 294 ++not_incognito; | |
| 295 } | |
| 296 | |
| 297 if (e.wants_file_access()) { | |
| 298 if (util::AllowFileAccess(e.id(), profile)) | |
| 299 ++file_access; | |
| 300 else | |
| 301 ++not_file_access; | |
| 302 } | |
| 303 } | |
| 304 | |
| 305 UMA_HISTOGRAM_COUNTS_100("Extensions.IncognitoAllowed", incognito); | |
| 306 UMA_HISTOGRAM_COUNTS_100("Extensions.IncognitoNotAllowed", not_incognito); | |
| 307 UMA_HISTOGRAM_COUNTS_100("Extensions.FileAccessAllowed", file_access); | |
| 308 UMA_HISTOGRAM_COUNTS_100("Extensions.FileAccessNotAllowed", not_file_access); | |
| 309 | |
| 267 UMA_HISTOGRAM_TIMES("Extensions.LoadAllTime", | 310 UMA_HISTOGRAM_TIMES("Extensions.LoadAllTime", |
| 268 base::TimeTicks::Now() - start_time); | 311 base::TimeTicks::Now() - start_time); |
| 269 | 312 |
| 270 int app_user_count = 0; | 313 int app_user_count = 0; |
| 271 int app_external_count = 0; | 314 int app_external_count = 0; |
| 272 int hosted_app_count = 0; | 315 int hosted_app_count = 0; |
| 273 int legacy_packaged_app_count = 0; | 316 int legacy_packaged_app_count = 0; |
| 274 int platform_app_count = 0; | 317 int platform_app_count = 0; |
| 275 int user_script_count = 0; | 318 int user_script_count = 0; |
| 276 int content_pack_count = 0; | 319 int content_pack_count = 0; |
| (...skipping 207 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 484 int InstalledLoader::GetCreationFlags(const ExtensionInfo* info) { | 527 int InstalledLoader::GetCreationFlags(const ExtensionInfo* info) { |
| 485 int flags = extension_prefs_->GetCreationFlags(info->extension_id); | 528 int flags = extension_prefs_->GetCreationFlags(info->extension_id); |
| 486 if (!Manifest::IsUnpackedLocation(info->extension_location)) | 529 if (!Manifest::IsUnpackedLocation(info->extension_location)) |
| 487 flags |= Extension::REQUIRE_KEY; | 530 flags |= Extension::REQUIRE_KEY; |
| 488 if (extension_prefs_->AllowFileAccess(info->extension_id)) | 531 if (extension_prefs_->AllowFileAccess(info->extension_id)) |
| 489 flags |= Extension::ALLOW_FILE_ACCESS; | 532 flags |= Extension::ALLOW_FILE_ACCESS; |
| 490 return flags; | 533 return flags; |
| 491 } | 534 } |
| 492 | 535 |
| 493 } // namespace extensions | 536 } // namespace extensions |
| OLD | NEW |