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/memory/weak_ptr.h" |
16 #include "base/threading/non_thread_safe.h" | 17 #include "base/threading/non_thread_safe.h" |
17 #include "components/browser_context_keyed_service/browser_context_keyed_service
.h" | 18 #include "components/browser_context_keyed_service/browser_context_keyed_service
.h" |
18 #include "content/public/browser/notification_observer.h" | 19 #include "content/public/browser/notification_observer.h" |
19 #include "content/public/browser/notification_registrar.h" | 20 #include "content/public/browser/notification_registrar.h" |
20 #include "ui/base/theme_provider.h" | 21 #include "ui/base/theme_provider.h" |
21 | 22 |
22 class CustomThemeSupplier; | 23 class CustomThemeSupplier; |
23 class BrowserThemePack; | 24 class BrowserThemePack; |
24 class ThemeSyncableService; | 25 class ThemeSyncableService; |
25 class Profile; | 26 class Profile; |
(...skipping 103 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
129 | 130 |
130 // This class needs to keep track of the number of theme infobars so that we | 131 // This class needs to keep track of the number of theme infobars so that we |
131 // clean up unused themes. | 132 // clean up unused themes. |
132 void OnInfobarDisplayed(); | 133 void OnInfobarDisplayed(); |
133 | 134 |
134 // Decrements the number of theme infobars. If the last infobar has been | 135 // Decrements the number of theme infobars. If the last infobar has been |
135 // destroyed, uninstalls all themes that aren't the currently selected. | 136 // destroyed, uninstalls all themes that aren't the currently selected. |
136 void OnInfobarDestroyed(); | 137 void OnInfobarDestroyed(); |
137 | 138 |
138 // Remove preference values for themes that are no longer in use. | 139 // Remove preference values for themes that are no longer in use. |
139 void RemoveUnusedThemes(); | 140 // |ignore_infobars| is whether unused themes should be removed despite |
| 141 // a theme infobar being visible. |
| 142 void RemoveUnusedThemes(bool ignore_infobars); |
140 | 143 |
141 // Returns the syncable service for syncing theme. The returned service is | 144 // Returns the syncable service for syncing theme. The returned service is |
142 // owned by |this| object. | 145 // owned by |this| object. |
143 virtual ThemeSyncableService* GetThemeSyncableService() const; | 146 virtual ThemeSyncableService* GetThemeSyncableService() const; |
144 | 147 |
145 // Save the images to be written to disk, mapping file path to id. | 148 // Save the images to be written to disk, mapping file path to id. |
146 typedef std::map<base::FilePath, int> ImagesDiskCache; | 149 typedef std::map<base::FilePath, int> ImagesDiskCache; |
147 | 150 |
148 protected: | 151 protected: |
149 // Set a custom default theme instead of the normal default theme. | 152 // Set a custom default theme instead of the normal default theme. |
(...skipping 28 matching lines...) Expand all Loading... |
178 | 181 |
179 void set_ready() { ready_ = true; } | 182 void set_ready() { ready_ = true; } |
180 | 183 |
181 const CustomThemeSupplier* get_theme_supplier() const { | 184 const CustomThemeSupplier* get_theme_supplier() const { |
182 return theme_supplier_.get(); | 185 return theme_supplier_.get(); |
183 } | 186 } |
184 | 187 |
185 private: | 188 private: |
186 friend class theme_service_internal::ThemeServiceTest; | 189 friend class theme_service_internal::ThemeServiceTest; |
187 | 190 |
| 191 // Called when the extension service is ready. |
| 192 void OnExtensionServiceReady(); |
| 193 |
| 194 // Migrate the theme to the new theme pack schema by recreating the data pack |
| 195 // from the extension. |
| 196 void MigrateTheme(); |
| 197 |
188 // Replaces the current theme supplier with a new one and calls | 198 // Replaces the current theme supplier with a new one and calls |
189 // StopUsingTheme() or StartUsingTheme() as appropriate. | 199 // StopUsingTheme() or StartUsingTheme() as appropriate. |
190 void SwapThemeSupplier(scoped_refptr<CustomThemeSupplier> theme_supplier); | 200 void SwapThemeSupplier(scoped_refptr<CustomThemeSupplier> theme_supplier); |
191 | 201 |
192 // Migrate the theme to the new theme pack schema by recreating the data pack | |
193 // from the extension. | |
194 void MigrateTheme(); | |
195 | |
196 // Saves the filename of the cached theme pack. | 202 // Saves the filename of the cached theme pack. |
197 void SavePackName(const base::FilePath& pack_path); | 203 void SavePackName(const base::FilePath& pack_path); |
198 | 204 |
199 // Save the id of the last theme installed. | 205 // Save the id of the last theme installed. |
200 void SaveThemeID(const std::string& id); | 206 void SaveThemeID(const std::string& id); |
201 | 207 |
202 // Implementation of SetTheme() (and the fallback from LoadThemePrefs() in | 208 // Implementation of SetTheme() (and the fallback from LoadThemePrefs() in |
203 // case we don't have a theme pack). | 209 // case we don't have a theme pack). |
204 void BuildFromExtension(const extensions::Extension* extension); | 210 void BuildFromExtension(const extensions::Extension* extension); |
205 | 211 |
(...skipping 27 matching lines...) Expand all Loading... |
233 ui::ResourceBundle& rb_; | 239 ui::ResourceBundle& rb_; |
234 Profile* profile_; | 240 Profile* profile_; |
235 | 241 |
236 // True if the theme service is ready to be used. | 242 // True if the theme service is ready to be used. |
237 // TODO(pkotwicz): Add DCHECKS to the theme service's getters once | 243 // TODO(pkotwicz): Add DCHECKS to the theme service's getters once |
238 // ThemeSource no longer uses the ThemeService when it is not ready. | 244 // ThemeSource no longer uses the ThemeService when it is not ready. |
239 bool ready_; | 245 bool ready_; |
240 | 246 |
241 scoped_refptr<CustomThemeSupplier> theme_supplier_; | 247 scoped_refptr<CustomThemeSupplier> theme_supplier_; |
242 | 248 |
| 249 // The id of the theme extension which has just been installed but has not |
| 250 // been loaded yet. The theme extension with |installed_pending_load_id_| may |
| 251 // never be loaded if the install is due to updating a disabled theme. |
| 252 // |pending_install_id_| should be set to |kDefaultThemeID| if there are no |
| 253 // recently installed theme extensions |
| 254 std::string installed_pending_load_id_; |
| 255 |
243 // The number of infobars currently displayed. | 256 // The number of infobars currently displayed. |
244 int number_of_infobars_; | 257 int number_of_infobars_; |
245 | 258 |
246 content::NotificationRegistrar registrar_; | 259 content::NotificationRegistrar registrar_; |
247 | 260 |
248 scoped_ptr<ThemeSyncableService> theme_syncable_service_; | 261 scoped_ptr<ThemeSyncableService> theme_syncable_service_; |
249 | 262 |
| 263 base::WeakPtrFactory<ThemeService> weak_ptr_factory_; |
| 264 |
250 DISALLOW_COPY_AND_ASSIGN(ThemeService); | 265 DISALLOW_COPY_AND_ASSIGN(ThemeService); |
251 }; | 266 }; |
252 | 267 |
253 #endif // CHROME_BROWSER_THEMES_THEME_SERVICE_H_ | 268 #endif // CHROME_BROWSER_THEMES_THEME_SERVICE_H_ |
OLD | NEW |