diff options
author | dpolukhin@chromium.org <dpolukhin@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2011-04-15 18:30:03 +0000 |
---|---|---|
committer | dpolukhin@chromium.org <dpolukhin@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2011-04-15 18:30:03 +0000 |
commit | 0436b1051562d498cacdf89c523293416d025038 (patch) | |
tree | 419595c4befcd2900bdb37a78c67401920b0dc07 | |
parent | 89398efa93833889426490b1010b37534d5b3dfc (diff) | |
download | chromium_src-0436b1051562d498cacdf89c523293416d025038.zip chromium_src-0436b1051562d498cacdf89c523293416d025038.tar.gz chromium_src-0436b1051562d498cacdf89c523293416d025038.tar.bz2 |
Put back "Enable component extensions for DefaultProfile used in login screen dialogs"
Initial commit: http://src.chromium.org/viewvc/chrome?view=rev&revision=79526
BUG=chromium-os:12741
TEST=Run debug Chrome on device
Review URL: http://codereview.chromium.org/6737028
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@81770 0039d316-1c4b-4281-b951-d872f2087c98
20 files changed, 72 insertions, 53 deletions
diff --git a/chrome/browser/browser_main.cc b/chrome/browser/browser_main.cc index e8b96c8..915aba4 100644 --- a/chrome/browser/browser_main.cc +++ b/chrome/browser/browser_main.cc @@ -1448,7 +1448,7 @@ int BrowserMain(const MainFunctionParams& parameters) { // This forces the ProfileManager to be created and register for the // notification it needs to track the logged in user. - g_browser_process->profile_manager()->GetDefaultProfile(); + g_browser_process->profile_manager(); // Allow access to file:// on ChromeOS for tests. if (parsed_command_line.HasSwitch(switches::kAllowFileAccess)) { diff --git a/chrome/browser/chromeos/login/login_browsertest.cc b/chrome/browser/chromeos/login/login_browsertest.cc index 86782cb..ac9dcef 100644 --- a/chrome/browser/chromeos/login/login_browsertest.cc +++ b/chrome/browser/chromeos/login/login_browsertest.cc @@ -90,8 +90,8 @@ IN_PROC_BROWSER_TEST_F(LoginProfileTest, UserNotPassed) { Profile* profile = browser()->profile(); EXPECT_EQ("Default", profile->GetPath().BaseName().value()); EXPECT_TRUE(profile->IsOffTheRecord()); - // Ensure there's no extension service for this profile. - EXPECT_EQ(NULL, profile->GetExtensionService()); + // Ensure there's extension service for this profile. + EXPECT_TRUE(profile->GetExtensionService()); } } // namespace chromeos diff --git a/chrome/browser/extensions/extension_management_api.cc b/chrome/browser/extensions/extension_management_api.cc index 70722bc..62879c4 100644 --- a/chrome/browser/extensions/extension_management_api.cc +++ b/chrome/browser/extensions/extension_management_api.cc @@ -264,10 +264,13 @@ void ExtensionManagementEventRouter::Init() { NotificationType::EXTENSION_UNLOADED }; - for (size_t i = 0; i < arraysize(types); i++) { - registrar_.Add(this, - types[i], - NotificationService::AllSources()); + // Don't re-init (eg in the case of multiple profiles). + if (registrar_.IsEmpty()) { + for (size_t i = 0; i < arraysize(types); i++) { + registrar_.Add(this, + types[i], + NotificationService::AllSources()); + } } } diff --git a/chrome/browser/extensions/extension_process_manager.cc b/chrome/browser/extensions/extension_process_manager.cc index 5eccb76..4a26c5f5 100644 --- a/chrome/browser/extensions/extension_process_manager.cc +++ b/chrome/browser/extensions/extension_process_manager.cc @@ -89,12 +89,13 @@ ExtensionProcessManager* ExtensionProcessManager::Create(Profile* profile) { ExtensionProcessManager::ExtensionProcessManager(Profile* profile) : browsing_instance_(new BrowsingInstance(profile)) { + Profile* original_profile = profile->GetOriginalProfile(); registrar_.Add(this, NotificationType::EXTENSIONS_READY, - NotificationService::AllSources()); + Source<Profile>(original_profile)); registrar_.Add(this, NotificationType::EXTENSION_LOADED, - NotificationService::AllSources()); + Source<Profile>(original_profile)); registrar_.Add(this, NotificationType::EXTENSION_UNLOADED, - NotificationService::AllSources()); + Source<Profile>(original_profile)); registrar_.Add(this, NotificationType::EXTENSION_HOST_DESTROYED, Source<Profile>(profile)); registrar_.Add(this, NotificationType::RENDERER_PROCESS_TERMINATED, diff --git a/chrome/browser/extensions/extension_service.cc b/chrome/browser/extensions/extension_service.cc index 8bf7764..d4d7f8d 100644 --- a/chrome/browser/extensions/extension_service.cc +++ b/chrome/browser/extensions/extension_service.cc @@ -401,12 +401,13 @@ ExtensionService::ExtensionService(Profile* profile, const CommandLine* command_line, const FilePath& install_directory, ExtensionPrefs* extension_prefs, - bool autoupdate_enabled) + bool autoupdate_enabled, + bool extensions_enabled) : profile_(profile), extension_prefs_(extension_prefs), ALLOW_THIS_IN_INITIALIZER_LIST(pending_extension_manager_(*this)), install_directory_(install_directory), - extensions_enabled_(true), + extensions_enabled_(extensions_enabled), show_extensions_prompts_(true), ready_(false), ALLOW_THIS_IN_INITIALIZER_LIST(toolbar_model_(this)), @@ -444,7 +445,7 @@ ExtensionService::ExtensionService(Profile* profile, backend_ = new ExtensionServiceBackend(install_directory_); - if (extensions_enabled()) { + if (extensions_enabled_) { ExternalExtensionProviderImpl::CreateExternalProviders( this, profile_, &external_extension_providers_); } diff --git a/chrome/browser/extensions/extension_service.h b/chrome/browser/extensions/extension_service.h index 6c6ad49..3c5b657 100644 --- a/chrome/browser/extensions/extension_service.h +++ b/chrome/browser/extensions/extension_service.h @@ -146,7 +146,8 @@ class ExtensionService const CommandLine* command_line, const FilePath& install_directory, ExtensionPrefs* extension_prefs, - bool autoupdate_enabled); + bool autoupdate_enabled, + bool extensions_enabled); // Gets the list of currently installed extensions. virtual const ExtensionList* extensions() const; diff --git a/chrome/browser/profiles/profile.cc b/chrome/browser/profiles/profile.cc index 57043c7..57118af 100644 --- a/chrome/browser/profiles/profile.cc +++ b/chrome/browser/profiles/profile.cc @@ -563,7 +563,7 @@ class OffTheRecordProfileImpl : public Profile, virtual void MarkAsCleanShutdown() { } - virtual void InitExtensions() { + virtual void InitExtensions(bool extensions_enabled) { NOTREACHED(); } diff --git a/chrome/browser/profiles/profile.h b/chrome/browser/profiles/profile.h index 9c5df2e..71ea976e 100644 --- a/chrome/browser/profiles/profile.h +++ b/chrome/browser/profiles/profile.h @@ -459,7 +459,10 @@ class Profile { // that it can be invoked when the user logs out/powers down (WM_ENDSESSION). virtual void MarkAsCleanShutdown() = 0; - virtual void InitExtensions() = 0; + // Initializes extensions machinery. + // Component extensions are always enabled, external and user extensions + // are controlled by |extensions_enabled|. + virtual void InitExtensions(bool extensions_enabled) = 0; // Start up service that gathers data from a promo resource feed. virtual void InitPromoResources() = 0; diff --git a/chrome/browser/profiles/profile_impl.cc b/chrome/browser/profiles/profile_impl.cc index 1f7be8e..21923bb 100644 --- a/chrome/browser/profiles/profile_impl.cc +++ b/chrome/browser/profiles/profile_impl.cc @@ -349,7 +349,7 @@ ProfileImpl::ProfileImpl(const FilePath& path) GetPolicyConnector()->Initialize(); } -void ProfileImpl::InitExtensions() { +void ProfileImpl::InitExtensions(bool extensions_enabled) { if (user_script_master_ || extensions_service_) return; // Already initialized. @@ -372,22 +372,31 @@ void ProfileImpl::InitExtensions() { bool autoupdate_enabled = true; #if defined(OS_CHROMEOS) - autoupdate_enabled = !command_line->HasSwitch(switches::kGuestSession); + if (!extensions_enabled) + autoupdate_enabled = false; + else + autoupdate_enabled = !command_line->HasSwitch(switches::kGuestSession); #endif extensions_service_ = new ExtensionService( this, CommandLine::ForCurrentProcess(), GetPath().AppendASCII(ExtensionService::kInstallDirectoryName), extension_prefs_.get(), - autoupdate_enabled); + autoupdate_enabled, + extensions_enabled); RegisterComponentExtensions(); extensions_service_->Init(); - // Load any extensions specified with --load-extension. - if (command_line->HasSwitch(switches::kLoadExtension)) { - FilePath path = command_line->GetSwitchValuePath(switches::kLoadExtension); - extensions_service_->LoadExtension(path); + if (extensions_enabled) { + InstallDefaultApps(); + + // Load any extensions specified with --load-extension. + if (command_line->HasSwitch(switches::kLoadExtension)) { + FilePath path = command_line->GetSwitchValuePath( + switches::kLoadExtension); + extensions_service_->LoadExtension(path); + } } // Make the chrome://extension-icon/ resource available. diff --git a/chrome/browser/profiles/profile_impl.h b/chrome/browser/profiles/profile_impl.h index dcb240f..de95edd 100644 --- a/chrome/browser/profiles/profile_impl.h +++ b/chrome/browser/profiles/profile_impl.h @@ -112,7 +112,7 @@ class ProfileImpl : public Profile, virtual WebKitContext* GetWebKitContext(); virtual StatusTray* GetStatusTray(); virtual void MarkAsCleanShutdown(); - virtual void InitExtensions(); + virtual void InitExtensions(bool extensions_enabled); virtual void InitPromoResources(); virtual void InitRegisteredProtocolHandlers(); virtual NTPResourceCache* GetNTPResourceCache(); diff --git a/chrome/browser/profiles/profile_manager.cc b/chrome/browser/profiles/profile_manager.cc index b893b25..863f4ce 100644 --- a/chrome/browser/profiles/profile_manager.cc +++ b/chrome/browser/profiles/profile_manager.cc @@ -154,11 +154,11 @@ Profile* ProfileManager::GetDefaultProfile(const FilePath& user_data_dir) { // TODO(davemoore) Fix the tests so they allow OTR profiles. if (!command_line.HasSwitch(switches::kTestType) || command_line.HasSwitch(switches::kLoginProfile)) { - // Don't init extensions for this profile - profile = GetProfile(default_profile_dir, false); + // Init only component extensions login profile. + profile = GetProfileImpl(default_profile_dir, false); profile = profile->GetOffTheRecordProfile(); } else { - profile = GetProfile(default_profile_dir, true); + profile = GetProfileImpl(default_profile_dir, true); } return profile; } @@ -167,7 +167,7 @@ Profile* ProfileManager::GetDefaultProfile(const FilePath& user_data_dir) { } Profile* ProfileManager::GetProfile(const FilePath& profile_dir) { - return GetProfile(profile_dir, true); + return GetProfileImpl(profile_dir, true); } Profile* ProfileManager::GetProfileWithId(ProfileId profile_id) { @@ -195,8 +195,8 @@ bool ProfileManager::IsValidProfile(Profile* profile) { return false; } -Profile* ProfileManager::GetProfile( - const FilePath& profile_dir, bool init_extensions) { +Profile* ProfileManager::GetProfileImpl( + const FilePath& profile_dir, bool extensions_enabled) { // If the profile is already loaded (e.g., chrome.exe launched twice), just // return it. Profile* profile = GetProfileByPath(profile_dir); @@ -212,7 +212,7 @@ Profile* ProfileManager::GetProfile( } DCHECK(profile); if (profile) { - bool result = AddProfile(profile, init_extensions); + bool result = AddProfile(profile, extensions_enabled); DCHECK(result); } return profile; @@ -222,7 +222,7 @@ void ProfileManager::RegisterProfile(Profile* profile) { profiles_.insert(profiles_.end(), profile); } -bool ProfileManager::AddProfile(Profile* profile, bool init_extensions) { +bool ProfileManager::AddProfile(Profile* profile, bool extensions_enabled) { DCHECK(profile); // Make sure that we're not loading a profile with the same ID as a profile @@ -235,8 +235,7 @@ bool ProfileManager::AddProfile(Profile* profile, bool init_extensions) { } profiles_.insert(profiles_.end(), profile); - if (init_extensions) - profile->InitExtensions(); + profile->InitExtensions(extensions_enabled); const CommandLine& command_line = *CommandLine::ForCurrentProcess(); if (!command_line.HasSwitch(switches::kDisableWebResources)) profile->InitPromoResources(); diff --git a/chrome/browser/profiles/profile_manager.h b/chrome/browser/profiles/profile_manager.h index c90834f..504e788 100644 --- a/chrome/browser/profiles/profile_manager.h +++ b/chrome/browser/profiles/profile_manager.h @@ -52,15 +52,6 @@ class ProfileManager : public base::NonThreadSafe, // profile. bool IsValidProfile(Profile* profile); - // Returns a profile for a specific profile directory within the user data - // dir with the option of controlling whether extensions are initialized - // or not. This will return an existing profile it had already been created, - // otherwise it will create and manage it. - // Note that if the profile has already been created, extensions may have - // been initialized. If this matters to you, you should call GetProfileByPath - // first to see if the profile already exists. - Profile* GetProfile(const FilePath& profile_dir, bool init_extensions); - // Returns the directory where the currently active profile is // stored, relative to the user data directory currently in use.. FilePath GetCurrentProfileDir(); @@ -110,6 +101,15 @@ class ProfileManager : public base::NonThreadSafe, private: friend class ExtensionEventRouterForwarderTest; + // Returns a profile for a specific profile directory within the user data + // dir with the option of controlling whether extensions are initialized + // or not. This will return an existing profile it had already been created, + // otherwise it will create and manage it. + // Note that if the profile has already been created, extensions may have + // been initialized. If this matters to you, you should call GetProfileByPath + // first to see if the profile already exists. + Profile* GetProfileImpl(const FilePath& profile_dir, bool extensions_enabled); + // Helper method for unit tests to inject |profile| into the ProfileManager. void RegisterProfile(Profile* profile); @@ -117,7 +117,7 @@ class ProfileManager : public base::NonThreadSafe, // ProfileManager. This ProfileManager takes ownership of the Profile. // The Profile should not already be managed by this ProfileManager. // Returns true if the profile was added, false otherwise. - bool AddProfile(Profile* profile, bool init_extensions); + bool AddProfile(Profile* profile, bool extensions_enabled); // We keep a simple vector of profiles rather than something fancier // because we expect there to be a small number of profiles active. diff --git a/chrome/browser/sync/glue/app_data_type_controller.cc b/chrome/browser/sync/glue/app_data_type_controller.cc index 713de10..cf025f6 100644 --- a/chrome/browser/sync/glue/app_data_type_controller.cc +++ b/chrome/browser/sync/glue/app_data_type_controller.cc @@ -27,7 +27,7 @@ syncable::ModelType AppDataTypeController::type() const { } bool AppDataTypeController::StartModels() { - profile_->InitExtensions(); + profile_->InitExtensions(true); return true; } diff --git a/chrome/browser/sync/glue/extension_data_type_controller.cc b/chrome/browser/sync/glue/extension_data_type_controller.cc index 1177eab..07d4d1c 100644 --- a/chrome/browser/sync/glue/extension_data_type_controller.cc +++ b/chrome/browser/sync/glue/extension_data_type_controller.cc @@ -27,7 +27,7 @@ syncable::ModelType ExtensionDataTypeController::type() const { } bool ExtensionDataTypeController::StartModels() { - profile_->InitExtensions(); + profile_->InitExtensions(true); return true; } diff --git a/chrome/browser/sync/glue/theme_data_type_controller.cc b/chrome/browser/sync/glue/theme_data_type_controller.cc index c2aa400..efcbe11 100644 --- a/chrome/browser/sync/glue/theme_data_type_controller.cc +++ b/chrome/browser/sync/glue/theme_data_type_controller.cc @@ -27,7 +27,7 @@ syncable::ModelType ThemeDataTypeController::type() const { } bool ThemeDataTypeController::StartModels() { - profile_->InitExtensions(); + profile_->InitExtensions(true); return true; } diff --git a/chrome/browser/ui/cocoa/extensions/extension_popup_controller_unittest.mm b/chrome/browser/ui/cocoa/extensions/extension_popup_controller_unittest.mm index 3c183ae..58e35a5 100644 --- a/chrome/browser/ui/cocoa/extensions/extension_popup_controller_unittest.mm +++ b/chrome/browser/ui/cocoa/extensions/extension_popup_controller_unittest.mm @@ -36,7 +36,8 @@ class ExtensionTestingProfile : public TestingProfile { CommandLine::ForCurrentProcess(), GetExtensionsInstallDir(), extension_prefs_.get(), - false); + false, + true); service_->set_extensions_enabled(true); service_->set_show_extensions_prompts(false); service_->ClearProvidersForTesting(); diff --git a/chrome/test/live_sync/live_extensions_sync_test_base.cc b/chrome/test/live_sync/live_extensions_sync_test_base.cc index 691330e..c97da04 100644 --- a/chrome/test/live_sync/live_extensions_sync_test_base.cc +++ b/chrome/test/live_sync/live_extensions_sync_test_base.cc @@ -63,9 +63,9 @@ bool LiveExtensionsSyncTestBase::SetupClients() { return false; for (int i = 0; i < num_clients(); ++i) { - GetProfile(i)->InitExtensions(); + GetProfile(i)->InitExtensions(true); } - verifier()->InitExtensions(); + verifier()->InitExtensions(true); if (!extension_base_dir_.CreateUniqueTempDir()) return false; diff --git a/chrome/test/testing_profile.cc b/chrome/test/testing_profile.cc index e829522..ce16f43 100644 --- a/chrome/test/testing_profile.cc +++ b/chrome/test/testing_profile.cc @@ -360,7 +360,8 @@ ExtensionService* TestingProfile::CreateExtensionService( command_line, install_directory, extension_prefs_.get(), - false); + false, + true); return extensions_service_; } diff --git a/chrome/test/testing_profile.h b/chrome/test/testing_profile.h index b2967f4..f43a87f 100644 --- a/chrome/test/testing_profile.h +++ b/chrome/test/testing_profile.h @@ -242,7 +242,7 @@ class TestingProfile : public Profile { virtual WebKitContext* GetWebKitContext(); virtual WebKitContext* GetOffTheRecordWebKitContext(); virtual void MarkAsCleanShutdown() {} - virtual void InitExtensions() {} + virtual void InitExtensions(bool extensions_enabled) {} virtual void InitPromoResources() {} virtual void InitRegisteredProtocolHandlers() {} virtual NTPResourceCache* GetNTPResourceCache(); diff --git a/chrome_frame/test/net/fake_external_tab.cc b/chrome_frame/test/net/fake_external_tab.cc index a4bd592..9455c77 100644 --- a/chrome_frame/test/net/fake_external_tab.cc +++ b/chrome_frame/test/net/fake_external_tab.cc @@ -223,7 +223,7 @@ void FakeExternalTab::Initialize() { FilePath profile_path(ProfileManager::GetDefaultProfileDir(user_data())); Profile* profile = g_browser_process->profile_manager()->GetProfile( - profile_path, false); + profile_path); // Create the child threads. g_browser_process->db_thread(); g_browser_process->file_thread(); |