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 <algorithm> | 7 #include <algorithm> |
8 #include <iterator> | 8 #include <iterator> |
9 #include <set> | 9 #include <set> |
10 | 10 |
(...skipping 332 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
343 profile_(profile), | 343 profile_(profile), |
344 system_(extensions::ExtensionSystem::Get(profile)), | 344 system_(extensions::ExtensionSystem::Get(profile)), |
345 extension_prefs_(extension_prefs), | 345 extension_prefs_(extension_prefs), |
346 blacklist_(blacklist), | 346 blacklist_(blacklist), |
347 settings_frontend_(extensions::SettingsFrontend::Create(profile)), | 347 settings_frontend_(extensions::SettingsFrontend::Create(profile)), |
348 pending_extension_manager_(*this), | 348 pending_extension_manager_(*this), |
349 install_directory_(install_directory), | 349 install_directory_(install_directory), |
350 extensions_enabled_(extensions_enabled), | 350 extensions_enabled_(extensions_enabled), |
351 show_extensions_prompts_(true), | 351 show_extensions_prompts_(true), |
352 install_updates_when_idle_(true), | 352 install_updates_when_idle_(true), |
353 ready_(false), | |
354 toolbar_model_(this), | 353 toolbar_model_(this), |
355 menu_manager_(profile), | 354 menu_manager_(profile), |
356 event_routers_initialized_(false), | 355 event_routers_initialized_(false), |
357 update_once_all_providers_are_ready_(false), | 356 update_once_all_providers_are_ready_(false), |
358 browser_terminating_(false), | 357 browser_terminating_(false), |
359 installs_delayed_(false), | 358 installs_delayed_(false), |
360 is_first_run_(false), | 359 is_first_run_(false), |
361 app_sync_bundle_(this), | 360 app_sync_bundle_(this), |
362 extension_sync_bundle_(this) { | 361 extension_sync_bundle_(this) { |
363 CHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 362 CHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
(...skipping 191 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
555 const Extension* extension = blacklisted_extensions_.GetByID(lowercase_id); | 554 const Extension* extension = blacklisted_extensions_.GetByID(lowercase_id); |
556 if (extension) | 555 if (extension) |
557 return extension; | 556 return extension; |
558 } | 557 } |
559 return NULL; | 558 return NULL; |
560 } | 559 } |
561 | 560 |
562 void ExtensionService::Init() { | 561 void ExtensionService::Init() { |
563 CHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 562 CHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
564 | 563 |
565 DCHECK(!ready_); // Can't redo init. | 564 DCHECK(!ready_.has_happened()); // Can't redo init. |
566 DCHECK_EQ(extensions_.size(), 0u); | 565 DCHECK_EQ(extensions_.size(), 0u); |
567 | 566 |
568 const CommandLine* cmd_line = CommandLine::ForCurrentProcess(); | 567 const CommandLine* cmd_line = CommandLine::ForCurrentProcess(); |
569 | 568 |
570 CHECK(!ProfileManager::IsImportProcess(*cmd_line)); | 569 CHECK(!ProfileManager::IsImportProcess(*cmd_line)); |
571 | 570 |
572 if (cmd_line->HasSwitch(switches::kInstallFromWebstore) || | 571 if (cmd_line->HasSwitch(switches::kInstallFromWebstore) || |
573 cmd_line->HasSwitch(switches::kLimitedInstallFromWebstore)) { | 572 cmd_line->HasSwitch(switches::kLimitedInstallFromWebstore)) { |
574 // The sole purpose of this launch is to install a new extension from CWS | 573 // The sole purpose of this launch is to install a new extension from CWS |
575 // and immediately terminate: loading already installed extensions is | 574 // and immediately terminate: loading already installed extensions is |
576 // unnecessary and may interfere with the inline install dialog (e.g. if an | 575 // unnecessary and may interfere with the inline install dialog (e.g. if an |
577 // extension listens to onStartup and opens a window). | 576 // extension listens to onStartup and opens a window). |
578 SetReadyAndNotifyListeners(); | 577 SetReadyAndNotifyListeners(); |
579 } else { | 578 } else { |
580 // TODO(mek): It might be cleaner to do the FinishDelayedInstallInfo stuff | 579 // TODO(mek): It might be cleaner to do the FinishDelayedInstallInfo stuff |
581 // here instead of in installedloader. | 580 // here instead of in installedloader. |
582 if (g_browser_process->profile_manager() && | 581 if (g_browser_process->profile_manager() && |
583 g_browser_process->profile_manager()->will_import()) { | 582 g_browser_process->profile_manager()->will_import()) { |
584 // Do not load any component extensions, since they may conflict with the | 583 // Do not load any component extensions, since they may conflict with the |
585 // import process. | 584 // import process. |
586 | 585 |
587 extensions::InstalledLoader(this).LoadAllExtensions(); | 586 extensions::InstalledLoader(this).LoadAllExtensions(); |
| 587 SetReadyAndNotifyListeners(); |
588 RegisterForImportFinished(); | 588 RegisterForImportFinished(); |
589 } else { | 589 } else { |
590 // In this case, LoadAllExtensions() calls OnLoadedInstalledExtensions(), | 590 // In this case, LoadAllExtensions() calls OnLoadedInstalledExtensions(). |
591 // which calls SetReadyAndNotifyListeners(). | |
592 component_loader_->LoadAll(); | 591 component_loader_->LoadAll(); |
593 extensions::InstalledLoader(this).LoadAllExtensions(); | 592 extensions::InstalledLoader(this).LoadAllExtensions(); |
| 593 SetReadyAndNotifyListeners(); |
594 | 594 |
595 // TODO(erikkay) this should probably be deferred to a future point | 595 // TODO(erikkay) this should probably be deferred to a future point |
596 // rather than running immediately at startup. | 596 // rather than running immediately at startup. |
597 CheckForExternalUpdates(); | 597 CheckForExternalUpdates(); |
598 | 598 |
599 // TODO(erikkay) this should probably be deferred as well. | 599 // TODO(erikkay) this should probably be deferred as well. |
600 GarbageCollectExtensions(); | 600 GarbageCollectExtensions(); |
601 } | 601 } |
602 | 602 |
603 if (extension_prefs_->NeedsStorageGarbageCollection()) { | 603 if (extension_prefs_->NeedsStorageGarbageCollection()) { |
(...skipping 623 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1227 } | 1227 } |
1228 | 1228 |
1229 extensions::SettingsFrontend* ExtensionService::settings_frontend() { | 1229 extensions::SettingsFrontend* ExtensionService::settings_frontend() { |
1230 return settings_frontend_.get(); | 1230 return settings_frontend_.get(); |
1231 } | 1231 } |
1232 | 1232 |
1233 extensions::ContentSettingsStore* ExtensionService::GetContentSettingsStore() { | 1233 extensions::ContentSettingsStore* ExtensionService::GetContentSettingsStore() { |
1234 return extension_prefs()->content_settings_store(); | 1234 return extension_prefs()->content_settings_store(); |
1235 } | 1235 } |
1236 | 1236 |
1237 bool ExtensionService::is_ready() { | |
1238 return ready_; | |
1239 } | |
1240 | |
1241 base::SequencedTaskRunner* ExtensionService::GetFileTaskRunner() { | 1237 base::SequencedTaskRunner* ExtensionService::GetFileTaskRunner() { |
1242 if (file_task_runner_) | 1238 if (file_task_runner_) |
1243 return file_task_runner_; | 1239 return file_task_runner_; |
1244 | 1240 |
1245 // We should be able to interrupt any part of extension install process during | 1241 // We should be able to interrupt any part of extension install process during |
1246 // shutdown. SKIP_ON_SHUTDOWN ensures that not started extension install tasks | 1242 // shutdown. SKIP_ON_SHUTDOWN ensures that not started extension install tasks |
1247 // will be ignored/deleted while we will block on started tasks. | 1243 // will be ignored/deleted while we will block on started tasks. |
1248 std::string token("ext_install-"); | 1244 std::string token("ext_install-"); |
1249 token.append(profile_->GetPath().AsUTF8Unsafe()); | 1245 token.append(profile_->GetPath().AsUTF8Unsafe()); |
1250 file_task_runner_ = BrowserThread::GetBlockingPool()-> | 1246 file_task_runner_ = BrowserThread::GetBlockingPool()-> |
(...skipping 701 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1952 | 1948 |
1953 // TODO(erikkay) should there be a notification for this? We can't use | 1949 // TODO(erikkay) should there be a notification for this? We can't use |
1954 // EXTENSION_UNLOADED since that implies that the extension has been disabled | 1950 // EXTENSION_UNLOADED since that implies that the extension has been disabled |
1955 // or uninstalled, and UnloadAll is just part of shutdown. | 1951 // or uninstalled, and UnloadAll is just part of shutdown. |
1956 } | 1952 } |
1957 | 1953 |
1958 void ExtensionService::ReloadExtensions() { | 1954 void ExtensionService::ReloadExtensions() { |
1959 UnloadAllExtensions(); | 1955 UnloadAllExtensions(); |
1960 component_loader_->LoadAll(); | 1956 component_loader_->LoadAll(); |
1961 extensions::InstalledLoader(this).LoadAllExtensions(); | 1957 extensions::InstalledLoader(this).LoadAllExtensions(); |
| 1958 // Don't call SetReadyAndNotifyListeners() since tests call this multiple |
| 1959 // times. |
1962 } | 1960 } |
1963 | 1961 |
1964 void ExtensionService::GarbageCollectExtensions() { | 1962 void ExtensionService::GarbageCollectExtensions() { |
1965 if (extension_prefs_->pref_service()->ReadOnly()) | 1963 if (extension_prefs_->pref_service()->ReadOnly()) |
1966 return; | 1964 return; |
1967 | 1965 |
1968 if (pending_extension_manager()->HasPendingExtensions()) { | 1966 if (pending_extension_manager()->HasPendingExtensions()) { |
1969 // Don't garbage collect while there are pending installations, which may | 1967 // Don't garbage collect while there are pending installations, which may |
1970 // be using the temporary installation directory. Try to garbage collect | 1968 // be using the temporary installation directory. Try to garbage collect |
1971 // again later. | 1969 // again later. |
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2010 | 2008 |
2011 void ExtensionService::SyncExtensionChangeIfNeeded(const Extension& extension) { | 2009 void ExtensionService::SyncExtensionChangeIfNeeded(const Extension& extension) { |
2012 if (app_sync_bundle_.HandlesApp(extension)) { | 2010 if (app_sync_bundle_.HandlesApp(extension)) { |
2013 app_sync_bundle_.SyncChangeIfNeeded(extension); | 2011 app_sync_bundle_.SyncChangeIfNeeded(extension); |
2014 } else if (extension_sync_bundle_.HandlesExtension(extension)) { | 2012 } else if (extension_sync_bundle_.HandlesExtension(extension)) { |
2015 extension_sync_bundle_.SyncChangeIfNeeded(extension); | 2013 extension_sync_bundle_.SyncChangeIfNeeded(extension); |
2016 } | 2014 } |
2017 } | 2015 } |
2018 | 2016 |
2019 void ExtensionService::SetReadyAndNotifyListeners() { | 2017 void ExtensionService::SetReadyAndNotifyListeners() { |
2020 ready_ = true; | 2018 ready_.MarkHappened(); |
2021 content::NotificationService::current()->Notify( | 2019 content::NotificationService::current()->Notify( |
2022 chrome::NOTIFICATION_EXTENSIONS_READY, | 2020 chrome::NOTIFICATION_EXTENSIONS_READY, |
2023 content::Source<Profile>(profile_), | 2021 content::Source<Profile>(profile_), |
2024 content::NotificationService::NoDetails()); | 2022 content::NotificationService::NoDetails()); |
2025 } | 2023 } |
2026 | 2024 |
2027 void ExtensionService::OnLoadedInstalledExtensions() { | 2025 void ExtensionService::OnLoadedInstalledExtensions() { |
2028 if (updater_) | 2026 if (updater_) |
2029 updater_->Start(); | 2027 updater_->Start(); |
2030 | 2028 |
2031 OnBlacklistUpdated(); | 2029 OnBlacklistUpdated(); |
2032 | |
2033 SetReadyAndNotifyListeners(); | |
2034 } | 2030 } |
2035 | 2031 |
2036 void ExtensionService::AddExtension(const Extension* extension) { | 2032 void ExtensionService::AddExtension(const Extension* extension) { |
2037 // TODO(jstritar): We may be able to get rid of this branch by overriding the | 2033 // TODO(jstritar): We may be able to get rid of this branch by overriding the |
2038 // default extension state to DISABLED when the --disable-extensions flag | 2034 // default extension state to DISABLED when the --disable-extensions flag |
2039 // is set (http://crbug.com/29067). | 2035 // is set (http://crbug.com/29067). |
2040 if (!extensions_enabled() && | 2036 if (!extensions_enabled() && |
2041 !extension->is_theme() && | 2037 !extension->is_theme() && |
2042 extension->location() != Manifest::COMPONENT && | 2038 extension->location() != Manifest::COMPONENT && |
2043 !Manifest::IsExternalLocation(extension->location())) { | 2039 !Manifest::IsExternalLocation(extension->location())) { |
(...skipping 1067 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3111 } | 3107 } |
3112 | 3108 |
3113 void ExtensionService::AddUpdateObserver(extensions::UpdateObserver* observer) { | 3109 void ExtensionService::AddUpdateObserver(extensions::UpdateObserver* observer) { |
3114 update_observers_.AddObserver(observer); | 3110 update_observers_.AddObserver(observer); |
3115 } | 3111 } |
3116 | 3112 |
3117 void ExtensionService::RemoveUpdateObserver( | 3113 void ExtensionService::RemoveUpdateObserver( |
3118 extensions::UpdateObserver* observer) { | 3114 extensions::UpdateObserver* observer) { |
3119 update_observers_.RemoveObserver(observer); | 3115 update_observers_.RemoveObserver(observer); |
3120 } | 3116 } |
OLD | NEW |