| 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 "base/file_util.h" | 7 #include "base/file_util.h" |
| 8 #include "base/gfx/png_decoder.h" | 8 #include "base/gfx/png_decoder.h" |
| 9 #include "base/gfx/png_encoder.h" | 9 #include "base/gfx/png_encoder.h" |
| 10 #include "base/string_util.h" | 10 #include "base/string_util.h" |
| (...skipping 1112 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1123 | 1123 |
| 1124 void BrowserThemeProvider::NotifyThemeChanged() { | 1124 void BrowserThemeProvider::NotifyThemeChanged() { |
| 1125 // Redraw! | 1125 // Redraw! |
| 1126 NotificationService* service = NotificationService::current(); | 1126 NotificationService* service = NotificationService::current(); |
| 1127 service->Notify(NotificationType::BROWSER_THEME_CHANGED, | 1127 service->Notify(NotificationType::BROWSER_THEME_CHANGED, |
| 1128 Source<BrowserThemeProvider>(this), | 1128 Source<BrowserThemeProvider>(this), |
| 1129 NotificationService::NoDetails()); | 1129 NotificationService::NoDetails()); |
| 1130 } | 1130 } |
| 1131 | 1131 |
| 1132 void BrowserThemeProvider::LoadThemePrefs() { | 1132 void BrowserThemeProvider::LoadThemePrefs() { |
| 1133 // Images were already processed when theme was set. | |
| 1134 process_images_ = false; | 1133 process_images_ = false; |
| 1135 | |
| 1136 PrefService* prefs = profile_->GetPrefs(); | 1134 PrefService* prefs = profile_->GetPrefs(); |
| 1137 | 1135 |
| 1138 // TODO(glen): Figure out if any custom prefs were loaded, and if so | 1136 // TODO(glen): Figure out if any custom prefs were loaded, and if so |
| 1139 // UMA-log the fact that a theme was loaded. | 1137 // UMA-log the fact that a theme was loaded. |
| 1140 if (prefs->HasPrefPath(prefs::kCurrentThemeImages) || | 1138 if (prefs->HasPrefPath(prefs::kCurrentThemeImages) || |
| 1141 prefs->HasPrefPath(prefs::kCurrentThemeColors) || | 1139 prefs->HasPrefPath(prefs::kCurrentThemeColors) || |
| 1142 prefs->HasPrefPath(prefs::kCurrentThemeTints)) { | 1140 prefs->HasPrefPath(prefs::kCurrentThemeTints)) { |
| 1143 // Our prefs already have the extension path baked in, so we don't need | 1141 // Our prefs already have the extension path baked in, so we don't need |
| 1144 // to provide it. | 1142 // to provide it. |
| 1145 SetImageData(prefs->GetMutableDictionary(prefs::kCurrentThemeImages), | 1143 SetImageData(prefs->GetMutableDictionary(prefs::kCurrentThemeImages), |
| 1146 FilePath()); | 1144 FilePath()); |
| 1147 SetColorData(prefs->GetMutableDictionary(prefs::kCurrentThemeColors)); | 1145 SetColorData(prefs->GetMutableDictionary(prefs::kCurrentThemeColors)); |
| 1148 SetTintData(prefs->GetMutableDictionary(prefs::kCurrentThemeTints)); | 1146 SetTintData(prefs->GetMutableDictionary(prefs::kCurrentThemeTints)); |
| 1149 SetDisplayPropertyData( | 1147 SetDisplayPropertyData( |
| 1150 prefs->GetMutableDictionary(prefs::kCurrentThemeDisplayProperties)); | 1148 prefs->GetMutableDictionary(prefs::kCurrentThemeDisplayProperties)); |
| 1149 |
| 1150 // If we're not loading the frame from the cached image dir, we are using |
| 1151 // an old preferences file, or the processed images were not saved |
| 1152 // correctly. Force image reprocessing and caching. |
| 1153 if (images_.count(IDR_THEME_FRAME) > 0) { |
| 1154 #if defined(OS_WIN) |
| 1155 FilePath cache_path = FilePath(UTF8ToWide(images_[IDR_THEME_FRAME])); |
| 1156 #else |
| 1157 FilePath cache_path = FilePath(images_[IDR_THEME_FRAME]); |
| 1158 #endif |
| 1159 process_images_ = !file_util::ContainsPath(image_dir_, cache_path); |
| 1160 } |
| 1161 |
| 1151 GenerateFrameColors(); | 1162 GenerateFrameColors(); |
| 1152 GenerateFrameImages(); | 1163 GenerateFrameImages(); |
| 1153 GenerateTabImages(); | 1164 GenerateTabImages(); |
| 1165 if (process_images_) { |
| 1166 WriteImagesToDisk(); |
| 1167 UserMetrics::RecordAction(L"Migrated noncached to cached theme.", |
| 1168 profile_); |
| 1169 } |
| 1154 UserMetrics::RecordAction(L"Themes_loaded", profile_); | 1170 UserMetrics::RecordAction(L"Themes_loaded", profile_); |
| 1155 } | 1171 } |
| 1156 } | 1172 } |
| 1157 | 1173 |
| 1158 void BrowserThemeProvider::ClearCaches() { | 1174 void BrowserThemeProvider::ClearCaches() { |
| 1159 FreePlatformCaches(); | 1175 FreePlatformCaches(); |
| 1160 for (ImageCache::iterator i = image_cache_.begin(); | 1176 for (ImageCache::iterator i = image_cache_.begin(); |
| 1161 i != image_cache_.end(); i++) { | 1177 i != image_cache_.end(); i++) { |
| 1162 delete i->second; | 1178 delete i->second; |
| 1163 } | 1179 } |
| 1164 image_cache_.clear(); | 1180 image_cache_.clear(); |
| 1165 | 1181 |
| 1166 // The SkBitmaps in the image_save_cache_ are a subset of those stored in | 1182 // The SkBitmaps in the image_save_cache_ are a subset of those stored in |
| 1167 // the image_cache_, and have therefore all been deleted in the lines above. | 1183 // the image_cache_, and have therefore all been deleted in the lines above. |
| 1168 // TODO(mirandac): make memory management clearer here. | 1184 // TODO(mirandac): make memory management clearer here. |
| 1169 image_save_cache_.clear(); | 1185 image_save_cache_.clear(); |
| 1170 } | 1186 } |
| 1171 | 1187 |
| 1172 #if defined(TOOLKIT_VIEWS) | 1188 #if defined(TOOLKIT_VIEWS) |
| 1173 void BrowserThemeProvider::FreePlatformCaches() { | 1189 void BrowserThemeProvider::FreePlatformCaches() { |
| 1174 // Views (Skia) has no platform image cache to clear. | 1190 // Views (Skia) has no platform image cache to clear. |
| 1175 } | 1191 } |
| 1176 #endif | 1192 #endif |
| OLD | NEW |