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

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

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 and add tests. 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 #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
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
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
244 // When loading the theme in LoadThemePrefs(), it is not necessary to call
245 // NotifyThemeChanged().
246 if (ready_)
pkotwicz 2013/07/22 20:17:28 Actually, you can skip checking |ready_| here. And
Adrian Kuegel 2013/07/23 08:13:29 Done.
247 NotifyThemeChanged();
248 }
249
250 bool ThemeService::ShouldInitWithNativeTheme() {
251 return false;
252 }
253
264 void ThemeService::RemoveUnusedThemes() { 254 void ThemeService::RemoveUnusedThemes() {
265 if (!profile_) 255 // We do not want to garbage collect themes on startup (|ready_| is false).
256 // Themes will get garbage collected once
257 // ExtensionService::GarbageCollectExtensions() runs
pkotwicz 2013/07/22 20:17:28 Nit '.' at the end of the sentence
Adrian Kuegel 2013/07/23 08:13:29 Done.
258 if (!profile_ || !ready_)
266 return; 259 return;
260
267 ExtensionService* service = profile_->GetExtensionService(); 261 ExtensionService* service = profile_->GetExtensionService();
268 if (!service) 262 if (!service)
269 return; 263 return;
270 std::string current_theme = GetThemeID(); 264 std::string current_theme = GetThemeID();
271 std::vector<std::string> remove_list; 265 std::vector<std::string> remove_list;
272 const ExtensionSet* extensions = service->extensions(); 266 const ExtensionSet* extensions = service->extensions();
273 for (ExtensionSet::const_iterator it = extensions->begin(); 267 for (ExtensionSet::const_iterator it = extensions->begin();
274 it != extensions->end(); ++it) { 268 it != extensions->end(); ++it) {
275 if ((*it)->is_theme() && (*it)->id() != current_theme) { 269 if ((*it)->is_theme() && (*it)->id() != current_theme) {
276 remove_list.push_back((*it)->id()); 270 remove_list.push_back((*it)->id());
277 } 271 }
278 } 272 }
279 for (size_t i = 0; i < remove_list.size(); ++i) 273 for (size_t i = 0; i < remove_list.size(); ++i)
280 service->UninstallExtension(remove_list[i], false, NULL); 274 service->UninstallExtension(remove_list[i], false, NULL);
281 } 275 }
282 276
283 void ThemeService::UseDefaultTheme() { 277 void ThemeService::UseDefaultTheme() {
278 content::RecordAction(UserMetricsAction("Themes_Reset"));
279 if (IsManagedUser()) {
280 SetManagedUserTheme();
281 return;
282 }
284 ClearAllThemeData(); 283 ClearAllThemeData();
285 NotifyThemeChanged(); 284 NotifyThemeChanged();
286 content::RecordAction(UserMetricsAction("Themes_Reset"));
287 } 285 }
288 286
289 void ThemeService::SetNativeTheme() { 287 void ThemeService::SetNativeTheme() {
290 UseDefaultTheme(); 288 UseDefaultTheme();
291 } 289 }
292 290
293 bool ThemeService::UsingDefaultTheme() const { 291 bool ThemeService::UsingDefaultTheme() const {
294 std::string id = GetThemeID(); 292 std::string id = GetThemeID();
pkotwicz 2013/07/22 20:17:28 Optional: You may not want to check |kDefaultTheme
Adrian Kuegel 2013/07/23 08:13:29 Right, good point. Changed.
295 return id == ThemeService::kDefaultThemeID || 293 return id == ThemeService::kDefaultThemeID ||
296 id == kDefaultThemeGalleryID; 294 id == kDefaultThemeGalleryID;
297 } 295 }
298 296
299 bool ThemeService::UsingNativeTheme() const { 297 bool ThemeService::UsingNativeTheme() const {
300 return UsingDefaultTheme(); 298 return UsingDefaultTheme();
301 } 299 }
302 300
303 std::string ThemeService::GetThemeID() const { 301 std::string ThemeService::GetThemeID() const {
304 return profile_->GetPrefs()->GetString(prefs::kCurrentThemeID); 302 return profile_->GetPrefs()->GetString(prefs::kCurrentThemeID);
305 } 303 }
306 304
307 color_utils::HSL ThemeService::GetTint(int id) const { 305 color_utils::HSL ThemeService::GetTint(int id) const {
308 DCHECK(CalledOnValidThread()); 306 DCHECK(CalledOnValidThread());
309 307
310 color_utils::HSL hsl; 308 color_utils::HSL hsl;
311 if (theme_pack_.get() && theme_pack_->GetTint(id, &hsl)) 309 if (theme_supplier_.get() && theme_supplier_->GetTint(id, &hsl))
312 return hsl; 310 return hsl;
313 311
314 return ThemeProperties::GetDefaultTint(id); 312 return ThemeProperties::GetDefaultTint(id);
315 } 313 }
316 314
317 void ThemeService::ClearAllThemeData() { 315 void ThemeService::ClearAllThemeData() {
316 SwapThemeSupplier(NULL);
317
318 // Clear our image cache. 318 // Clear our image cache.
319 FreePlatformCaches(); 319 FreePlatformCaches();
320 theme_pack_ = NULL; 320 theme_supplier_ = NULL;
pkotwicz 2013/07/22 20:17:28 The line above should be done for us by SwapThemeS
Adrian Kuegel 2013/07/23 08:13:29 Right. I have removed this line now.
321 321
322 profile_->GetPrefs()->ClearPref(prefs::kCurrentThemePackFilename); 322 profile_->GetPrefs()->ClearPref(prefs::kCurrentThemePackFilename);
323 SaveThemeID(kDefaultThemeID); 323 SaveThemeID(kDefaultThemeID);
324 324
325 RemoveUnusedThemes(); 325 RemoveUnusedThemes();
326 } 326 }
327 327
328 void ThemeService::LoadThemePrefs() { 328 void ThemeService::LoadThemePrefs() {
329 PrefService* prefs = profile_->GetPrefs(); 329 PrefService* prefs = profile_->GetPrefs();
330 330
331 std::string current_id = GetThemeID(); 331 std::string current_id = GetThemeID();
332 if (current_id == kDefaultThemeID) { 332 if (current_id == kDefaultThemeID) {
333 // Managed users should always have their own default theme.
pkotwicz 2013/07/22 20:17:28 How about: "Managed users have a different default
Adrian Kuegel 2013/07/23 08:13:29 Done.
334 if (IsManagedUser())
335 SetManagedUserTheme();
336 else if (ShouldInitWithNativeTheme())
337 SetNativeTheme();
pkotwicz 2013/07/22 20:17:28 I would rather call UseDefaultTheme() in the else
Adrian Kuegel 2013/07/23 08:13:29 Done.
333 set_ready(); 338 set_ready();
334 return; 339 return;
335 } 340 }
336 341
337 bool loaded_pack = false; 342 bool loaded_pack = false;
338 343
339 // If we don't have a file pack, we're updating from an old version. 344 // If we don't have a file pack, we're updating from an old version.
340 base::FilePath path = prefs->GetFilePath(prefs::kCurrentThemePackFilename); 345 base::FilePath path = prefs->GetFilePath(prefs::kCurrentThemePackFilename);
341 if (path != base::FilePath()) { 346 if (path != base::FilePath()) {
342 theme_pack_ = BrowserThemePack::BuildFromDataPack(path, current_id); 347 SwapThemeSupplier(BrowserThemePack::BuildFromDataPack(path, current_id));
343 loaded_pack = theme_pack_.get() != NULL; 348 loaded_pack = theme_supplier_.get() != NULL;
344 } 349 }
345 350
346 if (loaded_pack) { 351 if (loaded_pack) {
347 content::RecordAction(UserMetricsAction("Themes.Loaded")); 352 content::RecordAction(UserMetricsAction("Themes.Loaded"));
348 set_ready(); 353 set_ready();
349 } else { 354 } else {
350 // TODO(erg): We need to pop up a dialog informing the user that their 355 // TODO(erg): We need to pop up a dialog informing the user that their
351 // theme is being migrated. 356 // theme is being migrated.
352 ExtensionService* service = 357 ExtensionService* service =
353 extensions::ExtensionSystem::Get(profile_)->extension_service(); 358 extensions::ExtensionSystem::Get(profile_)->extension_service();
(...skipping 21 matching lines...) Expand all
375 theme_syncable_service_->OnThemeChange(); 380 theme_syncable_service_->OnThemeChange();
376 } 381 }
377 } 382 }
378 383
379 #if defined(OS_WIN) || defined(USE_AURA) 384 #if defined(OS_WIN) || defined(USE_AURA)
380 void ThemeService::FreePlatformCaches() { 385 void ThemeService::FreePlatformCaches() {
381 // Views (Skia) has no platform image cache to clear. 386 // Views (Skia) has no platform image cache to clear.
382 } 387 }
383 #endif 388 #endif
384 389
390 void ThemeService::SwapThemeSupplier(
391 scoped_refptr<CustomThemeSupplier> theme_supplier) {
392 if (theme_supplier_.get())
393 theme_supplier_->StopUsingTheme();
394 theme_supplier_ = theme_supplier;
395 if (theme_supplier_.get())
396 theme_supplier_->StartUsingTheme();
397 }
398
385 void ThemeService::MigrateTheme() { 399 void ThemeService::MigrateTheme() {
386 ExtensionService* service = 400 ExtensionService* service =
387 extensions::ExtensionSystem::Get(profile_)->extension_service(); 401 extensions::ExtensionSystem::Get(profile_)->extension_service();
388 const Extension* extension = service ? 402 const Extension* extension = service ?
389 service->GetExtensionById(GetThemeID(), false) : NULL; 403 service->GetExtensionById(GetThemeID(), false) : NULL;
390 if (extension) { 404 if (extension) {
391 DLOG(ERROR) << "Migrating theme"; 405 DLOG(ERROR) << "Migrating theme";
392 BuildFromExtension(extension); 406 BuildFromExtension(extension);
393 content::RecordAction(UserMetricsAction("Themes.Migrated")); 407 content::RecordAction(UserMetricsAction("Themes.Migrated"));
394 } else { 408 } else {
(...skipping 28 matching lines...) Expand all
423 return; 437 return;
424 438
425 // Write the packed file to disk. 439 // Write the packed file to disk.
426 base::FilePath pack_path = 440 base::FilePath pack_path =
427 extension->path().Append(chrome::kThemePackFilename); 441 extension->path().Append(chrome::kThemePackFilename);
428 service->GetFileTaskRunner()->PostTask( 442 service->GetFileTaskRunner()->PostTask(
429 FROM_HERE, 443 FROM_HERE,
430 base::Bind(&WritePackToDiskCallback, pack, pack_path)); 444 base::Bind(&WritePackToDiskCallback, pack, pack_path));
431 445
432 SavePackName(pack_path); 446 SavePackName(pack_path);
433 theme_pack_ = pack; 447 SwapThemeSupplier(pack);
434 } 448 }
435 449
436 bool ThemeService::IsManagedUser() const { 450 bool ThemeService::IsManagedUser() const {
437 #if defined(ENABLE_MANAGED_USERS) 451 #if defined(ENABLE_MANAGED_USERS)
438 return ManagedUserService::ProfileIsManaged(profile_); 452 return ManagedUserService::ProfileIsManaged(profile_);
439 #endif 453 #endif
440 return false; 454 return false;
441 } 455 }
442 456
457 void ThemeService::SetManagedUserTheme() {
458 #if defined(ENABLE_MANAGED_USERS)
459 SetCustomDefaultTheme(new ManagedUserTheme);
460 #endif
461 }
462
443 void ThemeService::OnInfobarDisplayed() { 463 void ThemeService::OnInfobarDisplayed() {
444 number_of_infobars_++; 464 number_of_infobars_++;
445 } 465 }
446 466
447 void ThemeService::OnInfobarDestroyed() { 467 void ThemeService::OnInfobarDestroyed() {
448 number_of_infobars_--; 468 number_of_infobars_--;
449 469
450 if (number_of_infobars_ == 0) 470 if (number_of_infobars_ == 0)
451 RemoveUnusedThemes(); 471 RemoveUnusedThemes();
452 } 472 }
453 473
454 ThemeSyncableService* ThemeService::GetThemeSyncableService() const { 474 ThemeSyncableService* ThemeService::GetThemeSyncableService() const {
455 return theme_syncable_service_.get(); 475 return theme_syncable_service_.get();
456 } 476 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698