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 449 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
460 // If decoded wallpaper is empty, we are probably failed to decode the file. | 460 // If decoded wallpaper is empty, we are probably failed to decode the file. |
461 // Use default wallpaper in this case. | 461 // Use default wallpaper in this case. |
462 if (wallpaper.image().isNull()) { | 462 if (wallpaper.image().isNull()) { |
463 ash::Shell::GetInstance()->desktop_background_controller()-> | 463 ash::Shell::GetInstance()->desktop_background_controller()-> |
464 SetDefaultWallpaper(ash::GetDefaultWallpaperIndex()); | 464 SetDefaultWallpaper(ash::GetDefaultWallpaperIndex()); |
465 return; | 465 return; |
466 } | 466 } |
467 | 467 |
468 bool is_persistent = ShouldPersistDataForUser(username); | 468 bool is_persistent = ShouldPersistDataForUser(username); |
469 | 469 |
| 470 wallpaper.image().EnsureRepsForSupportedScaleFactors(); |
| 471 scoped_ptr<gfx::ImageSkia> deep_copy(wallpaper.image().DeepCopy()); |
| 472 |
| 473 WallpaperInfo wallpaper_info = { |
| 474 wallpaper_path, |
| 475 layout, |
| 476 type, |
| 477 // Date field is not used. |
| 478 base::Time::Now().LocalMidnight() |
| 479 }; |
| 480 // TODO(bshe): This may break if RawImage becomes RefCountedMemory. |
470 BrowserThread::PostTask( | 481 BrowserThread::PostTask( |
471 BrowserThread::FILE, | |
472 FROM_HERE, | |
473 base::Bind(&WallpaperManager::GenerateUserWallpaperThumbnail, | |
474 base::Unretained(this), username, type, delegate, | |
475 wallpaper.image())); | |
476 | |
477 if (is_persistent) { | |
478 BrowserThread::PostTask( | |
479 BrowserThread::FILE, | 482 BrowserThread::FILE, |
480 FROM_HERE, | 483 FROM_HERE, |
481 base::Bind(&WallpaperManager::SaveCustomWallpaper, | 484 base::Bind(&WallpaperManager::ProcessCustomWallpaper, |
482 base::Unretained(this), | 485 base::Unretained(this), |
483 username, | 486 username, |
484 FilePath(wallpaper_path), | 487 is_persistent, |
485 layout, | 488 wallpaper_info, |
486 wallpaper)); | 489 delegate, |
487 } | 490 base::Passed(&deep_copy), |
488 | 491 wallpaper.raw_image())); |
489 ash::Shell::GetInstance()->desktop_background_controller()-> | 492 ash::Shell::GetInstance()->desktop_background_controller()-> |
490 SetCustomWallpaper(wallpaper.image(), layout); | 493 SetCustomWallpaper(wallpaper.image(), layout); |
491 | 494 |
492 // User's custom wallpaper path is determined by username/email and the | 495 // User's custom wallpaper path is determined by username/email and the |
493 // appropriate wallpaper resolution in GetCustomWallpaperInternal. So use | 496 // appropriate wallpaper resolution in GetCustomWallpaperInternal. So use |
494 // DUMMY as file name here. | 497 // DUMMY as file name here. |
495 WallpaperInfo info = { | 498 WallpaperInfo info = { |
496 "DUMMY", | 499 "DUMMY", |
497 layout, | 500 layout, |
498 User::CUSTOMIZED, | 501 User::CUSTOMIZED, |
(...skipping 598 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1097 // Only cache user wallpaper at login screen. | 1100 // Only cache user wallpaper at login screen. |
1098 if (!UserManager::Get()->IsUserLoggedIn()) { | 1101 if (!UserManager::Get()->IsUserLoggedIn()) { |
1099 wallpaper_cache_.insert(std::make_pair(email, wallpaper.image())); | 1102 wallpaper_cache_.insert(std::make_pair(email, wallpaper.image())); |
1100 } | 1103 } |
1101 if (update_wallpaper) { | 1104 if (update_wallpaper) { |
1102 ash::Shell::GetInstance()->desktop_background_controller()-> | 1105 ash::Shell::GetInstance()->desktop_background_controller()-> |
1103 SetCustomWallpaper(wallpaper.image(), layout); | 1106 SetCustomWallpaper(wallpaper.image(), layout); |
1104 } | 1107 } |
1105 } | 1108 } |
1106 | 1109 |
| 1110 void WallpaperManager::ProcessCustomWallpaper( |
| 1111 const std::string& email, |
| 1112 bool persistent, |
| 1113 const WallpaperInfo& info, |
| 1114 base::WeakPtr<WallpaperDelegate> delegate, |
| 1115 scoped_ptr<gfx::ImageSkia> image, |
| 1116 const UserImage::RawImage& raw_image) { |
| 1117 UserImage wallpaper(*image.get(), raw_image); |
| 1118 GenerateUserWallpaperThumbnail(email, info.type, delegate, wallpaper.image()); |
| 1119 if (persistent) |
| 1120 SaveCustomWallpaper(email, FilePath(info.file), info.layout, wallpaper); |
| 1121 } |
| 1122 |
1107 void WallpaperManager::OnWallpaperEncoded(const FilePath& path, | 1123 void WallpaperManager::OnWallpaperEncoded(const FilePath& path, |
1108 scoped_refptr<base::RefCountedBytes> data) { | 1124 scoped_refptr<base::RefCountedBytes> data) { |
1109 SaveWallpaperInternal(path, | 1125 SaveWallpaperInternal(path, |
1110 reinterpret_cast<const char*>(data->front()), | 1126 reinterpret_cast<const char*>(data->front()), |
1111 data->size()); | 1127 data->size()); |
1112 } | 1128 } |
1113 | 1129 |
1114 void WallpaperManager::SaveCustomWallpaper(const std::string& email, | 1130 void WallpaperManager::SaveCustomWallpaper(const std::string& email, |
1115 const FilePath& path, | 1131 const FilePath& path, |
1116 ash::WallpaperLayout layout, | 1132 ash::WallpaperLayout layout, |
(...skipping 90 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1207 FROM_HERE, | 1223 FROM_HERE, |
1208 base::Bind(&WallpaperManager::StartLoad, | 1224 base::Bind(&WallpaperManager::StartLoad, |
1209 base::Unretained(this), | 1225 base::Unretained(this), |
1210 email, | 1226 email, |
1211 info, | 1227 info, |
1212 update_wallpaper, | 1228 update_wallpaper, |
1213 valid_path)); | 1229 valid_path)); |
1214 } | 1230 } |
1215 | 1231 |
1216 } // chromeos | 1232 } // chromeos |
OLD | NEW |