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

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

Issue 2931063004: Extract colors from wallpaper and dynamically update login screen overlay (Closed)
Patch Set: Address comments Created 3 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
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 <utility> 7 #include <utility>
8 8
9 #include "ash/ash_constants.h" 9 #include "ash/ash_constants.h"
10 #include "ash/public/cpp/shelf_types.h" 10 #include "ash/public/cpp/shelf_types.h"
(...skipping 186 matching lines...) Expand 10 before | Expand all | Expand 10 after
197 void SetKnownUserWallpaperFilesId( 197 void SetKnownUserWallpaperFilesId(
198 const AccountId& account_id, 198 const AccountId& account_id,
199 const wallpaper::WallpaperFilesId& wallpaper_files_id) { 199 const wallpaper::WallpaperFilesId& wallpaper_files_id) {
200 user_manager::known_user::SetStringPref(account_id, kWallpaperFilesId, 200 user_manager::known_user::SetStringPref(account_id, kWallpaperFilesId,
201 wallpaper_files_id.id()); 201 wallpaper_files_id.id());
202 } 202 }
203 203
204 // A helper to set the wallpaper image for Classic Ash and Mash. 204 // A helper to set the wallpaper image for Classic Ash and Mash.
205 void SetWallpaper(const gfx::ImageSkia& image, 205 void SetWallpaper(const gfx::ImageSkia& image,
206 wallpaper::WallpaperLayout layout) { 206 wallpaper::WallpaperLayout layout) {
207 WallpaperManager::Get()->CalculateProminentColor(image);
207 if (ash_util::IsRunningInMash()) { 208 if (ash_util::IsRunningInMash()) {
208 // In mash, connect to the WallpaperController interface via mojo. 209 // In mash, connect to the WallpaperController interface via mojo.
209 service_manager::Connector* connector = 210 service_manager::Connector* connector =
210 content::ServiceManagerConnection::GetForProcess()->GetConnector(); 211 content::ServiceManagerConnection::GetForProcess()->GetConnector();
211 if (!connector) 212 if (!connector)
212 return; 213 return;
213 214
214 ash::mojom::WallpaperControllerPtr wallpaper_controller; 215 ash::mojom::WallpaperControllerPtr wallpaper_controller;
215 connector->BindInterface(ash::mojom::kServiceName, &wallpaper_controller); 216 connector->BindInterface(ash::mojom::kServiceName, &wallpaper_controller);
216 // TODO(crbug.com/655875): Optimize ash wallpaper transport; avoid sending 217 // TODO(crbug.com/655875): Optimize ash wallpaper transport; avoid sending
(...skipping 203 matching lines...) Expand 10 before | Expand all | Expand 10 after
420 421
421 bool WallpaperManager::IsPendingWallpaper(uint32_t image_id) { 422 bool WallpaperManager::IsPendingWallpaper(uint32_t image_id) {
422 for (size_t i = 0; i < loading_.size(); ++i) { 423 for (size_t i = 0; i < loading_.size(); ++i) {
423 if (loading_[i]->GetImageId() == image_id) { 424 if (loading_[i]->GetImageId() == image_id) {
424 return true; 425 return true;
425 } 426 }
426 } 427 }
427 return false; 428 return false;
428 } 429 }
429 430
431 void WallpaperManager::CalculateProminentColor(const gfx::ImageSkia& image) {
432 if (color_calculator_) {
433 color_calculator_->RemoveObserver(this);
jdufault 2017/06/12 21:37:28 Add a comment along the lines of // Cancel any
Wenzhao (Colin) Zang 2017/06/12 23:40:34 Done.
434 color_calculator_.reset();
435 }
436
437 color_utils::LumaRange luma = color_utils::LumaRange::DARK;
jdufault 2017/06/12 21:37:28 Eliminate the |luma| and |saturation| temporaries.
Wenzhao (Colin) Zang 2017/06/12 23:40:34 Done.
438 color_utils::SaturationRange saturation = color_utils::SaturationRange::MUTED;
439
440 color_calculator_ = base::MakeUnique<wallpaper::WallpaperColorCalculator>(
441 image, luma, saturation, task_runner_);
442 color_calculator_->AddObserver(this);
443 if (!color_calculator_->StartCalculation())
444 SetProminentColor(SK_ColorTRANSPARENT);
445 }
446
430 WallpaperManager::WallpaperResolution 447 WallpaperManager::WallpaperResolution
431 WallpaperManager::GetAppropriateResolution() { 448 WallpaperManager::GetAppropriateResolution() {
432 DCHECK_CURRENTLY_ON(BrowserThread::UI); 449 DCHECK_CURRENTLY_ON(BrowserThread::UI);
433 gfx::Size size = ash::WallpaperController::GetMaxDisplaySizeInNative(); 450 gfx::Size size = ash::WallpaperController::GetMaxDisplaySizeInNative();
434 return (size.width() > wallpaper::kSmallWallpaperMaxWidth || 451 return (size.width() > wallpaper::kSmallWallpaperMaxWidth ||
435 size.height() > wallpaper::kSmallWallpaperMaxHeight) 452 size.height() > wallpaper::kSmallWallpaperMaxHeight)
436 ? WALLPAPER_RESOLUTION_LARGE 453 ? WALLPAPER_RESOLUTION_LARGE
437 : WALLPAPER_RESOLUTION_SMALL; 454 : WALLPAPER_RESOLUTION_SMALL;
438 } 455 }
439 456
(...skipping 464 matching lines...) Expand 10 before | Expand all | Expand 10 after
904 window_observer_.Add(gained_active); 921 window_observer_.Add(gained_active);
905 } 922 }
906 } 923 }
907 924
908 void WallpaperManager::OnWindowDestroying(aura::Window* window) { 925 void WallpaperManager::OnWindowDestroying(aura::Window* window) {
909 window_observer_.Remove(window); 926 window_observer_.Remove(window);
910 chromeos::WallpaperWindowStateManager::RestoreWindows( 927 chromeos::WallpaperWindowStateManager::RestoreWindows(
911 user_manager::UserManager::Get()->GetActiveUser()->username_hash()); 928 user_manager::UserManager::Get()->GetActiveUser()->username_hash());
912 } 929 }
913 930
931 void WallpaperManager::OnColorCalculationComplete() {
932 const SkColor color = color_calculator_->prominent_color();
933 color_calculator_.reset();
jdufault 2017/06/12 21:37:28 Add a comment explaining why you cache color inste
Wenzhao (Colin) Zang 2017/06/12 23:40:34 Changed to using the color directly.
934 SetProminentColor(color);
935 }
936
914 // WallpaperManager, private: -------------------------------------------------- 937 // WallpaperManager, private: --------------------------------------------------
915 938
916 WallpaperManager::WallpaperManager() 939 WallpaperManager::WallpaperManager()
917 : binding_(this), 940 : binding_(this),
918 pending_inactive_(nullptr), 941 pending_inactive_(nullptr),
919 activation_client_observer_(this), 942 activation_client_observer_(this),
920 window_observer_(this), 943 window_observer_(this),
921 weak_factory_(this) { 944 weak_factory_(this) {
922 DCHECK_CURRENTLY_ON(BrowserThread::UI); 945 DCHECK_CURRENTLY_ON(BrowserThread::UI);
923 wallpaper::WallpaperManagerBase::SetPathIds( 946 wallpaper::WallpaperManagerBase::SetPathIds(
(...skipping 174 matching lines...) Expand 10 before | Expand all | Expand 10 after
1098 WallpaperInfo wallpaper_info = {GetDeviceWallpaperFilePath().value(), 1121 WallpaperInfo wallpaper_info = {GetDeviceWallpaperFilePath().value(),
1099 wallpaper::WALLPAPER_LAYOUT_CENTER_CROPPED, 1122 wallpaper::WALLPAPER_LAYOUT_CENTER_CROPPED,
1100 user_manager::User::DEVICE, 1123 user_manager::User::DEVICE,
1101 base::Time::Now().LocalMidnight()}; 1124 base::Time::Now().LocalMidnight()};
1102 DCHECK(!user_manager::UserManager::Get()->IsUserLoggedIn()); 1125 DCHECK(!user_manager::UserManager::Get()->IsUserLoggedIn());
1103 // In the login screen set the device wallpaper as the wallpaper. 1126 // In the login screen set the device wallpaper as the wallpaper.
1104 GetPendingWallpaper(user_manager::SignInAccountId(), false) 1127 GetPendingWallpaper(user_manager::SignInAccountId(), false)
1105 ->ResetSetWallpaperImage(user_image->image(), wallpaper_info); 1128 ->ResetSetWallpaperImage(user_image->image(), wallpaper_info);
1106 } 1129 }
1107 1130
1131 void WallpaperManager::SetProminentColor(SkColor color) {
1132 if (prominent_color_ == color)
1133 return;
1134
1135 prominent_color_ = color;
1136 for (auto& observer : observers_)
1137 observer.OnColorCalculationComplete();
1138 }
1139
1108 void WallpaperManager::InitializeRegisteredDeviceWallpaper() { 1140 void WallpaperManager::InitializeRegisteredDeviceWallpaper() {
1109 if (user_manager::UserManager::Get()->IsUserLoggedIn()) 1141 if (user_manager::UserManager::Get()->IsUserLoggedIn())
1110 return; 1142 return;
1111 1143
1112 bool disable_boot_animation = 1144 bool disable_boot_animation =
1113 GetCommandLine()->HasSwitch(switches::kDisableBootAnimation); 1145 GetCommandLine()->HasSwitch(switches::kDisableBootAnimation);
1114 bool show_users = true; 1146 bool show_users = true;
1115 bool result = CrosSettings::Get()->GetBoolean( 1147 bool result = CrosSettings::Get()->GetBoolean(
1116 kAccountsPrefShowUserNamesOnSignIn, &show_users); 1148 kAccountsPrefShowUserNamesOnSignIn, &show_users);
1117 DCHECK(result) << "Unable to fetch setting " 1149 DCHECK(result) << "Unable to fetch setting "
(...skipping 327 matching lines...) Expand 10 before | Expand all | Expand 10 after
1445 1477
1446 UMA_HISTOGRAM_ENUMERATION( 1478 UMA_HISTOGRAM_ENUMERATION(
1447 "Ash.Wallpaper.Apps", 1479 "Ash.Wallpaper.Apps",
1448 wallpaper_manager_util::ShouldUseAndroidWallpapersApp(profile) 1480 wallpaper_manager_util::ShouldUseAndroidWallpapersApp(profile)
1449 ? WALLPAPERS_APP_ANDROID 1481 ? WALLPAPERS_APP_ANDROID
1450 : WALLPAPERS_PICKER_APP_CHROMEOS, 1482 : WALLPAPERS_PICKER_APP_CHROMEOS,
1451 WALLPAPERS_APPS_NUM); 1483 WALLPAPERS_APPS_NUM);
1452 } 1484 }
1453 1485
1454 } // namespace chromeos 1486 } // namespace chromeos
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698