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 <stdint.h> | 7 #include <stdint.h> |
8 #include <numeric> | 8 #include <numeric> |
9 #include <utility> | 9 #include <utility> |
10 #include <vector> | 10 #include <vector> |
(...skipping 18 matching lines...) Expand all Loading... | |
29 #include "base/threading/worker_pool.h" | 29 #include "base/threading/worker_pool.h" |
30 #include "base/time/time.h" | 30 #include "base/time/time.h" |
31 #include "base/trace_event/trace_event.h" | 31 #include "base/trace_event/trace_event.h" |
32 #include "base/values.h" | 32 #include "base/values.h" |
33 #include "chrome/browser/browser_process.h" | 33 #include "chrome/browser/browser_process.h" |
34 #include "chrome/browser/chrome_notification_types.h" | 34 #include "chrome/browser/chrome_notification_types.h" |
35 #include "chrome/browser/chromeos/customization/customization_document.h" | 35 #include "chrome/browser/chromeos/customization/customization_document.h" |
36 #include "chrome/browser/chromeos/login/startup_utils.h" | 36 #include "chrome/browser/chromeos/login/startup_utils.h" |
37 #include "chrome/browser/chromeos/login/wizard_controller.h" | 37 #include "chrome/browser/chromeos/login/wizard_controller.h" |
38 #include "chrome/browser/chromeos/settings/cros_settings.h" | 38 #include "chrome/browser/chromeos/settings/cros_settings.h" |
39 #include "chrome/browser/ui/ash/ash_util.h" | |
39 #include "chrome/common/chrome_paths.h" | 40 #include "chrome/common/chrome_paths.h" |
40 #include "chrome/common/chrome_switches.h" | 41 #include "chrome/common/chrome_switches.h" |
41 #include "chrome/common/pref_names.h" | 42 #include "chrome/common/pref_names.h" |
42 #include "chromeos/chromeos_switches.h" | 43 #include "chromeos/chromeos_switches.h" |
43 #include "chromeos/cryptohome/system_salt_getter.h" | 44 #include "chromeos/cryptohome/system_salt_getter.h" |
44 #include "chromeos/dbus/dbus_thread_manager.h" | 45 #include "chromeos/dbus/dbus_thread_manager.h" |
45 #include "chromeos/login/user_names.h" | 46 #include "chromeos/login/user_names.h" |
46 #include "components/prefs/pref_registry_simple.h" | 47 #include "components/prefs/pref_registry_simple.h" |
47 #include "components/prefs/pref_service.h" | 48 #include "components/prefs/pref_service.h" |
48 #include "components/prefs/scoped_user_pref_update.h" | 49 #include "components/prefs/scoped_user_pref_update.h" |
49 #include "components/signin/core/account_id/account_id.h" | 50 #include "components/signin/core/account_id/account_id.h" |
50 #include "components/user_manager/known_user.h" | 51 #include "components/user_manager/known_user.h" |
51 #include "components/user_manager/user.h" | 52 #include "components/user_manager/user.h" |
52 #include "components/user_manager/user_image/user_image.h" | 53 #include "components/user_manager/user_image/user_image.h" |
53 #include "components/user_manager/user_manager.h" | 54 #include "components/user_manager/user_manager.h" |
54 #include "components/user_manager/user_type.h" | 55 #include "components/user_manager/user_type.h" |
55 #include "components/wallpaper/wallpaper_files_id.h" | 56 #include "components/wallpaper/wallpaper_files_id.h" |
56 #include "components/wallpaper/wallpaper_layout.h" | 57 #include "components/wallpaper/wallpaper_layout.h" |
57 #include "content/public/browser/browser_thread.h" | 58 #include "content/public/browser/browser_thread.h" |
58 #include "content/public/browser/notification_service.h" | 59 #include "content/public/browser/notification_service.h" |
59 #include "content/public/common/content_switches.h" | 60 #include "content/public/common/content_switches.h" |
61 #include "content/public/common/mojo_shell_connection.h" | |
62 #include "services/shell/public/cpp/connector.h" | |
63 #include "skia/public/type_converters.h" | |
60 #include "third_party/skia/include/core/SkColor.h" | 64 #include "third_party/skia/include/core/SkColor.h" |
61 #include "ui/gfx/codec/jpeg_codec.h" | 65 #include "ui/gfx/codec/jpeg_codec.h" |
62 #include "ui/gfx/image/image_skia_operations.h" | 66 #include "ui/gfx/image/image_skia_operations.h" |
63 #include "ui/gfx/skia_util.h" | 67 #include "ui/gfx/skia_util.h" |
64 | 68 |
69 #if defined(MOJO_SHELL_CLIENT) | |
70 #include "ash/mus/public/interfaces/wallpaper.mojom.h" | |
71 #endif | |
72 | |
65 using content::BrowserThread; | 73 using content::BrowserThread; |
66 using wallpaper::WallpaperManagerBase; | 74 using wallpaper::WallpaperManagerBase; |
67 using wallpaper::WallpaperInfo; | 75 using wallpaper::WallpaperInfo; |
68 using wallpaper::MovableOnDestroyCallback; | 76 using wallpaper::MovableOnDestroyCallback; |
69 using wallpaper::MovableOnDestroyCallbackHolder; | 77 using wallpaper::MovableOnDestroyCallbackHolder; |
70 | 78 |
71 namespace chromeos { | 79 namespace chromeos { |
72 | 80 |
73 namespace { | 81 namespace { |
74 | 82 |
(...skipping 90 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
165 return wallpaper::WallpaperFilesId::FromString(result); | 173 return wallpaper::WallpaperFilesId::FromString(result); |
166 } | 174 } |
167 | 175 |
168 void SetKnownUserWallpaperFilesId( | 176 void SetKnownUserWallpaperFilesId( |
169 const AccountId& account_id, | 177 const AccountId& account_id, |
170 const wallpaper::WallpaperFilesId& wallpaper_files_id) { | 178 const wallpaper::WallpaperFilesId& wallpaper_files_id) { |
171 user_manager::known_user::SetStringPref(account_id, kWallpaperFilesId, | 179 user_manager::known_user::SetStringPref(account_id, kWallpaperFilesId, |
172 wallpaper_files_id.id()); | 180 wallpaper_files_id.id()); |
173 } | 181 } |
174 | 182 |
183 // A helper to set the wallpaper image for Ash and Mash. | |
184 void SetWallpaper(const gfx::ImageSkia& image, | |
185 wallpaper::WallpaperLayout layout) { | |
186 #if defined(MOJO_SHELL_CLIENT) | |
187 if (chrome::IsRunningInMash()) { | |
188 shell::Connector* connector = | |
189 content::MojoShellConnection::Get()->GetConnector(); | |
190 ash::mus::mojom::WallpaperControllerPtr wallpaper_controller; | |
191 connector->ConnectToInterface("mojo:ash_sysui", &wallpaper_controller); | |
192 wallpaper_controller->SetWallpaper( | |
193 skia::mojom::Bitmap::From(*image.bitmap()), | |
dcheng
2016/05/24 18:53:37
Can we do this with a StructTraits instead? My wor
msw
2016/05/24 22:06:37
Yeah, Yuzhu gave me an intro to StructTraits, and
dcheng
2016/05/25 17:31:26
We can add the StructTraits without removing all u
msw
2016/05/25 18:16:41
I'd rather not pollute this wallpaper CL with the
dcheng
2016/05/25 19:56:40
I'd strongly prefer to see that. I thought it'd be
| |
194 static_cast<ash::mus::mojom::WallpaperLayout>(layout)); | |
dcheng
2016/05/24 18:53:37
Similarly, do StructTraits work for enums yet?
yzshen1
2016/05/24 22:04:42
Yes. For example:
module mojom;
enum SomeEnum {};
msw
2016/05/24 22:06:37
We can support enums within a struct, but I don't
msw
2016/05/24 22:06:37
Right, but in this case, I'm passing an enum value
dcheng
2016/05/25 19:56:40
and maybe in the meantime we can figure out someth
| |
195 return; | |
196 } | |
197 #endif | |
198 // Avoid loading unnecessary wallpapers in tests without a shell instance. | |
199 if (ash::Shell::HasInstance()) { | |
200 ash::Shell::GetInstance() | |
201 ->desktop_background_controller() | |
202 ->SetWallpaperImage(image, layout); | |
203 } | |
204 } | |
205 | |
175 } // namespace | 206 } // namespace |
176 | 207 |
177 // This is "wallpaper either scheduled to load, or loading right now". | 208 // This is "wallpaper either scheduled to load, or loading right now". |
178 // | 209 // |
179 // While enqueued, it defines moment in the future, when it will be loaded. | 210 // While enqueued, it defines moment in the future, when it will be loaded. |
180 // Enqueued but not started request might be updated by subsequent load | 211 // Enqueued but not started request might be updated by subsequent load |
181 // request. Therefore it's created empty, and updated being enqueued. | 212 // request. Therefore it's created empty, and updated being enqueued. |
182 // | 213 // |
183 // PendingWallpaper is owned by WallpaperManager, but reference to this object | 214 // PendingWallpaper is owned by WallpaperManager, but reference to this object |
184 // is passed to other threads by PostTask() calls, therefore it is | 215 // is passed to other threads by PostTask() calls, therefore it is |
(...skipping 10 matching lines...) Expand all Loading... | |
195 this))) { | 226 this))) { |
196 timer.Start( | 227 timer.Start( |
197 FROM_HERE, | 228 FROM_HERE, |
198 delay, | 229 delay, |
199 base::Bind(&WallpaperManager::PendingWallpaper::ProcessRequest, this)); | 230 base::Bind(&WallpaperManager::PendingWallpaper::ProcessRequest, this)); |
200 } | 231 } |
201 | 232 |
202 // There are 4 cases in SetUserWallpaper: | 233 // There are 4 cases in SetUserWallpaper: |
203 // 1) gfx::ImageSkia is found in cache. | 234 // 1) gfx::ImageSkia is found in cache. |
204 // - Schedule task to (probably) resize it and install: | 235 // - Schedule task to (probably) resize it and install: |
205 // call ash::Shell::GetInstance()->desktop_background_controller()-> | 236 // call SetWallpaper(user_wallpaper, layout); |
206 // SetCustomWallpaper(user_wallpaper, layout); | |
207 // 2) WallpaperInfo is found in cache | 237 // 2) WallpaperInfo is found in cache |
208 // - need to LoadWallpaper(), resize and install. | 238 // - need to LoadWallpaper(), resize and install. |
209 // 3) wallpaper path is not NULL, load image URL, then resize, etc... | 239 // 3) wallpaper path is not NULL, load image URL, then resize, etc... |
210 // 4) SetDefaultWallpaper (either on some error, or when user is new). | 240 // 4) SetDefaultWallpaper (either on some error, or when user is new). |
211 void ResetSetWallpaperImage(const gfx::ImageSkia& image, | 241 void ResetSetWallpaperImage(const gfx::ImageSkia& image, |
212 const wallpaper::WallpaperInfo& info) { | 242 const wallpaper::WallpaperInfo& info) { |
213 SetMode(image, info, base::FilePath(), false); | 243 SetMode(image, info, base::FilePath(), false); |
214 } | 244 } |
215 | 245 |
216 void ResetLoadWallpaper(const wallpaper::WallpaperInfo& info) { | 246 void ResetLoadWallpaper(const wallpaper::WallpaperInfo& info) { |
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
250 | 280 |
251 WallpaperManager* manager = WallpaperManager::Get(); | 281 WallpaperManager* manager = WallpaperManager::Get(); |
252 if (manager->pending_inactive_ == this) | 282 if (manager->pending_inactive_ == this) |
253 manager->pending_inactive_ = NULL; | 283 manager->pending_inactive_ = NULL; |
254 | 284 |
255 started_load_at_ = base::Time::Now(); | 285 started_load_at_ = base::Time::Now(); |
256 | 286 |
257 if (default_) { | 287 if (default_) { |
258 manager->DoSetDefaultWallpaper(account_id_, std::move(on_finish_)); | 288 manager->DoSetDefaultWallpaper(account_id_, std::move(on_finish_)); |
259 } else if (!user_wallpaper_.isNull()) { | 289 } else if (!user_wallpaper_.isNull()) { |
260 ash::Shell::GetInstance() | 290 SetWallpaper(user_wallpaper_, info_.layout); |
261 ->desktop_background_controller() | |
262 ->SetWallpaperImage(user_wallpaper_, info_.layout); | |
263 } else if (!wallpaper_path_.empty()) { | 291 } else if (!wallpaper_path_.empty()) { |
264 manager->task_runner_->PostTask( | 292 manager->task_runner_->PostTask( |
265 FROM_HERE, | 293 FROM_HERE, |
266 base::Bind(&WallpaperManager::GetCustomWallpaperInternal, account_id_, | 294 base::Bind(&WallpaperManager::GetCustomWallpaperInternal, account_id_, |
267 info_, wallpaper_path_, true /* update wallpaper */, | 295 info_, wallpaper_path_, true /* update wallpaper */, |
268 base::ThreadTaskRunnerHandle::Get(), | 296 base::ThreadTaskRunnerHandle::Get(), |
269 base::Passed(std::move(on_finish_)), | 297 base::Passed(std::move(on_finish_)), |
270 manager->weak_factory_.GetWeakPtr())); | 298 manager->weak_factory_.GetWeakPtr())); |
271 } else if (!info_.location.empty()) { | 299 } else if (!info_.location.empty()) { |
272 manager->LoadWallpaper(account_id_, info_, true, std::move(on_finish_)); | 300 manager->LoadWallpaper(account_id_, info_, true, std::move(on_finish_)); |
(...skipping 318 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
591 GetPendingWallpaper(account_id, true)->ResetSetDefaultWallpaper(); | 619 GetPendingWallpaper(account_id, true)->ResetSetDefaultWallpaper(); |
592 } | 620 } |
593 | 621 |
594 void WallpaperManager::DoSetDefaultWallpaper( | 622 void WallpaperManager::DoSetDefaultWallpaper( |
595 const AccountId& account_id, | 623 const AccountId& account_id, |
596 MovableOnDestroyCallbackHolder on_finish) { | 624 MovableOnDestroyCallbackHolder on_finish) { |
597 // There is no visible background in kiosk mode. | 625 // There is no visible background in kiosk mode. |
598 if (user_manager::UserManager::Get()->IsLoggedInAsKioskApp()) | 626 if (user_manager::UserManager::Get()->IsLoggedInAsKioskApp()) |
599 return; | 627 return; |
600 wallpaper_cache_.erase(account_id); | 628 wallpaper_cache_.erase(account_id); |
601 // Some browser tests do not have a shell instance. As no wallpaper is needed | |
602 // in these tests anyway, avoid loading one, preventing crashes and speeding | |
603 // up the tests. | |
604 if (!ash::Shell::HasInstance()) | |
605 return; | |
606 | 629 |
607 WallpaperResolution resolution = GetAppropriateResolution(); | 630 WallpaperResolution resolution = GetAppropriateResolution(); |
608 const bool use_small = (resolution == WALLPAPER_RESOLUTION_SMALL); | 631 const bool use_small = (resolution == WALLPAPER_RESOLUTION_SMALL); |
609 | 632 |
610 const base::FilePath* file = NULL; | 633 const base::FilePath* file = NULL; |
611 | 634 |
612 const user_manager::User* user = | 635 const user_manager::User* user = |
613 user_manager::UserManager::Get()->FindUser(account_id); | 636 user_manager::UserManager::Get()->FindUser(account_id); |
614 | 637 |
615 if (user_manager::UserManager::Get()->IsLoggedInAsGuest()) { | 638 if (user_manager::UserManager::Get()->IsLoggedInAsGuest()) { |
(...skipping 20 matching lines...) Expand all Loading... | |
636 return; | 659 return; |
637 } | 660 } |
638 | 661 |
639 CreateSolidDefaultWallpaper(); | 662 CreateSolidDefaultWallpaper(); |
640 } | 663 } |
641 // 1x1 wallpaper is actually solid color, so it should be stretched. | 664 // 1x1 wallpaper is actually solid color, so it should be stretched. |
642 if (default_wallpaper_image_->image().width() == 1 && | 665 if (default_wallpaper_image_->image().width() == 1 && |
643 default_wallpaper_image_->image().height() == 1) | 666 default_wallpaper_image_->image().height() == 1) |
644 layout = wallpaper::WALLPAPER_LAYOUT_STRETCH; | 667 layout = wallpaper::WALLPAPER_LAYOUT_STRETCH; |
645 | 668 |
646 ash::Shell::GetInstance()->desktop_background_controller()->SetWallpaperImage( | 669 SetWallpaper(default_wallpaper_image_->image(), layout); |
647 default_wallpaper_image_->image(), layout); | |
648 } | 670 } |
649 | 671 |
650 void WallpaperManager::SetUserWallpaperInfo(const AccountId& account_id, | 672 void WallpaperManager::SetUserWallpaperInfo(const AccountId& account_id, |
651 const WallpaperInfo& info, | 673 const WallpaperInfo& info, |
652 bool is_persistent) { | 674 bool is_persistent) { |
653 DCHECK_CURRENTLY_ON(BrowserThread::UI); | 675 DCHECK_CURRENTLY_ON(BrowserThread::UI); |
654 current_user_wallpaper_info_ = info; | 676 current_user_wallpaper_info_ = info; |
655 if (!is_persistent) | 677 if (!is_persistent) |
656 return; | 678 return; |
657 | 679 |
(...skipping 294 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
952 SetUserWallpaperInfo(account_id, info, true); | 974 SetUserWallpaperInfo(account_id, info, true); |
953 | 975 |
954 if (update_wallpaper) | 976 if (update_wallpaper) |
955 DoSetDefaultWallpaper(account_id, std::move(on_finish)); | 977 DoSetDefaultWallpaper(account_id, std::move(on_finish)); |
956 return; | 978 return; |
957 } | 979 } |
958 | 980 |
959 // Update the image, but keep the path which was set earlier. | 981 // Update the image, but keep the path which was set earlier. |
960 wallpaper_cache_[account_id].second = user_image->image(); | 982 wallpaper_cache_[account_id].second = user_image->image(); |
961 | 983 |
962 if (update_wallpaper) { | 984 if (update_wallpaper) |
963 ash::Shell::GetInstance() | 985 SetWallpaper(user_image->image(), layout); |
964 ->desktop_background_controller() | |
965 ->SetWallpaperImage(user_image->image(), layout); | |
966 } | |
967 } | 986 } |
968 | 987 |
969 void WallpaperManager::StartLoad(const AccountId& account_id, | 988 void WallpaperManager::StartLoad(const AccountId& account_id, |
970 const WallpaperInfo& info, | 989 const WallpaperInfo& info, |
971 bool update_wallpaper, | 990 bool update_wallpaper, |
972 const base::FilePath& wallpaper_path, | 991 const base::FilePath& wallpaper_path, |
973 MovableOnDestroyCallbackHolder on_finish) { | 992 MovableOnDestroyCallbackHolder on_finish) { |
974 DCHECK_CURRENTLY_ON(BrowserThread::UI); | 993 DCHECK_CURRENTLY_ON(BrowserThread::UI); |
975 TRACE_EVENT_ASYNC_BEGIN0("ui", "LoadAndDecodeWallpaper", this); | 994 TRACE_EVENT_ASYNC_BEGIN0("ui", "LoadAndDecodeWallpaper", this); |
976 if (update_wallpaper) { | 995 if (update_wallpaper) { |
(...skipping 84 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1061 default_wallpaper_image_.reset(); | 1080 default_wallpaper_image_.reset(); |
1062 } | 1081 } |
1063 | 1082 |
1064 void WallpaperManager::OnDefaultWallpaperDecoded( | 1083 void WallpaperManager::OnDefaultWallpaperDecoded( |
1065 const base::FilePath& path, | 1084 const base::FilePath& path, |
1066 const wallpaper::WallpaperLayout layout, | 1085 const wallpaper::WallpaperLayout layout, |
1067 std::unique_ptr<user_manager::UserImage>* result_out, | 1086 std::unique_ptr<user_manager::UserImage>* result_out, |
1068 MovableOnDestroyCallbackHolder on_finish, | 1087 MovableOnDestroyCallbackHolder on_finish, |
1069 std::unique_ptr<user_manager::UserImage> user_image) { | 1088 std::unique_ptr<user_manager::UserImage> user_image) { |
1070 *result_out = std::move(user_image); | 1089 *result_out = std::move(user_image); |
1071 ash::Shell::GetInstance()->desktop_background_controller()->SetWallpaperImage( | 1090 SetWallpaper((*result_out)->image(), layout); |
1072 (*result_out)->image(), layout); | |
1073 } | 1091 } |
1074 | 1092 |
1075 void WallpaperManager::StartLoadAndSetDefaultWallpaper( | 1093 void WallpaperManager::StartLoadAndSetDefaultWallpaper( |
1076 const base::FilePath& path, | 1094 const base::FilePath& path, |
1077 const wallpaper::WallpaperLayout layout, | 1095 const wallpaper::WallpaperLayout layout, |
1078 MovableOnDestroyCallbackHolder on_finish, | 1096 MovableOnDestroyCallbackHolder on_finish, |
1079 std::unique_ptr<user_manager::UserImage>* result_out) { | 1097 std::unique_ptr<user_manager::UserImage>* result_out) { |
1080 user_image_loader::StartWithFilePath( | 1098 user_image_loader::StartWithFilePath( |
1081 task_runner_, path, ImageDecoder::ROBUST_JPEG_CODEC, | 1099 task_runner_, path, ImageDecoder::ROBUST_JPEG_CODEC, |
1082 0, // Do not crop. | 1100 0, // Do not crop. |
(...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1135 &stored_value)) { | 1153 &stored_value)) { |
1136 return wallpaper::WallpaperFilesId::FromString(stored_value); | 1154 return wallpaper::WallpaperFilesId::FromString(stored_value); |
1137 } | 1155 } |
1138 const std::string& old_id = account_id.GetUserEmail(); // Migrated | 1156 const std::string& old_id = account_id.GetUserEmail(); // Migrated |
1139 const wallpaper::WallpaperFilesId files_id = HashWallpaperFilesIdStr(old_id); | 1157 const wallpaper::WallpaperFilesId files_id = HashWallpaperFilesIdStr(old_id); |
1140 SetKnownUserWallpaperFilesId(account_id, files_id); | 1158 SetKnownUserWallpaperFilesId(account_id, files_id); |
1141 return files_id; | 1159 return files_id; |
1142 } | 1160 } |
1143 | 1161 |
1144 } // namespace chromeos | 1162 } // namespace chromeos |
OLD | NEW |