| 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 "ash/desktop_background/desktop_background_controller.h" | 7 #include "ash/desktop_background/desktop_background_controller.h" |
| 8 #include "ash/shell.h" | 8 #include "ash/shell.h" |
| 9 #include "base/command_line.h" | 9 #include "base/command_line.h" |
| 10 #include "base/logging.h" | 10 #include "base/logging.h" |
| (...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 65 const char kNewWallpaperLayoutNodeName[] = "layout"; | 65 const char kNewWallpaperLayoutNodeName[] = "layout"; |
| 66 const char kNewWallpaperFileNodeName[] = "file"; | 66 const char kNewWallpaperFileNodeName[] = "file"; |
| 67 const char kNewWallpaperTypeNodeName[] = "type"; | 67 const char kNewWallpaperTypeNodeName[] = "type"; |
| 68 | 68 |
| 69 gfx::ImageSkia GetWallpaperThumbnail(const gfx::ImageSkia& wallpaper) { | 69 gfx::ImageSkia GetWallpaperThumbnail(const gfx::ImageSkia& wallpaper) { |
| 70 gfx::ImageSkia thumbnail = gfx::ImageSkiaOperations::CreateResizedImage( | 70 gfx::ImageSkia thumbnail = gfx::ImageSkiaOperations::CreateResizedImage( |
| 71 wallpaper, | 71 wallpaper, |
| 72 skia::ImageOperations::RESIZE_LANCZOS3, | 72 skia::ImageOperations::RESIZE_LANCZOS3, |
| 73 gfx::Size(kThumbnailWidth, kThumbnailHeight)); | 73 gfx::Size(kThumbnailWidth, kThumbnailHeight)); |
| 74 | 74 |
| 75 // Ideally, this would call thumbnail.GetRepresentations(). But since that | 75 thumbnail.EnsureRepsForSupportedScaleFactors(); |
| 76 // isn't exposed on non-mac yet, we have to do this here. | 76 thumbnail.SetReadOnly(); |
| 77 std::vector<ui::ScaleFactor> scales = ui::GetSupportedScaleFactors(); | |
| 78 for (size_t i = 0; i < scales.size(); ++i) { | |
| 79 if (wallpaper.HasRepresentation(scales[i])) | |
| 80 thumbnail.GetRepresentation(scales[i]); | |
| 81 } | |
| 82 | |
| 83 return thumbnail; | 77 return thumbnail; |
| 84 } | 78 } |
| 85 | 79 |
| 86 gfx::ImageSkia ImageSkiaDeepCopy(const gfx::ImageSkia& image) { | 80 gfx::ImageSkia ImageSkiaDeepCopy(const gfx::ImageSkia& image) { |
| 87 gfx::ImageSkia copy; | 81 gfx::ImageSkia copy; |
| 88 std::vector<gfx::ImageSkiaRep> reps = image.image_reps(); | 82 std::vector<gfx::ImageSkiaRep> reps = image.image_reps(); |
| 89 for (std::vector<gfx::ImageSkiaRep>::iterator iter = reps.begin(); | 83 for (std::vector<gfx::ImageSkiaRep>::iterator iter = reps.begin(); |
| 90 iter != reps.end(); ++iter) { | 84 iter != reps.end(); ++iter) { |
| 91 copy.AddRepresentation(*iter); | 85 copy.AddRepresentation(*iter); |
| 92 } | 86 } |
| 87 copy.SetReadOnly(); |
| 93 return copy; | 88 return copy; |
| 94 } | 89 } |
| 95 | 90 |
| 96 } // namespace | 91 } // namespace |
| 97 | 92 |
| 98 namespace chromeos { | 93 namespace chromeos { |
| 99 | 94 |
| 100 static WallpaperManager* g_wallpaper_manager = NULL; | 95 static WallpaperManager* g_wallpaper_manager = NULL; |
| 101 | 96 |
| 102 // WallpaperManager, public: --------------------------------------------------- | 97 // WallpaperManager, public: --------------------------------------------------- |
| (...skipping 81 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 184 suffix); | 179 suffix); |
| 185 FilePath user_data_dir; | 180 FilePath user_data_dir; |
| 186 PathService::Get(chrome::DIR_USER_DATA, &user_data_dir); | 181 PathService::Get(chrome::DIR_USER_DATA, &user_data_dir); |
| 187 return user_data_dir.AppendASCII(filename); | 182 return user_data_dir.AppendASCII(filename); |
| 188 } | 183 } |
| 189 | 184 |
| 190 gfx::ImageSkia WallpaperManager::GetCustomWallpaperThumbnail( | 185 gfx::ImageSkia WallpaperManager::GetCustomWallpaperThumbnail( |
| 191 const std::string& email) { | 186 const std::string& email) { |
| 192 CustomWallpaperMap::const_iterator it = | 187 CustomWallpaperMap::const_iterator it = |
| 193 custom_wallpaper_thumbnail_cache_.find(email); | 188 custom_wallpaper_thumbnail_cache_.find(email); |
| 194 if (it != custom_wallpaper_cache_.end()) | 189 if (it != custom_wallpaper_thumbnail_cache_.end()) |
| 195 return (*it).second; | 190 return (*it).second; |
| 196 else | 191 else |
| 197 return gfx::ImageSkia(); | 192 return gfx::ImageSkia(); |
| 198 } | 193 } |
| 199 | 194 |
| 200 void WallpaperManager::GetLoggedInUserWallpaperProperties( | 195 void WallpaperManager::GetLoggedInUserWallpaperProperties( |
| 201 User::WallpaperType* type, | 196 User::WallpaperType* type, |
| 202 int* index, | 197 int* index, |
| 203 base::Time* last_modification_date) { | 198 base::Time* last_modification_date) { |
| 204 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 199 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| (...skipping 317 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 522 } else { | 517 } else { |
| 523 ash::Shell::GetInstance()->desktop_background_controller()-> | 518 ash::Shell::GetInstance()->desktop_background_controller()-> |
| 524 CacheDefaultWallpaper(index); | 519 CacheDefaultWallpaper(index); |
| 525 } | 520 } |
| 526 } | 521 } |
| 527 | 522 |
| 528 void WallpaperManager::CacheWallpaper(const std::string& email, | 523 void WallpaperManager::CacheWallpaper(const std::string& email, |
| 529 const UserImage& wallpaper) { | 524 const UserImage& wallpaper) { |
| 530 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 525 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| 531 DCHECK(custom_wallpaper_cache_.find(email) == custom_wallpaper_cache_.end()); | 526 DCHECK(custom_wallpaper_cache_.find(email) == custom_wallpaper_cache_.end()); |
| 532 | |
| 533 BrowserThread::PostTask( | 527 BrowserThread::PostTask( |
| 534 BrowserThread::FILE, | 528 BrowserThread::FILE, |
| 535 FROM_HERE, | 529 FROM_HERE, |
| 536 base::Bind(&WallpaperManager::CacheThumbnail, | 530 base::Bind(&WallpaperManager::CacheThumbnail, |
| 537 base::Unretained(this), email, | 531 base::Unretained(this), email, |
| 538 ImageSkiaDeepCopy(wallpaper.image()))); | 532 wallpaper.image().DeepCopy())); |
| 539 | 533 |
| 540 custom_wallpaper_cache_.insert(std::make_pair(email, wallpaper.image())); | 534 custom_wallpaper_cache_.insert(std::make_pair(email, wallpaper.image())); |
| 541 } | 535 } |
| 542 | 536 |
| 543 void WallpaperManager::CacheThumbnail(const std::string& email, | 537 void WallpaperManager::CacheThumbnail(const std::string& email, |
| 544 const gfx::ImageSkia& wallpaper) { | 538 const gfx::ImageSkia& wallpaper) { |
| 545 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::FILE)); | 539 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::FILE)); |
| 546 custom_wallpaper_thumbnail_cache_[email] = GetWallpaperThumbnail(wallpaper); | 540 custom_wallpaper_thumbnail_cache_[email] = GetWallpaperThumbnail(wallpaper); |
| 547 } | 541 } |
| 548 | 542 |
| 549 void WallpaperManager::FetchWallpaper(const std::string& email, | 543 void WallpaperManager::FetchWallpaper(const std::string& email, |
| 550 ash::WallpaperLayout layout, | 544 ash::WallpaperLayout layout, |
| 551 const UserImage& wallpaper) { | 545 const UserImage& wallpaper) { |
| 552 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 546 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| 553 | |
| 554 BrowserThread::PostTask( | 547 BrowserThread::PostTask( |
| 555 BrowserThread::FILE, | 548 BrowserThread::FILE, |
| 556 FROM_HERE, | 549 FROM_HERE, |
| 557 base::Bind(&WallpaperManager::CacheThumbnail, | 550 base::Bind(&WallpaperManager::CacheThumbnail, |
| 558 base::Unretained(this), email, | 551 base::Unretained(this), email, |
| 559 ImageSkiaDeepCopy(wallpaper.image()))); | 552 wallpaper.image().DeepCopy())); |
| 560 | 553 |
| 561 custom_wallpaper_cache_.insert(std::make_pair(email, wallpaper.image())); | 554 custom_wallpaper_cache_.insert(std::make_pair(email, wallpaper.image())); |
| 562 ash::Shell::GetInstance()->desktop_background_controller()-> | 555 ash::Shell::GetInstance()->desktop_background_controller()-> |
| 563 SetCustomWallpaper(wallpaper.image(), layout); | 556 SetCustomWallpaper(wallpaper.image(), layout); |
| 564 } | 557 } |
| 565 | 558 |
| 566 void WallpaperManager::GetUserWallpaperProperties(const std::string& email, | 559 void WallpaperManager::GetUserWallpaperProperties(const std::string& email, |
| 567 User::WallpaperType* type, | 560 User::WallpaperType* type, |
| 568 int* index, | 561 int* index, |
| 569 base::Time* last_modification_date) { | 562 base::Time* last_modification_date) { |
| (...skipping 104 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 674 | 667 |
| 675 void WallpaperManager::SystemResumed() { | 668 void WallpaperManager::SystemResumed() { |
| 676 BatchUpdateWallpaper(); | 669 BatchUpdateWallpaper(); |
| 677 } | 670 } |
| 678 | 671 |
| 679 void WallpaperManager::TimezoneChanged(const icu::TimeZone& timezone) { | 672 void WallpaperManager::TimezoneChanged(const icu::TimeZone& timezone) { |
| 680 RestartTimer(); | 673 RestartTimer(); |
| 681 } | 674 } |
| 682 | 675 |
| 683 } // chromeos | 676 } // chromeos |
| OLD | NEW |