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/threading/non_thread_safe.h" | 16 #include "base/threading/non_thread_safe.h" |
17 #include "components/browser_context_keyed_service/browser_context_keyed_service
.h" | 17 #include "components/browser_context_keyed_service/browser_context_keyed_service
.h" |
18 #include "content/public/browser/notification_observer.h" | 18 #include "content/public/browser/notification_observer.h" |
19 #include "content/public/browser/notification_registrar.h" | 19 #include "content/public/browser/notification_registrar.h" |
20 #include "ui/base/theme_provider.h" | 20 #include "ui/base/theme_provider.h" |
21 | 21 |
| 22 class CustomThemeSupplier; |
22 class BrowserThemePack; | 23 class BrowserThemePack; |
23 class ThemeServiceTest; | |
24 class ThemeSyncableService; | 24 class ThemeSyncableService; |
25 class Profile; | 25 class Profile; |
26 | 26 |
27 namespace base { | 27 namespace base { |
28 class FilePath; | 28 class FilePath; |
29 } | 29 } |
30 | 30 |
31 namespace color_utils { | 31 namespace color_utils { |
32 struct HSL; | 32 struct HSL; |
33 } | 33 } |
34 | 34 |
35 namespace extensions { | 35 namespace extensions { |
36 class Extension; | 36 class Extension; |
37 } | 37 } |
38 | 38 |
39 namespace gfx { | 39 namespace gfx { |
40 class Image; | 40 class Image; |
41 } | 41 } |
42 | 42 |
| 43 namespace theme_service_internal { |
| 44 class ThemeServiceTest; |
| 45 } |
| 46 |
43 namespace ui { | 47 namespace ui { |
44 class ResourceBundle; | 48 class ResourceBundle; |
45 } | 49 } |
46 | 50 |
47 #ifdef __OBJC__ | 51 #ifdef __OBJC__ |
48 @class NSString; | 52 @class NSString; |
49 // Sent whenever the browser theme changes. Object => NSValue wrapping the | 53 // Sent whenever the browser theme changes. Object => NSValue wrapping the |
50 // ThemeService that changed. | 54 // ThemeService that changed. |
51 extern "C" NSString* const kBrowserThemeDidChangeNotification; | 55 extern "C" NSString* const kBrowserThemeDidChangeNotification; |
52 #endif // __OBJC__ | 56 #endif // __OBJC__ |
(...skipping 82 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
135 void RemoveUnusedThemes(); | 139 void RemoveUnusedThemes(); |
136 | 140 |
137 // Returns the syncable service for syncing theme. The returned service is | 141 // Returns the syncable service for syncing theme. The returned service is |
138 // owned by |this| object. | 142 // owned by |this| object. |
139 virtual ThemeSyncableService* GetThemeSyncableService() const; | 143 virtual ThemeSyncableService* GetThemeSyncableService() const; |
140 | 144 |
141 // Save the images to be written to disk, mapping file path to id. | 145 // Save the images to be written to disk, mapping file path to id. |
142 typedef std::map<base::FilePath, int> ImagesDiskCache; | 146 typedef std::map<base::FilePath, int> ImagesDiskCache; |
143 | 147 |
144 protected: | 148 protected: |
| 149 // Set a custom default theme instead of the normal default theme. |
| 150 virtual void SetCustomDefaultTheme( |
| 151 scoped_refptr<CustomThemeSupplier> theme_supplier); |
| 152 |
| 153 // Returns true if the ThemeService should use the native theme on startup. |
| 154 virtual bool ShouldInitWithNativeTheme() const; |
| 155 |
145 // Get the specified tint - |id| is one of the TINT_* enum values. | 156 // Get the specified tint - |id| is one of the TINT_* enum values. |
146 color_utils::HSL GetTint(int id) const; | 157 color_utils::HSL GetTint(int id) const; |
147 | 158 |
148 // Clears all the override fields and saves the dictionary. | 159 // Clears all the override fields and saves the dictionary. |
149 virtual void ClearAllThemeData(); | 160 virtual void ClearAllThemeData(); |
150 | 161 |
151 // Load theme data from preferences. | 162 // Load theme data from preferences. |
152 virtual void LoadThemePrefs(); | 163 virtual void LoadThemePrefs(); |
153 | 164 |
154 // Let all the browser views know that themes have changed. | 165 // Let all the browser views know that themes have changed. |
155 virtual void NotifyThemeChanged(); | 166 virtual void NotifyThemeChanged(); |
156 | 167 |
157 #if defined(OS_MACOSX) | 168 #if defined(OS_MACOSX) |
158 // Let all the browser views know that themes have changed in a platform way. | 169 // Let all the browser views know that themes have changed in a platform way. |
159 virtual void NotifyPlatformThemeChanged(); | 170 virtual void NotifyPlatformThemeChanged(); |
160 #endif // OS_MACOSX | 171 #endif // OS_MACOSX |
161 | 172 |
162 // Clears the platform-specific caches. Do not call directly; it's called | 173 // Clears the platform-specific caches. Do not call directly; it's called |
163 // from ClearCaches(). | 174 // from ClearCaches(). |
164 virtual void FreePlatformCaches(); | 175 virtual void FreePlatformCaches(); |
165 | 176 |
166 Profile* profile() const { return profile_; } | 177 Profile* profile() const { return profile_; } |
167 | 178 |
168 void set_ready() { ready_ = true; } | 179 void set_ready() { ready_ = true; } |
169 | 180 |
| 181 const CustomThemeSupplier* get_theme_supplier() const { |
| 182 return theme_supplier_.get(); |
| 183 } |
| 184 |
170 private: | 185 private: |
171 friend class ThemeServiceTest; | 186 friend class theme_service_internal::ThemeServiceTest; |
| 187 |
| 188 // Replaces the current theme supplier with a new one and calls |
| 189 // StopUsingTheme() or StartUsingTheme() as appropriate. |
| 190 void SwapThemeSupplier(scoped_refptr<CustomThemeSupplier> theme_supplier); |
172 | 191 |
173 // Migrate the theme to the new theme pack schema by recreating the data pack | 192 // Migrate the theme to the new theme pack schema by recreating the data pack |
174 // from the extension. | 193 // from the extension. |
175 void MigrateTheme(); | 194 void MigrateTheme(); |
176 | 195 |
177 // Saves the filename of the cached theme pack. | 196 // Saves the filename of the cached theme pack. |
178 void SavePackName(const base::FilePath& pack_path); | 197 void SavePackName(const base::FilePath& pack_path); |
179 | 198 |
180 // Save the id of the last theme installed. | 199 // Save the id of the last theme installed. |
181 void SaveThemeID(const std::string& id); | 200 void SaveThemeID(const std::string& id); |
182 | 201 |
183 // Implementation of SetTheme() (and the fallback from LoadThemePrefs() in | 202 // Implementation of SetTheme() (and the fallback from LoadThemePrefs() in |
184 // case we don't have a theme pack). | 203 // case we don't have a theme pack). |
185 void BuildFromExtension(const extensions::Extension* extension); | 204 void BuildFromExtension(const extensions::Extension* extension); |
186 | 205 |
187 // Returns true if the profile belongs to a managed user. | 206 // Returns true if the profile belongs to a managed user. |
188 bool IsManagedUser() const; | 207 bool IsManagedUser() const; |
189 | 208 |
| 209 // Sets the current theme to the managed user theme. Should only be used for |
| 210 // managed user profiles. |
| 211 void SetManagedUserTheme(); |
| 212 |
190 #if defined(TOOLKIT_GTK) | 213 #if defined(TOOLKIT_GTK) |
191 // Loads an image and flips it horizontally if |rtl_enabled| is true. | 214 // Loads an image and flips it horizontally if |rtl_enabled| is true. |
192 GdkPixbuf* GetPixbufImpl(int id, bool rtl_enabled) const; | 215 GdkPixbuf* GetPixbufImpl(int id, bool rtl_enabled) const; |
193 #endif | 216 #endif |
194 | 217 |
195 #if defined(TOOLKIT_GTK) | 218 #if defined(TOOLKIT_GTK) |
196 typedef std::map<int, GdkPixbuf*> GdkPixbufMap; | 219 typedef std::map<int, GdkPixbuf*> GdkPixbufMap; |
197 mutable GdkPixbufMap gdk_pixbufs_; | 220 mutable GdkPixbufMap gdk_pixbufs_; |
198 #elif defined(OS_MACOSX) | 221 #elif defined(OS_MACOSX) |
199 typedef std::map<int, NSImage*> NSImageMap; | 222 typedef std::map<int, NSImage*> NSImageMap; |
200 mutable NSImageMap nsimage_cache_; | 223 mutable NSImageMap nsimage_cache_; |
201 | 224 |
202 // The bool member of the pair is whether the color is a default color. | 225 // The bool member of the pair is whether the color is a default color. |
203 typedef std::map<int, std::pair<NSColor*, bool> > NSColorMap; | 226 typedef std::map<int, std::pair<NSColor*, bool> > NSColorMap; |
204 mutable NSColorMap nscolor_cache_; | 227 mutable NSColorMap nscolor_cache_; |
205 | 228 |
206 typedef std::map<int, NSGradient*> NSGradientMap; | 229 typedef std::map<int, NSGradient*> NSGradientMap; |
207 mutable NSGradientMap nsgradient_cache_; | 230 mutable NSGradientMap nsgradient_cache_; |
208 #endif | 231 #endif |
209 | 232 |
210 ui::ResourceBundle& rb_; | 233 ui::ResourceBundle& rb_; |
211 Profile* profile_; | 234 Profile* profile_; |
212 | 235 |
213 // True if the theme service is ready to be used. | 236 // True if the theme service is ready to be used. |
214 // TODO(pkotwicz): Add DCHECKS to the theme service's getters once | 237 // TODO(pkotwicz): Add DCHECKS to the theme service's getters once |
215 // ThemeSource no longer uses the ThemeService when it is not ready. | 238 // ThemeSource no longer uses the ThemeService when it is not ready. |
216 bool ready_; | 239 bool ready_; |
217 | 240 |
218 scoped_refptr<BrowserThemePack> theme_pack_; | 241 scoped_refptr<CustomThemeSupplier> theme_supplier_; |
219 | 242 |
220 // The number of infobars currently displayed. | 243 // The number of infobars currently displayed. |
221 int number_of_infobars_; | 244 int number_of_infobars_; |
222 | 245 |
223 content::NotificationRegistrar registrar_; | 246 content::NotificationRegistrar registrar_; |
224 | 247 |
225 scoped_ptr<ThemeSyncableService> theme_syncable_service_; | 248 scoped_ptr<ThemeSyncableService> theme_syncable_service_; |
226 | 249 |
227 DISALLOW_COPY_AND_ASSIGN(ThemeService); | 250 DISALLOW_COPY_AND_ASSIGN(ThemeService); |
228 }; | 251 }; |
229 | 252 |
230 #endif // CHROME_BROWSER_THEMES_THEME_SERVICE_H_ | 253 #endif // CHROME_BROWSER_THEMES_THEME_SERVICE_H_ |
OLD | NEW |