diff options
author | siggi@chromium.org <siggi@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2011-04-12 19:05:42 +0000 |
---|---|---|
committer | siggi@chromium.org <siggi@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2011-04-12 19:05:42 +0000 |
commit | fc1e52d59a43854f9be84dbe1dd03191c67ebaa3 (patch) | |
tree | b7240d58bca7faa802a5c536c129d89bbe9f7ade /chrome | |
parent | 9c5330953b0d6fb7120395b3b1465a789caf6bf9 (diff) | |
download | chromium_src-fc1e52d59a43854f9be84dbe1dd03191c67ebaa3.zip chromium_src-fc1e52d59a43854f9be84dbe1dd03191c67ebaa3.tar.gz chromium_src-fc1e52d59a43854f9be84dbe1dd03191c67ebaa3.tar.bz2 |
Revert 81277 - Profile shouldn't own DesktopNotificationService.DesktopNotificationService is now owned byDesktopNotificationServiceFactory, using Profile as a key. This uses theProfileKeyedService infrastructure originally created forThemeServiceFactory.BUG=77155TEST=existing testsReview URL: http://codereview.chromium.org/6803012
TBR=torne@chromium.org
Review URL: http://codereview.chromium.org/6813116
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@81280 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome')
27 files changed, 106 insertions, 191 deletions
diff --git a/chrome/browser/chromeos/notifications/balloon_view.cc b/chrome/browser/chromeos/notifications/balloon_view.cc index 6246e51..cac419a 100644 --- a/chrome/browser/chromeos/notifications/balloon_view.cc +++ b/chrome/browser/chromeos/notifications/balloon_view.cc @@ -12,7 +12,6 @@ #include "chrome/browser/chromeos/notifications/notification_panel.h" #include "chrome/browser/notifications/balloon.h" #include "chrome/browser/notifications/desktop_notification_service.h" -#include "chrome/browser/notifications/desktop_notification_service_factory.h" #include "chrome/browser/notifications/notification.h" #include "chrome/browser/profiles/profile.h" #include "chrome/browser/ui/views/notifications/balloon_view_host.h" @@ -339,7 +338,7 @@ void BalloonViewImpl::DelayedClose(bool by_user) { void BalloonViewImpl::DenyPermission() { DesktopNotificationService* service = - DesktopNotificationServiceFactory::GetForProfile(balloon_->profile()); + balloon_->profile()->GetDesktopNotificationService(); service->DenyPermission(balloon_->notification().origin_url()); } diff --git a/chrome/browser/content_settings/content_settings_notification_provider.cc b/chrome/browser/content_settings/content_settings_notification_provider.cc index 835bb14..1d81fbe 100644 --- a/chrome/browser/content_settings/content_settings_notification_provider.cc +++ b/chrome/browser/content_settings/content_settings_notification_provider.cc @@ -6,7 +6,6 @@ #include "chrome/browser/content_settings/content_settings_notification_provider.h" #include "base/string_util.h" -#include "chrome/browser/notifications/desktop_notification_service_factory.h" #include "chrome/browser/notifications/notification.h" #include "chrome/browser/notifications/notifications_prefs_cache.h" #include "chrome/browser/notifications/notification_ui_manager.h" @@ -228,7 +227,7 @@ void NotificationProvider::NotifySettingsChange() { NotificationService::current()->Notify( NotificationType::DESKTOP_NOTIFICATION_SETTINGS_CHANGED, Source<DesktopNotificationService>( - DesktopNotificationServiceFactory::GetForProfile(profile_)), + profile_->GetDesktopNotificationService()), NotificationService::NoDetails()); } diff --git a/chrome/browser/desktop_notification_handler.cc b/chrome/browser/desktop_notification_handler.cc index 986425a..8bd2ef2 100644 --- a/chrome/browser/desktop_notification_handler.cc +++ b/chrome/browser/desktop_notification_handler.cc @@ -5,7 +5,6 @@ #include "chrome/browser/desktop_notification_handler.h" #include "chrome/browser/notifications/desktop_notification_service.h" -#include "chrome/browser/notifications/desktop_notification_service_factory.h" #include "chrome/browser/profiles/profile.h" #include "content/browser/renderer_host/render_process_host.h" #include "content/browser/renderer_host/render_view_host.h" @@ -39,7 +38,7 @@ void DesktopNotificationHandler::OnShow( const DesktopNotificationHostMsg_Show_Params& params) { RenderProcessHost* process = render_view_host()->process(); DesktopNotificationService* service = - DesktopNotificationServiceFactory::GetForProfile(process->profile()); + process->profile()->GetDesktopNotificationService(); service->ShowDesktopNotification( params, @@ -51,7 +50,7 @@ void DesktopNotificationHandler::OnShow( void DesktopNotificationHandler::OnCancel(int notification_id) { RenderProcessHost* process = render_view_host()->process(); DesktopNotificationService* service = - DesktopNotificationServiceFactory::GetForProfile(process->profile()); + process->profile()->GetDesktopNotificationService(); service->CancelDesktopNotification( process->id(), @@ -68,7 +67,7 @@ void DesktopNotificationHandler::OnRequestPermission( RenderProcessHost* process = render_view_host()->process(); DesktopNotificationService* service = - DesktopNotificationServiceFactory::GetForProfile(process->profile()); + process->profile()->GetDesktopNotificationService(); service->RequestPermission( source_origin, process->id(), routing_id(), callback_context, NULL); } diff --git a/chrome/browser/extensions/notifications_apitest.cc b/chrome/browser/extensions/notifications_apitest.cc index 22eea07..7e2a34d 100644 --- a/chrome/browser/extensions/notifications_apitest.cc +++ b/chrome/browser/extensions/notifications_apitest.cc @@ -1,11 +1,10 @@ -// Copyright (c) 2011 The Chromium Authors. All rights reserved. +// Copyright (c) 2010 The Chromium Authors. All rights reserved. // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. #include "chrome/browser/extensions/extension_apitest.h" #include "chrome/browser/notifications/desktop_notification_service.h" -#include "chrome/browser/notifications/desktop_notification_service_factory.h" #include "chrome/browser/profiles/profile.h" #include "chrome/browser/ui/browser.h" @@ -17,10 +16,11 @@ IN_PROC_BROWSER_TEST_F(ExtensionApiTest, FLAKY_Notifications) { ASSERT_TRUE(RunExtensionTest("notifications/has_not_permission")) << message_; ASSERT_TRUE(RunExtensionTest("notifications/has_permission_manifest")) << message_; - DesktopNotificationServiceFactory::GetForProfile(browser()->profile()) + browser()->profile()->GetDesktopNotificationService() ->GrantPermission(GURL( "chrome-extension://peoadpeiejnhkmpaakpnompolbglelel")); ASSERT_TRUE(RunExtensionTest("notifications/has_permission_prefs")) << message_; #endif } + diff --git a/chrome/browser/notifications/desktop_notification_service.cc b/chrome/browser/notifications/desktop_notification_service.cc index bfe85ab..ef5bf76 100644 --- a/chrome/browser/notifications/desktop_notification_service.cc +++ b/chrome/browser/notifications/desktop_notification_service.cc @@ -9,7 +9,6 @@ #include "base/utf_string_conversions.h" #include "chrome/browser/content_settings/content_settings_provider.h" #include "chrome/browser/extensions/extension_service.h" -#include "chrome/browser/notifications/desktop_notification_service_factory.h" #include "chrome/browser/notifications/notification.h" #include "chrome/browser/notifications/notification_object_proxy.h" #include "chrome/browser/notifications/notification_ui_manager.h" @@ -188,16 +187,14 @@ string16 NotificationPermissionInfoBarDelegate::GetButtonLabel( bool NotificationPermissionInfoBarDelegate::Accept() { UMA_HISTOGRAM_COUNTS("NotificationPermissionRequest.Allowed", 1); - DesktopNotificationServiceFactory::GetForProfile(profile_)-> - GrantPermission(origin_); + profile_->GetDesktopNotificationService()->GrantPermission(origin_); action_taken_ = true; return true; } bool NotificationPermissionInfoBarDelegate::Cancel() { UMA_HISTOGRAM_COUNTS("NotificationPermissionRequest.Denied", 1); - DesktopNotificationServiceFactory::GetForProfile(profile_)-> - DenyPermission(origin_); + profile_->GetDesktopNotificationService()->DenyPermission(origin_); action_taken_ = true; return true; } diff --git a/chrome/browser/notifications/desktop_notification_service.h b/chrome/browser/notifications/desktop_notification_service.h index 50f28f5..a5c05a9 100644 --- a/chrome/browser/notifications/desktop_notification_service.h +++ b/chrome/browser/notifications/desktop_notification_service.h @@ -16,7 +16,6 @@ #include "chrome/browser/content_settings/content_settings_notification_provider.h" #include "chrome/browser/content_settings/content_settings_provider.h" #include "chrome/browser/prefs/pref_change_registrar.h" -#include "chrome/browser/profiles/profile_keyed_service.h" #include "chrome/common/content_settings.h" #include "content/common/notification_observer.h" #include "content/common/notification_registrar.h" @@ -33,8 +32,7 @@ struct DesktopNotificationHostMsg_Show_Params; // The DesktopNotificationService is an object, owned by the Profile, // which provides the creation of desktop "toasts" to web pages and workers. -class DesktopNotificationService : public NotificationObserver, - public ProfileKeyedService { +class DesktopNotificationService : public NotificationObserver { public: enum DesktopNotificationSource { PageNotification, diff --git a/chrome/browser/notifications/desktop_notification_service_factory.cc b/chrome/browser/notifications/desktop_notification_service_factory.cc deleted file mode 100644 index 1e24345..0000000 --- a/chrome/browser/notifications/desktop_notification_service_factory.cc +++ /dev/null @@ -1,44 +0,0 @@ -// Copyright (c) 2011 The Chromium Authors. All rights reserved. -// Use of this source code is governed by a BSD-style license that can be -// found in the LICENSE file. - -#include "chrome/browser/notifications/desktop_notification_service_factory.h" - -#include "chrome/browser/browser_process.h" -#include "chrome/browser/notifications/desktop_notification_service.h" -#include "chrome/browser/profiles/profile.h" -#include "chrome/browser/profiles/profile_dependency_manager.h" -#include "content/browser/browser_thread.h" - -// static -DesktopNotificationService* DesktopNotificationServiceFactory::GetForProfile( - Profile* profile) { - DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); - return static_cast<DesktopNotificationService*>( - GetInstance()->GetServiceForProfile(profile)); -} - -// static -DesktopNotificationServiceFactory* DesktopNotificationServiceFactory:: - GetInstance() { - return Singleton<DesktopNotificationServiceFactory>::get(); -} - -DesktopNotificationServiceFactory::DesktopNotificationServiceFactory() - : ProfileKeyedServiceFactory(ProfileDependencyManager::GetInstance()) { -} - -DesktopNotificationServiceFactory::~DesktopNotificationServiceFactory() { -} - -ProfileKeyedService* DesktopNotificationServiceFactory::BuildServiceInstanceFor( - Profile* profile) const { - DesktopNotificationService* service = new DesktopNotificationService(profile, - g_browser_process->notification_ui_manager()); - - return service; -} - -bool DesktopNotificationServiceFactory::ServiceHasOwnInstanceInIncognito() { - return true; -} diff --git a/chrome/browser/notifications/desktop_notification_service_factory.h b/chrome/browser/notifications/desktop_notification_service_factory.h deleted file mode 100644 index 10211b2..0000000 --- a/chrome/browser/notifications/desktop_notification_service_factory.h +++ /dev/null @@ -1,39 +0,0 @@ -// Copyright (c) 2011 The Chromium Authors. All rights reserved. -// Use of this source code is governed by a BSD-style license that can be -// found in the LICENSE file. - -#ifndef CHROME_BROWSER_NOTIFICATIONS_DESKTOP_NOTIFICATION_SERVICE_FACTORY_H_ -#define CHROME_BROWSER_NOTIFICATIONS_DESKTOP_NOTIFICATION_SERVICE_FACTORY_H_ - -#include "base/compiler_specific.h" -#include "base/memory/singleton.h" -#include "chrome/browser/profiles/profile_keyed_service_factory.h" - -class DesktopNotificationService; -class Profile; - -// Singleton that owns all DesktopNotificationServices and associates them with -// Profiles. Listens for the Profile's destruction notification and cleans up -// the associated DesktopNotificationService. -class DesktopNotificationServiceFactory : public ProfileKeyedServiceFactory { - public: - // Returns the DesktopNotificationService that provides desktop notifications - // for |profile|. - static DesktopNotificationService* GetForProfile(Profile* profile); - - static DesktopNotificationServiceFactory* GetInstance(); - - private: - friend struct DefaultSingletonTraits<DesktopNotificationServiceFactory>; - - DesktopNotificationServiceFactory(); - virtual ~DesktopNotificationServiceFactory(); - - // ProfileKeyedServiceFactory: - virtual ProfileKeyedService* BuildServiceInstanceFor( - Profile* profile) const OVERRIDE; - // Use a separate desktop notification service for incognito. - virtual bool ServiceHasOwnInstanceInIncognito() OVERRIDE; -}; - -#endif // CHROME_BROWSER_NOTIFICATIONS_DESKTOP_NOTIFICATION_SERVICE_FACTORY_H_ diff --git a/chrome/browser/notifications/desktop_notification_service_unittest.cc b/chrome/browser/notifications/desktop_notification_service_unittest.cc index a8fbbe3..0ad39cb 100644 --- a/chrome/browser/notifications/desktop_notification_service_unittest.cc +++ b/chrome/browser/notifications/desktop_notification_service_unittest.cc @@ -7,7 +7,6 @@ #include "base/memory/ref_counted.h" #include "base/message_loop.h" #include "base/synchronization/waitable_event.h" -#include "chrome/browser/notifications/desktop_notification_service_factory.h" #include "chrome/browser/notifications/notifications_prefs_cache.h" #include "chrome/browser/prefs/pref_service.h" #include "chrome/browser/prefs/scoped_user_pref_update.h" @@ -103,7 +102,7 @@ class DesktopNotificationServiceTest : public RenderViewHostTestHarness { // Creates the service, calls InitPrefs() on it which loads data from the // profile into the cache and then puts the cache in io thread mode. - service_ = DesktopNotificationServiceFactory::GetForProfile(profile()); + service_ = profile()->GetDesktopNotificationService(); cache_ = service_->prefs_cache(); } diff --git a/chrome/browser/notifications/notification_exceptions_table_model_unittest.cc b/chrome/browser/notifications/notification_exceptions_table_model_unittest.cc index 25f2680..6c6c182 100644 --- a/chrome/browser/notifications/notification_exceptions_table_model_unittest.cc +++ b/chrome/browser/notifications/notification_exceptions_table_model_unittest.cc @@ -1,11 +1,10 @@ -// Copyright (c) 2011 The Chromium Authors. All rights reserved. +// Copyright (c) 2010 The Chromium Authors. All rights reserved. // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. #include "chrome/browser/notifications/notification_exceptions_table_model.h" #include "base/utf_string_conversions.h" -#include "chrome/browser/notifications/desktop_notification_service_factory.h" #include "chrome/test/testing_profile.h" #include "content/browser/browser_thread.h" #include "content/browser/renderer_host/test_render_view_host.h" @@ -24,7 +23,7 @@ class NotificationExceptionsTableModelTest : public RenderViewHostTestHarness { virtual void SetUp() { RenderViewHostTestHarness::SetUp(); - service_ = DesktopNotificationServiceFactory::GetForProfile(profile()); + service_ = profile()->GetDesktopNotificationService(); ResetModel(); } diff --git a/chrome/browser/notifications/notification_options_menu_model.cc b/chrome/browser/notifications/notification_options_menu_model.cc index 7024142..0bf7533 100644 --- a/chrome/browser/notifications/notification_options_menu_model.cc +++ b/chrome/browser/notifications/notification_options_menu_model.cc @@ -12,7 +12,6 @@ #include "chrome/browser/notifications/balloon_collection.h" #include "chrome/browser/notifications/balloon_host.h" #include "chrome/browser/notifications/desktop_notification_service.h" -#include "chrome/browser/notifications/desktop_notification_service_factory.h" #include "chrome/browser/notifications/notification.h" #include "chrome/browser/notifications/notification_ui_manager.h" #include "chrome/browser/notifications/notifications_prefs_cache.h" @@ -161,7 +160,7 @@ string16 NotificationOptionsMenuModel::GetLabelForCommandId(int command_id) const GURL& origin = notification.origin_url(); DesktopNotificationService* service = - DesktopNotificationServiceFactory::GetForProfile(balloon_->profile()); + balloon_->profile()->GetDesktopNotificationService(); if (origin.SchemeIs(chrome::kExtensionScheme)) { ExtensionService* ext_service = balloon_->profile()->GetExtensionService(); @@ -211,7 +210,7 @@ bool NotificationOptionsMenuModel::GetAcceleratorForCommandId( void NotificationOptionsMenuModel::ExecuteCommand(int command_id) { DesktopNotificationService* service = - DesktopNotificationServiceFactory::GetForProfile(balloon_->profile()); + balloon_->profile()->GetDesktopNotificationService(); ExtensionService* ext_service = balloon_->profile()->GetExtensionService(); const GURL& origin = balloon_->notification().origin_url(); diff --git a/chrome/browser/profiles/profile.cc b/chrome/browser/profiles/profile.cc index 39460e5..1bd2bd9 100644 --- a/chrome/browser/profiles/profile.cc +++ b/chrome/browser/profiles/profile.cc @@ -23,6 +23,7 @@ #include "chrome/browser/extensions/extension_process_manager.h" #include "chrome/browser/extensions/extension_special_storage_policy.h" #include "chrome/browser/net/pref_proxy_config_service.h" +#include "chrome/browser/notifications/desktop_notification_service.h" #include "chrome/browser/prefs/pref_service.h" #include "chrome/browser/profiles/off_the_record_profile_io_data.h" #include "chrome/browser/profiles/profile_dependency_manager.h" @@ -504,6 +505,14 @@ class OffTheRecordProfileImpl : public Profile, return profile_->GetProtocolHandlerRegistry(); } + virtual DesktopNotificationService* GetDesktopNotificationService() { + if (!desktop_notification_service_.get()) { + desktop_notification_service_.reset(new DesktopNotificationService( + this, g_browser_process->notification_ui_manager())); + } + return desktop_notification_service_.get(); + } + virtual TokenService* GetTokenService() { return NULL; } @@ -693,6 +702,9 @@ class OffTheRecordProfileImpl : public Profile, // The download manager that only stores downloaded items in memory. scoped_refptr<DownloadManager> download_manager_; + // Use a separate desktop notification service for OTR. + scoped_ptr<DesktopNotificationService> desktop_notification_service_; + // We use a non-writable content settings map for OTR. scoped_refptr<HostContentSettingsMap> host_content_settings_map_; diff --git a/chrome/browser/profiles/profile.h b/chrome/browser/profiles/profile.h index 92d14ab..1054aad 100644 --- a/chrome/browser/profiles/profile.h +++ b/chrome/browser/profiles/profile.h @@ -49,6 +49,7 @@ class ChromeAppCacheService; class ChromeBlobStorageContext; class ChromeURLDataManager; class CloudPrintProxyService; +class DesktopNotificationService; class DownloadManager; class Extension; class ExtensionDevToolsManager; @@ -449,6 +450,9 @@ class Profile { // Returns the WebKitContext assigned to this profile. virtual WebKitContext* GetWebKitContext() = 0; + // Returns the provider of desktop notifications for this profile. + virtual DesktopNotificationService* GetDesktopNotificationService() = 0; + // Returns the service that manages BackgroundContents for this profile. virtual BackgroundContentsService* GetBackgroundContentsService() const = 0; diff --git a/chrome/browser/profiles/profile_dependency_manager_unittest.cc b/chrome/browser/profiles/profile_dependency_manager_unittest.cc index 3b99963..c50de50 100644 --- a/chrome/browser/profiles/profile_dependency_manager_unittest.cc +++ b/chrome/browser/profiles/profile_dependency_manager_unittest.cc @@ -6,6 +6,7 @@ #include "chrome/browser/profiles/profile_dependency_manager.h" #include "chrome/browser/profiles/profile_keyed_service_factory.h" +#include "chrome/test/testing_profile.h" class ProfileDependencyManagerUnittests : public ::testing::Test { protected: @@ -21,6 +22,11 @@ class ProfileDependencyManagerUnittests : public ::testing::Test { child->DependsOn(parent); } + void CreateAndDestroyTestProfile() { + TestingProfile profile; + profile.SetProfileDependencyManager(&dependency_manager_); + } + ProfileDependencyManager* manager() { return &dependency_manager_; } std::vector<std::string>* shutdown_order() { return &shutdown_order_; } @@ -60,7 +66,7 @@ class TestService : public ProfileKeyedServiceFactory { TEST_F(ProfileDependencyManagerUnittests, SingleCase) { TestService service("service", shutdown_order(), manager()); - manager()->DestroyProfileServices(NULL); + CreateAndDestroyTestProfile(); ASSERT_EQ(1U, shutdown_order()->size()); EXPECT_STREQ("service", (*shutdown_order())[0].c_str()); @@ -72,7 +78,7 @@ TEST_F(ProfileDependencyManagerUnittests, SimpleDependency) { TestService child("child", shutdown_order(), manager()); DependOn(&child, &parent); - manager()->DestroyProfileServices(NULL); + CreateAndDestroyTestProfile(); ASSERT_EQ(2U, shutdown_order()->size()); EXPECT_STREQ("child", (*shutdown_order())[0].c_str()); @@ -87,7 +93,7 @@ TEST_F(ProfileDependencyManagerUnittests, TwoChildrenOneParent) { DependOn(&child1, &parent); DependOn(&child2, &parent); - manager()->DestroyProfileServices(NULL); + CreateAndDestroyTestProfile(); ASSERT_EQ(3U, shutdown_order()->size()); EXPECT_STREQ("child2", (*shutdown_order())[0].c_str()); @@ -110,7 +116,7 @@ TEST_F(ProfileDependencyManagerUnittests, MConfiguration) { TestService child_of_2("child_of_2", shutdown_order(), manager()); DependOn(&child_of_2, &parent2); - manager()->DestroyProfileServices(NULL); + CreateAndDestroyTestProfile(); ASSERT_EQ(5U, shutdown_order()->size()); EXPECT_STREQ("child_of_2", (*shutdown_order())[0].c_str()); @@ -134,7 +140,7 @@ TEST_F(ProfileDependencyManagerUnittests, DiamondConfiguration) { DependOn(&bottom, &middle_row_1); DependOn(&bottom, &middle_row_2); - manager()->DestroyProfileServices(NULL); + CreateAndDestroyTestProfile(); ASSERT_EQ(4U, shutdown_order()->size()); EXPECT_STREQ("bottom", (*shutdown_order())[0].c_str()); @@ -167,7 +173,7 @@ TEST_F(ProfileDependencyManagerUnittests, ComplexGraph) { DependOn(&bottom, &specialized_service); DependOn(&bottom, &other_intermediary); - manager()->DestroyProfileServices(NULL); + CreateAndDestroyTestProfile(); ASSERT_EQ(6U, shutdown_order()->size()); EXPECT_STREQ("bottom", (*shutdown_order())[0].c_str()); diff --git a/chrome/browser/profiles/profile_impl.cc b/chrome/browser/profiles/profile_impl.cc index 4a71f99..66a28b1 100644 --- a/chrome/browser/profiles/profile_impl.cc +++ b/chrome/browser/profiles/profile_impl.cc @@ -46,6 +46,7 @@ #include "chrome/browser/net/net_pref_observer.h" #include "chrome/browser/net/pref_proxy_config_service.h" #include "chrome/browser/net/ssl_config_service_manager.h" +#include "chrome/browser/notifications/desktop_notification_service.h" #include "chrome/browser/password_manager/password_store_default.h" #include "chrome/browser/policy/configuration_policy_pref_store.h" #include "chrome/browser/policy/configuration_policy_provider.h" @@ -1236,6 +1237,15 @@ WebKitContext* ProfileImpl::GetWebKitContext() { return webkit_context_.get(); } +DesktopNotificationService* ProfileImpl::GetDesktopNotificationService() { + DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); + if (!desktop_notification_service_.get()) { + desktop_notification_service_.reset(new DesktopNotificationService( + this, g_browser_process->notification_ui_manager())); + } + return desktop_notification_service_.get(); +} + void ProfileImpl::MarkAsCleanShutdown() { if (prefs_.get()) { // The session cleanly exited, set kSessionExitedCleanly appropriately. diff --git a/chrome/browser/profiles/profile_impl.h b/chrome/browser/profiles/profile_impl.h index 460e9a66..7e7095f 100644 --- a/chrome/browser/profiles/profile_impl.h +++ b/chrome/browser/profiles/profile_impl.h @@ -111,6 +111,7 @@ class ProfileImpl : public Profile, virtual SpellCheckHost* GetSpellCheckHost(); virtual void ReinitializeSpellCheckHost(bool force); virtual WebKitContext* GetWebKitContext(); + virtual DesktopNotificationService* GetDesktopNotificationService(); virtual BackgroundContentsService* GetBackgroundContentsService() const; virtual StatusTray* GetStatusTray(); virtual void MarkAsCleanShutdown(); @@ -241,6 +242,7 @@ class ProfileImpl : public Profile, scoped_refptr<PasswordStore> password_store_; scoped_refptr<SessionService> session_service_; scoped_refptr<WebKitContext> webkit_context_; + scoped_ptr<DesktopNotificationService> desktop_notification_service_; scoped_ptr<BackgroundContentsService> background_contents_service_; scoped_ptr<BackgroundModeManager> background_mode_manager_; scoped_ptr<StatusTray> status_tray_; diff --git a/chrome/browser/profiles/profile_keyed_service_factory.cc b/chrome/browser/profiles/profile_keyed_service_factory.cc index 755409e..cea66c9 100644 --- a/chrome/browser/profiles/profile_keyed_service_factory.cc +++ b/chrome/browser/profiles/profile_keyed_service_factory.cc @@ -13,7 +13,7 @@ ProfileKeyedServiceFactory::ProfileKeyedServiceFactory( ProfileDependencyManager* manager) - : dependency_manager_(manager), factory_(NULL) { + : dependency_manager_(manager) { dependency_manager_->AddComponent(this); } @@ -35,22 +35,12 @@ ProfileKeyedService* ProfileKeyedServiceFactory::GetServiceForProfile( } } - ProfileKeyedService* service; - std::map<Profile*, ProfileKeyedService*>::iterator it = mapping_.find(profile); - if (it != mapping_.end()) { - service = it->second; - if (service || !factory_) - return service; - - // service is NULL but we have a mock factory function - mapping_.erase(it); - service = factory_(profile); - } else { - service = BuildServiceInstanceFor(profile); - } + if (it != mapping_.end()) + return it->second; + ProfileKeyedService* service = BuildServiceInstanceFor(profile); Associate(profile, service); return service; } @@ -76,7 +66,7 @@ bool ProfileKeyedServiceFactory::ServiceHasOwnInstanceInIncognito() { void ProfileKeyedServiceFactory::ProfileShutdown(Profile* profile) { std::map<Profile*, ProfileKeyedService*>::iterator it = mapping_.find(profile); - if (it != mapping_.end() && it->second) + if (it != mapping_.end()) it->second->Shutdown(); } diff --git a/chrome/browser/profiles/profile_keyed_service_factory.h b/chrome/browser/profiles/profile_keyed_service_factory.h index 8126207..fd33b15 100644 --- a/chrome/browser/profiles/profile_keyed_service_factory.h +++ b/chrome/browser/profiles/profile_keyed_service_factory.h @@ -20,26 +20,10 @@ class ProfileKeyedService; // shutdown/destruction order. In each derived classes' constructors, the // implementors must explicitly state which services are depended on. class ProfileKeyedServiceFactory { - public: - typedef ProfileKeyedService* (*FactoryFunction)(Profile* profile); - -#if defined(UNIT_TEST) - // Associate an already-created |service| with |profile| for this factory. - // The service may be a mock, or may be NULL to inhibit automatic creation of - // the service by the default function. A mock factory set with - // |set_test_factory| will be called instead if the service is NULL. - void ForceAssociationBetween(Profile* profile, ProfileKeyedService* service) { - Associate(profile, service); - } - - // Sets the factory function to use to create mock instances of this service. - // The factory function will only be called for profiles for which - // |ForceAssociationBetween| has been previously called with a NULL service - // pointer, and therefore does not affect normal non-test profiles. - void set_test_factory(FactoryFunction factory) { factory_ = factory; } -#endif - protected: + friend class ProfileDependencyManager; + friend class ProfileDependencyManagerUnittests; + // ProfileKeyedServiceFactories must communicate with a // ProfileDependencyManager. For all non-test code, write your subclass // constructors like this: @@ -90,9 +74,6 @@ class ProfileKeyedServiceFactory { virtual void ProfileDestroyed(Profile* profile); private: - friend class ProfileDependencyManager; - friend class ProfileDependencyManagerUnittests; - // The mapping between a Profile and its service. std::map<Profile*, ProfileKeyedService*> mapping_; @@ -100,9 +81,6 @@ class ProfileKeyedServiceFactory { // this will always be ProfileDependencyManager::GetInstance(), but unit // tests will want to use their own copy. ProfileDependencyManager* dependency_manager_; - - // A mock factory function to use to create the service, used by tests. - FactoryFunction factory_; }; #endif // CHROME_BROWSER_PROFILES_PROFILE_KEYED_SERVICE_FACTORY_H_ diff --git a/chrome/browser/sync/glue/theme_util_unittest.cc b/chrome/browser/sync/glue/theme_util_unittest.cc index d72eb4a..5c83117 100644 --- a/chrome/browser/sync/glue/theme_util_unittest.cc +++ b/chrome/browser/sync/glue/theme_util_unittest.cc @@ -102,8 +102,7 @@ TEST_F(ThemeUtilTest, SetCurrentThemeDefaultTheme) { sync_pb::ThemeSpecifics theme_specifics; TestingProfile profile; MockThemeService* mock_theme_service = new MockThemeService; - ThemeServiceFactory::GetInstance()->ForceAssociationBetween(&profile, - mock_theme_service); + ThemeServiceFactory::ForceAssociationBetween(&profile, mock_theme_service); EXPECT_CALL(*mock_theme_service, UseDefaultTheme()).Times(1); @@ -116,8 +115,7 @@ TEST_F(ThemeUtilTest, SetCurrentThemeSystemTheme) { TestingProfile profile; MockThemeService* mock_theme_service = new MockThemeService; - ThemeServiceFactory::GetInstance()->ForceAssociationBetween(&profile, - mock_theme_service); + ThemeServiceFactory::ForceAssociationBetween(&profile, mock_theme_service); EXPECT_CALL(*mock_theme_service, SetNativeTheme()).Times(1); @@ -217,8 +215,7 @@ TEST_F(ThemeUtilTest, GetThemeSpecificsHelperCustomThemeDistinct) { TEST_F(ThemeUtilTest, SetCurrentThemeIfNecessaryDefaultThemeNotNecessary) { TestingProfile profile; MockThemeService* mock_theme_service = new MockThemeService; - ThemeServiceFactory::GetInstance()->ForceAssociationBetween(&profile, - mock_theme_service); + ThemeServiceFactory::ForceAssociationBetween(&profile, mock_theme_service); EXPECT_CALL(*mock_theme_service, GetThemeID()).WillRepeatedly(Return( ThemeService::kDefaultThemeID)); diff --git a/chrome/browser/themes/theme_service_factory.cc b/chrome/browser/themes/theme_service_factory.cc index d0ba8eb..3a9e4b9 100644 --- a/chrome/browser/themes/theme_service_factory.cc +++ b/chrome/browser/themes/theme_service_factory.cc @@ -21,7 +21,6 @@ ThemeService* ThemeServiceFactory::GetForProfile(Profile* profile) { GetInstance()->GetServiceForProfile(profile)); } -// static const Extension* ThemeServiceFactory::GetThemeForProfile(Profile* profile) { std::string id = GetForProfile(profile)->GetThemeID(); if (id == ThemeService::kDefaultThemeID) @@ -30,7 +29,11 @@ const Extension* ThemeServiceFactory::GetThemeForProfile(Profile* profile) { return profile->GetExtensionService()->GetExtensionById(id, false); } -// static +void ThemeServiceFactory::ForceAssociationBetween(Profile* profile, + ThemeService* provider) { + GetInstance()->Associate(profile, provider); +} + ThemeServiceFactory* ThemeServiceFactory::GetInstance() { return Singleton<ThemeServiceFactory>::get(); } diff --git a/chrome/browser/themes/theme_service_factory.h b/chrome/browser/themes/theme_service_factory.h index 924704b..a837ee8 100644 --- a/chrome/browser/themes/theme_service_factory.h +++ b/chrome/browser/themes/theme_service_factory.h @@ -31,6 +31,11 @@ class ThemeServiceFactory : public ProfileKeyedServiceFactory { // no installed theme, or the theme was cleared. static const Extension* GetThemeForProfile(Profile* profile); + // Forces an association between |profile| and |provider|. Used in unit tests + // where we need to mock ThemeService. + static void ForceAssociationBetween(Profile* profile, + ThemeService* provider); + static ThemeServiceFactory* GetInstance(); private: diff --git a/chrome/browser/ui/cocoa/notifications/balloon_controller.mm b/chrome/browser/ui/cocoa/notifications/balloon_controller.mm index dec0b90..094ec95 100644 --- a/chrome/browser/ui/cocoa/notifications/balloon_controller.mm +++ b/chrome/browser/ui/cocoa/notifications/balloon_controller.mm @@ -11,7 +11,6 @@ #include "base/utf_string_conversions.h" #include "chrome/browser/notifications/balloon.h" #include "chrome/browser/notifications/desktop_notification_service.h" -#include "chrome/browser/notifications/desktop_notification_service_factory.h" #include "chrome/browser/notifications/notification.h" #include "chrome/browser/notifications/notification_options_menu_model.h" #include "chrome/browser/profiles/profile.h" @@ -145,7 +144,7 @@ const int kRightMargin = 2; - (IBAction)permissionRevoked:(id)sender { DesktopNotificationService* service = - DesktopNotificationServiceFactory::GetForProfile(balloon_->profile()); + balloon_->profile()->GetDesktopNotificationService(); service->DenyPermission(balloon_->notification().origin_url()); } diff --git a/chrome/browser/ui/options/options_util.cc b/chrome/browser/ui/options/options_util.cc index 43cd7dd..590c093 100644 --- a/chrome/browser/ui/options/options_util.cc +++ b/chrome/browser/ui/options/options_util.cc @@ -12,7 +12,6 @@ #include "chrome/browser/geolocation/geolocation_content_settings_map.h" #include "chrome/browser/metrics/metrics_service.h" #include "chrome/browser/notifications/desktop_notification_service.h" -#include "chrome/browser/notifications/desktop_notification_service_factory.h" #include "chrome/browser/prefs/pref_service.h" #include "chrome/browser/profiles/profile.h" #include "chrome/common/pref_names.h" @@ -84,8 +83,7 @@ void OptionsUtil::ResetToDefaults(Profile* profile) { profile->GetHostContentSettingsMap()->ResetToDefaults(); profile->GetGeolocationContentSettingsMap()->ResetToDefault(); profile->GetHostZoomMap()->ResetToDefaults(); - DesktopNotificationServiceFactory::GetForProfile(profile)-> - ResetToDefaultContentSetting(); + profile->GetDesktopNotificationService()->ResetToDefaultContentSetting(); for (size_t i = 0; i < arraysize(kUserPrefs); ++i) prefs->ClearPref(kUserPrefs[i]); diff --git a/chrome/browser/ui/webui/options/content_settings_handler.cc b/chrome/browser/ui/webui/options/content_settings_handler.cc index 6bbab55..3c631d2 100644 --- a/chrome/browser/ui/webui/options/content_settings_handler.cc +++ b/chrome/browser/ui/webui/options/content_settings_handler.cc @@ -13,7 +13,6 @@ #include "chrome/browser/content_settings/host_content_settings_map.h" #include "chrome/browser/geolocation/geolocation_content_settings_map.h" #include "chrome/browser/notifications/desktop_notification_service.h" -#include "chrome/browser/notifications/desktop_notification_service_factory.h" #include "chrome/browser/profiles/profile.h" #include "chrome/browser/ui/browser_list.h" #include "chrome/common/chrome_switches.h" @@ -376,8 +375,8 @@ std::string ContentSettingsHandler::GetSettingDefaultFromModel( default_setting = web_ui_->GetProfile()-> GetGeolocationContentSettingsMap()->GetDefaultContentSetting(); } else if (type == CONTENT_SETTINGS_TYPE_NOTIFICATIONS) { - default_setting = DesktopNotificationServiceFactory::GetForProfile( - web_ui_->GetProfile())->GetDefaultContentSetting(); + default_setting = web_ui_->GetProfile()-> + GetDesktopNotificationService()->GetDefaultContentSetting(); } else { default_setting = GetContentSettingsMap()->GetDefaultContentSetting(type); } @@ -391,8 +390,8 @@ bool ContentSettingsHandler::GetDefaultSettingManagedFromModel( return web_ui_->GetProfile()-> GetGeolocationContentSettingsMap()->IsDefaultContentSettingManaged(); } else if (type == CONTENT_SETTINGS_TYPE_NOTIFICATIONS) { - return DesktopNotificationServiceFactory::GetForProfile( - web_ui_->GetProfile())->IsDefaultContentSettingManaged(); + return web_ui_->GetProfile()-> + GetDesktopNotificationService()->IsDefaultContentSettingManaged(); } else { return GetContentSettingsMap()->IsDefaultContentSettingManaged(type); } @@ -492,7 +491,7 @@ void ContentSettingsHandler::UpdateGeolocationExceptionsView() { void ContentSettingsHandler::UpdateNotificationExceptionsView() { DesktopNotificationService* service = - DesktopNotificationServiceFactory::GetForProfile(web_ui_->GetProfile()); + web_ui_->GetProfile()->GetDesktopNotificationService(); std::vector<GURL> allowed(service->GetAllowedOrigins()); std::vector<GURL> blocked(service->GetBlockedOrigins()); @@ -591,7 +590,7 @@ void ContentSettingsHandler::SetContentFilter(const ListValue* args) { web_ui_->GetProfile()->GetGeolocationContentSettingsMap()-> SetDefaultContentSetting(default_setting); } else if (content_type == CONTENT_SETTINGS_TYPE_NOTIFICATIONS) { - DesktopNotificationServiceFactory::GetForProfile(web_ui_->GetProfile())-> + web_ui_->GetProfile()->GetDesktopNotificationService()-> SetDefaultContentSetting(default_setting); } else { GetContentSettingsMap()-> @@ -633,11 +632,11 @@ void ContentSettingsHandler::RemoveException(const ListValue* args) { DCHECK(rv); ContentSetting content_setting = ContentSettingFromString(setting); if (content_setting == CONTENT_SETTING_ALLOW) { - DesktopNotificationServiceFactory::GetForProfile(web_ui_->GetProfile())-> + web_ui_->GetProfile()->GetDesktopNotificationService()-> ResetAllowedOrigin(GURL(origin)); } else { DCHECK_EQ(content_setting, CONTENT_SETTING_BLOCK); - DesktopNotificationServiceFactory::GetForProfile(web_ui_->GetProfile())-> + web_ui_->GetProfile()->GetDesktopNotificationService()-> ResetBlockedOrigin(GURL(origin)); } } else { diff --git a/chrome/chrome_browser.gypi b/chrome/chrome_browser.gypi index 5490be5..1a6d3e3 100644 --- a/chrome/chrome_browser.gypi +++ b/chrome/chrome_browser.gypi @@ -1391,8 +1391,6 @@ 'browser/notifications/balloon_host.h', 'browser/notifications/desktop_notification_service.cc', 'browser/notifications/desktop_notification_service.h', - 'browser/notifications/desktop_notification_service_factory.cc', - 'browser/notifications/desktop_notification_service_factory.h', 'browser/notifications/notification.cc', 'browser/notifications/notification.h', 'browser/notifications/notification_delegate.h', diff --git a/chrome/test/testing_profile.cc b/chrome/test/testing_profile.cc index cab23da..468c051 100644 --- a/chrome/test/testing_profile.cc +++ b/chrome/test/testing_profile.cc @@ -27,7 +27,6 @@ #include "chrome/browser/net/gaia/token_service.h" #include "chrome/browser/net/pref_proxy_config_service.h" #include "chrome/browser/notifications/desktop_notification_service.h" -#include "chrome/browser/notifications/desktop_notification_service_factory.h" #include "chrome/browser/prefs/browser_prefs.h" #include "chrome/browser/prefs/testing_pref_store.h" #include "chrome/browser/prerender/prerender_manager.h" @@ -142,10 +141,6 @@ class TestExtensionURLRequestContextGetter scoped_refptr<net::URLRequestContext> context_; }; -ProfileKeyedService* CreateTestDesktopNotificationService(Profile* profile) { - return new DesktopNotificationService(profile, NULL); -} - } // namespace TestingProfile::TestingProfile() @@ -177,12 +172,6 @@ TestingProfile::TestingProfile() CHECK(temp_dir_.Set(system_tmp_dir)); } } - - // Install profile keyed service factory hooks for dummy/test services - DesktopNotificationServiceFactory::GetInstance()->set_test_factory( - &CreateTestDesktopNotificationService); - DesktopNotificationServiceFactory::GetInstance()->ForceAssociationBetween( - this, NULL); } TestingProfile::~TestingProfile() { @@ -373,6 +362,11 @@ TestingPrefService* TestingProfile::GetTestingPrefService() { return testing_prefs_; } +void TestingProfile::SetProfileDependencyManager( + ProfileDependencyManager* manager) { + profile_dependency_manager_ = manager; +} + ProfileId TestingProfile::GetRuntimeId() { return reinterpret_cast<ProfileId>(this); } @@ -699,6 +693,15 @@ NTPResourceCache* TestingProfile::GetNTPResourceCache() { return ntp_resource_cache_.get(); } +DesktopNotificationService* TestingProfile::GetDesktopNotificationService() { + DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); + if (!desktop_notification_service_.get()) { + desktop_notification_service_.reset(new DesktopNotificationService( + this, NULL)); + } + return desktop_notification_service_.get(); +} + BackgroundContentsService* TestingProfile::GetBackgroundContentsService() const { return NULL; diff --git a/chrome/test/testing_profile.h b/chrome/test/testing_profile.h index 8b519d2..154294f 100644 --- a/chrome/test/testing_profile.h +++ b/chrome/test/testing_profile.h @@ -27,6 +27,7 @@ class SpecialStoragePolicy; class AutocompleteClassifier; class BookmarkModel; class CommandLine; +class DesktopNotificationService; class ExtensionPrefs; class ExtensionPrefStore; class ExtensionPrefValueMap; @@ -129,6 +130,8 @@ class TestingProfile : public Profile { TestingPrefService* GetTestingPrefService(); + void SetProfileDependencyManager(ProfileDependencyManager* manager); + virtual ProfileId GetRuntimeId(); virtual FilePath GetPath(); @@ -247,6 +250,7 @@ class TestingProfile : public Profile { virtual void InitRegisteredProtocolHandlers() {} virtual NTPResourceCache* GetNTPResourceCache(); + virtual DesktopNotificationService* GetDesktopNotificationService(); virtual BackgroundContentsService* GetBackgroundContentsService() const; virtual StatusTray* GetStatusTray(); virtual FilePath last_selected_directory(); @@ -367,6 +371,7 @@ class TestingProfile : public Profile { scoped_refptr<GeolocationContentSettingsMap> geolocation_content_settings_map_; scoped_refptr<GeolocationPermissionContext> geolocation_permission_context_; + scoped_ptr<DesktopNotificationService> desktop_notification_service_; // Find bar state. Created lazily by GetFindBarState(). scoped_ptr<FindBarState> find_bar_state_; |