Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(18)

Side by Side Diff: chrome/browser/chromeos/login/users/wallpaper/wallpaper_manager.cc

Issue 1984433002: Hook up Chrome's wallpaper picker for mash. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Add explicit WallpaperLayout enum conversion functions. Created 4 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « chrome/browser/chromeos/extensions/wallpaper_private_api.cc ('k') | chrome/browser/ui/BUILD.gn » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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
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"
60 #include "third_party/skia/include/core/SkColor.h" 63 #include "third_party/skia/include/core/SkColor.h"
61 #include "ui/gfx/codec/jpeg_codec.h" 64 #include "ui/gfx/codec/jpeg_codec.h"
62 #include "ui/gfx/image/image_skia_operations.h" 65 #include "ui/gfx/image/image_skia_operations.h"
63 #include "ui/gfx/skia_util.h" 66 #include "ui/gfx/skia_util.h"
64 67
68 #if defined(MOJO_SHELL_CLIENT)
69 #include "ash/sysui/public/interfaces/wallpaper.mojom.h"
70 #endif
71
65 using content::BrowserThread; 72 using content::BrowserThread;
66 using wallpaper::WallpaperManagerBase; 73 using wallpaper::WallpaperManagerBase;
67 using wallpaper::WallpaperInfo; 74 using wallpaper::WallpaperInfo;
68 using wallpaper::MovableOnDestroyCallback; 75 using wallpaper::MovableOnDestroyCallback;
69 using wallpaper::MovableOnDestroyCallbackHolder; 76 using wallpaper::MovableOnDestroyCallbackHolder;
70 77
71 namespace chromeos { 78 namespace chromeos {
72 79
73 namespace { 80 namespace {
74 81
(...skipping 90 matching lines...) Expand 10 before | Expand all | Expand 10 after
165 return wallpaper::WallpaperFilesId::FromString(result); 172 return wallpaper::WallpaperFilesId::FromString(result);
166 } 173 }
167 174
168 void SetKnownUserWallpaperFilesId( 175 void SetKnownUserWallpaperFilesId(
169 const AccountId& account_id, 176 const AccountId& account_id,
170 const wallpaper::WallpaperFilesId& wallpaper_files_id) { 177 const wallpaper::WallpaperFilesId& wallpaper_files_id) {
171 user_manager::known_user::SetStringPref(account_id, kWallpaperFilesId, 178 user_manager::known_user::SetStringPref(account_id, kWallpaperFilesId,
172 wallpaper_files_id.id()); 179 wallpaper_files_id.id());
173 } 180 }
174 181
182 #if defined(MOJO_SHELL_CLIENT)
183 ash::sysui::mojom::WallpaperLayout WallpaperLayoutToMojo(
184 wallpaper::WallpaperLayout layout) {
185 switch (layout) {
186 case wallpaper::WALLPAPER_LAYOUT_CENTER:
187 return ash::sysui::mojom::WallpaperLayout::CENTER;
188 case wallpaper::WALLPAPER_LAYOUT_CENTER_CROPPED:
189 return ash::sysui::mojom::WallpaperLayout::CENTER_CROPPED;
190 case wallpaper::WALLPAPER_LAYOUT_STRETCH:
191 return ash::sysui::mojom::WallpaperLayout::STRETCH;
192 case wallpaper::WALLPAPER_LAYOUT_TILE:
193 return ash::sysui::mojom::WallpaperLayout::TILE;
194 case wallpaper::NUM_WALLPAPER_LAYOUT:
195 NOTREACHED();
196 return ash::sysui::mojom::WallpaperLayout::CENTER;
197 }
198 NOTREACHED();
199 return ash::sysui::mojom::WallpaperLayout::CENTER;
200 }
201 #endif
202
203 // A helper to set the wallpaper image for Ash and Mash.
204 void SetWallpaper(const gfx::ImageSkia& image,
205 wallpaper::WallpaperLayout layout) {
206 #if defined(MOJO_SHELL_CLIENT)
207 if (chrome::IsRunningInMash()) {
208 shell::Connector* connector =
209 content::MojoShellConnection::Get()->GetConnector();
210 ash::sysui::mojom::WallpaperControllerPtr wallpaper_controller;
211 connector->ConnectToInterface("mojo:ash_sysui", &wallpaper_controller);
212 wallpaper_controller->SetWallpaper(*image.bitmap(),
213 WallpaperLayoutToMojo(layout));
214 return;
215 }
216 #endif
217 // Avoid loading unnecessary wallpapers in tests without a shell instance.
218 if (ash::Shell::HasInstance()) {
219 ash::Shell::GetInstance()
220 ->desktop_background_controller()
221 ->SetWallpaperImage(image, layout);
222 }
223 }
224
175 } // namespace 225 } // namespace
176 226
177 // This is "wallpaper either scheduled to load, or loading right now". 227 // This is "wallpaper either scheduled to load, or loading right now".
178 // 228 //
179 // While enqueued, it defines moment in the future, when it will be loaded. 229 // 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 230 // Enqueued but not started request might be updated by subsequent load
181 // request. Therefore it's created empty, and updated being enqueued. 231 // request. Therefore it's created empty, and updated being enqueued.
182 // 232 //
183 // PendingWallpaper is owned by WallpaperManager, but reference to this object 233 // PendingWallpaper is owned by WallpaperManager, but reference to this object
184 // is passed to other threads by PostTask() calls, therefore it is 234 // is passed to other threads by PostTask() calls, therefore it is
(...skipping 10 matching lines...) Expand all
195 this))) { 245 this))) {
196 timer.Start( 246 timer.Start(
197 FROM_HERE, 247 FROM_HERE,
198 delay, 248 delay,
199 base::Bind(&WallpaperManager::PendingWallpaper::ProcessRequest, this)); 249 base::Bind(&WallpaperManager::PendingWallpaper::ProcessRequest, this));
200 } 250 }
201 251
202 // There are 4 cases in SetUserWallpaper: 252 // There are 4 cases in SetUserWallpaper:
203 // 1) gfx::ImageSkia is found in cache. 253 // 1) gfx::ImageSkia is found in cache.
204 // - Schedule task to (probably) resize it and install: 254 // - Schedule task to (probably) resize it and install:
205 // call ash::Shell::GetInstance()->desktop_background_controller()-> 255 // call SetWallpaper(user_wallpaper, layout);
206 // SetCustomWallpaper(user_wallpaper, layout);
207 // 2) WallpaperInfo is found in cache 256 // 2) WallpaperInfo is found in cache
208 // - need to LoadWallpaper(), resize and install. 257 // - need to LoadWallpaper(), resize and install.
209 // 3) wallpaper path is not NULL, load image URL, then resize, etc... 258 // 3) wallpaper path is not NULL, load image URL, then resize, etc...
210 // 4) SetDefaultWallpaper (either on some error, or when user is new). 259 // 4) SetDefaultWallpaper (either on some error, or when user is new).
211 void ResetSetWallpaperImage(const gfx::ImageSkia& image, 260 void ResetSetWallpaperImage(const gfx::ImageSkia& image,
212 const wallpaper::WallpaperInfo& info) { 261 const wallpaper::WallpaperInfo& info) {
213 SetMode(image, info, base::FilePath(), false); 262 SetMode(image, info, base::FilePath(), false);
214 } 263 }
215 264
216 void ResetLoadWallpaper(const wallpaper::WallpaperInfo& info) { 265 void ResetLoadWallpaper(const wallpaper::WallpaperInfo& info) {
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after
250 299
251 WallpaperManager* manager = WallpaperManager::Get(); 300 WallpaperManager* manager = WallpaperManager::Get();
252 if (manager->pending_inactive_ == this) 301 if (manager->pending_inactive_ == this)
253 manager->pending_inactive_ = NULL; 302 manager->pending_inactive_ = NULL;
254 303
255 started_load_at_ = base::Time::Now(); 304 started_load_at_ = base::Time::Now();
256 305
257 if (default_) { 306 if (default_) {
258 manager->DoSetDefaultWallpaper(account_id_, std::move(on_finish_)); 307 manager->DoSetDefaultWallpaper(account_id_, std::move(on_finish_));
259 } else if (!user_wallpaper_.isNull()) { 308 } else if (!user_wallpaper_.isNull()) {
260 ash::Shell::GetInstance() 309 SetWallpaper(user_wallpaper_, info_.layout);
261 ->desktop_background_controller()
262 ->SetWallpaperImage(user_wallpaper_, info_.layout);
263 } else if (!wallpaper_path_.empty()) { 310 } else if (!wallpaper_path_.empty()) {
264 manager->task_runner_->PostTask( 311 manager->task_runner_->PostTask(
265 FROM_HERE, 312 FROM_HERE,
266 base::Bind(&WallpaperManager::GetCustomWallpaperInternal, account_id_, 313 base::Bind(&WallpaperManager::GetCustomWallpaperInternal, account_id_,
267 info_, wallpaper_path_, true /* update wallpaper */, 314 info_, wallpaper_path_, true /* update wallpaper */,
268 base::ThreadTaskRunnerHandle::Get(), 315 base::ThreadTaskRunnerHandle::Get(),
269 base::Passed(std::move(on_finish_)), 316 base::Passed(std::move(on_finish_)),
270 manager->weak_factory_.GetWeakPtr())); 317 manager->weak_factory_.GetWeakPtr()));
271 } else if (!info_.location.empty()) { 318 } else if (!info_.location.empty()) {
272 manager->LoadWallpaper(account_id_, info_, true, std::move(on_finish_)); 319 manager->LoadWallpaper(account_id_, info_, true, std::move(on_finish_));
(...skipping 318 matching lines...) Expand 10 before | Expand all | Expand 10 after
591 GetPendingWallpaper(account_id, true)->ResetSetDefaultWallpaper(); 638 GetPendingWallpaper(account_id, true)->ResetSetDefaultWallpaper();
592 } 639 }
593 640
594 void WallpaperManager::DoSetDefaultWallpaper( 641 void WallpaperManager::DoSetDefaultWallpaper(
595 const AccountId& account_id, 642 const AccountId& account_id,
596 MovableOnDestroyCallbackHolder on_finish) { 643 MovableOnDestroyCallbackHolder on_finish) {
597 // There is no visible background in kiosk mode. 644 // There is no visible background in kiosk mode.
598 if (user_manager::UserManager::Get()->IsLoggedInAsKioskApp()) 645 if (user_manager::UserManager::Get()->IsLoggedInAsKioskApp())
599 return; 646 return;
600 wallpaper_cache_.erase(account_id); 647 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 648
607 WallpaperResolution resolution = GetAppropriateResolution(); 649 WallpaperResolution resolution = GetAppropriateResolution();
608 const bool use_small = (resolution == WALLPAPER_RESOLUTION_SMALL); 650 const bool use_small = (resolution == WALLPAPER_RESOLUTION_SMALL);
609 651
610 const base::FilePath* file = NULL; 652 const base::FilePath* file = NULL;
611 653
612 const user_manager::User* user = 654 const user_manager::User* user =
613 user_manager::UserManager::Get()->FindUser(account_id); 655 user_manager::UserManager::Get()->FindUser(account_id);
614 656
615 if (user_manager::UserManager::Get()->IsLoggedInAsGuest()) { 657 if (user_manager::UserManager::Get()->IsLoggedInAsGuest()) {
(...skipping 20 matching lines...) Expand all
636 return; 678 return;
637 } 679 }
638 680
639 CreateSolidDefaultWallpaper(); 681 CreateSolidDefaultWallpaper();
640 } 682 }
641 // 1x1 wallpaper is actually solid color, so it should be stretched. 683 // 1x1 wallpaper is actually solid color, so it should be stretched.
642 if (default_wallpaper_image_->image().width() == 1 && 684 if (default_wallpaper_image_->image().width() == 1 &&
643 default_wallpaper_image_->image().height() == 1) 685 default_wallpaper_image_->image().height() == 1)
644 layout = wallpaper::WALLPAPER_LAYOUT_STRETCH; 686 layout = wallpaper::WALLPAPER_LAYOUT_STRETCH;
645 687
646 ash::Shell::GetInstance()->desktop_background_controller()->SetWallpaperImage( 688 SetWallpaper(default_wallpaper_image_->image(), layout);
647 default_wallpaper_image_->image(), layout);
648 } 689 }
649 690
650 void WallpaperManager::SetUserWallpaperInfo(const AccountId& account_id, 691 void WallpaperManager::SetUserWallpaperInfo(const AccountId& account_id,
651 const WallpaperInfo& info, 692 const WallpaperInfo& info,
652 bool is_persistent) { 693 bool is_persistent) {
653 DCHECK_CURRENTLY_ON(BrowserThread::UI); 694 DCHECK_CURRENTLY_ON(BrowserThread::UI);
654 current_user_wallpaper_info_ = info; 695 current_user_wallpaper_info_ = info;
655 if (!is_persistent) 696 if (!is_persistent)
656 return; 697 return;
657 698
(...skipping 294 matching lines...) Expand 10 before | Expand all | Expand 10 after
952 SetUserWallpaperInfo(account_id, info, true); 993 SetUserWallpaperInfo(account_id, info, true);
953 994
954 if (update_wallpaper) 995 if (update_wallpaper)
955 DoSetDefaultWallpaper(account_id, std::move(on_finish)); 996 DoSetDefaultWallpaper(account_id, std::move(on_finish));
956 return; 997 return;
957 } 998 }
958 999
959 // Update the image, but keep the path which was set earlier. 1000 // Update the image, but keep the path which was set earlier.
960 wallpaper_cache_[account_id].second = user_image->image(); 1001 wallpaper_cache_[account_id].second = user_image->image();
961 1002
962 if (update_wallpaper) { 1003 if (update_wallpaper)
963 ash::Shell::GetInstance() 1004 SetWallpaper(user_image->image(), layout);
964 ->desktop_background_controller()
965 ->SetWallpaperImage(user_image->image(), layout);
966 }
967 } 1005 }
968 1006
969 void WallpaperManager::StartLoad(const AccountId& account_id, 1007 void WallpaperManager::StartLoad(const AccountId& account_id,
970 const WallpaperInfo& info, 1008 const WallpaperInfo& info,
971 bool update_wallpaper, 1009 bool update_wallpaper,
972 const base::FilePath& wallpaper_path, 1010 const base::FilePath& wallpaper_path,
973 MovableOnDestroyCallbackHolder on_finish) { 1011 MovableOnDestroyCallbackHolder on_finish) {
974 DCHECK_CURRENTLY_ON(BrowserThread::UI); 1012 DCHECK_CURRENTLY_ON(BrowserThread::UI);
975 TRACE_EVENT_ASYNC_BEGIN0("ui", "LoadAndDecodeWallpaper", this); 1013 TRACE_EVENT_ASYNC_BEGIN0("ui", "LoadAndDecodeWallpaper", this);
976 if (update_wallpaper) { 1014 if (update_wallpaper) {
(...skipping 84 matching lines...) Expand 10 before | Expand all | Expand 10 after
1061 default_wallpaper_image_.reset(); 1099 default_wallpaper_image_.reset();
1062 } 1100 }
1063 1101
1064 void WallpaperManager::OnDefaultWallpaperDecoded( 1102 void WallpaperManager::OnDefaultWallpaperDecoded(
1065 const base::FilePath& path, 1103 const base::FilePath& path,
1066 const wallpaper::WallpaperLayout layout, 1104 const wallpaper::WallpaperLayout layout,
1067 std::unique_ptr<user_manager::UserImage>* result_out, 1105 std::unique_ptr<user_manager::UserImage>* result_out,
1068 MovableOnDestroyCallbackHolder on_finish, 1106 MovableOnDestroyCallbackHolder on_finish,
1069 std::unique_ptr<user_manager::UserImage> user_image) { 1107 std::unique_ptr<user_manager::UserImage> user_image) {
1070 *result_out = std::move(user_image); 1108 *result_out = std::move(user_image);
1071 ash::Shell::GetInstance()->desktop_background_controller()->SetWallpaperImage( 1109 SetWallpaper((*result_out)->image(), layout);
1072 (*result_out)->image(), layout);
1073 } 1110 }
1074 1111
1075 void WallpaperManager::StartLoadAndSetDefaultWallpaper( 1112 void WallpaperManager::StartLoadAndSetDefaultWallpaper(
1076 const base::FilePath& path, 1113 const base::FilePath& path,
1077 const wallpaper::WallpaperLayout layout, 1114 const wallpaper::WallpaperLayout layout,
1078 MovableOnDestroyCallbackHolder on_finish, 1115 MovableOnDestroyCallbackHolder on_finish,
1079 std::unique_ptr<user_manager::UserImage>* result_out) { 1116 std::unique_ptr<user_manager::UserImage>* result_out) {
1080 user_image_loader::StartWithFilePath( 1117 user_image_loader::StartWithFilePath(
1081 task_runner_, path, ImageDecoder::ROBUST_JPEG_CODEC, 1118 task_runner_, path, ImageDecoder::ROBUST_JPEG_CODEC,
1082 0, // Do not crop. 1119 0, // Do not crop.
(...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after
1135 &stored_value)) { 1172 &stored_value)) {
1136 return wallpaper::WallpaperFilesId::FromString(stored_value); 1173 return wallpaper::WallpaperFilesId::FromString(stored_value);
1137 } 1174 }
1138 const std::string& old_id = account_id.GetUserEmail(); // Migrated 1175 const std::string& old_id = account_id.GetUserEmail(); // Migrated
1139 const wallpaper::WallpaperFilesId files_id = HashWallpaperFilesIdStr(old_id); 1176 const wallpaper::WallpaperFilesId files_id = HashWallpaperFilesIdStr(old_id);
1140 SetKnownUserWallpaperFilesId(account_id, files_id); 1177 SetKnownUserWallpaperFilesId(account_id, files_id);
1141 return files_id; 1178 return files_id;
1142 } 1179 }
1143 1180
1144 } // namespace chromeos 1181 } // namespace chromeos
OLDNEW
« no previous file with comments | « chrome/browser/chromeos/extensions/wallpaper_private_api.cc ('k') | chrome/browser/ui/BUILD.gn » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698