OLD | NEW |
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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/users/wallpaper/wallpaper_manager.h" | 5 #include "chrome/browser/chromeos/login/users/wallpaper/wallpaper_manager.h" |
6 | 6 |
7 #include <numeric> | 7 #include <numeric> |
8 #include <vector> | 8 #include <vector> |
9 | 9 |
10 #include "ash/ash_constants.h" | 10 #include "ash/ash_constants.h" |
(...skipping 1037 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1048 InitInitialUserWallpaper(user_id, true); | 1048 InitInitialUserWallpaper(user_id, true); |
1049 GetUserWallpaperInfo(user_id, &info); | 1049 GetUserWallpaperInfo(user_id, &info); |
1050 } | 1050 } |
1051 | 1051 |
1052 gfx::ImageSkia user_wallpaper; | 1052 gfx::ImageSkia user_wallpaper; |
1053 current_user_wallpaper_info_ = info; | 1053 current_user_wallpaper_info_ = info; |
1054 if (GetWallpaperFromCache(user_id, &user_wallpaper)) { | 1054 if (GetWallpaperFromCache(user_id, &user_wallpaper)) { |
1055 GetPendingWallpaper(user_id, delayed) | 1055 GetPendingWallpaper(user_id, delayed) |
1056 ->ResetSetWallpaperImage(user_wallpaper, info); | 1056 ->ResetSetWallpaperImage(user_wallpaper, info); |
1057 } else { | 1057 } else { |
| 1058 if (info.file.empty()) { |
| 1059 // Uses default built-in wallpaper when file is empty. Eventually, we |
| 1060 // will only ship one built-in wallpaper in ChromeOS image. |
| 1061 GetPendingWallpaper(user_id, delayed)->ResetSetDefaultWallpaper(); |
| 1062 return; |
| 1063 } |
| 1064 |
1058 if (info.type == User::CUSTOMIZED || info.type == User::POLICY) { | 1065 if (info.type == User::CUSTOMIZED || info.type == User::POLICY) { |
1059 const char* sub_dir = GetCustomWallpaperSubdirForCurrentResolution(); | 1066 const char* sub_dir = GetCustomWallpaperSubdirForCurrentResolution(); |
1060 // Wallpaper is not resized when layout is ash::WALLPAPER_LAYOUT_CENTER. | 1067 // Wallpaper is not resized when layout is ash::WALLPAPER_LAYOUT_CENTER. |
1061 // Original wallpaper should be used in this case. | 1068 // Original wallpaper should be used in this case. |
1062 // TODO(bshe): Generates cropped custom wallpaper for CENTER layout. | 1069 // TODO(bshe): Generates cropped custom wallpaper for CENTER layout. |
1063 if (info.layout == ash::WALLPAPER_LAYOUT_CENTER) | 1070 if (info.layout == ash::WALLPAPER_LAYOUT_CENTER) |
1064 sub_dir = kOriginalWallpaperSubDir; | 1071 sub_dir = kOriginalWallpaperSubDir; |
1065 base::FilePath wallpaper_path = GetCustomWallpaperDir(sub_dir); | 1072 base::FilePath wallpaper_path = GetCustomWallpaperDir(sub_dir); |
1066 wallpaper_path = wallpaper_path.Append(info.file); | 1073 wallpaper_path = wallpaper_path.Append(info.file); |
1067 if (current_wallpaper_path_ == wallpaper_path) | 1074 if (current_wallpaper_path_ == wallpaper_path) |
1068 return; | 1075 return; |
1069 current_wallpaper_path_ = wallpaper_path; | 1076 current_wallpaper_path_ = wallpaper_path; |
1070 loaded_wallpapers_++; | 1077 loaded_wallpapers_++; |
1071 | 1078 |
1072 GetPendingWallpaper(user_id, delayed) | 1079 GetPendingWallpaper(user_id, delayed) |
1073 ->ResetSetCustomWallpaper(info, wallpaper_path); | 1080 ->ResetSetCustomWallpaper(info, wallpaper_path); |
1074 return; | 1081 return; |
1075 } | 1082 } |
1076 | 1083 |
1077 if (info.file.empty()) { | |
1078 // Uses default built-in wallpaper when file is empty. Eventually, we | |
1079 // will only ship one built-in wallpaper in ChromeOS image. | |
1080 GetPendingWallpaper(user_id, delayed)->ResetSetDefaultWallpaper(); | |
1081 return; | |
1082 } | |
1083 | |
1084 // Load downloaded ONLINE or converted DEFAULT wallpapers. | 1084 // Load downloaded ONLINE or converted DEFAULT wallpapers. |
1085 GetPendingWallpaper(user_id, delayed)->ResetLoadWallpaper(info); | 1085 GetPendingWallpaper(user_id, delayed)->ResetLoadWallpaper(info); |
1086 } | 1086 } |
1087 } | 1087 } |
1088 | 1088 |
1089 void WallpaperManager::SetWallpaperFromImageSkia(const std::string& user_id, | 1089 void WallpaperManager::SetWallpaperFromImageSkia(const std::string& user_id, |
1090 const gfx::ImageSkia& image, | 1090 const gfx::ImageSkia& image, |
1091 ash::WallpaperLayout layout, | 1091 ash::WallpaperLayout layout, |
1092 bool update_wallpaper) { | 1092 bool update_wallpaper) { |
1093 DCHECK(UserManager::Get()->IsUserLoggedIn()); | 1093 DCHECK(UserManager::Get()->IsUserLoggedIn()); |
(...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1162 CacheUserWallpaper(user_id); | 1162 CacheUserWallpaper(user_id); |
1163 } | 1163 } |
1164 } | 1164 } |
1165 } | 1165 } |
1166 | 1166 |
1167 void WallpaperManager::CacheUserWallpaper(const std::string& user_id) { | 1167 void WallpaperManager::CacheUserWallpaper(const std::string& user_id) { |
1168 if (wallpaper_cache_.find(user_id) != wallpaper_cache_.end()) | 1168 if (wallpaper_cache_.find(user_id) != wallpaper_cache_.end()) |
1169 return; | 1169 return; |
1170 WallpaperInfo info; | 1170 WallpaperInfo info; |
1171 if (GetUserWallpaperInfo(user_id, &info)) { | 1171 if (GetUserWallpaperInfo(user_id, &info)) { |
| 1172 if (info.file.empty()) |
| 1173 return; |
| 1174 |
1172 base::FilePath wallpaper_dir; | 1175 base::FilePath wallpaper_dir; |
1173 base::FilePath wallpaper_path; | 1176 base::FilePath wallpaper_path; |
1174 if (info.type == User::CUSTOMIZED || info.type == User::POLICY) { | 1177 if (info.type == User::CUSTOMIZED || info.type == User::POLICY) { |
1175 const char* sub_dir = GetCustomWallpaperSubdirForCurrentResolution(); | 1178 const char* sub_dir = GetCustomWallpaperSubdirForCurrentResolution(); |
1176 base::FilePath wallpaper_path = GetCustomWallpaperDir(sub_dir); | 1179 base::FilePath wallpaper_path = GetCustomWallpaperDir(sub_dir); |
1177 wallpaper_path = wallpaper_path.Append(info.file); | 1180 wallpaper_path = wallpaper_path.Append(info.file); |
1178 task_runner_->PostTask( | 1181 task_runner_->PostTask( |
1179 FROM_HERE, | 1182 FROM_HERE, |
1180 base::Bind(&WallpaperManager::GetCustomWallpaperInternal, | 1183 base::Bind(&WallpaperManager::GetCustomWallpaperInternal, |
1181 base::Unretained(this), | 1184 base::Unretained(this), |
(...skipping 721 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1903 loaded_wallpapers_++; | 1906 loaded_wallpapers_++; |
1904 SkBitmap bitmap; | 1907 SkBitmap bitmap; |
1905 bitmap.setConfig(SkBitmap::kARGB_8888_Config, 1, 1, 0); | 1908 bitmap.setConfig(SkBitmap::kARGB_8888_Config, 1, 1, 0); |
1906 bitmap.allocPixels(); | 1909 bitmap.allocPixels(); |
1907 bitmap.eraseColor(kDefaultWallpaperColor); | 1910 bitmap.eraseColor(kDefaultWallpaperColor); |
1908 const gfx::ImageSkia image = gfx::ImageSkia::CreateFrom1xBitmap(bitmap); | 1911 const gfx::ImageSkia image = gfx::ImageSkia::CreateFrom1xBitmap(bitmap); |
1909 default_wallpaper_image_.reset(new UserImage(image)); | 1912 default_wallpaper_image_.reset(new UserImage(image)); |
1910 } | 1913 } |
1911 | 1914 |
1912 } // namespace chromeos | 1915 } // namespace chromeos |
OLD | NEW |