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 "chrome/browser/profiles/profile_keyed_service.h" | 17 #include "chrome/browser/profiles/profile_keyed_service.h" |
| 18 #include "content/public/browser/notification_observer.h" |
| 19 #include "content/public/browser/notification_registrar.h" |
18 #include "ui/base/theme_provider.h" | 20 #include "ui/base/theme_provider.h" |
19 | 21 |
20 class BrowserThemePack; | 22 class BrowserThemePack; |
21 class ThemeServiceTest; | 23 class ThemeServiceTest; |
22 class ThemeSyncableService; | 24 class ThemeSyncableService; |
23 class FilePath; | 25 class FilePath; |
24 class Profile; | 26 class Profile; |
25 | 27 |
26 namespace color_utils { | 28 namespace color_utils { |
27 struct HSL; | 29 struct HSL; |
(...skipping 12 matching lines...) Expand all Loading... |
40 } | 42 } |
41 | 43 |
42 #ifdef __OBJC__ | 44 #ifdef __OBJC__ |
43 @class NSString; | 45 @class NSString; |
44 // Sent whenever the browser theme changes. Object => NSValue wrapping the | 46 // Sent whenever the browser theme changes. Object => NSValue wrapping the |
45 // ThemeService that changed. | 47 // ThemeService that changed. |
46 extern "C" NSString* const kBrowserThemeDidChangeNotification; | 48 extern "C" NSString* const kBrowserThemeDidChangeNotification; |
47 #endif // __OBJC__ | 49 #endif // __OBJC__ |
48 | 50 |
49 class ThemeService : public base::NonThreadSafe, | 51 class ThemeService : public base::NonThreadSafe, |
| 52 public content::NotificationObserver, |
50 public ProfileKeyedService, | 53 public ProfileKeyedService, |
51 public ui::ThemeProvider { | 54 public ui::ThemeProvider { |
52 public: | 55 public: |
53 // Public constants used in ThemeService and its subclasses: | 56 // Public constants used in ThemeService and its subclasses: |
54 | 57 |
55 // Strings used in alignment properties. | 58 // Strings used in alignment properties. |
56 static const char* kAlignmentCenter; | 59 static const char* kAlignmentCenter; |
57 static const char* kAlignmentTop; | 60 static const char* kAlignmentTop; |
58 static const char* kAlignmentBottom; | 61 static const char* kAlignmentBottom; |
59 static const char* kAlignmentLeft; | 62 static const char* kAlignmentLeft; |
(...skipping 113 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
173 virtual NSGradient* GetNSGradient(int id) const OVERRIDE; | 176 virtual NSGradient* GetNSGradient(int id) const OVERRIDE; |
174 #elif defined(OS_POSIX) && !defined(TOOLKIT_VIEWS) && !defined(OS_ANDROID) | 177 #elif defined(OS_POSIX) && !defined(TOOLKIT_VIEWS) && !defined(OS_ANDROID) |
175 // This mismatch between what this class defines and whether or not it | 178 // This mismatch between what this class defines and whether or not it |
176 // overrides ui::ThemeProvider is http://crbug.com/105040 . | 179 // overrides ui::ThemeProvider is http://crbug.com/105040 . |
177 // GdkPixbufs returned by GetPixbufNamed and GetRTLEnabledPixbufNamed are | 180 // GdkPixbufs returned by GetPixbufNamed and GetRTLEnabledPixbufNamed are |
178 // shared instances owned by the theme provider and should not be freed. | 181 // shared instances owned by the theme provider and should not be freed. |
179 virtual GdkPixbuf* GetRTLEnabledPixbufNamed(int id) const OVERRIDE; | 182 virtual GdkPixbuf* GetRTLEnabledPixbufNamed(int id) const OVERRIDE; |
180 #endif | 183 #endif |
181 | 184 |
182 // Set the current theme to the theme defined in |extension|. | 185 // Set the current theme to the theme defined in |extension|. |
183 // |extension| must already be added to this profile's | |
184 // ExtensionService. | |
185 virtual void SetTheme(const extensions::Extension* extension); | 186 virtual void SetTheme(const extensions::Extension* extension); |
186 | 187 |
187 // Reset the theme to default. | 188 // Reset the theme to default. |
188 virtual void UseDefaultTheme(); | 189 virtual void UseDefaultTheme(); |
189 | 190 |
190 // Set the current theme to the native theme. On some platforms, the native | 191 // Set the current theme to the native theme. On some platforms, the native |
191 // theme is the default theme. | 192 // theme is the default theme. |
192 virtual void SetNativeTheme(); | 193 virtual void SetNativeTheme(); |
193 | 194 |
194 // Whether we're using the chrome default theme. Virtual so linux can check | 195 // Whether we're using the chrome default theme. Virtual so linux can check |
(...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
266 // Let all the browser views know that themes have changed in a platform way. | 267 // Let all the browser views know that themes have changed in a platform way. |
267 virtual void NotifyPlatformThemeChanged(); | 268 virtual void NotifyPlatformThemeChanged(); |
268 #endif // OS_MACOSX | 269 #endif // OS_MACOSX |
269 | 270 |
270 // Clears the platform-specific caches. Do not call directly; it's called | 271 // Clears the platform-specific caches. Do not call directly; it's called |
271 // from ClearCaches(). | 272 // from ClearCaches(). |
272 virtual void FreePlatformCaches(); | 273 virtual void FreePlatformCaches(); |
273 | 274 |
274 Profile* profile() { return profile_; } | 275 Profile* profile() { return profile_; } |
275 | 276 |
| 277 // content::NotificationObserver: |
| 278 virtual void Observe(int type, |
| 279 const content::NotificationSource& source, |
| 280 const content::NotificationDetails& details) OVERRIDE; |
| 281 |
276 private: | 282 private: |
277 friend class ThemeServiceTest; | 283 friend class ThemeServiceTest; |
278 | 284 |
279 // Saves the filename of the cached theme pack. | 285 // Saves the filename of the cached theme pack. |
280 void SavePackName(const FilePath& pack_path); | 286 void SavePackName(const FilePath& pack_path); |
281 | 287 |
282 // Save the id of the last theme installed. | 288 // Save the id of the last theme installed. |
283 void SaveThemeID(const std::string& id); | 289 void SaveThemeID(const std::string& id); |
284 | 290 |
285 // Implementation of SetTheme() (and the fallback from LoadThemePrefs() in | 291 // Implementation of SetTheme() (and the fallback from LoadThemePrefs() in |
(...skipping 21 matching lines...) Expand all Loading... |
307 #endif | 313 #endif |
308 | 314 |
309 ui::ResourceBundle& rb_; | 315 ui::ResourceBundle& rb_; |
310 Profile* profile_; | 316 Profile* profile_; |
311 | 317 |
312 scoped_refptr<BrowserThemePack> theme_pack_; | 318 scoped_refptr<BrowserThemePack> theme_pack_; |
313 | 319 |
314 // The number of infobars currently displayed. | 320 // The number of infobars currently displayed. |
315 int number_of_infobars_; | 321 int number_of_infobars_; |
316 | 322 |
| 323 content::NotificationRegistrar registrar_; |
| 324 |
317 scoped_ptr<ThemeSyncableService> theme_syncable_service_; | 325 scoped_ptr<ThemeSyncableService> theme_syncable_service_; |
318 | 326 |
319 DISALLOW_COPY_AND_ASSIGN(ThemeService); | 327 DISALLOW_COPY_AND_ASSIGN(ThemeService); |
320 }; | 328 }; |
321 | 329 |
322 #endif // CHROME_BROWSER_THEMES_THEME_SERVICE_H_ | 330 #endif // CHROME_BROWSER_THEMES_THEME_SERVICE_H_ |
OLD | NEW |