Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(4375)

Unified Diff: chrome/browser/themes/theme_service_factory.cc

Issue 6766004: Create a ProfileDependencyManager to order ProfileKeyedService destruction. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Fix improper usage of static_cast<> in existing mac code. Created 9 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: chrome/browser/themes/theme_service_factory.cc
diff --git a/chrome/browser/themes/theme_service_factory.cc b/chrome/browser/themes/theme_service_factory.cc
index f93b838a1592c19173395c508ccdafdaceb1de2c..3a9e4b9e724b49e4746a888386e6d0df689d31ed 100644
--- a/chrome/browser/themes/theme_service_factory.cc
+++ b/chrome/browser/themes/theme_service_factory.cc
@@ -7,6 +7,7 @@
#include "base/logging.h"
#include "chrome/browser/extensions/extension_service.h"
#include "chrome/browser/profiles/profile.h"
+#include "chrome/browser/profiles/profile_dependency_manager.h"
#include "chrome/browser/themes/theme_service.h"
#include "content/common/notification_service.h"
@@ -15,28 +16,9 @@
#endif
// static
-ThemeService* ThemeServiceFactory::GetForProfile(Profile* top_profile) {
- // We may be asked for the Theme of an incognito profile. Make sure we're
- // operating on the real profile.
- Profile* profile = top_profile->GetOriginalProfile();
-
- ThemeServiceFactory* service = GetInstance();
-
- std::map<Profile*, ThemeService*>::const_iterator it =
- service->mapping_.find(profile);
- if (it != service->mapping_.end())
- return it->second;
-
- ThemeService* provider = NULL;
-#if defined(TOOLKIT_USES_GTK)
- provider = new GtkThemeService;
-#else
- provider = new ThemeService;
-#endif
- provider->Init(profile);
-
- service->Associate(profile, provider);
- return provider;
+ThemeService* ThemeServiceFactory::GetForProfile(Profile* profile) {
+ return static_cast<ThemeService*>(
+ GetInstance()->GetServiceForProfile(profile));
}
const Extension* ThemeServiceFactory::GetThemeForProfile(Profile* profile) {
@@ -47,63 +29,35 @@ const Extension* ThemeServiceFactory::GetThemeForProfile(Profile* profile) {
return profile->GetExtensionService()->GetExtensionById(id, false);
}
-void ThemeServiceFactory::ForceAssociationBetween(Profile* top_profile,
+void ThemeServiceFactory::ForceAssociationBetween(Profile* profile,
ThemeService* provider) {
- ThemeServiceFactory* service = GetInstance();
- Profile* profile = top_profile->GetOriginalProfile();
-
- service->Associate(profile, provider);
+ GetInstance()->Associate(profile, provider);
}
ThemeServiceFactory* ThemeServiceFactory::GetInstance() {
return Singleton<ThemeServiceFactory>::get();
}
-ThemeServiceFactory::ThemeServiceFactory() {}
+ThemeServiceFactory::ThemeServiceFactory()
+ : ProfileKeyedServiceFactory(
+ ProfileDependencyManager::GetInstance())
+{}
-ThemeServiceFactory::~ThemeServiceFactory() {
- DCHECK(mapping_.empty());
-}
+ThemeServiceFactory::~ThemeServiceFactory() {}
-void ThemeServiceFactory::Associate(Profile* profile,
- ThemeService* provider) {
- DCHECK(mapping_.find(profile) == mapping_.end());
- mapping_.insert(std::make_pair(profile, provider));
+ProfileKeyedService* ThemeServiceFactory::BuildServiceInstanceFor(
+ Profile* profile) const {
+ ThemeService* provider = NULL;
+#if defined(TOOLKIT_USES_GTK)
+ provider = new GtkThemeService;
+#else
+ provider = new ThemeService;
+#endif
+ provider->Init(profile);
- registrar_.Add(this,
- NotificationType::PROFILE_DESTROYED,
- Source<Profile>(profile));
- registrar_.Add(this,
- NotificationType::THEME_INSTALLED,
- Source<Profile>(profile));
+ return provider;
}
-void ThemeServiceFactory::Observe(NotificationType type,
- const NotificationSource& source,
- const NotificationDetails& details) {
- std::map<Profile*, ThemeService*>::iterator it =
- mapping_.find(Source<Profile>(source).ptr());
- DCHECK(it != mapping_.end());
-
- if (NotificationType::PROFILE_DESTROYED == type) {
- delete it->second;
- mapping_.erase(it);
-
- // Remove ourselves from listening to all notifications because the source
- // profile has been deleted. We have to do this because several unit tests
- // are set up so a Profile is on the same place on the stack multiple
- // times, so while they are different instances, they have the same
- // addresses.
- registrar_.Remove(this,
- NotificationType::PROFILE_DESTROYED,
- source);
- registrar_.Remove(this,
- NotificationType::THEME_INSTALLED,
- source);
- } else if (NotificationType::THEME_INSTALLED == type) {
- const Extension* extension = Details<const Extension>(details).ptr();
- it->second->SetTheme(extension);
- } else {
- NOTREACHED();
- }
+bool ThemeServiceFactory::ServiceRedirectedInIncognito() {
+ return true;
}
« no previous file with comments | « chrome/browser/themes/theme_service_factory.h ('k') | chrome/browser/ui/cocoa/bookmarks/bookmark_bar_controller.mm » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698