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

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 171 matching lines...) Expand 10 before | Expand all | Expand 10 after
388 base::Time started_load_at_; 389 base::Time started_load_at_;
389 390
390 DISALLOW_COPY_AND_ASSIGN(PendingWallpaper); 391 DISALLOW_COPY_AND_ASSIGN(PendingWallpaper);
391 }; 392 };
392 393
393 // WallpaperManager, public: --------------------------------------------------- 394 // WallpaperManager, public: ---------------------------------------------------
394 395
395 WallpaperManager::~WallpaperManager() { 396 WallpaperManager::~WallpaperManager() {
396 show_user_name_on_signin_subscription_.reset(); 397 show_user_name_on_signin_subscription_.reset();
397 device_wallpaper_image_subscription_.reset(); 398 device_wallpaper_image_subscription_.reset();
398 user_manager::UserManager::Get()->RemoveSessionStateObserver(this); 399 user_manager::UserManager::Get()->RemoveSessionStateObserver(this);
xdai1 2017/06/14 18:23:40 Please also remove itself as an observer of Wallpa
Wenzhao (Colin) Zang 2017/06/15 18:14:40 Done.
399 weak_factory_.InvalidateWeakPtrs(); 400 weak_factory_.InvalidateWeakPtrs();
400 } 401 }
401 402
402 // static 403 // static
403 void WallpaperManager::Initialize() { 404 void WallpaperManager::Initialize() {
404 CHECK(!wallpaper_manager); 405 CHECK(!wallpaper_manager);
405 wallpaper_manager = new WallpaperManager(); 406 wallpaper_manager = new WallpaperManager();
406 } 407 }
407 408
408 // static 409 // static
(...skipping 11 matching lines...) Expand all
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 // Cancel in-flight color calculations, if any.
433 if (color_calculator_) {
434 color_calculator_->RemoveObserver(this);
435 color_calculator_.reset();
436 }
437
438 color_calculator_ = base::MakeUnique<wallpaper::WallpaperColorCalculator>(
439 image, color_utils::LumaRange::DARK, color_utils::SaturationRange::MUTED,
440 task_runner_);
441 color_calculator_->AddObserver(this);
442 if (!color_calculator_->StartCalculation()) {
443 if (!prominent_color_.has_value())
444 return;
445 prominent_color_.reset();
446 for (auto& observer : observers_)
447 observer.OnWallpaperColorsChanged();
448 }
449 }
450
430 WallpaperManager::WallpaperResolution 451 WallpaperManager::WallpaperResolution
431 WallpaperManager::GetAppropriateResolution() { 452 WallpaperManager::GetAppropriateResolution() {
432 DCHECK_CURRENTLY_ON(BrowserThread::UI); 453 DCHECK_CURRENTLY_ON(BrowserThread::UI);
433 gfx::Size size = ash::WallpaperController::GetMaxDisplaySizeInNative(); 454 gfx::Size size = ash::WallpaperController::GetMaxDisplaySizeInNative();
434 return (size.width() > wallpaper::kSmallWallpaperMaxWidth || 455 return (size.width() > wallpaper::kSmallWallpaperMaxWidth ||
435 size.height() > wallpaper::kSmallWallpaperMaxHeight) 456 size.height() > wallpaper::kSmallWallpaperMaxHeight)
436 ? WALLPAPER_RESOLUTION_LARGE 457 ? WALLPAPER_RESOLUTION_LARGE
437 : WALLPAPER_RESOLUTION_SMALL; 458 : WALLPAPER_RESOLUTION_SMALL;
438 } 459 }
439 460
(...skipping 464 matching lines...) Expand 10 before | Expand all | Expand 10 after
904 window_observer_.Add(gained_active); 925 window_observer_.Add(gained_active);
905 } 926 }
906 } 927 }
907 928
908 void WallpaperManager::OnWindowDestroying(aura::Window* window) { 929 void WallpaperManager::OnWindowDestroying(aura::Window* window) {
909 window_observer_.Remove(window); 930 window_observer_.Remove(window);
910 chromeos::WallpaperWindowStateManager::RestoreWindows( 931 chromeos::WallpaperWindowStateManager::RestoreWindows(
911 user_manager::UserManager::Get()->GetActiveUser()->username_hash()); 932 user_manager::UserManager::Get()->GetActiveUser()->username_hash());
912 } 933 }
913 934
935 void WallpaperManager::OnColorCalculationComplete() {
936 SkColor color = color_calculator_->prominent_color();
937 color_calculator_.reset();
938 if (prominent_color_ == color)
939 return;
940 prominent_color_ = color;
941
942 for (auto& observer : observers_)
943 observer.OnWallpaperColorsChanged();
944 }
945
914 // WallpaperManager, private: -------------------------------------------------- 946 // WallpaperManager, private: --------------------------------------------------
915 947
916 WallpaperManager::WallpaperManager() 948 WallpaperManager::WallpaperManager()
917 : binding_(this), 949 : binding_(this),
918 pending_inactive_(nullptr), 950 pending_inactive_(nullptr),
919 activation_client_observer_(this), 951 activation_client_observer_(this),
920 window_observer_(this), 952 window_observer_(this),
921 weak_factory_(this) { 953 weak_factory_(this) {
922 DCHECK_CURRENTLY_ON(BrowserThread::UI); 954 DCHECK_CURRENTLY_ON(BrowserThread::UI);
923 wallpaper::WallpaperManagerBase::SetPathIds( 955 wallpaper::WallpaperManagerBase::SetPathIds(
(...skipping 521 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