| 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" |
| (...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 67 // Writes the theme pack to disk on a separate thread. | 67 // Writes the theme pack to disk on a separate thread. |
| 68 void WritePackToDiskCallback(BrowserThemePack* pack, | 68 void WritePackToDiskCallback(BrowserThemePack* pack, |
| 69 const base::FilePath& path) { | 69 const base::FilePath& path) { |
| 70 if (!pack->WriteToDisk(path)) | 70 if (!pack->WriteToDisk(path)) |
| 71 NOTREACHED() << "Could not write theme pack to disk"; | 71 NOTREACHED() << "Could not write theme pack to disk"; |
| 72 } | 72 } |
| 73 | 73 |
| 74 } // namespace | 74 } // namespace |
| 75 | 75 |
| 76 ThemeService::ThemeService() | 76 ThemeService::ThemeService() |
| 77 : rb_(ResourceBundle::GetSharedInstance()), | 77 : ready_(false), |
| 78 rb_(ResourceBundle::GetSharedInstance()), |
| 78 profile_(NULL), | 79 profile_(NULL), |
| 79 ready_(false), | |
| 80 number_of_infobars_(0) { | 80 number_of_infobars_(0) { |
| 81 } | 81 } |
| 82 | 82 |
| 83 ThemeService::~ThemeService() { | 83 ThemeService::~ThemeService() { |
| 84 FreePlatformCaches(); | 84 FreePlatformCaches(); |
| 85 } | 85 } |
| 86 | 86 |
| 87 void ThemeService::Init(Profile* profile) { | 87 void ThemeService::Init(Profile* profile) { |
| 88 DCHECK(CalledOnValidThread()); | 88 DCHECK(CalledOnValidThread()); |
| 89 profile_ = profile; | 89 profile_ = profile; |
| (...skipping 176 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 266 service->UninstallExtension(remove_list[i], false, NULL); | 266 service->UninstallExtension(remove_list[i], false, NULL); |
| 267 } | 267 } |
| 268 | 268 |
| 269 void ThemeService::UseDefaultTheme() { | 269 void ThemeService::UseDefaultTheme() { |
| 270 if (ready_) | 270 if (ready_) |
| 271 content::RecordAction(UserMetricsAction("Themes_Reset")); | 271 content::RecordAction(UserMetricsAction("Themes_Reset")); |
| 272 if (IsManagedUser()) { | 272 if (IsManagedUser()) { |
| 273 SetManagedUserTheme(); | 273 SetManagedUserTheme(); |
| 274 return; | 274 return; |
| 275 } | 275 } |
| 276 if (ready_) { | 276 ClearAllThemeData(); |
| 277 ClearAllThemeData(); | 277 NotifyThemeChanged(); |
| 278 NotifyThemeChanged(); | |
| 279 } | |
| 280 } | 278 } |
| 281 | 279 |
| 282 void ThemeService::SetNativeTheme() { | 280 void ThemeService::SetNativeTheme() { |
| 283 UseDefaultTheme(); | 281 UseDefaultTheme(); |
| 284 } | 282 } |
| 285 | 283 |
| 286 bool ThemeService::UsingDefaultTheme() const { | 284 bool ThemeService::UsingDefaultTheme() const { |
| 287 std::string id = GetThemeID(); | 285 std::string id = GetThemeID(); |
| 288 return id == ThemeService::kDefaultThemeID || | 286 return id == ThemeService::kDefaultThemeID || |
| 289 (id == kDefaultThemeGalleryID && !IsManagedUser()); | 287 (id == kDefaultThemeGalleryID && !IsManagedUser()); |
| (...skipping 11 matching lines...) Expand all Loading... |
| 301 DCHECK(CalledOnValidThread()); | 299 DCHECK(CalledOnValidThread()); |
| 302 | 300 |
| 303 color_utils::HSL hsl; | 301 color_utils::HSL hsl; |
| 304 if (theme_supplier_.get() && theme_supplier_->GetTint(id, &hsl)) | 302 if (theme_supplier_.get() && theme_supplier_->GetTint(id, &hsl)) |
| 305 return hsl; | 303 return hsl; |
| 306 | 304 |
| 307 return ThemeProperties::GetDefaultTint(id); | 305 return ThemeProperties::GetDefaultTint(id); |
| 308 } | 306 } |
| 309 | 307 |
| 310 void ThemeService::ClearAllThemeData() { | 308 void ThemeService::ClearAllThemeData() { |
| 309 if (!ready_) |
| 310 return; |
| 311 |
| 311 SwapThemeSupplier(NULL); | 312 SwapThemeSupplier(NULL); |
| 312 | 313 |
| 313 // Clear our image cache. | 314 // Clear our image cache. |
| 314 FreePlatformCaches(); | 315 FreePlatformCaches(); |
| 315 | 316 |
| 316 profile_->GetPrefs()->ClearPref(prefs::kCurrentThemePackFilename); | 317 profile_->GetPrefs()->ClearPref(prefs::kCurrentThemePackFilename); |
| 317 SaveThemeID(kDefaultThemeID); | 318 SaveThemeID(kDefaultThemeID); |
| 318 | 319 |
| 319 RemoveUnusedThemes(); | 320 RemoveUnusedThemes(); |
| 320 } | 321 } |
| (...skipping 140 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 461 void ThemeService::OnInfobarDestroyed() { | 462 void ThemeService::OnInfobarDestroyed() { |
| 462 number_of_infobars_--; | 463 number_of_infobars_--; |
| 463 | 464 |
| 464 if (number_of_infobars_ == 0) | 465 if (number_of_infobars_ == 0) |
| 465 RemoveUnusedThemes(); | 466 RemoveUnusedThemes(); |
| 466 } | 467 } |
| 467 | 468 |
| 468 ThemeSyncableService* ThemeService::GetThemeSyncableService() const { | 469 ThemeSyncableService* ThemeService::GetThemeSyncableService() const { |
| 469 return theme_syncable_service_.get(); | 470 return theme_syncable_service_.get(); |
| 470 } | 471 } |
| OLD | NEW |