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

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

Issue 11416324: Revert changes to have ExtensionService notify ThemeService directly (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 8 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 | Annotate | Revision Log
« no previous file with comments | « chrome/browser/extensions/extension_service.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/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
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 130 matching lines...) Expand 10 before | Expand all | Expand 10 after
190 virtual void SetNativeTheme(); 193 virtual void SetNativeTheme();
191 194
192 // 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
193 // if we're using the GTK theme. 196 // if we're using the GTK theme.
194 virtual bool UsingDefaultTheme() const; 197 virtual bool UsingDefaultTheme() const;
195 198
196 // Whether we're using the native theme (which may or may not be the 199 // Whether we're using the native theme (which may or may not be the
197 // same as the default theme). 200 // same as the default theme).
198 virtual bool UsingNativeTheme() const; 201 virtual bool UsingNativeTheme() const;
199 202
203 // Gets the id of the last installed theme. (The theme may have been further
204 // locally customized.)
205 virtual std::string GetThemeID() const;
206
200 // This class needs to keep track of the number of theme infobars so that we 207 // This class needs to keep track of the number of theme infobars so that we
201 // clean up unused themes. 208 // clean up unused themes.
202 void OnInfobarDisplayed(); 209 void OnInfobarDisplayed();
203 210
204 // Decrements the number of theme infobars. If the last infobar has been 211 // Decrements the number of theme infobars. If the last infobar has been
205 // destroyed, uninstalls all themes that aren't the currently selected. 212 // destroyed, uninstalls all themes that aren't the currently selected.
206 void OnInfobarDestroyed(); 213 void OnInfobarDestroyed();
207 214
208 // Gets the id of the last installed theme for |profile|. (The theme
209 // may have been further locally customized.)
210 static std::string GetThemeIDForProfile(Profile* profile);
211
212 // Save the id of the last theme installed. If the theme service
213 // already exists, SetTheme() must be used instead.
214 static void SaveThemeIDForProfile(Profile* profile, const std::string& id);
215
216 // Uninstall extensions for themes that are no longer in use.
217 static void RemoveUnusedThemesForProfile(Profile* profile);
218
219 // Gets the id of the last installed theme. (The theme may have been
220 // further locally customized.)
221 //
222 // TODO(akalin): Make everything use GetThemeIDForProfile().
223 virtual std::string GetThemeID() const;
224
225 // Convert a bitfield alignment into a string like "top left". Public so that 215 // Convert a bitfield alignment into a string like "top left". Public so that
226 // it can be used to generate CSS values. Takes a bitmask of Alignment. 216 // it can be used to generate CSS values. Takes a bitmask of Alignment.
227 static std::string AlignmentToString(int alignment); 217 static std::string AlignmentToString(int alignment);
228 218
229 // Parse alignments from something like "top left" into a bitmask of 219 // Parse alignments from something like "top left" into a bitmask of
230 // Alignment. 220 // Alignment.
231 static int StringToAlignment(const std::string& alignment); 221 static int StringToAlignment(const std::string& alignment);
232 222
233 // Convert a tiling value into a string like "no-repeat". Public 223 // Convert a tiling value into a string like "no-repeat". Public
234 // so that it can be used to generate CSS values. Takes a Tiling. 224 // so that it can be used to generate CSS values. Takes a Tiling.
235 static std::string TilingToString(int tiling); 225 static std::string TilingToString(int tiling);
236 226
237 // Parse tiling values from something like "no-repeat" into a Tiling value. 227 // Parse tiling values from something like "no-repeat" into a Tiling value.
238 static int StringToTiling(const std::string& tiling); 228 static int StringToTiling(const std::string& tiling);
239 229
240 // Returns the default tint for the given tint |id| TINT_* enum value. 230 // Returns the default tint for the given tint |id| TINT_* enum value.
241 static color_utils::HSL GetDefaultTint(int id); 231 static color_utils::HSL GetDefaultTint(int id);
242 232
243 // Returns the default color for the given color |id| COLOR_* enum value. 233 // Returns the default color for the given color |id| COLOR_* enum value.
244 static SkColor GetDefaultColor(int id); 234 static SkColor GetDefaultColor(int id);
245 235
246 // Returns true and sets |result| to the requested default property, if |id| 236 // Returns true and sets |result| to the requested default property, if |id|
247 // is valid. 237 // is valid.
248 static bool GetDefaultDisplayProperty(int id, int* result); 238 static bool GetDefaultDisplayProperty(int id, int* result);
249 239
250 // Returns the set of IDR_* resources that should be tinted. 240 // Returns the set of IDR_* resources that should be tinted.
251 static const std::set<int>& GetTintableToolbarButtons(); 241 static const std::set<int>& GetTintableToolbarButtons();
252 242
243 // Remove preference values for themes that are no longer in use.
244 void RemoveUnusedThemes();
245
253 // Returns the syncable service for syncing theme. The returned service is 246 // Returns the syncable service for syncing theme. The returned service is
254 // owned by |this| object. 247 // owned by |this| object.
255 virtual ThemeSyncableService* GetThemeSyncableService() const; 248 virtual ThemeSyncableService* GetThemeSyncableService() const;
256 249
257 // Save the images to be written to disk, mapping file path to id. 250 // Save the images to be written to disk, mapping file path to id.
258 typedef std::map<FilePath, int> ImagesDiskCache; 251 typedef std::map<FilePath, int> ImagesDiskCache;
259 252
260 protected: 253 protected:
261 // Get the specified tint - |id| is one of the TINT_* enum values. 254 // Get the specified tint - |id| is one of the TINT_* enum values.
262 color_utils::HSL GetTint(int id) const; 255 color_utils::HSL GetTint(int id) const;
(...skipping 11 matching lines...) Expand all
274 // 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.
275 virtual void NotifyPlatformThemeChanged(); 268 virtual void NotifyPlatformThemeChanged();
276 #endif // OS_MACOSX 269 #endif // OS_MACOSX
277 270
278 // 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
279 // from ClearCaches(). 272 // from ClearCaches().
280 virtual void FreePlatformCaches(); 273 virtual void FreePlatformCaches();
281 274
282 Profile* profile() { return profile_; } 275 Profile* profile() { return profile_; }
283 276
277 // content::NotificationObserver:
278 virtual void Observe(int type,
279 const content::NotificationSource& source,
280 const content::NotificationDetails& details) OVERRIDE;
281
284 private: 282 private:
285 friend class ThemeServiceTest; 283 friend class ThemeServiceTest;
286 284
287 // Saves the filename of the cached theme pack. 285 // Saves the filename of the cached theme pack.
288 void SavePackName(const FilePath& pack_path); 286 void SavePackName(const FilePath& pack_path);
289 287
288 // Save the id of the last theme installed.
289 void SaveThemeID(const std::string& id);
290
290 // Implementation of SetTheme() (and the fallback from LoadThemePrefs() in 291 // Implementation of SetTheme() (and the fallback from LoadThemePrefs() in
291 // case we don't have a theme pack). 292 // case we don't have a theme pack).
292 void BuildFromExtension(const extensions::Extension* extension); 293 void BuildFromExtension(const extensions::Extension* extension);
293 294
294 #if defined(TOOLKIT_GTK) 295 #if defined(TOOLKIT_GTK)
295 // Loads an image and flips it horizontally if |rtl_enabled| is true. 296 // Loads an image and flips it horizontally if |rtl_enabled| is true.
296 GdkPixbuf* GetPixbufImpl(int id, bool rtl_enabled) const; 297 GdkPixbuf* GetPixbufImpl(int id, bool rtl_enabled) const;
297 #endif 298 #endif
298 299
299 #if defined(TOOLKIT_GTK) 300 #if defined(TOOLKIT_GTK)
(...skipping 12 matching lines...) Expand all
312 #endif 313 #endif
313 314
314 ui::ResourceBundle& rb_; 315 ui::ResourceBundle& rb_;
315 Profile* profile_; 316 Profile* profile_;
316 317
317 scoped_refptr<BrowserThemePack> theme_pack_; 318 scoped_refptr<BrowserThemePack> theme_pack_;
318 319
319 // The number of infobars currently displayed. 320 // The number of infobars currently displayed.
320 int number_of_infobars_; 321 int number_of_infobars_;
321 322
323 content::NotificationRegistrar registrar_;
324
322 scoped_ptr<ThemeSyncableService> theme_syncable_service_; 325 scoped_ptr<ThemeSyncableService> theme_syncable_service_;
323 326
324 DISALLOW_COPY_AND_ASSIGN(ThemeService); 327 DISALLOW_COPY_AND_ASSIGN(ThemeService);
325 }; 328 };
326 329
327 #endif // CHROME_BROWSER_THEMES_THEME_SERVICE_H_ 330 #endif // CHROME_BROWSER_THEMES_THEME_SERVICE_H_
OLDNEW
« no previous file with comments | « chrome/browser/extensions/extension_service.cc ('k') | chrome/browser/themes/theme_service.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698