summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authortorne@chromium.org <torne@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2011-04-20 12:24:27 +0000
committertorne@chromium.org <torne@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2011-04-20 12:24:27 +0000
commitbc36f2a13642d84acc1a71405f9a5fbb75c74cd5 (patch)
tree8d23d62d17cdc9bf9bcfe4296ad61676d0db8221
parentc2f82a2d33e6b08ca82e3f474cd020dc87bd76f6 (diff)
downloadchromium_src-bc36f2a13642d84acc1a71405f9a5fbb75c74cd5.zip
chromium_src-bc36f2a13642d84acc1a71405f9a5fbb75c74cd5.tar.gz
chromium_src-bc36f2a13642d84acc1a71405f9a5fbb75c74cd5.tar.bz2
Add optional creation to ProfileKeyedServiceFactory.
Add an extra parameter to ProfileKeyedServiceFactory::GetServiceForProfile so that individual service factories can choose whether the service should be created if it doesn't exist. BUG=77155 TEST=existing tests Review URL: http://codereview.chromium.org/6879031 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@82282 0039d316-1c4b-4281-b951-d872f2087c98
-rw-r--r--chrome/browser/background_contents_service_factory.cc2
-rw-r--r--chrome/browser/background_mode_manager_factory.cc2
-rw-r--r--chrome/browser/notifications/desktop_notification_service_factory.cc2
-rw-r--r--chrome/browser/profiles/profile_keyed_service_factory.cc11
-rw-r--r--chrome/browser/profiles/profile_keyed_service_factory.h5
-rw-r--r--chrome/browser/tabs/pinned_tab_service_factory.cc2
-rw-r--r--chrome/browser/themes/theme_service_factory.cc2
7 files changed, 16 insertions, 10 deletions
diff --git a/chrome/browser/background_contents_service_factory.cc b/chrome/browser/background_contents_service_factory.cc
index c30223b..5171201 100644
--- a/chrome/browser/background_contents_service_factory.cc
+++ b/chrome/browser/background_contents_service_factory.cc
@@ -13,7 +13,7 @@
BackgroundContentsService* BackgroundContentsServiceFactory::GetForProfile(
Profile* profile) {
return static_cast<BackgroundContentsService*>(
- GetInstance()->GetServiceForProfile(profile));
+ GetInstance()->GetServiceForProfile(profile, true));
}
// static
diff --git a/chrome/browser/background_mode_manager_factory.cc b/chrome/browser/background_mode_manager_factory.cc
index 7c2870f..9437f3b 100644
--- a/chrome/browser/background_mode_manager_factory.cc
+++ b/chrome/browser/background_mode_manager_factory.cc
@@ -13,7 +13,7 @@
BackgroundModeManager* BackgroundModeManagerFactory::GetForProfile(
Profile* profile) {
return static_cast<BackgroundModeManager*>(
- GetInstance()->GetServiceForProfile(profile));
+ GetInstance()->GetServiceForProfile(profile, true));
}
// static
diff --git a/chrome/browser/notifications/desktop_notification_service_factory.cc b/chrome/browser/notifications/desktop_notification_service_factory.cc
index 1e24345..122b080 100644
--- a/chrome/browser/notifications/desktop_notification_service_factory.cc
+++ b/chrome/browser/notifications/desktop_notification_service_factory.cc
@@ -15,7 +15,7 @@ DesktopNotificationService* DesktopNotificationServiceFactory::GetForProfile(
Profile* profile) {
DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
return static_cast<DesktopNotificationService*>(
- GetInstance()->GetServiceForProfile(profile));
+ GetInstance()->GetServiceForProfile(profile, true));
}
// static
diff --git a/chrome/browser/profiles/profile_keyed_service_factory.cc b/chrome/browser/profiles/profile_keyed_service_factory.cc
index 755409e..8515714 100644
--- a/chrome/browser/profiles/profile_keyed_service_factory.cc
+++ b/chrome/browser/profiles/profile_keyed_service_factory.cc
@@ -23,7 +23,8 @@ ProfileKeyedServiceFactory::~ProfileKeyedServiceFactory() {
}
ProfileKeyedService* ProfileKeyedServiceFactory::GetServiceForProfile(
- Profile* profile) {
+ Profile* profile,
+ bool create) {
// Possibly handle Incognito mode.
if (profile->IsOffTheRecord()) {
if (ServiceRedirectedInIncognito()) {
@@ -41,14 +42,18 @@ ProfileKeyedService* ProfileKeyedServiceFactory::GetServiceForProfile(
mapping_.find(profile);
if (it != mapping_.end()) {
service = it->second;
- if (service || !factory_)
+ if (service || !factory_ || !create)
return service;
// service is NULL but we have a mock factory function
mapping_.erase(it);
service = factory_(profile);
- } else {
+ } else if (create) {
+ // not found but creation allowed
service = BuildServiceInstanceFor(profile);
+ } else {
+ // not found, creation forbidden
+ return NULL;
}
Associate(profile, service);
diff --git a/chrome/browser/profiles/profile_keyed_service_factory.h b/chrome/browser/profiles/profile_keyed_service_factory.h
index 8126207..cc9c3bd 100644
--- a/chrome/browser/profiles/profile_keyed_service_factory.h
+++ b/chrome/browser/profiles/profile_keyed_service_factory.h
@@ -53,8 +53,9 @@ class ProfileKeyedServiceFactory {
// Common implementation that maps |profile| to some service object. Deals
// with incognito profiles per subclass instructions with
- // ServiceActiveInIncognito().
- ProfileKeyedService* GetServiceForProfile(Profile* profile);
+ // ServiceActiveInIncognito(). If |create| is true, the service will be
+ // created using BuildServiceInstanceFor() if it doesn't already exist.
+ ProfileKeyedService* GetServiceForProfile(Profile* profile, bool create);
// The main public interface for declaring dependencies between services
// created by factories.
diff --git a/chrome/browser/tabs/pinned_tab_service_factory.cc b/chrome/browser/tabs/pinned_tab_service_factory.cc
index 13789c6..5ef50a9 100644
--- a/chrome/browser/tabs/pinned_tab_service_factory.cc
+++ b/chrome/browser/tabs/pinned_tab_service_factory.cc
@@ -12,7 +12,7 @@
PinnedTabService* PinnedTabServiceFactory::GetForProfile(
Profile* profile) {
return static_cast<PinnedTabService*>(
- GetInstance()->GetServiceForProfile(profile));
+ GetInstance()->GetServiceForProfile(profile, true));
}
PinnedTabServiceFactory* PinnedTabServiceFactory::GetInstance() {
diff --git a/chrome/browser/themes/theme_service_factory.cc b/chrome/browser/themes/theme_service_factory.cc
index d0ba8eb..861614d 100644
--- a/chrome/browser/themes/theme_service_factory.cc
+++ b/chrome/browser/themes/theme_service_factory.cc
@@ -18,7 +18,7 @@
// static
ThemeService* ThemeServiceFactory::GetForProfile(Profile* profile) {
return static_cast<ThemeService*>(
- GetInstance()->GetServiceForProfile(profile));
+ GetInstance()->GetServiceForProfile(profile, true));
}
// static