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

Side by Side Diff: chrome/browser/themes/theme_service.h

Issue 1492423003: Rejigger ThemeService: move exposure of ThemeProvider interface to a (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: fix that unittest Created 5 years 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 unified diff | Download patch
« no previous file with comments | « chrome/browser/themes/theme_properties.cc ('k') | chrome/browser/themes/theme_service.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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/macros.h"
14 #include "base/memory/ref_counted.h" 15 #include "base/memory/ref_counted.h"
15 #include "base/memory/scoped_ptr.h" 16 #include "base/memory/scoped_ptr.h"
16 #include "base/memory/weak_ptr.h" 17 #include "base/memory/weak_ptr.h"
17 #include "base/threading/non_thread_safe.h" 18 #include "base/threading/non_thread_safe.h"
18 #include "components/keyed_service/core/keyed_service.h" 19 #include "components/keyed_service/core/keyed_service.h"
19 #include "content/public/browser/notification_observer.h" 20 #include "content/public/browser/notification_observer.h"
20 #include "content/public/browser/notification_registrar.h" 21 #include "content/public/browser/notification_registrar.h"
21 #include "ui/base/theme_provider.h" 22 #include "ui/base/theme_provider.h"
22 23
23 class CustomThemeSupplier; 24 class CustomThemeSupplier;
(...skipping 27 matching lines...) Expand all
51 52
52 #ifdef __OBJC__ 53 #ifdef __OBJC__
53 @class NSString; 54 @class NSString;
54 // Sent whenever the browser theme changes. Object => NSValue wrapping the 55 // Sent whenever the browser theme changes. Object => NSValue wrapping the
55 // ThemeService that changed. 56 // ThemeService that changed.
56 extern "C" NSString* const kBrowserThemeDidChangeNotification; 57 extern "C" NSString* const kBrowserThemeDidChangeNotification;
57 #endif // __OBJC__ 58 #endif // __OBJC__
58 59
59 class ThemeService : public base::NonThreadSafe, 60 class ThemeService : public base::NonThreadSafe,
60 public content::NotificationObserver, 61 public content::NotificationObserver,
61 public KeyedService, 62 public KeyedService {
62 public ui::ThemeProvider {
63 public: 63 public:
64 // Public constants used in ThemeService and its subclasses: 64 // Public constants used in ThemeService and its subclasses:
65 static const char* kDefaultThemeID; 65 static const char* kDefaultThemeID;
66 66
67 ThemeService(); 67 ThemeService();
68 ~ThemeService() override; 68 ~ThemeService() override;
69 69
70 virtual void Init(Profile* profile); 70 virtual void Init(Profile* profile);
71 71
72 // Returns a cross platform image for an id.
73 //
74 // TODO(erg): Make this part of the ui::ThemeProvider and the main way to get
75 // theme properties out of the theme provider since it's cross platform.
76 virtual gfx::Image GetImageNamed(int id) const;
77
78 // Overridden from ui::ThemeProvider:
79 bool UsingSystemTheme() const override;
80 gfx::ImageSkia* GetImageSkiaNamed(int id) const override;
81 SkColor GetColor(int id) const override;
82 int GetDisplayProperty(int id) const override;
83 bool ShouldUseNativeFrame() const override;
84 bool HasCustomImage(int id) const override;
85 base::RefCountedMemory* GetRawData(int id, ui::ScaleFactor scale_factor)
86 const override;
87 #if defined(OS_MACOSX)
88 NSImage* GetNSImageNamed(int id) const override;
89 NSColor* GetNSImageColorNamed(int id) const override;
90 NSColor* GetNSColor(int id) const override;
91 NSColor* GetNSColorTint(int id) const override;
92 NSGradient* GetNSGradient(int id) const override;
93 #endif
94
95 // KeyedService: 72 // KeyedService:
96 void Shutdown() override; 73 void Shutdown() override;
97 74
98 // Overridden from content::NotificationObserver: 75 // Overridden from content::NotificationObserver:
99 void Observe(int type, 76 void Observe(int type,
100 const content::NotificationSource& source, 77 const content::NotificationSource& source,
101 const content::NotificationDetails& details) override; 78 const content::NotificationDetails& details) override;
102 79
103 // Set the current theme to the theme defined in |extension|. 80 // Set the current theme to the theme defined in |extension|.
104 // |extension| must already be added to this profile's 81 // |extension| must already be added to this profile's
105 // ExtensionService. 82 // ExtensionService.
106 virtual void SetTheme(const extensions::Extension* extension); 83 virtual void SetTheme(const extensions::Extension* extension);
107 84
108 // Reset the theme to default. 85 // Reset the theme to default.
109 virtual void UseDefaultTheme(); 86 virtual void UseDefaultTheme();
110 87
111 // Set the current theme to the system theme. On some platforms, the system 88 // Set the current theme to the system theme. On some platforms, the system
112 // theme is the default theme. 89 // theme is the default theme.
113 virtual void UseSystemTheme(); 90 virtual void UseSystemTheme();
114 91
115 // Returns true if the default theme and system theme are not the same on 92 // Returns true if the default theme and system theme are not the same on
116 // this platform. 93 // this platform.
117 virtual bool IsSystemThemeDistinctFromDefaultTheme() const; 94 virtual bool IsSystemThemeDistinctFromDefaultTheme() const;
118 95
119 // Whether we're using the chrome default theme. Virtual so linux can check 96 // Whether we're using the chrome default theme. Virtual so linux can check
120 // if we're using the GTK theme. 97 // if we're using the GTK theme.
121 virtual bool UsingDefaultTheme() const; 98 virtual bool UsingDefaultTheme() const;
122 99
100 // Whether we are using the system theme. On GTK, the system theme is the GTK
101 // theme, not the "Classic" theme.
102 virtual bool UsingSystemTheme() const;
103
123 // Gets the id of the last installed theme. (The theme may have been further 104 // Gets the id of the last installed theme. (The theme may have been further
124 // locally customized.) 105 // locally customized.)
125 virtual std::string GetThemeID() const; 106 virtual std::string GetThemeID() const;
126 107
127 // This class needs to keep track of the number of theme infobars so that we 108 // This class needs to keep track of the number of theme infobars so that we
128 // clean up unused themes. 109 // clean up unused themes.
129 void OnInfobarDisplayed(); 110 void OnInfobarDisplayed();
130 111
131 // Decrements the number of theme infobars. If the last infobar has been 112 // Decrements the number of theme infobars. If the last infobar has been
132 // destroyed, uninstalls all themes that aren't the currently selected. 113 // destroyed, uninstalls all themes that aren't the currently selected.
133 void OnInfobarDestroyed(); 114 void OnInfobarDestroyed();
134 115
135 // Uninstall theme extensions which are no longer in use. |ignore_infobars| is 116 // Uninstall theme extensions which are no longer in use. |ignore_infobars| is
136 // whether unused themes should be removed despite a theme infobar being 117 // whether unused themes should be removed despite a theme infobar being
137 // visible. 118 // visible.
138 void RemoveUnusedThemes(bool ignore_infobars); 119 void RemoveUnusedThemes(bool ignore_infobars);
139 120
140 // Returns the syncable service for syncing theme. The returned service is 121 // Returns the syncable service for syncing theme. The returned service is
141 // owned by |this| object. 122 // owned by |this| object.
142 virtual ThemeSyncableService* GetThemeSyncableService() const; 123 virtual ThemeSyncableService* GetThemeSyncableService() const;
143 124
144 // Save the images to be written to disk, mapping file path to id. 125 // Gets the ThemeProvider for |profile|. This will be different for an
145 typedef std::map<base::FilePath, int> ImagesDiskCache; 126 // incognito profile and its original profile, even though both profiles use
127 // the same ThemeService.
128 static const ui::ThemeProvider& GetThemeProviderForProfile(Profile* profile);
146 129
147 protected: 130 protected:
148 // Set a custom default theme instead of the normal default theme. 131 // Set a custom default theme instead of the normal default theme.
149 virtual void SetCustomDefaultTheme( 132 virtual void SetCustomDefaultTheme(
150 scoped_refptr<CustomThemeSupplier> theme_supplier); 133 scoped_refptr<CustomThemeSupplier> theme_supplier);
151 134
152 // Returns true if the ThemeService should use the system theme on startup. 135 // Returns true if the ThemeService should use the system theme on startup.
153 virtual bool ShouldInitWithSystemTheme() const; 136 virtual bool ShouldInitWithSystemTheme() const;
154 137
155 // Get the specified tint - |id| is one of the TINT_* enum values. 138 // Get the specified tint - |id| is one of the TINT_* enum values.
(...skipping 24 matching lines...) Expand all
180 const CustomThemeSupplier* get_theme_supplier() const { 163 const CustomThemeSupplier* get_theme_supplier() const {
181 return theme_supplier_.get(); 164 return theme_supplier_.get();
182 } 165 }
183 166
184 // True if the theme service is ready to be used. 167 // True if the theme service is ready to be used.
185 // TODO(pkotwicz): Add DCHECKS to the theme service's getters once 168 // TODO(pkotwicz): Add DCHECKS to the theme service's getters once
186 // ThemeSource no longer uses the ThemeService when it is not ready. 169 // ThemeSource no longer uses the ThemeService when it is not ready.
187 bool ready_; 170 bool ready_;
188 171
189 private: 172 private:
173 // This class implements ui::ThemeProvider on behalf of ThemeService and keeps
174 // track of the incognito state of the calling code.
175 class BrowserThemeProvider : public ui::ThemeProvider {
176 public:
177 BrowserThemeProvider(const ThemeService& theme_service,
178 bool off_the_record);
179 ~BrowserThemeProvider() override;
180
181 // Overridden from ui::ThemeProvider:
182 gfx::ImageSkia* GetImageSkiaNamed(int id) const override;
183 SkColor GetColor(int original_id) const override;
184 int GetDisplayProperty(int id) const override;
185 bool ShouldUseNativeFrame() const override;
186 bool HasCustomImage(int id) const override;
187 base::RefCountedMemory* GetRawData(int id, ui::ScaleFactor scale_factor)
188 const override;
189 #if defined(OS_MACOSX)
190 bool UsingSystemTheme() const override;
191 NSImage* GetNSImageNamed(int id) const override;
192 NSColor* GetNSImageColorNamed(int id) const override;
193 NSColor* GetNSColor(int id) const override;
194 NSColor* GetNSColorTint(int id) const override;
195 NSGradient* GetNSGradient(int id) const override;
196 #endif
197
198 private:
199 const ThemeService& theme_service_;
200 bool off_the_record_;
201
202 DISALLOW_COPY_AND_ASSIGN(BrowserThemeProvider);
203 };
204 friend class BrowserThemeProvider;
190 friend class theme_service_internal::ThemeServiceTest; 205 friend class theme_service_internal::ThemeServiceTest;
191 206
207 const ui::ThemeProvider& GetOrCreateThemeProviderForProfile(Profile* profile);
208
209 // These methods provide the implementation for ui::ThemeProvider (exposed
210 // via BrowserThemeProvider).
211 gfx::ImageSkia* GetImageSkiaNamed(int id) const;
212 SkColor GetColor(int id, bool off_the_record) const;
213 int GetDisplayProperty(int id) const;
214 bool ShouldUseNativeFrame() const;
215 bool HasCustomImage(int id) const;
216 base::RefCountedMemory* GetRawData(int id,
217 ui::ScaleFactor scale_factor) const;
218 #if defined(OS_MACOSX)
219 NSImage* GetNSImageNamed(int id) const;
220 NSColor* GetNSImageColorNamed(int id) const;
221 NSColor* GetNSColor(int id) const;
222 NSColor* GetNSColorTint(int id) const;
223 NSGradient* GetNSGradient(int id) const;
224 #endif
225
226 // Returns a cross platform image for an id.
227 //
228 // TODO(erg): Make this part of the ui::ThemeProvider and the main way to get
229 // theme properties out of the theme provider since it's cross platform.
230 gfx::Image GetImageNamed(int id) const;
231
192 // Called when the extension service is ready. 232 // Called when the extension service is ready.
193 void OnExtensionServiceReady(); 233 void OnExtensionServiceReady();
194 234
195 // Migrate the theme to the new theme pack schema by recreating the data pack 235 // Migrate the theme to the new theme pack schema by recreating the data pack
196 // from the extension. 236 // from the extension.
197 void MigrateTheme(); 237 void MigrateTheme();
198 238
199 // Replaces the current theme supplier with a new one and calls 239 // Replaces the current theme supplier with a new one and calls
200 // StopUsingTheme() or StartUsingTheme() as appropriate. 240 // StopUsingTheme() or StartUsingTheme() as appropriate.
201 void SwapThemeSupplier(scoped_refptr<CustomThemeSupplier> theme_supplier); 241 void SwapThemeSupplier(scoped_refptr<CustomThemeSupplier> theme_supplier);
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after
249 289
250 content::NotificationRegistrar registrar_; 290 content::NotificationRegistrar registrar_;
251 291
252 scoped_ptr<ThemeSyncableService> theme_syncable_service_; 292 scoped_ptr<ThemeSyncableService> theme_syncable_service_;
253 293
254 #if defined(ENABLE_EXTENSIONS) 294 #if defined(ENABLE_EXTENSIONS)
255 class ThemeObserver; 295 class ThemeObserver;
256 scoped_ptr<ThemeObserver> theme_observer_; 296 scoped_ptr<ThemeObserver> theme_observer_;
257 #endif 297 #endif
258 298
299 BrowserThemeProvider original_theme_provider_;
300 BrowserThemeProvider otr_theme_provider_;
301
259 base::WeakPtrFactory<ThemeService> weak_ptr_factory_; 302 base::WeakPtrFactory<ThemeService> weak_ptr_factory_;
260 303
261 DISALLOW_COPY_AND_ASSIGN(ThemeService); 304 DISALLOW_COPY_AND_ASSIGN(ThemeService);
262 }; 305 };
263 306
264 #endif // CHROME_BROWSER_THEMES_THEME_SERVICE_H_ 307 #endif // CHROME_BROWSER_THEMES_THEME_SERVICE_H_
OLDNEW
« no previous file with comments | « chrome/browser/themes/theme_properties.cc ('k') | chrome/browser/themes/theme_service.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698