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

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

Issue 19471005: Add custom default theme support and create a managed user default theme. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Address review comments. Created 7 years, 5 months 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 | Annotate | Revision Log
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/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 ThemeServiceTest;
24 class ThemeSyncableService; 25 class ThemeSyncableService;
25 class Profile; 26 class Profile;
26 27
27 namespace base { 28 namespace base {
28 class FilePath; 29 class FilePath;
29 } 30 }
30 31
31 namespace color_utils { 32 namespace color_utils {
(...skipping 103 matching lines...) Expand 10 before | Expand all | Expand 10 after
135 void RemoveUnusedThemes(); 136 void RemoveUnusedThemes();
136 137
137 // Returns the syncable service for syncing theme. The returned service is 138 // Returns the syncable service for syncing theme. The returned service is
138 // owned by |this| object. 139 // owned by |this| object.
139 virtual ThemeSyncableService* GetThemeSyncableService() const; 140 virtual ThemeSyncableService* GetThemeSyncableService() const;
140 141
141 // Save the images to be written to disk, mapping file path to id. 142 // Save the images to be written to disk, mapping file path to id.
142 typedef std::map<base::FilePath, int> ImagesDiskCache; 143 typedef std::map<base::FilePath, int> ImagesDiskCache;
143 144
144 protected: 145 protected:
146 // Set a custom default theme instead of the normal default theme.
147 virtual void SetCustomDefaultTheme(
148 scoped_refptr<CustomThemeSupplier> theme_supplier);
149
150 // If the native theme should be used as default.
pkotwicz 2013/07/19 18:33:20 How about: "Returns true if the ThemeService shoul
Adrian Kuegel 2013/07/22 12:58:08 Done.
151 virtual bool ShouldInitWithNativeTheme();
152
145 // Get the specified tint - |id| is one of the TINT_* enum values. 153 // Get the specified tint - |id| is one of the TINT_* enum values.
146 color_utils::HSL GetTint(int id) const; 154 color_utils::HSL GetTint(int id) const;
147 155
148 // Clears all the override fields and saves the dictionary. 156 // Clears all the override fields and saves the dictionary.
149 virtual void ClearAllThemeData(); 157 virtual void ClearAllThemeData();
150 158
151 // Load theme data from preferences. 159 // Load theme data from preferences.
152 virtual void LoadThemePrefs(); 160 virtual void LoadThemePrefs();
153 161
154 // Let all the browser views know that themes have changed. 162 // Let all the browser views know that themes have changed.
155 virtual void NotifyThemeChanged(); 163 virtual void NotifyThemeChanged();
156 164
157 #if defined(OS_MACOSX) 165 #if defined(OS_MACOSX)
158 // Let all the browser views know that themes have changed in a platform way. 166 // Let all the browser views know that themes have changed in a platform way.
159 virtual void NotifyPlatformThemeChanged(); 167 virtual void NotifyPlatformThemeChanged();
160 #endif // OS_MACOSX 168 #endif // OS_MACOSX
161 169
162 // Clears the platform-specific caches. Do not call directly; it's called 170 // Clears the platform-specific caches. Do not call directly; it's called
163 // from ClearCaches(). 171 // from ClearCaches().
164 virtual void FreePlatformCaches(); 172 virtual void FreePlatformCaches();
165 173
166 Profile* profile() const { return profile_; } 174 Profile* profile() const { return profile_; }
167 175
168 void set_ready() { ready_ = true; } 176 void set_ready() { ready_ = true; }
169 177
178 const CustomThemeSupplier* GetThemeSupplier() const {
pkotwicz 2013/07/19 18:33:20 I think that get_theme_supplier() is the preferred
Adrian Kuegel 2013/07/22 12:58:08 Done.
179 return theme_supplier_.get();
180 }
181
170 private: 182 private:
171 friend class ThemeServiceTest; 183 friend class ThemeServiceTest;
172 184
185 // Replace the current theme supplier with a new one and call StopUsingTheme
186 // or StartUsingTheme as appropriate.
pkotwicz 2013/07/19 18:33:20 Nit: StartUsingTheme(), StopUsingTheme().
Adrian Kuegel 2013/07/22 12:58:08 Done.
187 void SwapThemeSupplier(scoped_refptr<CustomThemeSupplier> theme_supplier);
188
173 // Migrate the theme to the new theme pack schema by recreating the data pack 189 // Migrate the theme to the new theme pack schema by recreating the data pack
174 // from the extension. 190 // from the extension.
175 void MigrateTheme(); 191 void MigrateTheme();
176 192
177 // Saves the filename of the cached theme pack. 193 // Saves the filename of the cached theme pack.
178 void SavePackName(const base::FilePath& pack_path); 194 void SavePackName(const base::FilePath& pack_path);
179 195
180 // Save the id of the last theme installed. 196 // Save the id of the last theme installed.
181 void SaveThemeID(const std::string& id); 197 void SaveThemeID(const std::string& id);
182 198
183 // Implementation of SetTheme() (and the fallback from LoadThemePrefs() in 199 // Implementation of SetTheme() (and the fallback from LoadThemePrefs() in
184 // case we don't have a theme pack). 200 // case we don't have a theme pack).
185 void BuildFromExtension(const extensions::Extension* extension); 201 void BuildFromExtension(const extensions::Extension* extension);
186 202
187 // Returns true if the profile belongs to a managed user. 203 // Returns true if the profile belongs to a managed user.
188 bool IsManagedUser() const; 204 bool IsManagedUser() const;
189 205
206 void SetManagedUserTheme();
pkotwicz 2013/07/19 18:33:20 Add a comment here.
Adrian Kuegel 2013/07/22 12:58:08 Done.
207
190 #if defined(TOOLKIT_GTK) 208 #if defined(TOOLKIT_GTK)
191 // Loads an image and flips it horizontally if |rtl_enabled| is true. 209 // Loads an image and flips it horizontally if |rtl_enabled| is true.
192 GdkPixbuf* GetPixbufImpl(int id, bool rtl_enabled) const; 210 GdkPixbuf* GetPixbufImpl(int id, bool rtl_enabled) const;
193 #endif 211 #endif
194 212
195 #if defined(TOOLKIT_GTK) 213 #if defined(TOOLKIT_GTK)
196 typedef std::map<int, GdkPixbuf*> GdkPixbufMap; 214 typedef std::map<int, GdkPixbuf*> GdkPixbufMap;
197 mutable GdkPixbufMap gdk_pixbufs_; 215 mutable GdkPixbufMap gdk_pixbufs_;
198 #elif defined(OS_MACOSX) 216 #elif defined(OS_MACOSX)
199 typedef std::map<int, NSImage*> NSImageMap; 217 typedef std::map<int, NSImage*> NSImageMap;
200 mutable NSImageMap nsimage_cache_; 218 mutable NSImageMap nsimage_cache_;
201 219
202 // The bool member of the pair is whether the color is a default color. 220 // The bool member of the pair is whether the color is a default color.
203 typedef std::map<int, std::pair<NSColor*, bool> > NSColorMap; 221 typedef std::map<int, std::pair<NSColor*, bool> > NSColorMap;
204 mutable NSColorMap nscolor_cache_; 222 mutable NSColorMap nscolor_cache_;
205 223
206 typedef std::map<int, NSGradient*> NSGradientMap; 224 typedef std::map<int, NSGradient*> NSGradientMap;
207 mutable NSGradientMap nsgradient_cache_; 225 mutable NSGradientMap nsgradient_cache_;
208 #endif 226 #endif
209 227
210 ui::ResourceBundle& rb_; 228 ui::ResourceBundle& rb_;
211 Profile* profile_; 229 Profile* profile_;
212 230
213 // True if the theme service is ready to be used. 231 // True if the theme service is ready to be used.
214 // TODO(pkotwicz): Add DCHECKS to the theme service's getters once 232 // TODO(pkotwicz): Add DCHECKS to the theme service's getters once
215 // ThemeSource no longer uses the ThemeService when it is not ready. 233 // ThemeSource no longer uses the ThemeService when it is not ready.
216 bool ready_; 234 bool ready_;
217 235
218 scoped_refptr<BrowserThemePack> theme_pack_; 236 scoped_refptr<CustomThemeSupplier> theme_supplier_;
219 237
220 // The number of infobars currently displayed. 238 // The number of infobars currently displayed.
221 int number_of_infobars_; 239 int number_of_infobars_;
222 240
223 content::NotificationRegistrar registrar_; 241 content::NotificationRegistrar registrar_;
224 242
225 scoped_ptr<ThemeSyncableService> theme_syncable_service_; 243 scoped_ptr<ThemeSyncableService> theme_syncable_service_;
226 244
227 DISALLOW_COPY_AND_ASSIGN(ThemeService); 245 DISALLOW_COPY_AND_ASSIGN(ThemeService);
228 }; 246 };
229 247
230 #endif // CHROME_BROWSER_THEMES_THEME_SERVICE_H_ 248 #endif // CHROME_BROWSER_THEMES_THEME_SERVICE_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698