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

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 and rebase with master 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);
398 user_manager::UserManager::Get()->RemoveSessionStateObserver(this); 401 user_manager::UserManager::Get()->RemoveSessionStateObserver(this);
399 weak_factory_.InvalidateWeakPtrs(); 402 weak_factory_.InvalidateWeakPtrs();
400 } 403 }
401 404
402 // static 405 // static
403 void WallpaperManager::Initialize() { 406 void WallpaperManager::Initialize() {
404 CHECK(!wallpaper_manager); 407 CHECK(!wallpaper_manager);
405 wallpaper_manager = new WallpaperManager(); 408 wallpaper_manager = new WallpaperManager();
406 } 409 }
407 410
(...skipping 12 matching lines...) Expand all
420 423
421 bool WallpaperManager::IsPendingWallpaper(uint32_t image_id) { 424 bool WallpaperManager::IsPendingWallpaper(uint32_t image_id) {
422 for (size_t i = 0; i < loading_.size(); ++i) { 425 for (size_t i = 0; i < loading_.size(); ++i) {
423 if (loading_[i]->GetImageId() == image_id) { 426 if (loading_[i]->GetImageId() == image_id) {
424 return true; 427 return true;
425 } 428 }
426 } 429 }
427 return false; 430 return false;
428 } 431 }
429 432
433 void WallpaperManager::CalculateProminentColor(const gfx::ImageSkia& image) {
434 // Cancel in-flight color calculations, if any.
435 if (color_calculator_) {
436 color_calculator_->RemoveObserver(this);
437 color_calculator_.reset();
438 }
439
440 color_calculator_ = base::MakeUnique<wallpaper::WallpaperColorCalculator>(
441 image, color_utils::LumaRange::DARK, color_utils::SaturationRange::MUTED,
442 task_runner_);
443 color_calculator_->AddObserver(this);
444 if (!color_calculator_->StartCalculation()) {
445 color_calculator_.reset();
xdai1 2017/06/15 18:27:51 Remove WallpaperManager as an observer before rese
Wenzhao (Colin) Zang 2017/06/15 19:04:14 Done. Then RemoveObserver() should also be added i
446 if (!prominent_color_.has_value())
447 return;
448 prominent_color_.reset();
449 for (auto& observer : observers_)
450 observer.OnWallpaperColorsChanged();
451 }
452 }
453
430 WallpaperManager::WallpaperResolution 454 WallpaperManager::WallpaperResolution
431 WallpaperManager::GetAppropriateResolution() { 455 WallpaperManager::GetAppropriateResolution() {
432 DCHECK_CURRENTLY_ON(BrowserThread::UI); 456 DCHECK_CURRENTLY_ON(BrowserThread::UI);
433 gfx::Size size = ash::WallpaperController::GetMaxDisplaySizeInNative(); 457 gfx::Size size = ash::WallpaperController::GetMaxDisplaySizeInNative();
434 return (size.width() > wallpaper::kSmallWallpaperMaxWidth || 458 return (size.width() > wallpaper::kSmallWallpaperMaxWidth ||
435 size.height() > wallpaper::kSmallWallpaperMaxHeight) 459 size.height() > wallpaper::kSmallWallpaperMaxHeight)
436 ? WALLPAPER_RESOLUTION_LARGE 460 ? WALLPAPER_RESOLUTION_LARGE
437 : WALLPAPER_RESOLUTION_SMALL; 461 : WALLPAPER_RESOLUTION_SMALL;
438 } 462 }
439 463
(...skipping 464 matching lines...) Expand 10 before | Expand all | Expand 10 after
904 window_observer_.Add(gained_active); 928 window_observer_.Add(gained_active);
905 } 929 }
906 } 930 }
907 931
908 void WallpaperManager::OnWindowDestroying(aura::Window* window) { 932 void WallpaperManager::OnWindowDestroying(aura::Window* window) {
909 window_observer_.Remove(window); 933 window_observer_.Remove(window);
910 chromeos::WallpaperWindowStateManager::RestoreWindows( 934 chromeos::WallpaperWindowStateManager::RestoreWindows(
911 user_manager::UserManager::Get()->GetActiveUser()->username_hash()); 935 user_manager::UserManager::Get()->GetActiveUser()->username_hash());
912 } 936 }
913 937
938 void WallpaperManager::OnColorCalculationComplete() {
939 SkColor color = color_calculator_->prominent_color();
940 color_calculator_.reset();
941 if (prominent_color_ == color)
942 return;
943 prominent_color_ = color;
944
945 for (auto& observer : observers_)
946 observer.OnWallpaperColorsChanged();
947 }
948
914 // WallpaperManager, private: -------------------------------------------------- 949 // WallpaperManager, private: --------------------------------------------------
915 950
916 WallpaperManager::WallpaperManager() 951 WallpaperManager::WallpaperManager()
917 : binding_(this), 952 : binding_(this),
918 pending_inactive_(nullptr), 953 pending_inactive_(nullptr),
919 activation_client_observer_(this), 954 activation_client_observer_(this),
920 window_observer_(this), 955 window_observer_(this),
921 weak_factory_(this) { 956 weak_factory_(this) {
922 DCHECK_CURRENTLY_ON(BrowserThread::UI); 957 DCHECK_CURRENTLY_ON(BrowserThread::UI);
923 wallpaper::WallpaperManagerBase::SetPathIds( 958 wallpaper::WallpaperManagerBase::SetPathIds(
(...skipping 526 matching lines...) Expand 10 before | Expand all | Expand 10 after
1450 1485
1451 UMA_HISTOGRAM_ENUMERATION( 1486 UMA_HISTOGRAM_ENUMERATION(
1452 "Ash.Wallpaper.Apps", 1487 "Ash.Wallpaper.Apps",
1453 wallpaper_manager_util::ShouldUseAndroidWallpapersApp(profile) 1488 wallpaper_manager_util::ShouldUseAndroidWallpapersApp(profile)
1454 ? WALLPAPERS_APP_ANDROID 1489 ? WALLPAPERS_APP_ANDROID
1455 : WALLPAPERS_PICKER_APP_CHROMEOS, 1490 : WALLPAPERS_PICKER_APP_CHROMEOS,
1456 WALLPAPERS_APPS_NUM); 1491 WALLPAPERS_APPS_NUM);
1457 } 1492 }
1458 1493
1459 } // namespace chromeos 1494 } // namespace chromeos
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698