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

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: Will clean up this CL when crbug.com/733709 is fixed 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();
399 if (color_calculator_) {
400 color_calculator_->RemoveObserver(this);
401 color_calculator_.reset();
402 }
398 user_manager::UserManager::Get()->RemoveSessionStateObserver(this); 403 user_manager::UserManager::Get()->RemoveSessionStateObserver(this);
399 weak_factory_.InvalidateWeakPtrs(); 404 weak_factory_.InvalidateWeakPtrs();
400 } 405 }
401 406
402 // static 407 // static
403 void WallpaperManager::Initialize() { 408 void WallpaperManager::Initialize() {
404 CHECK(!wallpaper_manager); 409 CHECK(!wallpaper_manager);
405 wallpaper_manager = new WallpaperManager(); 410 wallpaper_manager = new WallpaperManager();
406 } 411 }
407 412
408 // static 413 // static
409 WallpaperManager* WallpaperManager::Get() { 414 WallpaperManager* WallpaperManager::Get() {
410 DCHECK(wallpaper_manager); 415 DCHECK(wallpaper_manager);
411 return wallpaper_manager; 416 return wallpaper_manager;
412 } 417 }
413 418
414 // static 419 // static
415 void WallpaperManager::Shutdown() { 420 void WallpaperManager::Shutdown() {
416 CHECK(wallpaper_manager); 421 CHECK(wallpaper_manager);
417 delete wallpaper_manager; 422 delete wallpaper_manager;
418 wallpaper_manager = nullptr; 423 wallpaper_manager = nullptr;
419 } 424 }
420 425
426 // static
427 bool WallpaperManager::HasInstance() {
428 return wallpaper_manager != nullptr;
429 }
430
421 bool WallpaperManager::IsPendingWallpaper(uint32_t image_id) { 431 bool WallpaperManager::IsPendingWallpaper(uint32_t image_id) {
422 for (size_t i = 0; i < loading_.size(); ++i) { 432 for (size_t i = 0; i < loading_.size(); ++i) {
423 if (loading_[i]->GetImageId() == image_id) { 433 if (loading_[i]->GetImageId() == image_id) {
424 return true; 434 return true;
425 } 435 }
426 } 436 }
427 return false; 437 return false;
428 } 438 }
429 439
440 void WallpaperManager::CalculateProminentColor(const gfx::ImageSkia& image) {
441 // Cancel in-flight color calculations, if any.
442 if (color_calculator_) {
443 color_calculator_->RemoveObserver(this);
444 color_calculator_.reset();
445 }
446
447 color_calculator_ = base::MakeUnique<wallpaper::WallpaperColorCalculator>(
448 image, color_utils::LumaRange::DARK, color_utils::SaturationRange::MUTED,
449 task_runner_);
450 color_calculator_->AddObserver(this);
451 if (!color_calculator_->StartCalculation()) {
452 color_calculator_->RemoveObserver(this);
453 color_calculator_.reset();
454 if (!prominent_color_.has_value())
455 return;
456 prominent_color_.reset();
457 for (auto& observer : observers_)
458 observer.OnWallpaperColorsChanged();
459 }
460 }
461
430 WallpaperManager::WallpaperResolution 462 WallpaperManager::WallpaperResolution
431 WallpaperManager::GetAppropriateResolution() { 463 WallpaperManager::GetAppropriateResolution() {
432 DCHECK_CURRENTLY_ON(BrowserThread::UI); 464 DCHECK_CURRENTLY_ON(BrowserThread::UI);
433 gfx::Size size = ash::WallpaperController::GetMaxDisplaySizeInNative(); 465 gfx::Size size = ash::WallpaperController::GetMaxDisplaySizeInNative();
434 return (size.width() > wallpaper::kSmallWallpaperMaxWidth || 466 return (size.width() > wallpaper::kSmallWallpaperMaxWidth ||
435 size.height() > wallpaper::kSmallWallpaperMaxHeight) 467 size.height() > wallpaper::kSmallWallpaperMaxHeight)
436 ? WALLPAPER_RESOLUTION_LARGE 468 ? WALLPAPER_RESOLUTION_LARGE
437 : WALLPAPER_RESOLUTION_SMALL; 469 : WALLPAPER_RESOLUTION_SMALL;
438 } 470 }
439 471
(...skipping 464 matching lines...) Expand 10 before | Expand all | Expand 10 after
904 window_observer_.Add(gained_active); 936 window_observer_.Add(gained_active);
905 } 937 }
906 } 938 }
907 939
908 void WallpaperManager::OnWindowDestroying(aura::Window* window) { 940 void WallpaperManager::OnWindowDestroying(aura::Window* window) {
909 window_observer_.Remove(window); 941 window_observer_.Remove(window);
910 chromeos::WallpaperWindowStateManager::RestoreWindows( 942 chromeos::WallpaperWindowStateManager::RestoreWindows(
911 user_manager::UserManager::Get()->GetActiveUser()->username_hash()); 943 user_manager::UserManager::Get()->GetActiveUser()->username_hash());
912 } 944 }
913 945
946 void WallpaperManager::OnColorCalculationComplete() {
947 SkColor color = color_calculator_->prominent_color();
948 color_calculator_->RemoveObserver(this);
949 color_calculator_.reset();
950 if (prominent_color_ == color)
951 return;
952 prominent_color_ = color;
953
954 for (auto& observer : observers_)
955 observer.OnWallpaperColorsChanged();
956 }
957
914 // WallpaperManager, private: -------------------------------------------------- 958 // WallpaperManager, private: --------------------------------------------------
915 959
916 WallpaperManager::WallpaperManager() 960 WallpaperManager::WallpaperManager()
917 : binding_(this), 961 : binding_(this),
918 pending_inactive_(nullptr), 962 pending_inactive_(nullptr),
919 activation_client_observer_(this), 963 activation_client_observer_(this),
920 window_observer_(this), 964 window_observer_(this),
921 weak_factory_(this) { 965 weak_factory_(this) {
922 DCHECK_CURRENTLY_ON(BrowserThread::UI); 966 DCHECK_CURRENTLY_ON(BrowserThread::UI);
923 wallpaper::WallpaperManagerBase::SetPathIds( 967 wallpaper::WallpaperManagerBase::SetPathIds(
(...skipping 526 matching lines...) Expand 10 before | Expand all | Expand 10 after
1450 1494
1451 UMA_HISTOGRAM_ENUMERATION( 1495 UMA_HISTOGRAM_ENUMERATION(
1452 "Ash.Wallpaper.Apps", 1496 "Ash.Wallpaper.Apps",
1453 wallpaper_manager_util::ShouldUseAndroidWallpapersApp(profile) 1497 wallpaper_manager_util::ShouldUseAndroidWallpapersApp(profile)
1454 ? WALLPAPERS_APP_ANDROID 1498 ? WALLPAPERS_APP_ANDROID
1455 : WALLPAPERS_PICKER_APP_CHROMEOS, 1499 : WALLPAPERS_PICKER_APP_CHROMEOS,
1456 WALLPAPERS_APPS_NUM); 1500 WALLPAPERS_APPS_NUM);
1457 } 1501 }
1458 1502
1459 } // namespace chromeos 1503 } // namespace chromeos
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698