| 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 107 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 420 CHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 422 CHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| 421 TRACE_EVENT0("browser,startup", "ExtensionService::Init"); | 423 TRACE_EVENT0("browser,startup", "ExtensionService::Init"); |
| 422 SCOPED_UMA_HISTOGRAM_TIMER("Extensions.ExtensionServiceInitTime"); | 424 SCOPED_UMA_HISTOGRAM_TIMER("Extensions.ExtensionServiceInitTime"); |
| 423 | 425 |
| 424 DCHECK(!is_ready()); // Can't redo init. | 426 DCHECK(!is_ready()); // Can't redo init. |
| 425 DCHECK_EQ(registry_->enabled_extensions().size(), 0u); | 427 DCHECK_EQ(registry_->enabled_extensions().size(), 0u); |
| 426 | 428 |
| 427 // LoadAllExtensions() calls OnLoadedInstalledExtensions(). | 429 // LoadAllExtensions() calls OnLoadedInstalledExtensions(). |
| 428 component_loader_->LoadAll(); | 430 component_loader_->LoadAll(); |
| 429 extensions::InstalledLoader(this).LoadAllExtensions(); | 431 extensions::InstalledLoader(this).LoadAllExtensions(); |
| 430 | 432 LoadExtensionsFromCommandLineFlag(switches::kDisableExtensionsExcept); |
| 433 if (extensions_enabled_) |
| 434 LoadExtensionsFromCommandLineFlag(switches::kLoadExtension); |
| 431 EnabledReloadableExtensions(); | 435 EnabledReloadableExtensions(); |
| 432 MaybeFinishShutdownDelayed(); | 436 MaybeFinishShutdownDelayed(); |
| 433 SetReadyAndNotifyListeners(); | 437 SetReadyAndNotifyListeners(); |
| 434 | 438 |
| 435 // TODO(erikkay): this should probably be deferred to a future point | 439 // TODO(erikkay): this should probably be deferred to a future point |
| 436 // rather than running immediately at startup. | 440 // rather than running immediately at startup. |
| 437 CheckForExternalUpdates(); | 441 CheckForExternalUpdates(); |
| 438 | 442 |
| 439 LoadGreylistFromPrefs(); | 443 LoadGreylistFromPrefs(); |
| 440 } | 444 } |
| (...skipping 148 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 589 installer->set_delete_source(file_ownership_passed); | 593 installer->set_delete_source(file_ownership_passed); |
| 590 installer->set_install_cause(extension_misc::INSTALL_CAUSE_UPDATE); | 594 installer->set_install_cause(extension_misc::INSTALL_CAUSE_UPDATE); |
| 591 installer->InstallCrxFile(file); | 595 installer->InstallCrxFile(file); |
| 592 | 596 |
| 593 if (out_crx_installer) | 597 if (out_crx_installer) |
| 594 *out_crx_installer = installer.get(); | 598 *out_crx_installer = installer.get(); |
| 595 | 599 |
| 596 return true; | 600 return true; |
| 597 } | 601 } |
| 598 | 602 |
| 603 void ExtensionService::LoadExtensionsFromCommandLineFlag( |
| 604 const char* switch_name) { |
| 605 if (command_line_->HasSwitch(switch_name)) { |
| 606 base::CommandLine::StringType path_list = |
| 607 command_line_->GetSwitchValueNative(switch_name); |
| 608 base::StringTokenizerT<base::CommandLine::StringType, |
| 609 base::CommandLine::StringType::const_iterator> |
| 610 t(path_list, FILE_PATH_LITERAL(",")); |
| 611 while (t.GetNext()) { |
| 612 std::string extension_id; |
| 613 extensions::UnpackedInstaller::Create(this)->LoadFromCommandLine( |
| 614 base::FilePath(t.token()), &extension_id, false /*only-allow-apps*/); |
| 615 // Extension id is added to whitelist after its extension is loaded |
| 616 // because code is executed asynchronously. |
| 617 if (switch_name == switches::kDisableExtensionsExcept) |
| 618 disable_flag_exempted_extensions_.insert(extension_id); |
| 619 } |
| 620 } |
| 621 } |
| 622 |
| 599 void ExtensionService::ReloadExtensionImpl( | 623 void ExtensionService::ReloadExtensionImpl( |
| 600 // "transient" because the process of reloading may cause the reference | 624 // "transient" because the process of reloading may cause the reference |
| 601 // to become invalid. Instead, use |extension_id|, a copy. | 625 // to become invalid. Instead, use |extension_id|, a copy. |
| 602 const std::string& transient_extension_id, | 626 const std::string& transient_extension_id, |
| 603 bool be_noisy) { | 627 bool be_noisy) { |
| 604 CHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 628 CHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| 605 | 629 |
| 606 // If the extension is already reloading, don't reload again. | 630 // If the extension is already reloading, don't reload again. |
| 607 if (extension_prefs_->GetDisableReasons(transient_extension_id) & | 631 if (extension_prefs_->GetDisableReasons(transient_extension_id) & |
| 608 Extension::DISABLE_RELOAD) { | 632 Extension::DISABLE_RELOAD) { |
| (...skipping 806 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 disable_flag_exempted_extensions_.count(extension->id()) == 0) { |
| 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 |