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

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: respond to comments 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
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 static const ui::ThemeProvider& GetThemeProviderForProfile(Profile* profile);
145 typedef std::map<base::FilePath, int> ImagesDiskCache;
146 126
147 protected: 127 protected:
148 // Set a custom default theme instead of the normal default theme. 128 // Set a custom default theme instead of the normal default theme.
149 virtual void SetCustomDefaultTheme( 129 virtual void SetCustomDefaultTheme(
150 scoped_refptr<CustomThemeSupplier> theme_supplier); 130 scoped_refptr<CustomThemeSupplier> theme_supplier);
151 131
152 // Returns true if the ThemeService should use the system theme on startup. 132 // Returns true if the ThemeService should use the system theme on startup.
153 virtual bool ShouldInitWithSystemTheme() const; 133 virtual bool ShouldInitWithSystemTheme() const;
154 134
155 // Get the specified tint - |id| is one of the TINT_* enum values. 135 // 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 { 160 const CustomThemeSupplier* get_theme_supplier() const {
181 return theme_supplier_.get(); 161 return theme_supplier_.get();
182 } 162 }
183 163
184 // True if the theme service is ready to be used. 164 // True if the theme service is ready to be used.
185 // TODO(pkotwicz): Add DCHECKS to the theme service's getters once 165 // TODO(pkotwicz): Add DCHECKS to the theme service's getters once
186 // ThemeSource no longer uses the ThemeService when it is not ready. 166 // ThemeSource no longer uses the ThemeService when it is not ready.
187 bool ready_; 167 bool ready_;
188 168
189 private: 169 private:
190 friend class theme_service_internal::ThemeServiceTest; 170 friend class theme_service_internal::ThemeServiceTest;
Peter Kasting 2015/12/09 01:31:59 Nit: I would keep the two friend declarations toge
Evan Stade 2015/12/09 01:57:06 Done.
191 171
172 // This class implements ui::ThemeProvider on behalf of ThemeService and keeps
173 // track of the incognito state of the calling code.
174 class BrowserThemeProvider : public ui::ThemeProvider {
175 public:
176 BrowserThemeProvider(const ThemeService& theme_service, bool otr);
177 ~BrowserThemeProvider() override;
178
179 // Overridden from ui::ThemeProvider:
180 gfx::ImageSkia* GetImageSkiaNamed(int id) const override;
181 SkColor GetColor(int original_id, bool otr) const override;
182 int GetDisplayProperty(int id) const override;
183 bool ShouldUseNativeFrame() const override;
184 bool HasCustomImage(int id) const override;
185 base::RefCountedMemory* GetRawData(int id, ui::ScaleFactor scale_factor)
186 const override;
187 #if defined(OS_MACOSX)
188 bool UsingSystemTheme() const override;
189 NSImage* GetNSImageNamed(int id) const override;
190 NSColor* GetNSImageColorNamed(int id) const override;
191 NSColor* GetNSColor(int id) const override;
192 NSColor* GetNSColorTint(int id) const override;
193 NSGradient* GetNSGradient(int id) const override;
194 #endif
195
196 private:
197 const ThemeService& theme_service_;
198 bool off_the_record_;
199
200 DISALLOW_COPY_AND_ASSIGN(BrowserThemeProvider);
201 };
202 friend class BrowserThemeProvider;
203
204 const ui::ThemeProvider& GetOrCreateThemeProviderForProfile(Profile* profile);
205
206 // These methods provide the implementation for ui::ThemeProvider (exposed
207 // via BrowserThemeProvider).
208 gfx::ImageSkia* GetImageSkiaNamed(int id) const;
209 SkColor GetColor(int id, bool otr) const;
210 int GetDisplayProperty(int id) const;
211 bool ShouldUseNativeFrame() const;
212 bool HasCustomImage(int id) const;
213 base::RefCountedMemory* GetRawData(int id,
214 ui::ScaleFactor scale_factor) const;
215 #if defined(OS_MACOSX)
216 NSImage* GetNSImageNamed(int id) const;
217 NSColor* GetNSImageColorNamed(int id) const;
218 NSColor* GetNSColor(int id) const;
219 NSColor* GetNSColorTint(int id) const;
220 NSGradient* GetNSGradient(int id) const;
221 #endif
222
223 // Returns a cross platform image for an id.
224 //
225 // TODO(erg): Make this part of the ui::ThemeProvider and the main way to get
226 // theme properties out of the theme provider since it's cross platform.
227 virtual gfx::Image GetImageNamed(int id) const;
228
192 // Called when the extension service is ready. 229 // Called when the extension service is ready.
193 void OnExtensionServiceReady(); 230 void OnExtensionServiceReady();
194 231
195 // Migrate the theme to the new theme pack schema by recreating the data pack 232 // Migrate the theme to the new theme pack schema by recreating the data pack
196 // from the extension. 233 // from the extension.
197 void MigrateTheme(); 234 void MigrateTheme();
198 235
199 // Replaces the current theme supplier with a new one and calls 236 // Replaces the current theme supplier with a new one and calls
200 // StopUsingTheme() or StartUsingTheme() as appropriate. 237 // StopUsingTheme() or StartUsingTheme() as appropriate.
201 void SwapThemeSupplier(scoped_refptr<CustomThemeSupplier> theme_supplier); 238 void SwapThemeSupplier(scoped_refptr<CustomThemeSupplier> theme_supplier);
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after
249 286
250 content::NotificationRegistrar registrar_; 287 content::NotificationRegistrar registrar_;
251 288
252 scoped_ptr<ThemeSyncableService> theme_syncable_service_; 289 scoped_ptr<ThemeSyncableService> theme_syncable_service_;
253 290
254 #if defined(ENABLE_EXTENSIONS) 291 #if defined(ENABLE_EXTENSIONS)
255 class ThemeObserver; 292 class ThemeObserver;
256 scoped_ptr<ThemeObserver> theme_observer_; 293 scoped_ptr<ThemeObserver> theme_observer_;
257 #endif 294 #endif
258 295
296 BrowserThemeProvider original_theme_provider_;
297 BrowserThemeProvider otr_theme_provider_;
298
259 base::WeakPtrFactory<ThemeService> weak_ptr_factory_; 299 base::WeakPtrFactory<ThemeService> weak_ptr_factory_;
260 300
261 DISALLOW_COPY_AND_ASSIGN(ThemeService); 301 DISALLOW_COPY_AND_ASSIGN(ThemeService);
262 }; 302 };
263 303
264 #endif // CHROME_BROWSER_THEMES_THEME_SERVICE_H_ 304 #endif // CHROME_BROWSER_THEMES_THEME_SERVICE_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698