diff options
Diffstat (limited to 'chrome/browser/profiles')
-rw-r--r-- | chrome/browser/profiles/profile.cc | 12 | ||||
-rw-r--r-- | chrome/browser/profiles/profile.h | 4 | ||||
-rw-r--r-- | chrome/browser/profiles/profile_dependency_manager_unittest.cc | 18 | ||||
-rw-r--r-- | chrome/browser/profiles/profile_impl.cc | 10 | ||||
-rw-r--r-- | chrome/browser/profiles/profile_impl.h | 2 | ||||
-rw-r--r-- | chrome/browser/profiles/profile_keyed_service_factory.cc | 20 | ||||
-rw-r--r-- | chrome/browser/profiles/profile_keyed_service_factory.h | 28 |
7 files changed, 48 insertions, 46 deletions
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_ |