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/chromeos/login/wallpaper_manager.h" | 5 #include "chrome/browser/chromeos/login/wallpaper_manager.h" |
6 | 6 |
7 #include <vector> | 7 #include <vector> |
8 | 8 |
9 #include "ash/desktop_background/desktop_background_controller.h" | 9 #include "ash/desktop_background/desktop_background_controller.h" |
10 #include "ash/desktop_background/desktop_background_resources.h" | 10 #include "ash/desktop_background/desktop_background_resources.h" |
(...skipping 466 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
477 // If decoded wallpaper is empty, we are probably failed to decode the file. | 477 // If decoded wallpaper is empty, we are probably failed to decode the file. |
478 // Use default wallpaper in this case. | 478 // Use default wallpaper in this case. |
479 if (wallpaper.image().isNull()) { | 479 if (wallpaper.image().isNull()) { |
480 ash::Shell::GetInstance()->desktop_background_controller()-> | 480 ash::Shell::GetInstance()->desktop_background_controller()-> |
481 SetDefaultWallpaper(ash::GetDefaultWallpaperIndex()); | 481 SetDefaultWallpaper(ash::GetDefaultWallpaperIndex()); |
482 return; | 482 return; |
483 } | 483 } |
484 | 484 |
485 bool is_persistent = ShouldPersistDataForUser(username); | 485 bool is_persistent = ShouldPersistDataForUser(username); |
486 | 486 |
487 wallpaper.image().EnsureRepsForSupportedScaleFactors(); | |
488 scoped_ptr<gfx::ImageSkia> deep_copy(wallpaper.image().DeepCopy()); | |
489 | |
490 WallpaperInfo info = { | |
491 wallpaper_path, | |
492 layout, | |
493 User::CUSTOMIZED, | |
oshima
2012/11/13 17:46:42
shouldn't this be "type"?
bshe
2012/11/13 21:18:45
Aha. You are right. Sorry.
| |
494 base::Time::Now().LocalMidnight() | |
oshima
2012/11/13 17:46:42
add comment that this isn't used.
bshe
2012/11/13 21:18:45
Done.
| |
495 }; | |
487 BrowserThread::PostTask( | 496 BrowserThread::PostTask( |
488 BrowserThread::FILE, | |
489 FROM_HERE, | |
490 base::Bind(&WallpaperManager::GenerateUserWallpaperThumbnail, | |
491 base::Unretained(this), username, type, delegate, | |
492 wallpaper.image())); | |
493 | |
494 if (is_persistent) { | |
495 BrowserThread::PostTask( | |
496 BrowserThread::FILE, | 497 BrowserThread::FILE, |
497 FROM_HERE, | 498 FROM_HERE, |
498 base::Bind(&WallpaperManager::SaveCustomWallpaper, | 499 base::Bind(&WallpaperManager::ProcessCustomWallpaper, |
499 base::Unretained(this), | 500 base::Unretained(this), |
500 username, | 501 username, |
501 FilePath(wallpaper_path), | 502 is_persistent, |
502 layout, | 503 info, |
503 wallpaper)); | 504 delegate, |
504 } | 505 base::Passed(&deep_copy), |
505 | 506 wallpaper.raw_image())); |
oshima
2012/11/12 16:39:28
Can you remove or update TODO for raw_image()? Thi
bshe
2012/11/12 19:12:48
Good point. Added a TODO.
On 2012/11/12 16:39:28,
| |
506 ash::Shell::GetInstance()->desktop_background_controller()-> | 507 ash::Shell::GetInstance()->desktop_background_controller()-> |
507 SetCustomWallpaper(wallpaper.image(), layout); | 508 SetCustomWallpaper(wallpaper.image(), layout); |
508 | 509 |
509 bool new_wallpaper_ui_disabled = CommandLine::ForCurrentProcess()-> | 510 bool new_wallpaper_ui_disabled = CommandLine::ForCurrentProcess()-> |
510 HasSwitch(switches::kDisableNewWallpaperUI); | 511 HasSwitch(switches::kDisableNewWallpaperUI); |
511 if (!new_wallpaper_ui_disabled) { | 512 if (!new_wallpaper_ui_disabled) { |
512 // User's custom wallpaper path is determined by username/email and the | 513 // User's custom wallpaper path is determined by username/email and the |
513 // appropriate wallpaper resolution in GetCustomWallpaperInternal. So use | 514 // appropriate wallpaper resolution in GetCustomWallpaperInternal. So use |
514 // DUMMY as file name here. | 515 // DUMMY as file name here. |
515 WallpaperInfo info = { | 516 WallpaperInfo info = { |
(...skipping 288 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
804 if (type == User::CUSTOMIZED) { | 805 if (type == User::CUSTOMIZED) { |
805 GetCustomWallpaper(email, false /* do not update wallpaper */); | 806 GetCustomWallpaper(email, false /* do not update wallpaper */); |
806 return; | 807 return; |
807 } | 808 } |
808 ash::Shell::GetInstance()->desktop_background_controller()-> | 809 ash::Shell::GetInstance()->desktop_background_controller()-> |
809 CacheDefaultWallpaper(index); | 810 CacheDefaultWallpaper(index); |
810 } | 811 } |
811 } | 812 } |
812 | 813 |
813 void WallpaperManager::CacheThumbnail(const std::string& email, | 814 void WallpaperManager::CacheThumbnail(const std::string& email, |
814 const gfx::ImageSkia& wallpaper) { | 815 scoped_ptr<gfx::ImageSkia> wallpaper) { |
815 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::FILE)); | 816 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::FILE)); |
816 custom_wallpaper_thumbnail_cache_[email] = GetWallpaperThumbnail(wallpaper); | 817 custom_wallpaper_thumbnail_cache_[email] = |
818 GetWallpaperThumbnail(*wallpaper.get()); | |
817 } | 819 } |
818 | 820 |
819 void WallpaperManager::DeleteWallpaperInList( | 821 void WallpaperManager::DeleteWallpaperInList( |
820 const std::vector<FilePath>& file_list) { | 822 const std::vector<FilePath>& file_list) { |
821 for (std::vector<FilePath>::const_iterator it = file_list.begin(); | 823 for (std::vector<FilePath>::const_iterator it = file_list.begin(); |
822 it != file_list.end(); ++it) { | 824 it != file_list.end(); ++it) { |
823 FilePath path = *it; | 825 FilePath path = *it; |
824 if (!file_util::Delete(path, false)) { | 826 if (!file_util::Delete(path, false)) { |
825 LOG(ERROR) << "Failed to remove user wallpaper."; | 827 LOG(ERROR) << "Failed to remove user wallpaper."; |
826 } | 828 } |
(...skipping 330 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1157 | 1159 |
1158 if (update_wallpaper) { | 1160 if (update_wallpaper) { |
1159 ash::Shell::GetInstance()->desktop_background_controller()-> | 1161 ash::Shell::GetInstance()->desktop_background_controller()-> |
1160 SetDefaultWallpaper(ash::GetDefaultWallpaperIndex()); | 1162 SetDefaultWallpaper(ash::GetDefaultWallpaperIndex()); |
1161 } else { | 1163 } else { |
1162 ash::Shell::GetInstance()->desktop_background_controller()-> | 1164 ash::Shell::GetInstance()->desktop_background_controller()-> |
1163 CacheDefaultWallpaper(ash::GetDefaultWallpaperIndex()); | 1165 CacheDefaultWallpaper(ash::GetDefaultWallpaperIndex()); |
1164 } | 1166 } |
1165 return; | 1167 return; |
1166 } | 1168 } |
1169 // Generate all reps before passing to another thread. | |
1170 wallpaper.image().EnsureRepsForSupportedScaleFactors(); | |
1171 scoped_ptr<gfx::ImageSkia> deep_copy(wallpaper.image().DeepCopy()); | |
1167 | 1172 |
1168 BrowserThread::PostTask( | 1173 BrowserThread::PostTask( |
1169 BrowserThread::FILE, | 1174 BrowserThread::FILE, |
1170 FROM_HERE, | 1175 FROM_HERE, |
1171 base::Bind(&WallpaperManager::CacheThumbnail, | 1176 base::Bind(&WallpaperManager::CacheThumbnail, |
1172 base::Unretained(this), email, | 1177 base::Unretained(this), email, |
1173 wallpaper.image().DeepCopy())); | 1178 base::Passed(&deep_copy))); |
1174 // Only cache user wallpaper at login screen. | 1179 // Only cache user wallpaper at login screen. |
1175 if (!UserManager::Get()->IsUserLoggedIn()) { | 1180 if (!UserManager::Get()->IsUserLoggedIn()) { |
1176 wallpaper_cache_.insert(std::make_pair(email, wallpaper.image())); | 1181 wallpaper_cache_.insert(std::make_pair(email, wallpaper.image())); |
1177 } | 1182 } |
1178 if (update_wallpaper) { | 1183 if (update_wallpaper) { |
1179 ash::Shell::GetInstance()->desktop_background_controller()-> | 1184 ash::Shell::GetInstance()->desktop_background_controller()-> |
1180 SetCustomWallpaper(wallpaper.image(), layout); | 1185 SetCustomWallpaper(wallpaper.image(), layout); |
1181 } | 1186 } |
1182 } | 1187 } |
1183 | 1188 |
1189 void WallpaperManager::ProcessCustomWallpaper( | |
1190 const std::string& email, | |
1191 bool persistent, | |
1192 const WallpaperInfo& info, | |
1193 base::WeakPtr<WallpaperDelegate> delegate, | |
1194 scoped_ptr<gfx::ImageSkia> image, | |
1195 const UserImage::RawImage& raw_image) { | |
1196 UserImage wallpaper(*image.get(), raw_image); | |
1197 GenerateUserWallpaperThumbnail(email, info.type, delegate, wallpaper.image()); | |
1198 if (persistent) | |
1199 SaveCustomWallpaper(email, FilePath(info.file), info.layout, wallpaper); | |
1200 } | |
1201 | |
1202 | |
1203 | |
1184 void WallpaperManager::OnWallpaperEncoded(const FilePath& path, | 1204 void WallpaperManager::OnWallpaperEncoded(const FilePath& path, |
1185 scoped_refptr<base::RefCountedBytes> data) { | 1205 scoped_refptr<base::RefCountedBytes> data) { |
1186 SaveWallpaperInternal(path, | 1206 SaveWallpaperInternal(path, |
1187 reinterpret_cast<const char*>(data->front()), | 1207 reinterpret_cast<const char*>(data->front()), |
1188 data->size()); | 1208 data->size()); |
1189 } | 1209 } |
1190 | 1210 |
1191 void WallpaperManager::SaveCustomWallpaper(const std::string& email, | 1211 void WallpaperManager::SaveCustomWallpaper(const std::string& email, |
1192 const FilePath& path, | 1212 const FilePath& path, |
1193 ash::WallpaperLayout layout, | 1213 ash::WallpaperLayout layout, |
(...skipping 83 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1277 FROM_HERE, | 1297 FROM_HERE, |
1278 base::Bind(&WallpaperManager::StartLoad, | 1298 base::Bind(&WallpaperManager::StartLoad, |
1279 base::Unretained(this), | 1299 base::Unretained(this), |
1280 email, | 1300 email, |
1281 info, | 1301 info, |
1282 update_wallpaper, | 1302 update_wallpaper, |
1283 valid_path)); | 1303 valid_path)); |
1284 } | 1304 } |
1285 | 1305 |
1286 } // chromeos | 1306 } // chromeos |
OLD | NEW |