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

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: Fix gyp builds; address Sadrul's comment. Created 4 years, 7 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
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"
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 "mash/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
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 mash::mojom::WallpaperControllerPtr wallpaper_controller;
191 connector->ConnectToInterface("mojo:ash_sysui", &wallpaper_controller);
192 wallpaper_controller->SetWallpaper(
193 skia::mojom::Bitmap::From(*image.bitmap()),
194 static_cast<int32_t>(layout));
195 return;
196 }
197 #endif
198 ash::Shell::GetInstance()->desktop_background_controller()->SetWallpaperImage(
James Cook 2016/05/19 22:30:00 Do you need to do this in the mash case? In partic
msw 2016/05/20 19:53:05 Perhaps you missed the early return on line 195, o
James Cook 2016/05/20 20:47:13 Yeah, I missed the early return. I think it's wor
msw 2016/05/20 21:31:48 Done. I filed http://crbug.com/613707
199 image, layout);
200 }
201
175 } // namespace 202 } // namespace
176 203
177 // This is "wallpaper either scheduled to load, or loading right now". 204 // This is "wallpaper either scheduled to load, or loading right now".
178 // 205 //
179 // While enqueued, it defines moment in the future, when it will be loaded. 206 // 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 207 // Enqueued but not started request might be updated by subsequent load
181 // request. Therefore it's created empty, and updated being enqueued. 208 // request. Therefore it's created empty, and updated being enqueued.
182 // 209 //
183 // PendingWallpaper is owned by WallpaperManager, but reference to this object 210 // PendingWallpaper is owned by WallpaperManager, but reference to this object
184 // is passed to other threads by PostTask() calls, therefore it is 211 // is passed to other threads by PostTask() calls, therefore it is
(...skipping 10 matching lines...) Expand all
195 this))) { 222 this))) {
196 timer.Start( 223 timer.Start(
197 FROM_HERE, 224 FROM_HERE,
198 delay, 225 delay,
199 base::Bind(&WallpaperManager::PendingWallpaper::ProcessRequest, this)); 226 base::Bind(&WallpaperManager::PendingWallpaper::ProcessRequest, this));
200 } 227 }
201 228
202 // There are 4 cases in SetUserWallpaper: 229 // There are 4 cases in SetUserWallpaper:
203 // 1) gfx::ImageSkia is found in cache. 230 // 1) gfx::ImageSkia is found in cache.
204 // - Schedule task to (probably) resize it and install: 231 // - Schedule task to (probably) resize it and install:
205 // call ash::Shell::GetInstance()->desktop_background_controller()-> 232 // call SetWallpaper(user_wallpaper, layout);
206 // SetCustomWallpaper(user_wallpaper, layout);
207 // 2) WallpaperInfo is found in cache 233 // 2) WallpaperInfo is found in cache
208 // - need to LoadWallpaper(), resize and install. 234 // - need to LoadWallpaper(), resize and install.
209 // 3) wallpaper path is not NULL, load image URL, then resize, etc... 235 // 3) wallpaper path is not NULL, load image URL, then resize, etc...
210 // 4) SetDefaultWallpaper (either on some error, or when user is new). 236 // 4) SetDefaultWallpaper (either on some error, or when user is new).
211 void ResetSetWallpaperImage(const gfx::ImageSkia& image, 237 void ResetSetWallpaperImage(const gfx::ImageSkia& image,
212 const wallpaper::WallpaperInfo& info) { 238 const wallpaper::WallpaperInfo& info) {
213 SetMode(image, info, base::FilePath(), false); 239 SetMode(image, info, base::FilePath(), false);
214 } 240 }
215 241
216 void ResetLoadWallpaper(const wallpaper::WallpaperInfo& info) { 242 void ResetLoadWallpaper(const wallpaper::WallpaperInfo& info) {
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after
250 276
251 WallpaperManager* manager = WallpaperManager::Get(); 277 WallpaperManager* manager = WallpaperManager::Get();
252 if (manager->pending_inactive_ == this) 278 if (manager->pending_inactive_ == this)
253 manager->pending_inactive_ = NULL; 279 manager->pending_inactive_ = NULL;
254 280
255 started_load_at_ = base::Time::Now(); 281 started_load_at_ = base::Time::Now();
256 282
257 if (default_) { 283 if (default_) {
258 manager->DoSetDefaultWallpaper(account_id_, std::move(on_finish_)); 284 manager->DoSetDefaultWallpaper(account_id_, std::move(on_finish_));
259 } else if (!user_wallpaper_.isNull()) { 285 } else if (!user_wallpaper_.isNull()) {
260 ash::Shell::GetInstance() 286 SetWallpaper(user_wallpaper_, info_.layout);
261 ->desktop_background_controller()
262 ->SetWallpaperImage(user_wallpaper_, info_.layout);
263 } else if (!wallpaper_path_.empty()) { 287 } else if (!wallpaper_path_.empty()) {
264 manager->task_runner_->PostTask( 288 manager->task_runner_->PostTask(
265 FROM_HERE, 289 FROM_HERE,
266 base::Bind(&WallpaperManager::GetCustomWallpaperInternal, account_id_, 290 base::Bind(&WallpaperManager::GetCustomWallpaperInternal, account_id_,
267 info_, wallpaper_path_, true /* update wallpaper */, 291 info_, wallpaper_path_, true /* update wallpaper */,
268 base::ThreadTaskRunnerHandle::Get(), 292 base::ThreadTaskRunnerHandle::Get(),
269 base::Passed(std::move(on_finish_)), 293 base::Passed(std::move(on_finish_)),
270 manager->weak_factory_.GetWeakPtr())); 294 manager->weak_factory_.GetWeakPtr()));
271 } else if (!info_.location.empty()) { 295 } else if (!info_.location.empty()) {
272 manager->LoadWallpaper(account_id_, info_, true, std::move(on_finish_)); 296 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(); 615 GetPendingWallpaper(account_id, true)->ResetSetDefaultWallpaper();
592 } 616 }
593 617
594 void WallpaperManager::DoSetDefaultWallpaper( 618 void WallpaperManager::DoSetDefaultWallpaper(
595 const AccountId& account_id, 619 const AccountId& account_id,
596 MovableOnDestroyCallbackHolder on_finish) { 620 MovableOnDestroyCallbackHolder on_finish) {
597 // There is no visible background in kiosk mode. 621 // There is no visible background in kiosk mode.
598 if (user_manager::UserManager::Get()->IsLoggedInAsKioskApp()) 622 if (user_manager::UserManager::Get()->IsLoggedInAsKioskApp())
599 return; 623 return;
600 wallpaper_cache_.erase(account_id); 624 wallpaper_cache_.erase(account_id);
601 // Some browser tests do not have a shell instance. As no wallpaper is needed
James Cook 2016/05/19 22:30:00 Maybe this should be unit tests? It looks like som
msw 2016/05/20 19:53:05 Done; added GetMaxDisplaySizeInNative and SetWallp
602 // in these tests anyway, avoid loading one, preventing crashes and speeding
603 // up the tests.
604 if (!ash::Shell::HasInstance())
605 return;
606 625
607 WallpaperResolution resolution = GetAppropriateResolution(); 626 WallpaperResolution resolution = GetAppropriateResolution();
608 const bool use_small = (resolution == WALLPAPER_RESOLUTION_SMALL); 627 const bool use_small = (resolution == WALLPAPER_RESOLUTION_SMALL);
609 628
610 const base::FilePath* file = NULL; 629 const base::FilePath* file = NULL;
611 630
612 const user_manager::User* user = 631 const user_manager::User* user =
613 user_manager::UserManager::Get()->FindUser(account_id); 632 user_manager::UserManager::Get()->FindUser(account_id);
614 633
615 if (user_manager::UserManager::Get()->IsLoggedInAsGuest()) { 634 if (user_manager::UserManager::Get()->IsLoggedInAsGuest()) {
(...skipping 20 matching lines...) Expand all
636 return; 655 return;
637 } 656 }
638 657
639 CreateSolidDefaultWallpaper(); 658 CreateSolidDefaultWallpaper();
640 } 659 }
641 // 1x1 wallpaper is actually solid color, so it should be stretched. 660 // 1x1 wallpaper is actually solid color, so it should be stretched.
642 if (default_wallpaper_image_->image().width() == 1 && 661 if (default_wallpaper_image_->image().width() == 1 &&
643 default_wallpaper_image_->image().height() == 1) 662 default_wallpaper_image_->image().height() == 1)
644 layout = wallpaper::WALLPAPER_LAYOUT_STRETCH; 663 layout = wallpaper::WALLPAPER_LAYOUT_STRETCH;
645 664
646 ash::Shell::GetInstance()->desktop_background_controller()->SetWallpaperImage( 665 SetWallpaper(default_wallpaper_image_->image(), layout);
647 default_wallpaper_image_->image(), layout);
648 } 666 }
649 667
650 void WallpaperManager::SetUserWallpaperInfo(const AccountId& account_id, 668 void WallpaperManager::SetUserWallpaperInfo(const AccountId& account_id,
651 const WallpaperInfo& info, 669 const WallpaperInfo& info,
652 bool is_persistent) { 670 bool is_persistent) {
653 DCHECK_CURRENTLY_ON(BrowserThread::UI); 671 DCHECK_CURRENTLY_ON(BrowserThread::UI);
654 current_user_wallpaper_info_ = info; 672 current_user_wallpaper_info_ = info;
655 if (!is_persistent) 673 if (!is_persistent)
656 return; 674 return;
657 675
(...skipping 294 matching lines...) Expand 10 before | Expand all | Expand 10 after
952 SetUserWallpaperInfo(account_id, info, true); 970 SetUserWallpaperInfo(account_id, info, true);
953 971
954 if (update_wallpaper) 972 if (update_wallpaper)
955 DoSetDefaultWallpaper(account_id, std::move(on_finish)); 973 DoSetDefaultWallpaper(account_id, std::move(on_finish));
956 return; 974 return;
957 } 975 }
958 976
959 // Update the image, but keep the path which was set earlier. 977 // Update the image, but keep the path which was set earlier.
960 wallpaper_cache_[account_id].second = user_image->image(); 978 wallpaper_cache_[account_id].second = user_image->image();
961 979
962 if (update_wallpaper) { 980 if (update_wallpaper)
963 ash::Shell::GetInstance() 981 SetWallpaper(user_image->image(), layout);
964 ->desktop_background_controller()
965 ->SetWallpaperImage(user_image->image(), layout);
966 }
967 } 982 }
968 983
969 void WallpaperManager::StartLoad(const AccountId& account_id, 984 void WallpaperManager::StartLoad(const AccountId& account_id,
970 const WallpaperInfo& info, 985 const WallpaperInfo& info,
971 bool update_wallpaper, 986 bool update_wallpaper,
972 const base::FilePath& wallpaper_path, 987 const base::FilePath& wallpaper_path,
973 MovableOnDestroyCallbackHolder on_finish) { 988 MovableOnDestroyCallbackHolder on_finish) {
974 DCHECK_CURRENTLY_ON(BrowserThread::UI); 989 DCHECK_CURRENTLY_ON(BrowserThread::UI);
975 TRACE_EVENT_ASYNC_BEGIN0("ui", "LoadAndDecodeWallpaper", this); 990 TRACE_EVENT_ASYNC_BEGIN0("ui", "LoadAndDecodeWallpaper", this);
976 if (update_wallpaper) { 991 if (update_wallpaper) {
(...skipping 84 matching lines...) Expand 10 before | Expand all | Expand 10 after
1061 default_wallpaper_image_.reset(); 1076 default_wallpaper_image_.reset();
1062 } 1077 }
1063 1078
1064 void WallpaperManager::OnDefaultWallpaperDecoded( 1079 void WallpaperManager::OnDefaultWallpaperDecoded(
1065 const base::FilePath& path, 1080 const base::FilePath& path,
1066 const wallpaper::WallpaperLayout layout, 1081 const wallpaper::WallpaperLayout layout,
1067 std::unique_ptr<user_manager::UserImage>* result_out, 1082 std::unique_ptr<user_manager::UserImage>* result_out,
1068 MovableOnDestroyCallbackHolder on_finish, 1083 MovableOnDestroyCallbackHolder on_finish,
1069 std::unique_ptr<user_manager::UserImage> user_image) { 1084 std::unique_ptr<user_manager::UserImage> user_image) {
1070 *result_out = std::move(user_image); 1085 *result_out = std::move(user_image);
1071 ash::Shell::GetInstance()->desktop_background_controller()->SetWallpaperImage( 1086 SetWallpaper((*result_out)->image(), layout);
1072 (*result_out)->image(), layout);
1073 } 1087 }
1074 1088
1075 void WallpaperManager::StartLoadAndSetDefaultWallpaper( 1089 void WallpaperManager::StartLoadAndSetDefaultWallpaper(
1076 const base::FilePath& path, 1090 const base::FilePath& path,
1077 const wallpaper::WallpaperLayout layout, 1091 const wallpaper::WallpaperLayout layout,
1078 MovableOnDestroyCallbackHolder on_finish, 1092 MovableOnDestroyCallbackHolder on_finish,
1079 std::unique_ptr<user_manager::UserImage>* result_out) { 1093 std::unique_ptr<user_manager::UserImage>* result_out) {
1080 user_image_loader::StartWithFilePath( 1094 user_image_loader::StartWithFilePath(
1081 task_runner_, path, ImageDecoder::ROBUST_JPEG_CODEC, 1095 task_runner_, path, ImageDecoder::ROBUST_JPEG_CODEC,
1082 0, // Do not crop. 1096 0, // Do not crop.
(...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after
1135 &stored_value)) { 1149 &stored_value)) {
1136 return wallpaper::WallpaperFilesId::FromString(stored_value); 1150 return wallpaper::WallpaperFilesId::FromString(stored_value);
1137 } 1151 }
1138 const std::string& old_id = account_id.GetUserEmail(); // Migrated 1152 const std::string& old_id = account_id.GetUserEmail(); // Migrated
1139 const wallpaper::WallpaperFilesId files_id = HashWallpaperFilesIdStr(old_id); 1153 const wallpaper::WallpaperFilesId files_id = HashWallpaperFilesIdStr(old_id);
1140 SetKnownUserWallpaperFilesId(account_id, files_id); 1154 SetKnownUserWallpaperFilesId(account_id, files_id);
1141 return files_id; 1155 return files_id;
1142 } 1156 }
1143 1157
1144 } // namespace chromeos 1158 } // namespace chromeos
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698