Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright (c) 2013 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2013 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/extension_service.h" | 5 #include "chrome/browser/extensions/extension_service.h" |
| 6 | 6 |
| 7 #include <stddef.h> | 7 #include <stddef.h> |
| 8 | 8 |
| 9 #include <algorithm> | 9 #include <algorithm> |
| 10 #include <iterator> | 10 #include <iterator> |
| 11 #include <set> | 11 #include <set> |
| 12 | 12 |
| 13 #include "base/command_line.h" | 13 #include "base/command_line.h" |
| 14 #include "base/location.h" | 14 #include "base/location.h" |
| 15 #include "base/metrics/histogram_macros.h" | 15 #include "base/metrics/histogram_macros.h" |
| 16 #include "base/single_thread_task_runner.h" | 16 #include "base/single_thread_task_runner.h" |
| 17 #include "base/strings/string_number_conversions.h" | 17 #include "base/strings/string_number_conversions.h" |
| 18 #include "base/strings/string_tokenizer.h" | |
| 18 #include "base/strings/stringprintf.h" | 19 #include "base/strings/stringprintf.h" |
| 19 #include "base/strings/utf_string_conversions.h" | 20 #include "base/strings/utf_string_conversions.h" |
| 20 #include "base/threading/sequenced_worker_pool.h" | 21 #include "base/threading/sequenced_worker_pool.h" |
| 21 #include "base/threading/thread_restrictions.h" | 22 #include "base/threading/thread_restrictions.h" |
| 22 #include "base/threading/thread_task_runner_handle.h" | 23 #include "base/threading/thread_task_runner_handle.h" |
| 23 #include "base/time/time.h" | 24 #include "base/time/time.h" |
| 24 #include "base/trace_event/trace_event.h" | 25 #include "base/trace_event/trace_event.h" |
| 25 #include "build/build_config.h" | 26 #include "build/build_config.h" |
| 26 #include "chrome/browser/browser_process.h" | 27 #include "chrome/browser/browser_process.h" |
| 27 #include "chrome/browser/chrome_notification_types.h" | 28 #include "chrome/browser/chrome_notification_types.h" |
| (...skipping 265 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 293 | 294 |
| 294 ExtensionService::ExtensionService(Profile* profile, | 295 ExtensionService::ExtensionService(Profile* profile, |
| 295 const base::CommandLine* command_line, | 296 const base::CommandLine* command_line, |
| 296 const base::FilePath& install_directory, | 297 const base::FilePath& install_directory, |
| 297 extensions::ExtensionPrefs* extension_prefs, | 298 extensions::ExtensionPrefs* extension_prefs, |
| 298 extensions::Blacklist* blacklist, | 299 extensions::Blacklist* blacklist, |
| 299 bool autoupdate_enabled, | 300 bool autoupdate_enabled, |
| 300 bool extensions_enabled, | 301 bool extensions_enabled, |
| 301 extensions::OneShotEvent* ready) | 302 extensions::OneShotEvent* ready) |
| 302 : extensions::Blacklist::Observer(blacklist), | 303 : extensions::Blacklist::Observer(blacklist), |
| 304 command_line_(command_line), | |
| 303 profile_(profile), | 305 profile_(profile), |
| 304 system_(extensions::ExtensionSystem::Get(profile)), | 306 system_(extensions::ExtensionSystem::Get(profile)), |
| 305 extension_prefs_(extension_prefs), | 307 extension_prefs_(extension_prefs), |
| 306 blacklist_(blacklist), | 308 blacklist_(blacklist), |
| 307 registry_(extensions::ExtensionRegistry::Get(profile)), | 309 registry_(extensions::ExtensionRegistry::Get(profile)), |
| 308 pending_extension_manager_(profile), | 310 pending_extension_manager_(profile), |
| 309 install_directory_(install_directory), | 311 install_directory_(install_directory), |
| 310 extensions_enabled_(extensions_enabled), | 312 extensions_enabled_(extensions_enabled), |
| 311 ready_(ready), | 313 ready_(ready), |
| 312 shared_module_service_(new extensions::SharedModuleService(profile_)), | 314 shared_module_service_(new extensions::SharedModuleService(profile_)), |
| (...skipping 96 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 409 if (include_disabled) { | 411 if (include_disabled) { |
| 410 // Include blacklisted and blocked extensions here because there are | 412 // Include blacklisted and blocked extensions here because there are |
| 411 // hundreds of callers of this function, and many might assume that this | 413 // hundreds of callers of this function, and many might assume that this |
| 412 // includes those that have been disabled due to blacklisting or blocking. | 414 // includes those that have been disabled due to blacklisting or blocking. |
| 413 include_mask |= ExtensionRegistry::DISABLED | | 415 include_mask |= ExtensionRegistry::DISABLED | |
| 414 ExtensionRegistry::BLACKLISTED | ExtensionRegistry::BLOCKED; | 416 ExtensionRegistry::BLACKLISTED | ExtensionRegistry::BLOCKED; |
| 415 } | 417 } |
| 416 return registry_->GetExtensionById(id, include_mask); | 418 return registry_->GetExtensionById(id, include_mask); |
| 417 } | 419 } |
| 418 | 420 |
| 421 void ExtensionService::LoadExtensionsFromCommandLineFlag( | |
| 422 const char* switch_name) { | |
| 423 if (command_line_->HasSwitch(switch_name)) { | |
| 424 base::CommandLine::StringType path_list = | |
| 425 command_line_->GetSwitchValueNative(switch_name); | |
| 426 base::StringTokenizerT<base::CommandLine::StringType, | |
| 427 base::CommandLine::StringType::const_iterator> | |
| 428 t(path_list, FILE_PATH_LITERAL(",")); | |
| 429 while (t.GetNext()) { | |
| 430 std::string extension_id; | |
| 431 extensions::UnpackedInstaller::Create(this)->LoadFromCommandLine( | |
| 432 base::FilePath(t.token()), &extension_id, false /*only-allow-apps*/); | |
| 433 if (std::strcmp(switch_name, switches::kDisableExtensionsExcept) == 0) { | |
|
Devlin
2016/08/10 19:22:31
Any reason to not compare directly?
catmullings
2016/08/29 20:42:27
Done.
| |
| 434 AddExtensionToExemptedFromDisableFlag(extension_id); | |
|
Devlin
2016/08/10 19:22:31
We should probably add it to the whitelist before
| |
| 435 } | |
| 436 } | |
| 437 } | |
| 438 } | |
| 439 | |
| 419 void ExtensionService::Init() { | 440 void ExtensionService::Init() { |
| 420 CHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 441 CHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| 421 TRACE_EVENT0("browser,startup", "ExtensionService::Init"); | 442 TRACE_EVENT0("browser,startup", "ExtensionService::Init"); |
| 422 SCOPED_UMA_HISTOGRAM_TIMER("Extensions.ExtensionServiceInitTime"); | 443 SCOPED_UMA_HISTOGRAM_TIMER("Extensions.ExtensionServiceInitTime"); |
| 423 | 444 |
| 424 DCHECK(!is_ready()); // Can't redo init. | 445 DCHECK(!is_ready()); // Can't redo init. |
| 425 DCHECK_EQ(registry_->enabled_extensions().size(), 0u); | 446 DCHECK_EQ(registry_->enabled_extensions().size(), 0u); |
| 426 | 447 |
| 448 LoadExtensionsFromCommandLineFlag(switches::kDisableExtensionsExcept); | |
| 427 // LoadAllExtensions() calls OnLoadedInstalledExtensions(). | 449 // LoadAllExtensions() calls OnLoadedInstalledExtensions(). |
| 428 component_loader_->LoadAll(); | 450 component_loader_->LoadAll(); |
| 429 extensions::InstalledLoader(this).LoadAllExtensions(); | 451 if (extensions_enabled_) { |
| 430 | 452 extensions::InstalledLoader(this).LoadAllExtensions(); |
| 453 LoadExtensionsFromCommandLineFlag(switches::kLoadExtension); | |
| 454 } | |
| 431 EnabledReloadableExtensions(); | 455 EnabledReloadableExtensions(); |
| 432 MaybeFinishShutdownDelayed(); | 456 MaybeFinishShutdownDelayed(); |
| 433 SetReadyAndNotifyListeners(); | 457 SetReadyAndNotifyListeners(); |
| 434 | 458 |
| 435 // TODO(erikkay): this should probably be deferred to a future point | 459 // TODO(erikkay): this should probably be deferred to a future point |
| 436 // rather than running immediately at startup. | 460 // rather than running immediately at startup. |
| 437 CheckForExternalUpdates(); | 461 CheckForExternalUpdates(); |
| 438 | 462 |
| 439 LoadGreylistFromPrefs(); | 463 LoadGreylistFromPrefs(); |
| 440 } | 464 } |
| (...skipping 974 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1415 EnableExtension(extension->id()); | 1439 EnableExtension(extension->id()); |
| 1416 } | 1440 } |
| 1417 | 1441 |
| 1418 OnBlacklistUpdated(); | 1442 OnBlacklistUpdated(); |
| 1419 } | 1443 } |
| 1420 | 1444 |
| 1421 void ExtensionService::AddExtension(const Extension* extension) { | 1445 void ExtensionService::AddExtension(const Extension* extension) { |
| 1422 // TODO(jstritar): We may be able to get rid of this branch by overriding the | 1446 // TODO(jstritar): We may be able to get rid of this branch by overriding the |
| 1423 // default extension state to DISABLED when the --disable-extensions flag | 1447 // default extension state to DISABLED when the --disable-extensions flag |
| 1424 // is set (http://crbug.com/29067). | 1448 // is set (http://crbug.com/29067). |
| 1425 if (!extensions_enabled() && | 1449 if (!extensions_enabled() && !extension->is_theme() && |
| 1426 !extension->is_theme() && | |
| 1427 extension->location() != Manifest::COMPONENT && | 1450 extension->location() != Manifest::COMPONENT && |
| 1428 !Manifest::IsExternalLocation(extension->location())) { | 1451 !Manifest::IsExternalLocation(extension->location()) && |
| 1452 !IsExtensionExemptedFromDisableFlag(extension->id())) { | |
| 1429 return; | 1453 return; |
| 1430 } | 1454 } |
| 1431 | 1455 |
| 1432 bool is_extension_upgrade = false; | 1456 bool is_extension_upgrade = false; |
| 1433 bool is_extension_loaded = false; | 1457 bool is_extension_loaded = false; |
| 1434 const Extension* old = GetInstalledExtension(extension->id()); | 1458 const Extension* old = GetInstalledExtension(extension->id()); |
| 1435 if (old) { | 1459 if (old) { |
| 1436 is_extension_loaded = true; | 1460 is_extension_loaded = true; |
| 1437 int version_compare_result = | 1461 int version_compare_result = |
| 1438 extension->version()->CompareTo(*(old->version())); | 1462 extension->version()->CompareTo(*(old->version())); |
| (...skipping 1005 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 2444 } | 2468 } |
| 2445 | 2469 |
| 2446 void ExtensionService::OnProfileDestructionStarted() { | 2470 void ExtensionService::OnProfileDestructionStarted() { |
| 2447 ExtensionIdSet ids_to_unload = registry_->enabled_extensions().GetIDs(); | 2471 ExtensionIdSet ids_to_unload = registry_->enabled_extensions().GetIDs(); |
| 2448 for (ExtensionIdSet::iterator it = ids_to_unload.begin(); | 2472 for (ExtensionIdSet::iterator it = ids_to_unload.begin(); |
| 2449 it != ids_to_unload.end(); | 2473 it != ids_to_unload.end(); |
| 2450 ++it) { | 2474 ++it) { |
| 2451 UnloadExtension(*it, UnloadedExtensionInfo::REASON_PROFILE_SHUTDOWN); | 2475 UnloadExtension(*it, UnloadedExtensionInfo::REASON_PROFILE_SHUTDOWN); |
| 2452 } | 2476 } |
| 2453 } | 2477 } |
| OLD | NEW |