| OLD | NEW |
| 1 // Copyright (c) 2009 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2009 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/browser_theme_provider.h" | 5 #include "chrome/browser/browser_theme_provider.h" |
| 6 | 6 |
| 7 #include "app/gfx/codec/png_codec.h" | 7 #include "app/gfx/codec/png_codec.h" |
| 8 #include "app/gfx/skbitmap_operations.h" | 8 #include "app/gfx/skbitmap_operations.h" |
| 9 #include "base/file_util.h" | 9 #include "base/file_util.h" |
| 10 #include "base/stl_util-inl.h" | 10 #include "base/stl_util-inl.h" |
| 11 #include "base/string_util.h" | 11 #include "base/string_util.h" |
| 12 #include "base/thread.h" | 12 #include "base/thread.h" |
| 13 #include "base/values.h" | 13 #include "base/values.h" |
| 14 #include "chrome/browser/browser_list.h" | 14 #include "chrome/browser/browser_list.h" |
| 15 #include "chrome/browser/browser_process.h" | 15 #include "chrome/browser/browser_process.h" |
| 16 #include "chrome/browser/browser_window.h" | 16 #include "chrome/browser/browser_window.h" |
| 17 #include "chrome/browser/extensions/extensions_service.h" |
| 17 #include "chrome/browser/metrics/user_metrics.h" | 18 #include "chrome/browser/metrics/user_metrics.h" |
| 18 #include "chrome/browser/profile.h" | 19 #include "chrome/browser/profile.h" |
| 19 #include "chrome/browser/theme_resources_util.h" | 20 #include "chrome/browser/theme_resources_util.h" |
| 20 #include "chrome/common/chrome_constants.h" | 21 #include "chrome/common/chrome_constants.h" |
| 21 #include "chrome/common/extensions/extension.h" | 22 #include "chrome/common/extensions/extension.h" |
| 22 #include "chrome/common/notification_service.h" | 23 #include "chrome/common/notification_service.h" |
| 23 #include "chrome/common/notification_type.h" | 24 #include "chrome/common/notification_type.h" |
| 24 #include "chrome/common/pref_names.h" | 25 #include "chrome/common/pref_names.h" |
| 25 #include "chrome/common/pref_service.h" | 26 #include "chrome/common/pref_service.h" |
| 26 #include "grit/app_resources.h" | 27 #include "grit/app_resources.h" |
| (...skipping 265 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 292 resource_names_[IDR_THEME_NTP_BACKGROUND] = "theme_ntp_background"; | 293 resource_names_[IDR_THEME_NTP_BACKGROUND] = "theme_ntp_background"; |
| 293 resource_names_[IDR_THEME_BUTTON_BACKGROUND] = "theme_button_background"; | 294 resource_names_[IDR_THEME_BUTTON_BACKGROUND] = "theme_button_background"; |
| 294 resource_names_[IDR_THEME_NTP_ATTRIBUTION] = "theme_ntp_attribution"; | 295 resource_names_[IDR_THEME_NTP_ATTRIBUTION] = "theme_ntp_attribution"; |
| 295 resource_names_[IDR_THEME_WINDOW_CONTROL_BACKGROUND] = | 296 resource_names_[IDR_THEME_WINDOW_CONTROL_BACKGROUND] = |
| 296 "theme_window_control_background"; | 297 "theme_window_control_background"; |
| 297 } | 298 } |
| 298 } | 299 } |
| 299 | 300 |
| 300 BrowserThemeProvider::~BrowserThemeProvider() { | 301 BrowserThemeProvider::~BrowserThemeProvider() { |
| 301 ClearCaches(); | 302 ClearCaches(); |
| 303 |
| 304 RemoveUnusedThemes(); |
| 302 } | 305 } |
| 303 | 306 |
| 304 void BrowserThemeProvider::Init(Profile* profile) { | 307 void BrowserThemeProvider::Init(Profile* profile) { |
| 305 DCHECK(CalledOnValidThread()); | 308 DCHECK(CalledOnValidThread()); |
| 306 profile_ = profile; | 309 profile_ = profile; |
| 307 | 310 |
| 308 image_dir_ = profile_->GetPath().Append(chrome::kThemeImagesDirname); | 311 image_dir_ = profile_->GetPath().Append(chrome::kThemeImagesDirname); |
| 309 if (!file_util::PathExists(image_dir_)) | 312 if (!file_util::PathExists(image_dir_)) |
| 310 file_util::CreateDirectory(image_dir_); | 313 file_util::CreateDirectory(image_dir_); |
| 311 | 314 |
| (...skipping 190 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 502 AutoLock lock(themed_image_cache_lock_); | 505 AutoLock lock(themed_image_cache_lock_); |
| 503 GenerateFrameImages(); | 506 GenerateFrameImages(); |
| 504 GenerateTabImages(); | 507 GenerateTabImages(); |
| 505 } | 508 } |
| 506 | 509 |
| 507 WriteImagesToDisk(); | 510 WriteImagesToDisk(); |
| 508 NotifyThemeChanged(); | 511 NotifyThemeChanged(); |
| 509 UserMetrics::RecordAction(L"Themes_Installed", profile_); | 512 UserMetrics::RecordAction(L"Themes_Installed", profile_); |
| 510 } | 513 } |
| 511 | 514 |
| 515 void BrowserThemeProvider::RemoveUnusedThemes() { |
| 516 if (!profile_) |
| 517 return; |
| 518 ExtensionsService* service = profile_->GetExtensionsService(); |
| 519 if (!service) |
| 520 return; |
| 521 std::string current_theme = GetThemeID(); |
| 522 std::vector<std::string> remove_list; |
| 523 const ExtensionList* extensions = service->extensions(); |
| 524 for (ExtensionList::const_iterator it = extensions->begin(); |
| 525 it != extensions->end(); ++it) { |
| 526 if ((*it)->IsTheme() && (*it)->id() != current_theme) { |
| 527 remove_list.push_back((*it)->id()); |
| 528 } |
| 529 } |
| 530 for (size_t i = 0; i < remove_list.size(); ++i) |
| 531 service->UninstallExtension(remove_list[i], false); |
| 532 } |
| 533 |
| 512 void BrowserThemeProvider::UseDefaultTheme() { | 534 void BrowserThemeProvider::UseDefaultTheme() { |
| 513 ClearAllThemeData(); | 535 ClearAllThemeData(); |
| 514 NotifyThemeChanged(); | 536 NotifyThemeChanged(); |
| 515 UserMetrics::RecordAction(L"Themes_Reset", profile_); | 537 UserMetrics::RecordAction(L"Themes_Reset", profile_); |
| 516 } | 538 } |
| 517 | 539 |
| 518 std::string BrowserThemeProvider::GetThemeID() const { | 540 std::string BrowserThemeProvider::GetThemeID() const { |
| 519 std::wstring id = profile_->GetPrefs()->GetString(prefs::kCurrentThemeID); | 541 std::wstring id = profile_->GetPrefs()->GetString(prefs::kCurrentThemeID); |
| 520 return WideToUTF8(id); | 542 return WideToUTF8(id); |
| 521 } | 543 } |
| (...skipping 752 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1274 void BrowserThemeProvider::SaveCachedImageData() const { | 1296 void BrowserThemeProvider::SaveCachedImageData() const { |
| 1275 DictionaryValue* pref_images = | 1297 DictionaryValue* pref_images = |
| 1276 profile_->GetPrefs()->GetMutableDictionary(prefs::kCurrentThemeImages); | 1298 profile_->GetPrefs()->GetMutableDictionary(prefs::kCurrentThemeImages); |
| 1277 | 1299 |
| 1278 for (ImagesDiskCache::const_iterator it(images_disk_cache_.begin()); | 1300 for (ImagesDiskCache::const_iterator it(images_disk_cache_.begin()); |
| 1279 it != images_disk_cache_.end(); ++it) { | 1301 it != images_disk_cache_.end(); ++it) { |
| 1280 std::wstring disk_path = it->first.ToWStringHack(); | 1302 std::wstring disk_path = it->first.ToWStringHack(); |
| 1281 std::string pref_name = resource_names_.find(it->second)->second; | 1303 std::string pref_name = resource_names_.find(it->second)->second; |
| 1282 pref_images->SetString(UTF8ToWide(pref_name), WideToUTF8(disk_path)); | 1304 pref_images->SetString(UTF8ToWide(pref_name), WideToUTF8(disk_path)); |
| 1283 } | 1305 } |
| 1284 profile_->GetPrefs()->SavePersistentPrefs(); | 1306 profile_->GetPrefs()->ScheduleSavePersistentPrefs(); |
| 1285 } | 1307 } |
| 1286 | 1308 |
| 1287 void BrowserThemeProvider::SaveThemeID(const std::string& id) { | 1309 void BrowserThemeProvider::SaveThemeID(const std::string& id) { |
| 1288 profile_->GetPrefs()->SetString(prefs::kCurrentThemeID, UTF8ToWide(id)); | 1310 profile_->GetPrefs()->SetString(prefs::kCurrentThemeID, UTF8ToWide(id)); |
| 1289 } | 1311 } |
| 1290 | 1312 |
| 1291 void BrowserThemeProvider::ClearCaches() { | 1313 void BrowserThemeProvider::ClearCaches() { |
| 1292 FreePlatformCaches(); | 1314 FreePlatformCaches(); |
| 1293 STLDeleteValues(&image_cache_); | 1315 STLDeleteValues(&image_cache_); |
| 1294 | 1316 |
| (...skipping 13 matching lines...) Expand all Loading... |
| 1308 } | 1330 } |
| 1309 | 1331 |
| 1310 bool BrowserThemeProvider::ShouldTintFrames() const { | 1332 bool BrowserThemeProvider::ShouldTintFrames() const { |
| 1311 return (HasCustomImage(IDR_THEME_FRAME) || | 1333 return (HasCustomImage(IDR_THEME_FRAME) || |
| 1312 tints_.count(GetTintKey(TINT_BACKGROUND_TAB)) || | 1334 tints_.count(GetTintKey(TINT_BACKGROUND_TAB)) || |
| 1313 tints_.count(GetTintKey(TINT_FRAME)) || | 1335 tints_.count(GetTintKey(TINT_FRAME)) || |
| 1314 tints_.count(GetTintKey(TINT_FRAME_INACTIVE)) || | 1336 tints_.count(GetTintKey(TINT_FRAME_INACTIVE)) || |
| 1315 tints_.count(GetTintKey(TINT_FRAME_INCOGNITO)) || | 1337 tints_.count(GetTintKey(TINT_FRAME_INCOGNITO)) || |
| 1316 tints_.count(GetTintKey(TINT_FRAME_INCOGNITO_INACTIVE))); | 1338 tints_.count(GetTintKey(TINT_FRAME_INCOGNITO_INACTIVE))); |
| 1317 } | 1339 } |
| OLD | NEW |