OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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_H_ | 5 #ifndef CHROME_BROWSER_THEMES_THEME_SERVICE_H_ |
6 #define CHROME_BROWSER_THEMES_THEME_SERVICE_H_ | 6 #define CHROME_BROWSER_THEMES_THEME_SERVICE_H_ |
7 | 7 |
8 #include <map> | 8 #include <map> |
9 #include <set> | 9 #include <set> |
10 #include <string> | 10 #include <string> |
11 #include <utility> | 11 #include <utility> |
12 | 12 |
13 #include "base/compiler_specific.h" | 13 #include "base/compiler_specific.h" |
14 #include "base/memory/ref_counted.h" | 14 #include "base/memory/ref_counted.h" |
15 #include "base/memory/scoped_ptr.h" | 15 #include "base/memory/scoped_ptr.h" |
| 16 #include "base/memory/weak_ptr.h" |
16 #include "base/threading/non_thread_safe.h" | 17 #include "base/threading/non_thread_safe.h" |
17 #include "chrome/browser/profiles/profile_keyed_service.h" | 18 #include "chrome/browser/profiles/profile_keyed_service.h" |
18 #include "content/public/browser/notification_observer.h" | |
19 #include "content/public/browser/notification_registrar.h" | |
20 #include "ui/base/theme_provider.h" | 19 #include "ui/base/theme_provider.h" |
21 | 20 |
22 class BrowserThemePack; | 21 class BrowserThemePack; |
23 class ThemeServiceTest; | 22 class ThemeServiceTest; |
24 class ThemeSyncableService; | 23 class ThemeSyncableService; |
25 class Profile; | 24 class Profile; |
26 | 25 |
27 namespace base { | 26 namespace base { |
28 class FilePath; | 27 class FilePath; |
29 } | 28 } |
(...skipping 15 matching lines...) Expand all Loading... |
45 } | 44 } |
46 | 45 |
47 #ifdef __OBJC__ | 46 #ifdef __OBJC__ |
48 @class NSString; | 47 @class NSString; |
49 // Sent whenever the browser theme changes. Object => NSValue wrapping the | 48 // Sent whenever the browser theme changes. Object => NSValue wrapping the |
50 // ThemeService that changed. | 49 // ThemeService that changed. |
51 extern "C" NSString* const kBrowserThemeDidChangeNotification; | 50 extern "C" NSString* const kBrowserThemeDidChangeNotification; |
52 #endif // __OBJC__ | 51 #endif // __OBJC__ |
53 | 52 |
54 class ThemeService : public base::NonThreadSafe, | 53 class ThemeService : public base::NonThreadSafe, |
55 public content::NotificationObserver, | |
56 public ProfileKeyedService, | 54 public ProfileKeyedService, |
57 public ui::ThemeProvider { | 55 public ui::ThemeProvider { |
58 public: | 56 public: |
59 // Public constants used in ThemeService and its subclasses: | 57 // Public constants used in ThemeService and its subclasses: |
60 static const char* kDefaultThemeID; | 58 static const char* kDefaultThemeID; |
61 | 59 |
62 ThemeService(); | 60 ThemeService(); |
63 virtual ~ThemeService(); | 61 virtual ~ThemeService(); |
64 | 62 |
65 virtual void Init(Profile* profile); | 63 virtual void Init(Profile* profile); |
(...skipping 21 matching lines...) Expand all Loading... |
87 virtual NSColor* GetNSColorTint(int id, bool allow_default) const OVERRIDE; | 85 virtual NSColor* GetNSColorTint(int id, bool allow_default) const OVERRIDE; |
88 virtual NSGradient* GetNSGradient(int id) const OVERRIDE; | 86 virtual NSGradient* GetNSGradient(int id) const OVERRIDE; |
89 #elif defined(OS_POSIX) && !defined(TOOLKIT_VIEWS) && !defined(OS_ANDROID) | 87 #elif defined(OS_POSIX) && !defined(TOOLKIT_VIEWS) && !defined(OS_ANDROID) |
90 // This mismatch between what this class defines and whether or not it | 88 // This mismatch between what this class defines and whether or not it |
91 // overrides ui::ThemeProvider is http://crbug.com/105040 . | 89 // overrides ui::ThemeProvider is http://crbug.com/105040 . |
92 // GdkPixbufs returned by GetPixbufNamed and GetRTLEnabledPixbufNamed are | 90 // GdkPixbufs returned by GetPixbufNamed and GetRTLEnabledPixbufNamed are |
93 // shared instances owned by the theme provider and should not be freed. | 91 // shared instances owned by the theme provider and should not be freed. |
94 virtual GdkPixbuf* GetRTLEnabledPixbufNamed(int id) const OVERRIDE; | 92 virtual GdkPixbuf* GetRTLEnabledPixbufNamed(int id) const OVERRIDE; |
95 #endif | 93 #endif |
96 | 94 |
97 // Overridden from content::NotificationObserver: | |
98 virtual void Observe(int type, | |
99 const content::NotificationSource& source, | |
100 const content::NotificationDetails& details) OVERRIDE; | |
101 | |
102 // Set the current theme to the theme defined in |extension|. | 95 // Set the current theme to the theme defined in |extension|. |
103 // |extension| must already be added to this profile's | 96 // |extension| must already be added to this profile's |
104 // ExtensionService. | 97 // ExtensionService. |
105 virtual void SetTheme(const extensions::Extension* extension); | 98 virtual void SetTheme(const extensions::Extension* extension); |
106 | 99 |
107 // Reset the theme to default. | 100 // Reset the theme to default. |
108 virtual void UseDefaultTheme(); | 101 virtual void UseDefaultTheme(); |
109 | 102 |
110 // Set the current theme to the native theme. On some platforms, the native | 103 // Set the current theme to the native theme. On some platforms, the native |
111 // theme is the default theme. | 104 // theme is the default theme. |
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
163 // from ClearCaches(). | 156 // from ClearCaches(). |
164 virtual void FreePlatformCaches(); | 157 virtual void FreePlatformCaches(); |
165 | 158 |
166 Profile* profile() { return profile_; } | 159 Profile* profile() { return profile_; } |
167 | 160 |
168 void set_ready() { ready_ = true; } | 161 void set_ready() { ready_ = true; } |
169 | 162 |
170 private: | 163 private: |
171 friend class ThemeServiceTest; | 164 friend class ThemeServiceTest; |
172 | 165 |
| 166 void FinishLoadingAfterExtensionsReady(); |
| 167 |
173 // Migrate the theme to the new theme pack schema by recreating the data pack | 168 // Migrate the theme to the new theme pack schema by recreating the data pack |
174 // from the extension. | 169 // from the extension. |
175 void MigrateTheme(); | 170 void MigrateTheme(); |
176 | 171 |
177 // Saves the filename of the cached theme pack. | 172 // Saves the filename of the cached theme pack. |
178 void SavePackName(const base::FilePath& pack_path); | 173 void SavePackName(const base::FilePath& pack_path); |
179 | 174 |
180 // Save the id of the last theme installed. | 175 // Save the id of the last theme installed. |
181 void SaveThemeID(const std::string& id); | 176 void SaveThemeID(const std::string& id); |
182 | 177 |
(...skipping 27 matching lines...) Expand all Loading... |
210 // True if the theme service is ready to be used. | 205 // True if the theme service is ready to be used. |
211 // TODO(pkotwicz): Add DCHECKS to the theme service's getters once | 206 // TODO(pkotwicz): Add DCHECKS to the theme service's getters once |
212 // ThemeSource no longer uses the ThemeService when it is not ready. | 207 // ThemeSource no longer uses the ThemeService when it is not ready. |
213 bool ready_; | 208 bool ready_; |
214 | 209 |
215 scoped_refptr<BrowserThemePack> theme_pack_; | 210 scoped_refptr<BrowserThemePack> theme_pack_; |
216 | 211 |
217 // The number of infobars currently displayed. | 212 // The number of infobars currently displayed. |
218 int number_of_infobars_; | 213 int number_of_infobars_; |
219 | 214 |
220 content::NotificationRegistrar registrar_; | 215 base::WeakPtrFactory<ThemeService> weak_ptr_factory_; |
221 | 216 |
222 scoped_ptr<ThemeSyncableService> theme_syncable_service_; | 217 scoped_ptr<ThemeSyncableService> theme_syncable_service_; |
223 | 218 |
224 DISALLOW_COPY_AND_ASSIGN(ThemeService); | 219 DISALLOW_COPY_AND_ASSIGN(ThemeService); |
225 }; | 220 }; |
226 | 221 |
227 #endif // CHROME_BROWSER_THEMES_THEME_SERVICE_H_ | 222 #endif // CHROME_BROWSER_THEMES_THEME_SERVICE_H_ |
OLD | NEW |