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 <utility> | 7 #include <utility> |
8 | 8 |
9 #include "ash/common/ash_constants.h" | 9 #include "ash/common/ash_constants.h" |
10 #include "ash/common/wallpaper/wallpaper_controller.h" | 10 #include "ash/common/wallpaper/wallpaper_controller.h" |
11 #include "ash/common/wm_shell.h" | 11 #include "ash/common/wm_shell.h" |
12 #include "base/bind.h" | 12 #include "base/bind.h" |
13 #include "base/bind_helpers.h" | 13 #include "base/bind_helpers.h" |
14 #include "base/command_line.h" | 14 #include "base/command_line.h" |
15 #include "base/files/file_path.h" | 15 #include "base/files/file_path.h" |
16 #include "base/logging.h" | 16 #include "base/logging.h" |
17 #include "base/metrics/histogram_macros.h" | 17 #include "base/metrics/histogram_macros.h" |
| 18 #include "base/path_service.h" |
18 #include "base/sha1.h" | 19 #include "base/sha1.h" |
19 #include "base/strings/string_number_conversions.h" | 20 #include "base/strings/string_number_conversions.h" |
20 #include "base/sys_info.h" | 21 #include "base/sys_info.h" |
21 #include "base/threading/worker_pool.h" | 22 #include "base/threading/worker_pool.h" |
22 #include "base/time/time.h" | 23 #include "base/time/time.h" |
23 #include "base/trace_event/trace_event.h" | 24 #include "base/trace_event/trace_event.h" |
24 #include "base/values.h" | 25 #include "base/values.h" |
25 #include "chrome/browser/browser_process.h" | 26 #include "chrome/browser/browser_process.h" |
26 #include "chrome/browser/chrome_notification_types.h" | 27 #include "chrome/browser/chrome_notification_types.h" |
27 #include "chrome/browser/chromeos/customization/customization_document.h" | 28 #include "chrome/browser/chromeos/customization/customization_document.h" |
28 #include "chrome/browser/chromeos/extensions/wallpaper_manager_util.h" | 29 #include "chrome/browser/chromeos/extensions/wallpaper_manager_util.h" |
29 #include "chrome/browser/chromeos/login/startup_utils.h" | 30 #include "chrome/browser/chromeos/login/startup_utils.h" |
30 #include "chrome/browser/chromeos/login/users/avatar/user_image_loader.h" | 31 #include "chrome/browser/chromeos/login/users/avatar/user_image_loader.h" |
31 #include "chrome/browser/chromeos/login/wizard_controller.h" | 32 #include "chrome/browser/chromeos/login/wizard_controller.h" |
| 33 #include "chrome/browser/chromeos/policy/browser_policy_connector_chromeos.h" |
32 #include "chrome/browser/image_decoder.h" | 34 #include "chrome/browser/image_decoder.h" |
33 #include "chrome/browser/ui/ash/ash_util.h" | 35 #include "chrome/browser/ui/ash/ash_util.h" |
34 #include "chrome/common/chrome_paths.h" | 36 #include "chrome/common/chrome_paths.h" |
35 #include "chrome/common/chrome_switches.h" | 37 #include "chrome/common/chrome_switches.h" |
36 #include "chrome/common/pref_names.h" | 38 #include "chrome/common/pref_names.h" |
37 #include "chromeos/chromeos_switches.h" | 39 #include "chromeos/chromeos_switches.h" |
38 #include "chromeos/cryptohome/system_salt_getter.h" | 40 #include "chromeos/cryptohome/system_salt_getter.h" |
39 #include "components/prefs/pref_registry_simple.h" | 41 #include "components/prefs/pref_registry_simple.h" |
40 #include "components/prefs/pref_service.h" | 42 #include "components/prefs/pref_service.h" |
41 #include "components/prefs/scoped_user_pref_update.h" | 43 #include "components/prefs/scoped_user_pref_update.h" |
42 #include "components/signin/core/account_id/account_id.h" | 44 #include "components/signin/core/account_id/account_id.h" |
43 #include "components/user_manager/known_user.h" | 45 #include "components/user_manager/known_user.h" |
44 #include "components/user_manager/user_names.h" | 46 #include "components/user_manager/user_names.h" |
45 #include "components/user_manager/user_type.h" | 47 #include "components/user_manager/user_type.h" |
46 #include "components/wallpaper/wallpaper_files_id.h" | 48 #include "components/wallpaper/wallpaper_files_id.h" |
47 #include "components/wallpaper/wallpaper_layout.h" | 49 #include "components/wallpaper/wallpaper_layout.h" |
48 #include "content/public/browser/browser_thread.h" | 50 #include "content/public/browser/browser_thread.h" |
49 #include "content/public/browser/notification_service.h" | 51 #include "content/public/browser/notification_service.h" |
50 #include "content/public/common/content_switches.h" | 52 #include "content/public/common/content_switches.h" |
51 #include "content/public/common/service_manager_connection.h" | 53 #include "content/public/common/service_manager_connection.h" |
| 54 #include "crypto/sha2.h" |
52 #include "services/service_manager/public/cpp/connector.h" | 55 #include "services/service_manager/public/cpp/connector.h" |
| 56 #include "url/gurl.h" |
53 | 57 |
54 using content::BrowserThread; | 58 using content::BrowserThread; |
55 using wallpaper::WallpaperManagerBase; | 59 using wallpaper::WallpaperManagerBase; |
56 using wallpaper::WallpaperInfo; | 60 using wallpaper::WallpaperInfo; |
57 using wallpaper::MovableOnDestroyCallback; | 61 using wallpaper::MovableOnDestroyCallback; |
58 using wallpaper::MovableOnDestroyCallbackHolder; | 62 using wallpaper::MovableOnDestroyCallbackHolder; |
59 | 63 |
60 namespace chromeos { | 64 namespace chromeos { |
61 | 65 |
62 namespace { | 66 namespace { |
63 | 67 |
64 WallpaperManager* wallpaper_manager = nullptr; | 68 WallpaperManager* wallpaper_manager = nullptr; |
65 | 69 |
66 // The amount of delay before starts to move custom wallpapers to the new place. | 70 // The amount of delay before starts to move custom wallpapers to the new place. |
67 const int kMoveCustomWallpaperDelaySeconds = 30; | 71 const int kMoveCustomWallpaperDelaySeconds = 30; |
68 | 72 |
69 const int kCacheWallpaperDelayMs = 500; | 73 const int kCacheWallpaperDelayMs = 500; |
70 | 74 |
71 // Names of nodes with info about wallpaper in |kUserWallpapersProperties| | 75 // Names of nodes with info about wallpaper in |kUserWallpapersProperties| |
72 // dictionary. | 76 // dictionary. |
73 const char kNewWallpaperDateNodeName[] = "date"; | 77 const char kNewWallpaperDateNodeName[] = "date"; |
74 const char kNewWallpaperLayoutNodeName[] = "layout"; | 78 const char kNewWallpaperLayoutNodeName[] = "layout"; |
75 const char kNewWallpaperLocationNodeName[] = "file"; | 79 const char kNewWallpaperLocationNodeName[] = "file"; |
76 const char kNewWallpaperTypeNodeName[] = "type"; | 80 const char kNewWallpaperTypeNodeName[] = "type"; |
77 | 81 |
78 // Known user keys. | 82 // Known user keys. |
79 const char kWallpaperFilesId[] = "wallpaper-files-id"; | 83 const char kWallpaperFilesId[] = "wallpaper-files-id"; |
80 | 84 |
| 85 // The directory and file name to save the downloaded device policy controlled |
| 86 // wallpaper. |
| 87 const char kDeviceWallpaperDir[] = "device_wallpaper"; |
| 88 const char kDeviceWallpaperFile[] = "device_wallpaper_image.jpg"; |
| 89 |
81 // These global default values are used to set customized default | 90 // These global default values are used to set customized default |
82 // wallpaper path in WallpaperManager::InitializeWallpaper(). | 91 // wallpaper path in WallpaperManager::InitializeWallpaper(). |
83 base::FilePath GetCustomizedWallpaperDefaultRescaledFileName( | 92 base::FilePath GetCustomizedWallpaperDefaultRescaledFileName( |
84 const std::string& suffix) { | 93 const std::string& suffix) { |
85 const base::FilePath default_downloaded_file_name = | 94 const base::FilePath default_downloaded_file_name = |
86 ServicesCustomizationDocument::GetCustomizedWallpaperDownloadedFileName(); | 95 ServicesCustomizationDocument::GetCustomizedWallpaperDownloadedFileName(); |
87 const base::FilePath default_cache_dir = | 96 const base::FilePath default_cache_dir = |
88 ServicesCustomizationDocument::GetCustomizedWallpaperCacheDir(); | 97 ServicesCustomizationDocument::GetCustomizedWallpaperCacheDir(); |
89 if (default_downloaded_file_name.empty() || default_cache_dir.empty()) | 98 if (default_downloaded_file_name.empty() || default_cache_dir.empty()) |
90 return base::FilePath(); | 99 return base::FilePath(); |
(...skipping 97 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
188 // large bitmaps over Mojo; use shared memory like BitmapUploader, etc. | 197 // large bitmaps over Mojo; use shared memory like BitmapUploader, etc. |
189 wallpaper_controller->SetWallpaper(*image.bitmap(), layout); | 198 wallpaper_controller->SetWallpaper(*image.bitmap(), layout); |
190 } else if (ash::WmShell::HasInstance()) { | 199 } else if (ash::WmShell::HasInstance()) { |
191 // Note: Wallpaper setting is skipped in unit tests without shell instances. | 200 // Note: Wallpaper setting is skipped in unit tests without shell instances. |
192 // In classic ash, interact with the WallpaperController class directly. | 201 // In classic ash, interact with the WallpaperController class directly. |
193 ash::WmShell::Get()->wallpaper_controller()->SetWallpaperImage(image, | 202 ash::WmShell::Get()->wallpaper_controller()->SetWallpaperImage(image, |
194 layout); | 203 layout); |
195 } | 204 } |
196 } | 205 } |
197 | 206 |
| 207 // A helper function to check the existing/downloaded device wallpaper file's |
| 208 // hash value matches with the hash value provided in the policy settings. |
| 209 bool CheckDeviceWallpaperMatchHash(const base::FilePath& device_wallpaper_file, |
| 210 const std::string& hash) { |
| 211 std::string image_data; |
| 212 if (base::ReadFileToString(device_wallpaper_file, &image_data)) { |
| 213 std::string sha_hash = crypto::SHA256HashString(image_data); |
| 214 if (base::ToLowerASCII(base::HexEncode( |
| 215 sha_hash.c_str(), sha_hash.size())) == base::ToLowerASCII(hash)) { |
| 216 return true; |
| 217 } |
| 218 } |
| 219 return false; |
| 220 } |
| 221 |
198 } // namespace | 222 } // namespace |
199 | 223 |
200 // This is "wallpaper either scheduled to load, or loading right now". | 224 // This is "wallpaper either scheduled to load, or loading right now". |
201 // | 225 // |
202 // While enqueued, it defines moment in the future, when it will be loaded. | 226 // While enqueued, it defines moment in the future, when it will be loaded. |
203 // Enqueued but not started request might be updated by subsequent load | 227 // Enqueued but not started request might be updated by subsequent load |
204 // request. Therefore it's created empty, and updated being enqueued. | 228 // request. Therefore it's created empty, and updated being enqueued. |
205 // | 229 // |
206 // PendingWallpaper is owned by WallpaperManager, but reference to this object | 230 // PendingWallpaper is owned by WallpaperManager, but reference to this object |
207 // is passed to other threads by PostTask() calls, therefore it is | 231 // is passed to other threads by PostTask() calls, therefore it is |
(...skipping 132 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
340 // Load start time to calculate duration. | 364 // Load start time to calculate duration. |
341 base::Time started_load_at_; | 365 base::Time started_load_at_; |
342 | 366 |
343 DISALLOW_COPY_AND_ASSIGN(PendingWallpaper); | 367 DISALLOW_COPY_AND_ASSIGN(PendingWallpaper); |
344 }; | 368 }; |
345 | 369 |
346 // WallpaperManager, public: --------------------------------------------------- | 370 // WallpaperManager, public: --------------------------------------------------- |
347 | 371 |
348 WallpaperManager::~WallpaperManager() { | 372 WallpaperManager::~WallpaperManager() { |
349 show_user_name_on_signin_subscription_.reset(); | 373 show_user_name_on_signin_subscription_.reset(); |
| 374 device_wallpaper_image_subscription_.reset(); |
350 user_manager::UserManager::Get()->RemoveSessionStateObserver(this); | 375 user_manager::UserManager::Get()->RemoveSessionStateObserver(this); |
351 weak_factory_.InvalidateWeakPtrs(); | 376 weak_factory_.InvalidateWeakPtrs(); |
352 } | 377 } |
353 | 378 |
354 // static | 379 // static |
355 void WallpaperManager::Initialize() { | 380 void WallpaperManager::Initialize() { |
356 CHECK(!wallpaper_manager); | 381 CHECK(!wallpaper_manager); |
357 wallpaper_manager = new WallpaperManager(); | 382 wallpaper_manager = new WallpaperManager(); |
358 } | 383 } |
359 | 384 |
(...skipping 19 matching lines...) Expand all Loading... |
379 ? WALLPAPER_RESOLUTION_LARGE | 404 ? WALLPAPER_RESOLUTION_LARGE |
380 : WALLPAPER_RESOLUTION_SMALL; | 405 : WALLPAPER_RESOLUTION_SMALL; |
381 } | 406 } |
382 | 407 |
383 void WallpaperManager::AddObservers() { | 408 void WallpaperManager::AddObservers() { |
384 show_user_name_on_signin_subscription_ = | 409 show_user_name_on_signin_subscription_ = |
385 CrosSettings::Get()->AddSettingsObserver( | 410 CrosSettings::Get()->AddSettingsObserver( |
386 kAccountsPrefShowUserNamesOnSignIn, | 411 kAccountsPrefShowUserNamesOnSignIn, |
387 base::Bind(&WallpaperManager::InitializeRegisteredDeviceWallpaper, | 412 base::Bind(&WallpaperManager::InitializeRegisteredDeviceWallpaper, |
388 weak_factory_.GetWeakPtr())); | 413 weak_factory_.GetWeakPtr())); |
| 414 device_wallpaper_image_subscription_ = |
| 415 CrosSettings::Get()->AddSettingsObserver( |
| 416 kDeviceWallpaperImage, |
| 417 base::Bind(&WallpaperManager::OnDeviceWallpaperPolicyChanged, |
| 418 weak_factory_.GetWeakPtr())); |
389 } | 419 } |
390 | 420 |
391 void WallpaperManager::EnsureLoggedInUserWallpaperLoaded() { | 421 void WallpaperManager::EnsureLoggedInUserWallpaperLoaded() { |
392 WallpaperInfo info; | 422 WallpaperInfo info; |
393 if (GetLoggedInUserWallpaperInfo(&info)) { | 423 if (GetLoggedInUserWallpaperInfo(&info)) { |
394 UMA_HISTOGRAM_ENUMERATION("Ash.Wallpaper.Type", info.type, | 424 UMA_HISTOGRAM_ENUMERATION("Ash.Wallpaper.Type", info.type, |
395 user_manager::User::WALLPAPER_TYPE_COUNT); | 425 user_manager::User::WALLPAPER_TYPE_COUNT); |
396 if (info == current_user_wallpaper_info_) | 426 if (info == current_user_wallpaper_info_) |
397 return; | 427 return; |
398 } | 428 } |
(...skipping 291 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
690 | 720 |
691 const user_manager::User* user = | 721 const user_manager::User* user = |
692 user_manager::UserManager::Get()->FindUser(account_id); | 722 user_manager::UserManager::Get()->FindUser(account_id); |
693 | 723 |
694 // User is unknown or there is no visible wallpaper in kiosk mode. | 724 // User is unknown or there is no visible wallpaper in kiosk mode. |
695 if (!user || user->GetType() == user_manager::USER_TYPE_KIOSK_APP || | 725 if (!user || user->GetType() == user_manager::USER_TYPE_KIOSK_APP || |
696 user->GetType() == user_manager::USER_TYPE_ARC_KIOSK_APP) { | 726 user->GetType() == user_manager::USER_TYPE_ARC_KIOSK_APP) { |
697 return; | 727 return; |
698 } | 728 } |
699 | 729 |
| 730 // For a enterprise managed user, set the device wallpaper if we're at the |
| 731 // login screen. |
| 732 if (!user_manager::UserManager::Get()->IsUserLoggedIn() && |
| 733 SetDeviceWallpaperIfApplicable(account_id)) |
| 734 return; |
| 735 |
700 // Guest user or regular user in ephemeral mode. | 736 // Guest user or regular user in ephemeral mode. |
701 if ((user_manager::UserManager::Get()->IsUserNonCryptohomeDataEphemeral( | 737 if ((user_manager::UserManager::Get()->IsUserNonCryptohomeDataEphemeral( |
702 account_id) && | 738 account_id) && |
703 user->HasGaiaAccount()) || | 739 user->HasGaiaAccount()) || |
704 user->GetType() == user_manager::USER_TYPE_GUEST) { | 740 user->GetType() == user_manager::USER_TYPE_GUEST) { |
705 InitInitialUserWallpaper(account_id, false); | 741 InitInitialUserWallpaper(account_id, false); |
706 GetPendingWallpaper(account_id, delayed)->ResetSetDefaultWallpaper(); | 742 GetPendingWallpaper(account_id, delayed)->ResetSetDefaultWallpaper(); |
707 if (base::SysInfo::IsRunningOnChromeOS()) { | 743 if (base::SysInfo::IsRunningOnChromeOS()) { |
708 LOG(ERROR) | 744 LOG(ERROR) |
709 << "User is ephemeral or guest! Fallback to default wallpaper."; | 745 << "User is ephemeral or guest! Fallback to default wallpaper."; |
(...skipping 17 matching lines...) Expand all Loading... |
727 ->ResetSetWallpaperImage(user_wallpaper, info); | 763 ->ResetSetWallpaperImage(user_wallpaper, info); |
728 } else { | 764 } else { |
729 if (info.location.empty()) { | 765 if (info.location.empty()) { |
730 // Uses default built-in wallpaper when file is empty. Eventually, we | 766 // Uses default built-in wallpaper when file is empty. Eventually, we |
731 // will only ship one built-in wallpaper in ChromeOS image. | 767 // will only ship one built-in wallpaper in ChromeOS image. |
732 GetPendingWallpaper(account_id, delayed)->ResetSetDefaultWallpaper(); | 768 GetPendingWallpaper(account_id, delayed)->ResetSetDefaultWallpaper(); |
733 return; | 769 return; |
734 } | 770 } |
735 | 771 |
736 if (info.type == user_manager::User::CUSTOMIZED || | 772 if (info.type == user_manager::User::CUSTOMIZED || |
737 info.type == user_manager::User::POLICY) { | 773 info.type == user_manager::User::POLICY || |
738 const char* sub_dir = GetCustomWallpaperSubdirForCurrentResolution(); | 774 info.type == user_manager::User::DEVICE) { |
739 // Wallpaper is not resized when layout is | 775 base::FilePath wallpaper_path; |
740 // wallpaper::WALLPAPER_LAYOUT_CENTER. | 776 if (info.type != user_manager::User::DEVICE) { |
741 // Original wallpaper should be used in this case. | 777 const char* sub_dir = GetCustomWallpaperSubdirForCurrentResolution(); |
742 // TODO(bshe): Generates cropped custom wallpaper for CENTER layout. | 778 // Wallpaper is not resized when layout is |
743 if (info.layout == wallpaper::WALLPAPER_LAYOUT_CENTER) | 779 // wallpaper::WALLPAPER_LAYOUT_CENTER. |
744 sub_dir = wallpaper::kOriginalWallpaperSubDir; | 780 // Original wallpaper should be used in this case. |
745 base::FilePath wallpaper_path = GetCustomWallpaperDir(sub_dir); | 781 // TODO(bshe): Generates cropped custom wallpaper for CENTER layout. |
746 wallpaper_path = wallpaper_path.Append(info.location); | 782 if (info.layout == wallpaper::WALLPAPER_LAYOUT_CENTER) |
| 783 sub_dir = wallpaper::kOriginalWallpaperSubDir; |
| 784 wallpaper_path = GetCustomWallpaperDir(sub_dir); |
| 785 wallpaper_path = wallpaper_path.Append(info.location); |
| 786 } else { |
| 787 wallpaper_path = GetDeviceWallpaperFilePath(); |
| 788 } |
| 789 |
747 CustomWallpaperMap::iterator it = wallpaper_cache_.find(account_id); | 790 CustomWallpaperMap::iterator it = wallpaper_cache_.find(account_id); |
748 // Do not try to load the wallpaper if the path is the same. Since loading | 791 // Do not try to load the wallpaper if the path is the same. Since loading |
749 // could still be in progress, we ignore the existence of the image. | 792 // could still be in progress, we ignore the existence of the image. |
750 if (it != wallpaper_cache_.end() && it->second.first == wallpaper_path) | 793 if (it != wallpaper_cache_.end() && it->second.first == wallpaper_path) |
751 return; | 794 return; |
752 | 795 |
753 // Set the new path and reset the existing image - the image will be | 796 // Set the new path and reset the existing image - the image will be |
754 // added once it becomes available. | 797 // added once it becomes available. |
755 wallpaper_cache_[account_id] = | 798 wallpaper_cache_[account_id] = |
756 CustomWallpaperElement(wallpaper_path, gfx::ImageSkia()); | 799 CustomWallpaperElement(wallpaper_path, gfx::ImageSkia()); |
(...skipping 127 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
884 | 927 |
885 if (!wallpaper_files_id.is_valid()) | 928 if (!wallpaper_files_id.is_valid()) |
886 LOG(FATAL) << "Wallpaper flies id if invalid!"; | 929 LOG(FATAL) << "Wallpaper flies id if invalid!"; |
887 | 930 |
888 SetCustomWallpaper(account_id, wallpaper_files_id, "policy-controlled.jpeg", | 931 SetCustomWallpaper(account_id, wallpaper_files_id, "policy-controlled.jpeg", |
889 wallpaper::WALLPAPER_LAYOUT_CENTER_CROPPED, | 932 wallpaper::WALLPAPER_LAYOUT_CENTER_CROPPED, |
890 user_manager::User::POLICY, user_image->image(), | 933 user_manager::User::POLICY, user_image->image(), |
891 true /* update wallpaper */); | 934 true /* update wallpaper */); |
892 } | 935 } |
893 | 936 |
| 937 void WallpaperManager::OnDeviceWallpaperPolicyChanged() { |
| 938 SetDeviceWallpaperIfApplicable( |
| 939 user_manager::UserManager::Get()->IsUserLoggedIn() |
| 940 ? user_manager::UserManager::Get()->GetActiveUser()->GetAccountId() |
| 941 : user_manager::SignInAccountId()); |
| 942 } |
| 943 |
| 944 void WallpaperManager::OnDeviceWallpaperExists(const AccountId& account_id, |
| 945 const std::string& url, |
| 946 const std::string& hash, |
| 947 bool exist) { |
| 948 if (exist) { |
| 949 base::PostTaskAndReplyWithResult( |
| 950 BrowserThread::GetBlockingPool(), FROM_HERE, |
| 951 base::Bind(&CheckDeviceWallpaperMatchHash, GetDeviceWallpaperFilePath(), |
| 952 hash), |
| 953 base::Bind(&WallpaperManager::OnCheckDeviceWallpaperMatchHash, |
| 954 weak_factory_.GetWeakPtr(), account_id, url, hash)); |
| 955 } else { |
| 956 GURL device_wallpaper_url(url); |
| 957 device_wallpaper_downloader_.reset(new CustomizationWallpaperDownloader( |
| 958 g_browser_process->system_request_context(), device_wallpaper_url, |
| 959 GetDeviceWallpaperDir(), GetDeviceWallpaperFilePath(), |
| 960 base::Bind(&WallpaperManager::OnDeviceWallpaperDownloaded, |
| 961 weak_factory_.GetWeakPtr(), account_id, hash))); |
| 962 device_wallpaper_downloader_->Start(); |
| 963 } |
| 964 } |
| 965 |
| 966 void WallpaperManager::OnDeviceWallpaperDownloaded(const AccountId& account_id, |
| 967 const std::string& hash, |
| 968 bool success, |
| 969 const GURL& url) { |
| 970 if (!success) { |
| 971 LOG(ERROR) << "Failed to download the device wallpaper. Fallback to " |
| 972 "default wallpaper."; |
| 973 SetDefaultWallpaperDelayed(account_id); |
| 974 return; |
| 975 } |
| 976 |
| 977 base::PostTaskAndReplyWithResult( |
| 978 BrowserThread::GetBlockingPool(), FROM_HERE, |
| 979 base::Bind(&CheckDeviceWallpaperMatchHash, GetDeviceWallpaperFilePath(), |
| 980 hash), |
| 981 base::Bind(&WallpaperManager::OnCheckDeviceWallpaperMatchHash, |
| 982 weak_factory_.GetWeakPtr(), account_id, url.spec(), hash)); |
| 983 } |
| 984 |
| 985 void WallpaperManager::OnCheckDeviceWallpaperMatchHash( |
| 986 const AccountId& account_id, |
| 987 const std::string& url, |
| 988 const std::string& hash, |
| 989 bool match) { |
| 990 if (!match) { |
| 991 if (retry_download_if_failed_) { |
| 992 // We only retry to download the device wallpaper one more time if the |
| 993 // hash doesn't match. |
| 994 retry_download_if_failed_ = false; |
| 995 GURL device_wallpaper_url(url); |
| 996 device_wallpaper_downloader_.reset(new CustomizationWallpaperDownloader( |
| 997 g_browser_process->system_request_context(), device_wallpaper_url, |
| 998 GetDeviceWallpaperDir(), GetDeviceWallpaperFilePath(), |
| 999 base::Bind(&WallpaperManager::OnDeviceWallpaperDownloaded, |
| 1000 weak_factory_.GetWeakPtr(), account_id, hash))); |
| 1001 device_wallpaper_downloader_->Start(); |
| 1002 } else { |
| 1003 LOG(ERROR) << "The device wallpaper hash doesn't match with provided " |
| 1004 "hash value. Fallback to default wallpaper! "; |
| 1005 SetDefaultWallpaperDelayed(account_id); |
| 1006 |
| 1007 // Reset the boolean variable so that it can retry to download when the |
| 1008 // next device wallpaper request comes in. |
| 1009 retry_download_if_failed_ = true; |
| 1010 } |
| 1011 return; |
| 1012 } |
| 1013 |
| 1014 user_image_loader::StartWithFilePath( |
| 1015 task_runner_, GetDeviceWallpaperFilePath(), |
| 1016 ImageDecoder::ROBUST_JPEG_CODEC, |
| 1017 0, // Do not crop. |
| 1018 base::Bind(&WallpaperManager::OnDeviceWallpaperDecoded, |
| 1019 weak_factory_.GetWeakPtr(), account_id)); |
| 1020 } |
| 1021 |
| 1022 void WallpaperManager::OnDeviceWallpaperDecoded( |
| 1023 const AccountId& account_id, |
| 1024 std::unique_ptr<user_manager::UserImage> user_image) { |
| 1025 WallpaperInfo wallpaper_info = {GetDeviceWallpaperFilePath().value(), |
| 1026 wallpaper::WALLPAPER_LAYOUT_CENTER_CROPPED, |
| 1027 user_manager::User::DEVICE, |
| 1028 base::Time::Now().LocalMidnight()}; |
| 1029 if (user_manager::UserManager::Get()->IsUserLoggedIn()) { |
| 1030 // In a user's session treat the device wallpaper as a normal custom |
| 1031 // wallpaper. It should be persistent and can be overriden by other user |
| 1032 // selected wallpapers. |
| 1033 SetUserWallpaperInfo(account_id, wallpaper_info, true /* is_persistent */); |
| 1034 GetPendingWallpaper(account_id, false) |
| 1035 ->ResetSetWallpaperImage(user_image->image(), wallpaper_info); |
| 1036 wallpaper_cache_[account_id] = CustomWallpaperElement( |
| 1037 GetDeviceWallpaperFilePath(), user_image->image()); |
| 1038 } else { |
| 1039 // In the login screen set the device wallpaper as the wallpaper. |
| 1040 GetPendingWallpaper(user_manager::SignInAccountId(), false) |
| 1041 ->ResetSetWallpaperImage(user_image->image(), wallpaper_info); |
| 1042 } |
| 1043 } |
| 1044 |
894 void WallpaperManager::InitializeRegisteredDeviceWallpaper() { | 1045 void WallpaperManager::InitializeRegisteredDeviceWallpaper() { |
895 if (user_manager::UserManager::Get()->IsUserLoggedIn()) | 1046 if (user_manager::UserManager::Get()->IsUserLoggedIn()) |
896 return; | 1047 return; |
897 | 1048 |
898 bool disable_boot_animation = | 1049 bool disable_boot_animation = |
899 GetCommandLine()->HasSwitch(switches::kDisableBootAnimation); | 1050 GetCommandLine()->HasSwitch(switches::kDisableBootAnimation); |
900 bool show_users = true; | 1051 bool show_users = true; |
901 bool result = CrosSettings::Get()->GetBoolean( | 1052 bool result = CrosSettings::Get()->GetBoolean( |
902 kAccountsPrefShowUserNamesOnSignIn, &show_users); | 1053 kAccountsPrefShowUserNamesOnSignIn, &show_users); |
903 DCHECK(result) << "Unable to fetch setting " | 1054 DCHECK(result) << "Unable to fetch setting " |
904 << kAccountsPrefShowUserNamesOnSignIn; | 1055 << kAccountsPrefShowUserNamesOnSignIn; |
905 const user_manager::UserList& users = | 1056 const user_manager::UserList& users = |
906 user_manager::UserManager::Get()->GetUsers(); | 1057 user_manager::UserManager::Get()->GetUsers(); |
907 int public_session_user_index = FindPublicSession(users); | 1058 int public_session_user_index = FindPublicSession(users); |
908 if ((!show_users && public_session_user_index == -1) || users.empty()) { | 1059 if ((!show_users && public_session_user_index == -1) || users.empty()) { |
909 // Boot into sign in form, preload default wallpaper. | 1060 // Boot into sign in form, preload default wallpaper. |
910 SetDefaultWallpaperDelayed(user_manager::SignInAccountId()); | 1061 if (!SetDeviceWallpaperIfApplicable(user_manager::SignInAccountId())) |
| 1062 SetDefaultWallpaperDelayed(user_manager::SignInAccountId()); |
911 return; | 1063 return; |
912 } | 1064 } |
913 | 1065 |
914 if (!disable_boot_animation) { | 1066 if (!disable_boot_animation) { |
915 int index = public_session_user_index != -1 ? public_session_user_index : 0; | 1067 int index = public_session_user_index != -1 ? public_session_user_index : 0; |
916 // Normal boot, load user wallpaper. | 1068 // Normal boot, load user wallpaper. |
917 // If normal boot animation is disabled wallpaper would be set | 1069 // If normal boot animation is disabled wallpaper would be set |
918 // asynchronously once user pods are loaded. | 1070 // asynchronously once user pods are loaded. |
919 SetUserWallpaperDelayed(users[index]->GetAccountId()); | 1071 SetUserWallpaperDelayed(users[index]->GetAccountId()); |
920 } | 1072 } |
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
959 if (!base::StringToInt64(date_string, &date_val)) | 1111 if (!base::StringToInt64(date_string, &date_val)) |
960 return false; | 1112 return false; |
961 | 1113 |
962 info->location = location; | 1114 info->location = location; |
963 info->layout = static_cast<wallpaper::WallpaperLayout>(layout); | 1115 info->layout = static_cast<wallpaper::WallpaperLayout>(layout); |
964 info->type = static_cast<user_manager::User::WallpaperType>(type); | 1116 info->type = static_cast<user_manager::User::WallpaperType>(type); |
965 info->date = base::Time::FromInternalValue(date_val); | 1117 info->date = base::Time::FromInternalValue(date_val); |
966 return true; | 1118 return true; |
967 } | 1119 } |
968 | 1120 |
| 1121 bool WallpaperManager::ShouldSetDeviceWallpaper(const AccountId& account_id, |
| 1122 std::string* url, |
| 1123 std::string* hash) { |
| 1124 // Only allow the device wallpaper for enterprise managed devices. |
| 1125 if (!g_browser_process->platform_part() |
| 1126 ->browser_policy_connector_chromeos() |
| 1127 ->IsEnterpriseManaged()) { |
| 1128 return false; |
| 1129 } |
| 1130 |
| 1131 const base::DictionaryValue* dict = nullptr; |
| 1132 if (!CrosSettings::Get()->GetDictionary(kDeviceWallpaperImage, &dict) || |
| 1133 !dict->GetStringWithoutPathExpansion("url", url) || |
| 1134 !dict->GetStringWithoutPathExpansion("hash", hash)) { |
| 1135 return false; |
| 1136 } |
| 1137 |
| 1138 // Only set the device wallpaper if 1) we're at the login screen or 2) there |
| 1139 // is no user policy wallpaper in a user session and the user has the default |
| 1140 // wallpaper or device wallpaper in a user session. Note in the latter case, |
| 1141 // the device wallpaper can be overridden by user-selected wallpapers. |
| 1142 if (user_manager::UserManager::Get()->IsUserLoggedIn()) { |
| 1143 WallpaperInfo info; |
| 1144 if (GetUserWallpaperInfo(account_id, &info) && |
| 1145 (info.type == user_manager::User::POLICY || |
| 1146 (info.type != user_manager::User::DEFAULT && |
| 1147 info.type != user_manager::User::DEVICE))) { |
| 1148 return false; |
| 1149 } |
| 1150 } |
| 1151 |
| 1152 return true; |
| 1153 } |
| 1154 |
| 1155 base::FilePath WallpaperManager::GetDeviceWallpaperDir() { |
| 1156 base::FilePath wallpaper_dir; |
| 1157 if (!PathService::Get(chrome::DIR_CHROMEOS_WALLPAPERS, &wallpaper_dir)) { |
| 1158 LOG(ERROR) << "Unable to get wallpaper dir."; |
| 1159 return base::FilePath(); |
| 1160 } |
| 1161 return wallpaper_dir.Append(kDeviceWallpaperDir); |
| 1162 } |
| 1163 |
| 1164 base::FilePath WallpaperManager::GetDeviceWallpaperFilePath() { |
| 1165 return GetDeviceWallpaperDir().Append(kDeviceWallpaperFile); |
| 1166 } |
| 1167 |
969 void WallpaperManager::OnWallpaperDecoded( | 1168 void WallpaperManager::OnWallpaperDecoded( |
970 const AccountId& account_id, | 1169 const AccountId& account_id, |
971 wallpaper::WallpaperLayout layout, | 1170 wallpaper::WallpaperLayout layout, |
972 bool update_wallpaper, | 1171 bool update_wallpaper, |
973 MovableOnDestroyCallbackHolder on_finish, | 1172 MovableOnDestroyCallbackHolder on_finish, |
974 std::unique_ptr<user_manager::UserImage> user_image) { | 1173 std::unique_ptr<user_manager::UserImage> user_image) { |
975 DCHECK_CURRENTLY_ON(BrowserThread::UI); | 1174 DCHECK_CURRENTLY_ON(BrowserThread::UI); |
976 TRACE_EVENT_ASYNC_END0("ui", "LoadAndDecodeWallpaper", this); | 1175 TRACE_EVENT_ASYNC_END0("ui", "LoadAndDecodeWallpaper", this); |
977 | 1176 |
978 // If decoded wallpaper is empty, we have probably failed to decode the file. | 1177 // If decoded wallpaper is empty, we have probably failed to decode the file. |
(...skipping 85 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1064 SetDefaultWallpaperPath( | 1263 SetDefaultWallpaperPath( |
1065 rescaled_files->path_rescaled_small(), std::move(small_wallpaper_image), | 1264 rescaled_files->path_rescaled_small(), std::move(small_wallpaper_image), |
1066 rescaled_files->path_rescaled_large(), std::move(large_wallpaper_image)); | 1265 rescaled_files->path_rescaled_large(), std::move(large_wallpaper_image)); |
1067 VLOG(1) << "Customized default wallpaper applied."; | 1266 VLOG(1) << "Customized default wallpaper applied."; |
1068 } | 1267 } |
1069 | 1268 |
1070 size_t WallpaperManager::GetPendingListSizeForTesting() const { | 1269 size_t WallpaperManager::GetPendingListSizeForTesting() const { |
1071 return loading_.size(); | 1270 return loading_.size(); |
1072 } | 1271 } |
1073 | 1272 |
| 1273 wallpaper::WallpaperFilesId WallpaperManager::GetFilesId( |
| 1274 const AccountId& account_id) const { |
| 1275 std::string stored_value; |
| 1276 if (user_manager::known_user::GetStringPref(account_id, kWallpaperFilesId, |
| 1277 &stored_value)) { |
| 1278 return wallpaper::WallpaperFilesId::FromString(stored_value); |
| 1279 } |
| 1280 const std::string& old_id = account_id.GetUserEmail(); // Migrated |
| 1281 const wallpaper::WallpaperFilesId files_id = HashWallpaperFilesIdStr(old_id); |
| 1282 SetKnownUserWallpaperFilesId(account_id, files_id); |
| 1283 return files_id; |
| 1284 } |
| 1285 |
| 1286 bool WallpaperManager::SetDeviceWallpaperIfApplicable( |
| 1287 const AccountId& account_id) { |
| 1288 std::string url; |
| 1289 std::string hash; |
| 1290 if (ShouldSetDeviceWallpaper(account_id, &url, &hash)) { |
| 1291 // Check if the device wallpaper exists and matches the hash. If so, use it |
| 1292 // directly. Otherwise download it first. |
| 1293 base::PostTaskAndReplyWithResult( |
| 1294 BrowserThread::GetBlockingPool(), FROM_HERE, |
| 1295 base::Bind(&base::PathExists, GetDeviceWallpaperFilePath()), |
| 1296 base::Bind(&WallpaperManager::OnDeviceWallpaperExists, |
| 1297 weak_factory_.GetWeakPtr(), account_id, url, hash)); |
| 1298 return true; |
| 1299 } |
| 1300 return false; |
| 1301 } |
| 1302 |
1074 void WallpaperManager::UserChangedChildStatus(user_manager::User* user) { | 1303 void WallpaperManager::UserChangedChildStatus(user_manager::User* user) { |
1075 SetUserWallpaperNow(user->GetAccountId()); | 1304 SetUserWallpaperNow(user->GetAccountId()); |
1076 } | 1305 } |
1077 | 1306 |
1078 void WallpaperManager::SetDefaultWallpaperPathsFromCommandLine( | 1307 void WallpaperManager::SetDefaultWallpaperPathsFromCommandLine( |
1079 base::CommandLine* command_line) { | 1308 base::CommandLine* command_line) { |
1080 default_small_wallpaper_file_ = command_line->GetSwitchValuePath( | 1309 default_small_wallpaper_file_ = command_line->GetSwitchValuePath( |
1081 chromeos::switches::kDefaultWallpaperSmall); | 1310 chromeos::switches::kDefaultWallpaperSmall); |
1082 default_large_wallpaper_file_ = command_line->GetSwitchValuePath( | 1311 default_large_wallpaper_file_ = command_line->GetSwitchValuePath( |
1083 chromeos::switches::kDefaultWallpaperLarge); | 1312 chromeos::switches::kDefaultWallpaperLarge); |
(...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1150 default_wallpaper_image_.reset( | 1379 default_wallpaper_image_.reset( |
1151 new user_manager::UserImage(*large_wallpaper_image)); | 1380 new user_manager::UserImage(*large_wallpaper_image)); |
1152 default_wallpaper_image_->set_file_path(default_large_wallpaper_file); | 1381 default_wallpaper_image_->set_file_path(default_large_wallpaper_file); |
1153 } | 1382 } |
1154 } | 1383 } |
1155 | 1384 |
1156 if (need_update_screen) | 1385 if (need_update_screen) |
1157 DoSetDefaultWallpaper(EmptyAccountId(), MovableOnDestroyCallbackHolder()); | 1386 DoSetDefaultWallpaper(EmptyAccountId(), MovableOnDestroyCallbackHolder()); |
1158 } | 1387 } |
1159 | 1388 |
1160 wallpaper::WallpaperFilesId WallpaperManager::GetFilesId( | |
1161 const AccountId& account_id) const { | |
1162 std::string stored_value; | |
1163 if (user_manager::known_user::GetStringPref(account_id, kWallpaperFilesId, | |
1164 &stored_value)) { | |
1165 return wallpaper::WallpaperFilesId::FromString(stored_value); | |
1166 } | |
1167 const std::string& old_id = account_id.GetUserEmail(); // Migrated | |
1168 const wallpaper::WallpaperFilesId files_id = HashWallpaperFilesIdStr(old_id); | |
1169 SetKnownUserWallpaperFilesId(account_id, files_id); | |
1170 return files_id; | |
1171 } | |
1172 | |
1173 } // namespace chromeos | 1389 } // namespace chromeos |
OLD | NEW |