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 #include "chrome/browser/themes/theme_service.h" | 5 #include "chrome/browser/themes/theme_service.h" |
6 | 6 |
7 #include "base/bind.h" | 7 #include "base/bind.h" |
8 #include "base/memory/ref_counted_memory.h" | 8 #include "base/memory/ref_counted_memory.h" |
9 #include "base/prefs/pref_service.h" | 9 #include "base/prefs/pref_service.h" |
10 #include "base/sequenced_task_runner.h" | 10 #include "base/sequenced_task_runner.h" |
11 #include "base/strings/string_util.h" | 11 #include "base/strings/string_util.h" |
12 #include "base/strings/utf_string_conversions.h" | 12 #include "base/strings/utf_string_conversions.h" |
13 #include "chrome/browser/chrome_notification_types.h" | 13 #include "chrome/browser/chrome_notification_types.h" |
14 #include "chrome/browser/extensions/extension_service.h" | 14 #include "chrome/browser/extensions/extension_service.h" |
15 #include "chrome/browser/extensions/extension_system.h" | 15 #include "chrome/browser/extensions/extension_system.h" |
16 #include "chrome/browser/profiles/profile.h" | 16 #include "chrome/browser/profiles/profile.h" |
17 #include "chrome/browser/themes/browser_theme_pack.h" | 17 #include "chrome/browser/themes/browser_theme_pack.h" |
| 18 #include "chrome/browser/themes/custom_theme_supplier.h" |
18 #include "chrome/browser/themes/theme_properties.h" | 19 #include "chrome/browser/themes/theme_properties.h" |
19 #include "chrome/browser/themes/theme_syncable_service.h" | 20 #include "chrome/browser/themes/theme_syncable_service.h" |
20 #include "chrome/common/chrome_constants.h" | 21 #include "chrome/common/chrome_constants.h" |
21 #include "chrome/common/extensions/extension_manifest_constants.h" | 22 #include "chrome/common/extensions/extension_manifest_constants.h" |
22 #include "chrome/common/pref_names.h" | 23 #include "chrome/common/pref_names.h" |
23 #include "content/public/browser/notification_service.h" | 24 #include "content/public/browser/notification_service.h" |
24 #include "content/public/browser/user_metrics.h" | 25 #include "content/public/browser/user_metrics.h" |
25 #include "grit/theme_resources.h" | 26 #include "grit/theme_resources.h" |
26 #include "grit/ui_resources.h" | 27 #include "grit/ui_resources.h" |
27 #include "ui/base/layout.h" | 28 #include "ui/base/layout.h" |
28 #include "ui/base/resource/resource_bundle.h" | 29 #include "ui/base/resource/resource_bundle.h" |
29 #include "ui/gfx/image/image_skia.h" | 30 #include "ui/gfx/image/image_skia.h" |
30 | 31 |
31 #if defined(OS_WIN) | 32 #if defined(OS_WIN) |
32 #include "ui/base/win/shell.h" | 33 #include "ui/base/win/shell.h" |
33 #endif | 34 #endif |
34 | 35 |
35 #if defined(ENABLE_MANAGED_USERS) | 36 #if defined(ENABLE_MANAGED_USERS) |
36 #include "chrome/browser/managed_mode/managed_user_service.h" | 37 #include "chrome/browser/managed_mode/managed_user_service.h" |
| 38 #include "chrome/browser/managed_mode/managed_user_theme.h" |
37 #endif | 39 #endif |
38 | 40 |
39 using content::BrowserThread; | 41 using content::BrowserThread; |
40 using content::UserMetricsAction; | 42 using content::UserMetricsAction; |
41 using extensions::Extension; | 43 using extensions::Extension; |
42 using ui::ResourceBundle; | 44 using ui::ResourceBundle; |
43 | 45 |
44 typedef ThemeProperties Properties; | 46 typedef ThemeProperties Properties; |
45 | 47 |
46 // The default theme if we haven't installed a theme yet or if we've clicked | 48 // The default theme if we haven't installed a theme yet or if we've clicked |
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
97 chrome::NOTIFICATION_EXTENSIONS_READY, | 99 chrome::NOTIFICATION_EXTENSIONS_READY, |
98 content::Source<Profile>(profile_)); | 100 content::Source<Profile>(profile_)); |
99 } | 101 } |
100 | 102 |
101 theme_syncable_service_.reset(new ThemeSyncableService(profile_, this)); | 103 theme_syncable_service_.reset(new ThemeSyncableService(profile_, this)); |
102 } | 104 } |
103 | 105 |
104 gfx::Image ThemeService::GetImageNamed(int id) const { | 106 gfx::Image ThemeService::GetImageNamed(int id) const { |
105 DCHECK(CalledOnValidThread()); | 107 DCHECK(CalledOnValidThread()); |
106 | 108 |
107 // For a managed user, use the special frame instead of the default one. | |
108 // TODO(akuegel): Remove this once we have the default managed user theme. | |
109 if (IsManagedUser()) { | |
110 if (id == IDR_THEME_FRAME) | |
111 id = IDR_MANAGED_USER_THEME_FRAME; | |
112 else if (id == IDR_THEME_FRAME_INACTIVE) | |
113 id = IDR_MANAGED_USER_THEME_FRAME_INACTIVE; | |
114 else if (id == IDR_THEME_TAB_BACKGROUND || id == IDR_THEME_TAB_BACKGROUND_V) | |
115 id = IDR_MANAGED_USER_THEME_TAB_BACKGROUND; | |
116 } | |
117 | |
118 gfx::Image image; | 109 gfx::Image image; |
119 if (theme_pack_.get()) | 110 if (theme_supplier_.get()) |
120 image = theme_pack_->GetImageNamed(id); | 111 image = theme_supplier_->GetImageNamed(id); |
121 | 112 |
122 if (image.IsEmpty()) | 113 if (image.IsEmpty()) |
123 image = rb_.GetNativeImageNamed(id); | 114 image = rb_.GetNativeImageNamed(id); |
124 | 115 |
125 return image; | 116 return image; |
126 } | 117 } |
127 | 118 |
128 gfx::ImageSkia* ThemeService::GetImageSkiaNamed(int id) const { | 119 gfx::ImageSkia* ThemeService::GetImageSkiaNamed(int id) const { |
129 gfx::Image image = GetImageNamed(id); | 120 gfx::Image image = GetImageNamed(id); |
130 if (image.IsEmpty()) | 121 if (image.IsEmpty()) |
131 return NULL; | 122 return NULL; |
132 // TODO(pkotwicz): Remove this const cast. The gfx::Image interface returns | 123 // TODO(pkotwicz): Remove this const cast. The gfx::Image interface returns |
133 // its images const. GetImageSkiaNamed() also should but has many callsites. | 124 // its images const. GetImageSkiaNamed() also should but has many callsites. |
134 return const_cast<gfx::ImageSkia*>(image.ToImageSkia()); | 125 return const_cast<gfx::ImageSkia*>(image.ToImageSkia()); |
135 } | 126 } |
136 | 127 |
137 SkColor ThemeService::GetColor(int id) const { | 128 SkColor ThemeService::GetColor(int id) const { |
138 DCHECK(CalledOnValidThread()); | 129 DCHECK(CalledOnValidThread()); |
139 | |
140 // TODO(akuegel): Remove this once we have the default managed user theme. | |
141 if (IsManagedUser()) { | |
142 if (id == Properties::COLOR_FRAME) | |
143 id = Properties::COLOR_FRAME_MANAGED_USER; | |
144 else if (id == Properties::COLOR_FRAME_INACTIVE) | |
145 id = Properties::COLOR_FRAME_MANAGED_USER_INACTIVE; | |
146 } | |
147 | |
148 SkColor color; | 130 SkColor color; |
149 if (theme_pack_.get() && theme_pack_->GetColor(id, &color)) | 131 if (theme_supplier_.get() && theme_supplier_->GetColor(id, &color)) |
150 return color; | 132 return color; |
151 | 133 |
152 // For backward compat with older themes, some newer colors are generated from | 134 // For backward compat with older themes, some newer colors are generated from |
153 // older ones if they are missing. | 135 // older ones if they are missing. |
154 switch (id) { | 136 switch (id) { |
155 case Properties::COLOR_NTP_SECTION_HEADER_TEXT: | 137 case Properties::COLOR_NTP_SECTION_HEADER_TEXT: |
156 return IncreaseLightness(GetColor(Properties::COLOR_NTP_TEXT), 0.30); | 138 return IncreaseLightness(GetColor(Properties::COLOR_NTP_TEXT), 0.30); |
157 case Properties::COLOR_NTP_SECTION_HEADER_TEXT_HOVER: | 139 case Properties::COLOR_NTP_SECTION_HEADER_TEXT_HOVER: |
158 return GetColor(Properties::COLOR_NTP_TEXT); | 140 return GetColor(Properties::COLOR_NTP_TEXT); |
159 case Properties::COLOR_NTP_SECTION_HEADER_RULE: | 141 case Properties::COLOR_NTP_SECTION_HEADER_RULE: |
160 return IncreaseLightness(GetColor(Properties::COLOR_NTP_TEXT), 0.70); | 142 return IncreaseLightness(GetColor(Properties::COLOR_NTP_TEXT), 0.70); |
161 case Properties::COLOR_NTP_SECTION_HEADER_RULE_LIGHT: | 143 case Properties::COLOR_NTP_SECTION_HEADER_RULE_LIGHT: |
162 return IncreaseLightness(GetColor(Properties::COLOR_NTP_TEXT), 0.86); | 144 return IncreaseLightness(GetColor(Properties::COLOR_NTP_TEXT), 0.86); |
163 case Properties::COLOR_NTP_TEXT_LIGHT: | 145 case Properties::COLOR_NTP_TEXT_LIGHT: |
164 return IncreaseLightness(GetColor(Properties::COLOR_NTP_TEXT), 0.40); | 146 return IncreaseLightness(GetColor(Properties::COLOR_NTP_TEXT), 0.40); |
165 case Properties::COLOR_MANAGED_USER_LABEL: | 147 case Properties::COLOR_MANAGED_USER_LABEL: |
166 // TODO(akuegel): Use GetReadableColor() once we want to support other | 148 return color_utils::GetReadableColor( |
167 // themes as well. | 149 SK_ColorWHITE, |
168 return SkColorSetRGB(231, 245, 255); | 150 GetColor(Properties::COLOR_MANAGED_USER_LABEL_BACKGROUND)); |
169 case Properties::COLOR_MANAGED_USER_LABEL_BACKGROUND: | 151 case Properties::COLOR_MANAGED_USER_LABEL_BACKGROUND: |
170 // TODO(akuegel): Replace this constant by a color calculated from the | 152 return color_utils::BlendTowardOppositeLuminance( |
171 // frame color once the default managed user theme is finished and we | 153 GetColor(Properties::COLOR_FRAME), 0x80); |
172 // allow managed users to install other themes. | |
173 return SkColorSetRGB(108, 167, 210); | |
174 } | 154 } |
175 | 155 |
176 return Properties::GetDefaultColor(id); | 156 return Properties::GetDefaultColor(id); |
177 } | 157 } |
178 | 158 |
179 bool ThemeService::GetDisplayProperty(int id, int* result) const { | 159 bool ThemeService::GetDisplayProperty(int id, int* result) const { |
180 if (theme_pack_.get()) | 160 if (theme_supplier_.get()) |
181 return theme_pack_->GetDisplayProperty(id, result); | 161 return theme_supplier_->GetDisplayProperty(id, result); |
182 | 162 |
183 return Properties::GetDefaultDisplayProperty(id, result); | 163 return Properties::GetDefaultDisplayProperty(id, result); |
184 } | 164 } |
185 | 165 |
186 bool ThemeService::ShouldUseNativeFrame() const { | 166 bool ThemeService::ShouldUseNativeFrame() const { |
187 if (HasCustomImage(IDR_THEME_FRAME)) | 167 if (HasCustomImage(IDR_THEME_FRAME)) |
188 return false; | 168 return false; |
189 #if defined(OS_WIN) | 169 #if defined(OS_WIN) |
190 return ui::win::IsAeroGlassEnabled(); | 170 return ui::win::IsAeroGlassEnabled(); |
191 #else | 171 #else |
192 return false; | 172 return false; |
193 #endif | 173 #endif |
194 } | 174 } |
195 | 175 |
196 bool ThemeService::HasCustomImage(int id) const { | 176 bool ThemeService::HasCustomImage(int id) const { |
197 if (!Properties::IsThemeableImage(id)) | 177 if (!Properties::IsThemeableImage(id)) |
198 return false; | 178 return false; |
199 | 179 |
200 if (theme_pack_.get()) | 180 if (theme_supplier_.get()) |
201 return theme_pack_->HasCustomImage(id); | 181 return theme_supplier_->HasCustomImage(id); |
202 | |
203 if (IsManagedUser() && | |
204 (id == IDR_THEME_FRAME || id == IDR_THEME_FRAME_INACTIVE || | |
205 id == IDR_THEME_TAB_BACKGROUND || id == IDR_THEME_TAB_BACKGROUND_V)) | |
206 return true; | |
207 | 182 |
208 return false; | 183 return false; |
209 } | 184 } |
210 | 185 |
211 base::RefCountedMemory* ThemeService::GetRawData( | 186 base::RefCountedMemory* ThemeService::GetRawData( |
212 int id, | 187 int id, |
213 ui::ScaleFactor scale_factor) const { | 188 ui::ScaleFactor scale_factor) const { |
214 // Check to see whether we should substitute some images. | 189 // Check to see whether we should substitute some images. |
215 int ntp_alternate; | 190 int ntp_alternate; |
216 GetDisplayProperty(Properties::NTP_LOGO_ALTERNATE, &ntp_alternate); | 191 GetDisplayProperty(Properties::NTP_LOGO_ALTERNATE, &ntp_alternate); |
217 if (id == IDR_PRODUCT_LOGO && ntp_alternate != 0) | 192 if (id == IDR_PRODUCT_LOGO && ntp_alternate != 0) |
218 id = IDR_PRODUCT_LOGO_WHITE; | 193 id = IDR_PRODUCT_LOGO_WHITE; |
219 | 194 |
220 base::RefCountedMemory* data = NULL; | 195 base::RefCountedMemory* data = NULL; |
221 if (theme_pack_.get()) | 196 if (theme_supplier_.get()) |
222 data = theme_pack_->GetRawData(id, scale_factor); | 197 data = theme_supplier_->GetRawData(id, scale_factor); |
223 if (!data) | 198 if (!data) |
224 data = rb_.LoadDataResourceBytesForScale(id, ui::SCALE_FACTOR_100P); | 199 data = rb_.LoadDataResourceBytesForScale(id, ui::SCALE_FACTOR_100P); |
225 | 200 |
226 return data; | 201 return data; |
227 } | 202 } |
228 | 203 |
229 void ThemeService::Observe(int type, | 204 void ThemeService::Observe(int type, |
230 const content::NotificationSource& source, | 205 const content::NotificationSource& source, |
231 const content::NotificationDetails& details) { | 206 const content::NotificationDetails& details) { |
232 DCHECK(type == chrome::NOTIFICATION_EXTENSIONS_READY); | 207 DCHECK(type == chrome::NOTIFICATION_EXTENSIONS_READY); |
(...skipping 21 matching lines...) Expand all Loading... |
254 DCHECK(service->GetExtensionById(extension->id(), false)); | 229 DCHECK(service->GetExtensionById(extension->id(), false)); |
255 } | 230 } |
256 | 231 |
257 BuildFromExtension(extension); | 232 BuildFromExtension(extension); |
258 SaveThemeID(extension->id()); | 233 SaveThemeID(extension->id()); |
259 | 234 |
260 NotifyThemeChanged(); | 235 NotifyThemeChanged(); |
261 content::RecordAction(UserMetricsAction("Themes_Installed")); | 236 content::RecordAction(UserMetricsAction("Themes_Installed")); |
262 } | 237 } |
263 | 238 |
| 239 void ThemeService::SetCustomDefaultTheme( |
| 240 scoped_refptr<CustomThemeSupplier> theme_supplier) { |
| 241 ClearAllThemeData(); |
| 242 SwapThemeSupplier(theme_supplier); |
| 243 NotifyThemeChanged(); |
| 244 } |
| 245 |
| 246 bool ThemeService::ShouldInitWithNativeTheme() { |
| 247 return false; |
| 248 } |
| 249 |
264 void ThemeService::RemoveUnusedThemes() { | 250 void ThemeService::RemoveUnusedThemes() { |
265 if (!profile_) | 251 // We do not want to garbage collect themes on startup (|ready_| is false). |
| 252 // Themes will get garbage collected once |
| 253 // ExtensionService::GarbageCollectExtensions() runs. |
| 254 if (!profile_ || !ready_) |
266 return; | 255 return; |
| 256 |
267 ExtensionService* service = profile_->GetExtensionService(); | 257 ExtensionService* service = profile_->GetExtensionService(); |
268 if (!service) | 258 if (!service) |
269 return; | 259 return; |
270 std::string current_theme = GetThemeID(); | 260 std::string current_theme = GetThemeID(); |
271 std::vector<std::string> remove_list; | 261 std::vector<std::string> remove_list; |
272 const ExtensionSet* extensions = service->extensions(); | 262 const ExtensionSet* extensions = service->extensions(); |
273 for (ExtensionSet::const_iterator it = extensions->begin(); | 263 for (ExtensionSet::const_iterator it = extensions->begin(); |
274 it != extensions->end(); ++it) { | 264 it != extensions->end(); ++it) { |
275 if ((*it)->is_theme() && (*it)->id() != current_theme) { | 265 if ((*it)->is_theme() && (*it)->id() != current_theme) { |
276 remove_list.push_back((*it)->id()); | 266 remove_list.push_back((*it)->id()); |
277 } | 267 } |
278 } | 268 } |
279 for (size_t i = 0; i < remove_list.size(); ++i) | 269 for (size_t i = 0; i < remove_list.size(); ++i) |
280 service->UninstallExtension(remove_list[i], false, NULL); | 270 service->UninstallExtension(remove_list[i], false, NULL); |
281 } | 271 } |
282 | 272 |
283 void ThemeService::UseDefaultTheme() { | 273 void ThemeService::UseDefaultTheme() { |
| 274 if (ready_) |
| 275 content::RecordAction(UserMetricsAction("Themes_Reset")); |
| 276 if (IsManagedUser()) { |
| 277 SetManagedUserTheme(); |
| 278 return; |
| 279 } |
284 ClearAllThemeData(); | 280 ClearAllThemeData(); |
285 NotifyThemeChanged(); | 281 NotifyThemeChanged(); |
286 content::RecordAction(UserMetricsAction("Themes_Reset")); | |
287 } | 282 } |
288 | 283 |
289 void ThemeService::SetNativeTheme() { | 284 void ThemeService::SetNativeTheme() { |
290 UseDefaultTheme(); | 285 UseDefaultTheme(); |
291 } | 286 } |
292 | 287 |
293 bool ThemeService::UsingDefaultTheme() const { | 288 bool ThemeService::UsingDefaultTheme() const { |
294 std::string id = GetThemeID(); | 289 std::string id = GetThemeID(); |
295 return id == ThemeService::kDefaultThemeID || | 290 return id == ThemeService::kDefaultThemeID || |
296 id == kDefaultThemeGalleryID; | 291 (id == kDefaultThemeGalleryID && !IsManagedUser()); |
297 } | 292 } |
298 | 293 |
299 bool ThemeService::UsingNativeTheme() const { | 294 bool ThemeService::UsingNativeTheme() const { |
300 return UsingDefaultTheme(); | 295 return UsingDefaultTheme(); |
301 } | 296 } |
302 | 297 |
303 std::string ThemeService::GetThemeID() const { | 298 std::string ThemeService::GetThemeID() const { |
304 return profile_->GetPrefs()->GetString(prefs::kCurrentThemeID); | 299 return profile_->GetPrefs()->GetString(prefs::kCurrentThemeID); |
305 } | 300 } |
306 | 301 |
307 color_utils::HSL ThemeService::GetTint(int id) const { | 302 color_utils::HSL ThemeService::GetTint(int id) const { |
308 DCHECK(CalledOnValidThread()); | 303 DCHECK(CalledOnValidThread()); |
309 | 304 |
310 color_utils::HSL hsl; | 305 color_utils::HSL hsl; |
311 if (theme_pack_.get() && theme_pack_->GetTint(id, &hsl)) | 306 if (theme_supplier_.get() && theme_supplier_->GetTint(id, &hsl)) |
312 return hsl; | 307 return hsl; |
313 | 308 |
314 return ThemeProperties::GetDefaultTint(id); | 309 return ThemeProperties::GetDefaultTint(id); |
315 } | 310 } |
316 | 311 |
317 void ThemeService::ClearAllThemeData() { | 312 void ThemeService::ClearAllThemeData() { |
| 313 SwapThemeSupplier(NULL); |
| 314 |
318 // Clear our image cache. | 315 // Clear our image cache. |
319 FreePlatformCaches(); | 316 FreePlatformCaches(); |
320 theme_pack_ = NULL; | |
321 | 317 |
322 profile_->GetPrefs()->ClearPref(prefs::kCurrentThemePackFilename); | 318 profile_->GetPrefs()->ClearPref(prefs::kCurrentThemePackFilename); |
323 SaveThemeID(kDefaultThemeID); | 319 SaveThemeID(kDefaultThemeID); |
324 | 320 |
325 RemoveUnusedThemes(); | 321 RemoveUnusedThemes(); |
326 } | 322 } |
327 | 323 |
328 void ThemeService::LoadThemePrefs() { | 324 void ThemeService::LoadThemePrefs() { |
329 PrefService* prefs = profile_->GetPrefs(); | 325 PrefService* prefs = profile_->GetPrefs(); |
330 | 326 |
331 std::string current_id = GetThemeID(); | 327 std::string current_id = GetThemeID(); |
332 if (current_id == kDefaultThemeID) { | 328 if (current_id == kDefaultThemeID) { |
| 329 // Managed users have a different default theme. |
| 330 if (IsManagedUser()) |
| 331 SetManagedUserTheme(); |
| 332 else if (ShouldInitWithNativeTheme()) |
| 333 SetNativeTheme(); |
| 334 else |
| 335 UseDefaultTheme(); |
333 set_ready(); | 336 set_ready(); |
334 return; | 337 return; |
335 } | 338 } |
336 | 339 |
337 bool loaded_pack = false; | 340 bool loaded_pack = false; |
338 | 341 |
339 // If we don't have a file pack, we're updating from an old version. | 342 // If we don't have a file pack, we're updating from an old version. |
340 base::FilePath path = prefs->GetFilePath(prefs::kCurrentThemePackFilename); | 343 base::FilePath path = prefs->GetFilePath(prefs::kCurrentThemePackFilename); |
341 if (path != base::FilePath()) { | 344 if (path != base::FilePath()) { |
342 theme_pack_ = BrowserThemePack::BuildFromDataPack(path, current_id); | 345 SwapThemeSupplier(BrowserThemePack::BuildFromDataPack(path, current_id)); |
343 loaded_pack = theme_pack_.get() != NULL; | 346 loaded_pack = theme_supplier_.get() != NULL; |
344 } | 347 } |
345 | 348 |
346 if (loaded_pack) { | 349 if (loaded_pack) { |
347 content::RecordAction(UserMetricsAction("Themes.Loaded")); | 350 content::RecordAction(UserMetricsAction("Themes.Loaded")); |
348 set_ready(); | 351 set_ready(); |
349 } else { | 352 } else { |
350 // TODO(erg): We need to pop up a dialog informing the user that their | 353 // TODO(erg): We need to pop up a dialog informing the user that their |
351 // theme is being migrated. | 354 // theme is being migrated. |
352 ExtensionService* service = | 355 ExtensionService* service = |
353 extensions::ExtensionSystem::Get(profile_)->extension_service(); | 356 extensions::ExtensionSystem::Get(profile_)->extension_service(); |
(...skipping 21 matching lines...) Expand all Loading... |
375 theme_syncable_service_->OnThemeChange(); | 378 theme_syncable_service_->OnThemeChange(); |
376 } | 379 } |
377 } | 380 } |
378 | 381 |
379 #if defined(OS_WIN) || defined(USE_AURA) | 382 #if defined(OS_WIN) || defined(USE_AURA) |
380 void ThemeService::FreePlatformCaches() { | 383 void ThemeService::FreePlatformCaches() { |
381 // Views (Skia) has no platform image cache to clear. | 384 // Views (Skia) has no platform image cache to clear. |
382 } | 385 } |
383 #endif | 386 #endif |
384 | 387 |
| 388 void ThemeService::SwapThemeSupplier( |
| 389 scoped_refptr<CustomThemeSupplier> theme_supplier) { |
| 390 if (theme_supplier_.get()) |
| 391 theme_supplier_->StopUsingTheme(); |
| 392 theme_supplier_ = theme_supplier; |
| 393 if (theme_supplier_.get()) |
| 394 theme_supplier_->StartUsingTheme(); |
| 395 } |
| 396 |
385 void ThemeService::MigrateTheme() { | 397 void ThemeService::MigrateTheme() { |
386 ExtensionService* service = | 398 ExtensionService* service = |
387 extensions::ExtensionSystem::Get(profile_)->extension_service(); | 399 extensions::ExtensionSystem::Get(profile_)->extension_service(); |
388 const Extension* extension = service ? | 400 const Extension* extension = service ? |
389 service->GetExtensionById(GetThemeID(), false) : NULL; | 401 service->GetExtensionById(GetThemeID(), false) : NULL; |
390 if (extension) { | 402 if (extension) { |
391 DLOG(ERROR) << "Migrating theme"; | 403 DLOG(ERROR) << "Migrating theme"; |
392 BuildFromExtension(extension); | 404 BuildFromExtension(extension); |
393 content::RecordAction(UserMetricsAction("Themes.Migrated")); | 405 content::RecordAction(UserMetricsAction("Themes.Migrated")); |
394 } else { | 406 } else { |
(...skipping 28 matching lines...) Expand all Loading... |
423 return; | 435 return; |
424 | 436 |
425 // Write the packed file to disk. | 437 // Write the packed file to disk. |
426 base::FilePath pack_path = | 438 base::FilePath pack_path = |
427 extension->path().Append(chrome::kThemePackFilename); | 439 extension->path().Append(chrome::kThemePackFilename); |
428 service->GetFileTaskRunner()->PostTask( | 440 service->GetFileTaskRunner()->PostTask( |
429 FROM_HERE, | 441 FROM_HERE, |
430 base::Bind(&WritePackToDiskCallback, pack, pack_path)); | 442 base::Bind(&WritePackToDiskCallback, pack, pack_path)); |
431 | 443 |
432 SavePackName(pack_path); | 444 SavePackName(pack_path); |
433 theme_pack_ = pack; | 445 SwapThemeSupplier(pack); |
434 } | 446 } |
435 | 447 |
436 bool ThemeService::IsManagedUser() const { | 448 bool ThemeService::IsManagedUser() const { |
437 #if defined(ENABLE_MANAGED_USERS) | 449 #if defined(ENABLE_MANAGED_USERS) |
438 return ManagedUserService::ProfileIsManaged(profile_); | 450 return ManagedUserService::ProfileIsManaged(profile_); |
439 #endif | 451 #endif |
440 return false; | 452 return false; |
441 } | 453 } |
442 | 454 |
| 455 void ThemeService::SetManagedUserTheme() { |
| 456 #if defined(ENABLE_MANAGED_USERS) |
| 457 SetCustomDefaultTheme(new ManagedUserTheme); |
| 458 #endif |
| 459 } |
| 460 |
443 void ThemeService::OnInfobarDisplayed() { | 461 void ThemeService::OnInfobarDisplayed() { |
444 number_of_infobars_++; | 462 number_of_infobars_++; |
445 } | 463 } |
446 | 464 |
447 void ThemeService::OnInfobarDestroyed() { | 465 void ThemeService::OnInfobarDestroyed() { |
448 number_of_infobars_--; | 466 number_of_infobars_--; |
449 | 467 |
450 if (number_of_infobars_ == 0) | 468 if (number_of_infobars_ == 0) |
451 RemoveUnusedThemes(); | 469 RemoveUnusedThemes(); |
452 } | 470 } |
453 | 471 |
454 ThemeSyncableService* ThemeService::GetThemeSyncableService() const { | 472 ThemeSyncableService* ThemeService::GetThemeSyncableService() const { |
455 return theme_syncable_service_.get(); | 473 return theme_syncable_service_.get(); |
456 } | 474 } |
OLD | NEW |