| OLD | NEW |
| 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #ifndef CHROME_BROWSER_THEMES_THEME_SERVICE_FACTORY_H_ | 5 #ifndef CHROME_BROWSER_THEMES_THEME_SERVICE_FACTORY_H_ |
| 6 #define CHROME_BROWSER_THEMES_THEME_SERVICE_FACTORY_H_ | 6 #define CHROME_BROWSER_THEMES_THEME_SERVICE_FACTORY_H_ |
| 7 | 7 |
| 8 #include <map> | 8 #include <map> |
| 9 | 9 |
| 10 #include "base/memory/singleton.h" | 10 #include "base/memory/singleton.h" |
| 11 #include "chrome/browser/profiles/profile_keyed_service_factory.h" |
| 11 #include "content/common/notification_observer.h" | 12 #include "content/common/notification_observer.h" |
| 12 #include "content/common/notification_registrar.h" | 13 #include "content/common/notification_registrar.h" |
| 13 | 14 |
| 14 class ThemeService; | 15 class ThemeService; |
| 15 class Extension; | 16 class Extension; |
| 16 class Profile; | 17 class Profile; |
| 17 | 18 |
| 18 // Singleton that owns all ThemeServices and associates them with | 19 // Singleton that owns all ThemeServices and associates them with |
| 19 // Profiles. Listens for the Profile's destruction notification and cleans up | 20 // Profiles. Listens for the Profile's destruction notification and cleans up |
| 20 // the associated ThemeService. | 21 // the associated ThemeService. |
| 21 class ThemeServiceFactory : public NotificationObserver { | 22 class ThemeServiceFactory : public ProfileKeyedServiceFactory { |
| 22 public: | 23 public: |
| 23 // Returns the ThemeService that provides theming resources for | 24 // Returns the ThemeService that provides theming resources for |
| 24 // |profile|. Note that even if a Profile doesn't have a theme installed, it | 25 // |profile|. Note that even if a Profile doesn't have a theme installed, it |
| 25 // still needs a ThemeService to hand back the default theme images. | 26 // still needs a ThemeService to hand back the default theme images. |
| 26 static ThemeService* GetForProfile(Profile* profile); | 27 static ThemeService* GetForProfile(Profile* profile); |
| 27 | 28 |
| 28 // Returns the Extension that implements the theme associated with | 29 // Returns the Extension that implements the theme associated with |
| 29 // |profile|. Returns NULL if the theme is no longer installed, if there is | 30 // |profile|. Returns NULL if the theme is no longer installed, if there is |
| 30 // no installed theme, or the theme was cleared. | 31 // no installed theme, or the theme was cleared. |
| 31 static const Extension* GetThemeForProfile(Profile* profile); | 32 static const Extension* GetThemeForProfile(Profile* profile); |
| 32 | 33 |
| 33 // Forces an association between |profile| and |provider|. Used in unit tests | 34 // Forces an association between |profile| and |provider|. Used in unit tests |
| 34 // where we need to mock ThemeService. | 35 // where we need to mock ThemeService. |
| 35 static void ForceAssociationBetween(Profile* profile, | 36 static void ForceAssociationBetween(Profile* profile, |
| 36 ThemeService* provider); | 37 ThemeService* provider); |
| 37 | 38 |
| 38 static ThemeServiceFactory* GetInstance(); | 39 static ThemeServiceFactory* GetInstance(); |
| 39 | 40 |
| 40 private: | 41 private: |
| 41 friend struct DefaultSingletonTraits<ThemeServiceFactory>; | 42 friend struct DefaultSingletonTraits<ThemeServiceFactory>; |
| 42 | 43 |
| 43 ThemeServiceFactory(); | 44 ThemeServiceFactory(); |
| 44 ~ThemeServiceFactory(); | 45 virtual ~ThemeServiceFactory(); |
| 45 | 46 |
| 46 // Maps |profile| to |provider| and listens for notifications relating to | 47 // ProfileKeyedServiceFactory: |
| 47 // either. | 48 virtual ProfileKeyedService* BuildServiceInstanceFor(Profile* profile) const; |
| 48 void Associate(Profile* profile, ThemeService* provider); | 49 virtual bool ServiceRedirectedInIncognito(); |
| 49 | |
| 50 // NotificationObserver: | |
| 51 virtual void Observe(NotificationType type, | |
| 52 const NotificationSource& source, | |
| 53 const NotificationDetails& details); | |
| 54 | |
| 55 NotificationRegistrar registrar_; | |
| 56 std::map<Profile*, ThemeService*> mapping_; | |
| 57 }; | 50 }; |
| 58 | 51 |
| 59 #endif // CHROME_BROWSER_THEMES_THEME_SERVICE_FACTORY_H_ | 52 #endif // CHROME_BROWSER_THEMES_THEME_SERVICE_FACTORY_H_ |
| OLD | NEW |