OLD | NEW |
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> |
11 | 11 |
12 #include "ash/common/ash_constants.h" | 12 #include "ash/common/ash_constants.h" |
13 #include "ash/common/ash_switches.h" | 13 #include "ash/common/ash_switches.h" |
14 #include "ash/desktop_background/desktop_background_controller.h" | |
15 #include "ash/public/interfaces/wallpaper.mojom.h" | 14 #include "ash/public/interfaces/wallpaper.mojom.h" |
16 #include "ash/shell.h" | 15 #include "ash/shell.h" |
| 16 #include "ash/wallpaper/wallpaper_controller.h" |
17 #include "base/bind.h" | 17 #include "base/bind.h" |
18 #include "base/bind_helpers.h" | 18 #include "base/bind_helpers.h" |
19 #include "base/command_line.h" | 19 #include "base/command_line.h" |
20 #include "base/files/file_enumerator.h" | 20 #include "base/files/file_enumerator.h" |
21 #include "base/files/file_path.h" | 21 #include "base/files/file_path.h" |
22 #include "base/files/file_util.h" | 22 #include "base/files/file_util.h" |
23 #include "base/logging.h" | 23 #include "base/logging.h" |
24 #include "base/macros.h" | 24 #include "base/macros.h" |
25 #include "base/metrics/histogram.h" | 25 #include "base/metrics/histogram.h" |
26 #include "base/path_service.h" | 26 #include "base/path_service.h" |
(...skipping 75 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
102 const base::FilePath default_downloaded_file_name = | 102 const base::FilePath default_downloaded_file_name = |
103 ServicesCustomizationDocument::GetCustomizedWallpaperDownloadedFileName(); | 103 ServicesCustomizationDocument::GetCustomizedWallpaperDownloadedFileName(); |
104 const base::FilePath default_cache_dir = | 104 const base::FilePath default_cache_dir = |
105 ServicesCustomizationDocument::GetCustomizedWallpaperCacheDir(); | 105 ServicesCustomizationDocument::GetCustomizedWallpaperCacheDir(); |
106 if (default_downloaded_file_name.empty() || default_cache_dir.empty()) | 106 if (default_downloaded_file_name.empty() || default_cache_dir.empty()) |
107 return base::FilePath(); | 107 return base::FilePath(); |
108 return default_cache_dir.Append( | 108 return default_cache_dir.Append( |
109 default_downloaded_file_name.BaseName().value() + suffix); | 109 default_downloaded_file_name.BaseName().value() + suffix); |
110 } | 110 } |
111 | 111 |
112 // Whether DesktopBackgroundController should start with customized default | 112 // Whether WallpaperController should start with customized default |
113 // wallpaper in WallpaperManager::InitializeWallpaper() or not. | 113 // wallpaper in WallpaperManager::InitializeWallpaper() or not. |
114 bool ShouldUseCustomizedDefaultWallpaper() { | 114 bool ShouldUseCustomizedDefaultWallpaper() { |
115 PrefService* pref_service = g_browser_process->local_state(); | 115 PrefService* pref_service = g_browser_process->local_state(); |
116 | 116 |
117 return !(pref_service->FindPreference( | 117 return !(pref_service->FindPreference( |
118 prefs::kCustomizationDefaultWallpaperURL)->IsDefaultValue()); | 118 prefs::kCustomizationDefaultWallpaperURL)->IsDefaultValue()); |
119 } | 119 } |
120 | 120 |
121 // Returns index of the first public session user found in |users| | 121 // Returns index of the first public session user found in |users| |
122 // or -1 otherwise. | 122 // or -1 otherwise. |
(...skipping 91 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
214 shell::Connector* connector = | 214 shell::Connector* connector = |
215 content::MojoShellConnection::GetForProcess()->GetConnector(); | 215 content::MojoShellConnection::GetForProcess()->GetConnector(); |
216 ash::mojom::WallpaperControllerPtr wallpaper_controller; | 216 ash::mojom::WallpaperControllerPtr wallpaper_controller; |
217 connector->ConnectToInterface("mojo:ash", &wallpaper_controller); | 217 connector->ConnectToInterface("mojo:ash", &wallpaper_controller); |
218 wallpaper_controller->SetWallpaper(*image.bitmap(), | 218 wallpaper_controller->SetWallpaper(*image.bitmap(), |
219 WallpaperLayoutToMojo(layout)); | 219 WallpaperLayoutToMojo(layout)); |
220 return; | 220 return; |
221 } | 221 } |
222 // Avoid loading unnecessary wallpapers in tests without a shell instance. | 222 // Avoid loading unnecessary wallpapers in tests without a shell instance. |
223 if (ash::Shell::HasInstance()) { | 223 if (ash::Shell::HasInstance()) { |
224 ash::Shell::GetInstance() | 224 ash::Shell::GetInstance()->wallpaper_controller()->SetWallpaperImage( |
225 ->desktop_background_controller() | 225 image, layout); |
226 ->SetWallpaperImage(image, layout); | |
227 } | 226 } |
228 } | 227 } |
229 | 228 |
230 } // namespace | 229 } // namespace |
231 | 230 |
232 // This is "wallpaper either scheduled to load, or loading right now". | 231 // This is "wallpaper either scheduled to load, or loading right now". |
233 // | 232 // |
234 // While enqueued, it defines moment in the future, when it will be loaded. | 233 // While enqueued, it defines moment in the future, when it will be loaded. |
235 // Enqueued but not started request might be updated by subsequent load | 234 // Enqueued but not started request might be updated by subsequent load |
236 // request. Therefore it's created empty, and updated being enqueued. | 235 // request. Therefore it's created empty, and updated being enqueued. |
(...skipping 161 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
398 // static | 397 // static |
399 void WallpaperManager::Shutdown() { | 398 void WallpaperManager::Shutdown() { |
400 CHECK(wallpaper_manager); | 399 CHECK(wallpaper_manager); |
401 delete wallpaper_manager; | 400 delete wallpaper_manager; |
402 wallpaper_manager = nullptr; | 401 wallpaper_manager = nullptr; |
403 } | 402 } |
404 | 403 |
405 WallpaperManager::WallpaperResolution | 404 WallpaperManager::WallpaperResolution |
406 WallpaperManager::GetAppropriateResolution() { | 405 WallpaperManager::GetAppropriateResolution() { |
407 DCHECK_CURRENTLY_ON(BrowserThread::UI); | 406 DCHECK_CURRENTLY_ON(BrowserThread::UI); |
408 gfx::Size size = | 407 gfx::Size size = ash::WallpaperController::GetMaxDisplaySizeInNative(); |
409 ash::DesktopBackgroundController::GetMaxDisplaySizeInNative(); | |
410 return (size.width() > wallpaper::kSmallWallpaperMaxWidth || | 408 return (size.width() > wallpaper::kSmallWallpaperMaxWidth || |
411 size.height() > wallpaper::kSmallWallpaperMaxHeight) | 409 size.height() > wallpaper::kSmallWallpaperMaxHeight) |
412 ? WALLPAPER_RESOLUTION_LARGE | 410 ? WALLPAPER_RESOLUTION_LARGE |
413 : WALLPAPER_RESOLUTION_SMALL; | 411 : WALLPAPER_RESOLUTION_SMALL; |
414 } | 412 } |
415 | 413 |
416 void WallpaperManager::AddObservers() { | 414 void WallpaperManager::AddObservers() { |
417 show_user_name_on_signin_subscription_ = | 415 show_user_name_on_signin_subscription_ = |
418 CrosSettings::Get()->AddSettingsObserver( | 416 CrosSettings::Get()->AddSettingsObserver( |
419 kAccountsPrefShowUserNamesOnSignIn, | 417 kAccountsPrefShowUserNamesOnSignIn, |
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
460 // used here to determine if current user is guest. | 458 // used here to determine if current user is guest. |
461 return; | 459 return; |
462 } | 460 } |
463 | 461 |
464 if (command_line->HasSwitch(::switches::kTestType)) | 462 if (command_line->HasSwitch(::switches::kTestType)) |
465 WizardController::SetZeroDelays(); | 463 WizardController::SetZeroDelays(); |
466 | 464 |
467 // Zero delays is also set in autotests. | 465 // Zero delays is also set in autotests. |
468 if (WizardController::IsZeroDelayEnabled()) { | 466 if (WizardController::IsZeroDelayEnabled()) { |
469 // Ensure tests have some sort of wallpaper. | 467 // Ensure tests have some sort of wallpaper. |
470 ash::Shell::GetInstance()->desktop_background_controller()-> | 468 ash::Shell::GetInstance()->wallpaper_controller()->CreateEmptyWallpaper(); |
471 CreateEmptyWallpaper(); | |
472 return; | 469 return; |
473 } | 470 } |
474 | 471 |
475 if (!user_manager->IsUserLoggedIn()) { | 472 if (!user_manager->IsUserLoggedIn()) { |
476 if (!StartupUtils::IsDeviceRegistered()) | 473 if (!StartupUtils::IsDeviceRegistered()) |
477 SetDefaultWallpaperDelayed(login::SignInAccountId()); | 474 SetDefaultWallpaperDelayed(login::SignInAccountId()); |
478 else | 475 else |
479 InitializeRegisteredDeviceWallpaper(); | 476 InitializeRegisteredDeviceWallpaper(); |
480 return; | 477 return; |
481 } | 478 } |
(...skipping 77 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
559 void WallpaperManager::SetCustomWallpaper( | 556 void WallpaperManager::SetCustomWallpaper( |
560 const AccountId& account_id, | 557 const AccountId& account_id, |
561 const wallpaper::WallpaperFilesId& wallpaper_files_id, | 558 const wallpaper::WallpaperFilesId& wallpaper_files_id, |
562 const std::string& file, | 559 const std::string& file, |
563 wallpaper::WallpaperLayout layout, | 560 wallpaper::WallpaperLayout layout, |
564 user_manager::User::WallpaperType type, | 561 user_manager::User::WallpaperType type, |
565 const gfx::ImageSkia& image, | 562 const gfx::ImageSkia& image, |
566 bool update_wallpaper) { | 563 bool update_wallpaper) { |
567 DCHECK_CURRENTLY_ON(BrowserThread::UI); | 564 DCHECK_CURRENTLY_ON(BrowserThread::UI); |
568 | 565 |
569 // There is no visible background in kiosk mode. | 566 // There is no visible wallpaper in kiosk mode. |
570 if (user_manager::UserManager::Get()->IsLoggedInAsKioskApp()) | 567 if (user_manager::UserManager::Get()->IsLoggedInAsKioskApp()) |
571 return; | 568 return; |
572 | 569 |
573 // Don't allow custom wallpapers while policy is in effect. | 570 // Don't allow custom wallpapers while policy is in effect. |
574 if (type != user_manager::User::POLICY && IsPolicyControlled(account_id)) | 571 if (type != user_manager::User::POLICY && IsPolicyControlled(account_id)) |
575 return; | 572 return; |
576 | 573 |
577 base::FilePath wallpaper_path = GetCustomWallpaperPath( | 574 base::FilePath wallpaper_path = GetCustomWallpaperPath( |
578 wallpaper::kOriginalWallpaperSubDir, wallpaper_files_id, file); | 575 wallpaper::kOriginalWallpaperSubDir, wallpaper_files_id, file); |
579 | 576 |
(...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
639 GetPendingWallpaper(account_id, false)->ResetSetDefaultWallpaper(); | 636 GetPendingWallpaper(account_id, false)->ResetSetDefaultWallpaper(); |
640 } | 637 } |
641 | 638 |
642 void WallpaperManager::SetDefaultWallpaperDelayed(const AccountId& account_id) { | 639 void WallpaperManager::SetDefaultWallpaperDelayed(const AccountId& account_id) { |
643 GetPendingWallpaper(account_id, true)->ResetSetDefaultWallpaper(); | 640 GetPendingWallpaper(account_id, true)->ResetSetDefaultWallpaper(); |
644 } | 641 } |
645 | 642 |
646 void WallpaperManager::DoSetDefaultWallpaper( | 643 void WallpaperManager::DoSetDefaultWallpaper( |
647 const AccountId& account_id, | 644 const AccountId& account_id, |
648 MovableOnDestroyCallbackHolder on_finish) { | 645 MovableOnDestroyCallbackHolder on_finish) { |
649 // There is no visible background in kiosk mode. | 646 // There is no visible wallpaper in kiosk mode. |
650 if (user_manager::UserManager::Get()->IsLoggedInAsKioskApp()) | 647 if (user_manager::UserManager::Get()->IsLoggedInAsKioskApp()) |
651 return; | 648 return; |
652 wallpaper_cache_.erase(account_id); | 649 wallpaper_cache_.erase(account_id); |
653 | 650 |
654 WallpaperResolution resolution = GetAppropriateResolution(); | 651 WallpaperResolution resolution = GetAppropriateResolution(); |
655 const bool use_small = (resolution == WALLPAPER_RESOLUTION_SMALL); | 652 const bool use_small = (resolution == WALLPAPER_RESOLUTION_SMALL); |
656 | 653 |
657 const base::FilePath* file = NULL; | 654 const base::FilePath* file = NULL; |
658 | 655 |
659 const user_manager::User* user = | 656 const user_manager::User* user = |
(...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
720 DCHECK_CURRENTLY_ON(BrowserThread::UI); | 717 DCHECK_CURRENTLY_ON(BrowserThread::UI); |
721 // Some unit tests come here without a UserManager or without a pref system. | 718 // Some unit tests come here without a UserManager or without a pref system. |
722 if (!user_manager::UserManager::IsInitialized() || | 719 if (!user_manager::UserManager::IsInitialized() || |
723 !g_browser_process->local_state()) { | 720 !g_browser_process->local_state()) { |
724 return; | 721 return; |
725 } | 722 } |
726 | 723 |
727 const user_manager::User* user = | 724 const user_manager::User* user = |
728 user_manager::UserManager::Get()->FindUser(account_id); | 725 user_manager::UserManager::Get()->FindUser(account_id); |
729 | 726 |
730 // User is unknown or there is no visible background in kiosk mode. | 727 // User is unknown or there is no visible wallpaper in kiosk mode. |
731 if (!user || user->GetType() == user_manager::USER_TYPE_KIOSK_APP) | 728 if (!user || user->GetType() == user_manager::USER_TYPE_KIOSK_APP) |
732 return; | 729 return; |
733 | 730 |
734 // Guest user or regular user in ephemeral mode. | 731 // Guest user or regular user in ephemeral mode. |
735 if ((user_manager::UserManager::Get()->IsUserNonCryptohomeDataEphemeral( | 732 if ((user_manager::UserManager::Get()->IsUserNonCryptohomeDataEphemeral( |
736 account_id) && | 733 account_id) && |
737 user->HasGaiaAccount()) || | 734 user->HasGaiaAccount()) || |
738 user->GetType() == user_manager::USER_TYPE_GUEST) { | 735 user->GetType() == user_manager::USER_TYPE_GUEST) { |
739 InitInitialUserWallpaper(account_id, false); | 736 InitInitialUserWallpaper(account_id, false); |
740 GetPendingWallpaper(account_id, delayed)->ResetSetDefaultWallpaper(); | 737 GetPendingWallpaper(account_id, delayed)->ResetSetDefaultWallpaper(); |
(...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
800 } | 797 } |
801 } | 798 } |
802 | 799 |
803 void WallpaperManager::SetWallpaperFromImageSkia( | 800 void WallpaperManager::SetWallpaperFromImageSkia( |
804 const AccountId& account_id, | 801 const AccountId& account_id, |
805 const gfx::ImageSkia& image, | 802 const gfx::ImageSkia& image, |
806 wallpaper::WallpaperLayout layout, | 803 wallpaper::WallpaperLayout layout, |
807 bool update_wallpaper) { | 804 bool update_wallpaper) { |
808 DCHECK(user_manager::UserManager::Get()->IsUserLoggedIn()); | 805 DCHECK(user_manager::UserManager::Get()->IsUserLoggedIn()); |
809 | 806 |
810 // There is no visible background in kiosk mode. | 807 // There is no visible wallpaper in kiosk mode. |
811 if (user_manager::UserManager::Get()->IsLoggedInAsKioskApp()) | 808 if (user_manager::UserManager::Get()->IsLoggedInAsKioskApp()) |
812 return; | 809 return; |
813 WallpaperInfo info; | 810 WallpaperInfo info; |
814 info.layout = layout; | 811 info.layout = layout; |
815 | 812 |
816 // This is an API call and we do not know the path. So we set the image, but | 813 // This is an API call and we do not know the path. So we set the image, but |
817 // no path. | 814 // no path. |
818 wallpaper_cache_[account_id] = | 815 wallpaper_cache_[account_id] = |
819 CustomWallpaperElement(base::FilePath(), image); | 816 CustomWallpaperElement(base::FilePath(), image); |
820 | 817 |
(...skipping 316 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1137 } | 1134 } |
1138 | 1135 |
1139 void WallpaperManager::SetDefaultWallpaperPath( | 1136 void WallpaperManager::SetDefaultWallpaperPath( |
1140 const base::FilePath& default_small_wallpaper_file, | 1137 const base::FilePath& default_small_wallpaper_file, |
1141 std::unique_ptr<gfx::ImageSkia> small_wallpaper_image, | 1138 std::unique_ptr<gfx::ImageSkia> small_wallpaper_image, |
1142 const base::FilePath& default_large_wallpaper_file, | 1139 const base::FilePath& default_large_wallpaper_file, |
1143 std::unique_ptr<gfx::ImageSkia> large_wallpaper_image) { | 1140 std::unique_ptr<gfx::ImageSkia> large_wallpaper_image) { |
1144 default_small_wallpaper_file_ = default_small_wallpaper_file; | 1141 default_small_wallpaper_file_ = default_small_wallpaper_file; |
1145 default_large_wallpaper_file_ = default_large_wallpaper_file; | 1142 default_large_wallpaper_file_ = default_large_wallpaper_file; |
1146 | 1143 |
1147 ash::DesktopBackgroundController* dbc = | 1144 ash::WallpaperController* controller = |
1148 ash::Shell::GetInstance()->desktop_background_controller(); | 1145 ash::Shell::GetInstance()->wallpaper_controller(); |
1149 | 1146 |
1150 // |need_update_screen| is true if the previous default wallpaper is visible | 1147 // |need_update_screen| is true if the previous default wallpaper is visible |
1151 // now, so we need to update wallpaper on the screen. | 1148 // now, so we need to update wallpaper on the screen. |
1152 // | 1149 // |
1153 // Layout is ignored here, so wallpaper::WALLPAPER_LAYOUT_CENTER is used | 1150 // Layout is ignored here, so wallpaper::WALLPAPER_LAYOUT_CENTER is used |
1154 // as a placeholder only. | 1151 // as a placeholder only. |
1155 const bool need_update_screen = | 1152 const bool need_update_screen = |
1156 default_wallpaper_image_.get() && | 1153 default_wallpaper_image_.get() && |
1157 dbc->WallpaperIsAlreadyLoaded(default_wallpaper_image_->image(), | 1154 controller->WallpaperIsAlreadyLoaded(default_wallpaper_image_->image(), |
1158 false /* compare_layouts */, | 1155 false /* compare_layouts */, |
1159 wallpaper::WALLPAPER_LAYOUT_CENTER); | 1156 wallpaper::WALLPAPER_LAYOUT_CENTER); |
1160 | 1157 |
1161 default_wallpaper_image_.reset(); | 1158 default_wallpaper_image_.reset(); |
1162 if (GetAppropriateResolution() == WALLPAPER_RESOLUTION_SMALL) { | 1159 if (GetAppropriateResolution() == WALLPAPER_RESOLUTION_SMALL) { |
1163 if (small_wallpaper_image) { | 1160 if (small_wallpaper_image) { |
1164 default_wallpaper_image_.reset( | 1161 default_wallpaper_image_.reset( |
1165 new user_manager::UserImage(*small_wallpaper_image)); | 1162 new user_manager::UserImage(*small_wallpaper_image)); |
1166 default_wallpaper_image_->set_file_path(default_small_wallpaper_file); | 1163 default_wallpaper_image_->set_file_path(default_small_wallpaper_file); |
1167 } | 1164 } |
1168 } else { | 1165 } else { |
1169 if (large_wallpaper_image) { | 1166 if (large_wallpaper_image) { |
1170 default_wallpaper_image_.reset( | 1167 default_wallpaper_image_.reset( |
1171 new user_manager::UserImage(*large_wallpaper_image)); | 1168 new user_manager::UserImage(*large_wallpaper_image)); |
1172 default_wallpaper_image_->set_file_path(default_large_wallpaper_file); | 1169 default_wallpaper_image_->set_file_path(default_large_wallpaper_file); |
1173 } | 1170 } |
1174 } | 1171 } |
1175 | 1172 |
1176 if (need_update_screen) { | 1173 if (need_update_screen) |
1177 DoSetDefaultWallpaper(EmptyAccountId(), MovableOnDestroyCallbackHolder()); | 1174 DoSetDefaultWallpaper(EmptyAccountId(), MovableOnDestroyCallbackHolder()); |
1178 } | |
1179 } | 1175 } |
1180 | 1176 |
1181 wallpaper::WallpaperFilesId WallpaperManager::GetFilesId( | 1177 wallpaper::WallpaperFilesId WallpaperManager::GetFilesId( |
1182 const AccountId& account_id) const { | 1178 const AccountId& account_id) const { |
1183 std::string stored_value; | 1179 std::string stored_value; |
1184 if (user_manager::known_user::GetStringPref(account_id, kWallpaperFilesId, | 1180 if (user_manager::known_user::GetStringPref(account_id, kWallpaperFilesId, |
1185 &stored_value)) { | 1181 &stored_value)) { |
1186 return wallpaper::WallpaperFilesId::FromString(stored_value); | 1182 return wallpaper::WallpaperFilesId::FromString(stored_value); |
1187 } | 1183 } |
1188 const std::string& old_id = account_id.GetUserEmail(); // Migrated | 1184 const std::string& old_id = account_id.GetUserEmail(); // Migrated |
1189 const wallpaper::WallpaperFilesId files_id = HashWallpaperFilesIdStr(old_id); | 1185 const wallpaper::WallpaperFilesId files_id = HashWallpaperFilesIdStr(old_id); |
1190 SetKnownUserWallpaperFilesId(account_id, files_id); | 1186 SetKnownUserWallpaperFilesId(account_id, files_id); |
1191 return files_id; | 1187 return files_id; |
1192 } | 1188 } |
1193 | 1189 |
1194 } // namespace chromeos | 1190 } // namespace chromeos |
OLD | NEW |