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

Side by Side Diff: chrome/browser/chromeos/login/users/wallpaper/wallpaper_manager.cc

Issue 443163002: Rename WallpaperInfo::file --> WallpaperInfo::location. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 6 years, 4 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
« no previous file with comments | « chrome/browser/chromeos/login/users/wallpaper/wallpaper_manager.h ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 <numeric> 7 #include <numeric>
8 #include <vector> 8 #include <vector>
9 9
10 #include "ash/ash_constants.h" 10 #include "ash/ash_constants.h"
(...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after
72 72
73 const int kCacheWallpaperDelayMs = 500; 73 const int kCacheWallpaperDelayMs = 500;
74 74
75 // A dictionary pref that maps usernames to wallpaper properties. 75 // A dictionary pref that maps usernames to wallpaper properties.
76 const char kUserWallpapersProperties[] = "UserWallpapersProperties"; 76 const char kUserWallpapersProperties[] = "UserWallpapersProperties";
77 77
78 // Names of nodes with info about wallpaper in |kUserWallpapersProperties| 78 // Names of nodes with info about wallpaper in |kUserWallpapersProperties|
79 // dictionary. 79 // dictionary.
80 const char kNewWallpaperDateNodeName[] = "date"; 80 const char kNewWallpaperDateNodeName[] = "date";
81 const char kNewWallpaperLayoutNodeName[] = "layout"; 81 const char kNewWallpaperLayoutNodeName[] = "layout";
82 const char kNewWallpaperFileNodeName[] = "file"; 82 const char kNewWallpaperLocationNodeName[] = "file";
83 const char kNewWallpaperTypeNodeName[] = "type"; 83 const char kNewWallpaperTypeNodeName[] = "type";
84 84
85 // Maximum number of wallpapers cached by CacheUsersWallpapers(). 85 // Maximum number of wallpapers cached by CacheUsersWallpapers().
86 const int kMaxWallpapersToCache = 3; 86 const int kMaxWallpapersToCache = 3;
87 87
88 // Maximum number of entries in WallpaperManager::last_load_times_ . 88 // Maximum number of entries in WallpaperManager::last_load_times_ .
89 const size_t kLastLoadsStatsMsMaxSize = 4; 89 const size_t kLastLoadsStatsMsMaxSize = 4;
90 90
91 // Minimum delay between wallpaper loads, milliseconds. 91 // Minimum delay between wallpaper loads, milliseconds.
92 const unsigned kLoadMinDelayMs = 50; 92 const unsigned kLoadMinDelayMs = 50;
(...skipping 296 matching lines...) Expand 10 before | Expand all | Expand 10 after
389 } else if (!wallpaper_path_.empty()) { 389 } else if (!wallpaper_path_.empty()) {
390 manager->task_runner_->PostTask( 390 manager->task_runner_->PostTask(
391 FROM_HERE, 391 FROM_HERE,
392 base::Bind(&WallpaperManager::GetCustomWallpaperInternal, 392 base::Bind(&WallpaperManager::GetCustomWallpaperInternal,
393 user_id_, 393 user_id_,
394 info_, 394 info_,
395 wallpaper_path_, 395 wallpaper_path_,
396 true /* update wallpaper */, 396 true /* update wallpaper */,
397 base::Passed(on_finish_.Pass()), 397 base::Passed(on_finish_.Pass()),
398 manager->weak_factory_.GetWeakPtr())); 398 manager->weak_factory_.GetWeakPtr()));
399 } else if (!info_.file.empty()) { 399 } else if (!info_.location.empty()) {
400 manager->LoadWallpaper(user_id_, info_, true, on_finish_.Pass()); 400 manager->LoadWallpaper(user_id_, info_, true, on_finish_.Pass());
401 } else { 401 } else {
402 // PendingWallpaper was created and never initialized? 402 // PendingWallpaper was created and never initialized?
403 NOTREACHED(); 403 NOTREACHED();
404 // Error. Do not record time. 404 // Error. Do not record time.
405 started_load_at_ = base::Time(); 405 started_load_at_ = base::Time();
406 } 406 }
407 on_finish_.reset(); 407 on_finish_.reset();
408 } 408 }
409 409
(...skipping 150 matching lines...) Expand 10 before | Expand all | Expand 10 after
560 logged_in_users_cache.insert(*it); 560 logged_in_users_cache.insert(*it);
561 } 561 }
562 } 562 }
563 wallpaper_cache_ = logged_in_users_cache; 563 wallpaper_cache_ = logged_in_users_cache;
564 } 564 }
565 565
566 bool WallpaperManager::GetLoggedInUserWallpaperInfo(WallpaperInfo* info) { 566 bool WallpaperManager::GetLoggedInUserWallpaperInfo(WallpaperInfo* info) {
567 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 567 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
568 568
569 if (UserManager::Get()->IsLoggedInAsStub()) { 569 if (UserManager::Get()->IsLoggedInAsStub()) {
570 info->file = current_user_wallpaper_info_.file = ""; 570 info->location = current_user_wallpaper_info_.location = "";
571 info->layout = current_user_wallpaper_info_.layout = 571 info->layout = current_user_wallpaper_info_.layout =
572 ash::WALLPAPER_LAYOUT_CENTER_CROPPED; 572 ash::WALLPAPER_LAYOUT_CENTER_CROPPED;
573 info->type = current_user_wallpaper_info_.type = 573 info->type = current_user_wallpaper_info_.type =
574 user_manager::User::DEFAULT; 574 user_manager::User::DEFAULT;
575 info->date = current_user_wallpaper_info_.date = 575 info->date = current_user_wallpaper_info_.date =
576 base::Time::Now().LocalMidnight(); 576 base::Time::Now().LocalMidnight();
577 return true; 577 return true;
578 } 578 }
579 579
580 return GetUserWallpaperInfo(UserManager::Get()->GetLoggedInUser()->email(), 580 return GetUserWallpaperInfo(UserManager::Get()->GetLoggedInUser()->email(),
(...skipping 86 matching lines...) Expand 10 before | Expand all | Expand 10 after
667 } 667 }
668 } 668 }
669 669
670 void WallpaperManager::RemoveUserWallpaperInfo(const std::string& user_id) { 670 void WallpaperManager::RemoveUserWallpaperInfo(const std::string& user_id) {
671 WallpaperInfo info; 671 WallpaperInfo info;
672 GetUserWallpaperInfo(user_id, &info); 672 GetUserWallpaperInfo(user_id, &info);
673 PrefService* prefs = g_browser_process->local_state(); 673 PrefService* prefs = g_browser_process->local_state();
674 DictionaryPrefUpdate prefs_wallpapers_info_update(prefs, 674 DictionaryPrefUpdate prefs_wallpapers_info_update(prefs,
675 prefs::kUsersWallpaperInfo); 675 prefs::kUsersWallpaperInfo);
676 prefs_wallpapers_info_update->RemoveWithoutPathExpansion(user_id, NULL); 676 prefs_wallpapers_info_update->RemoveWithoutPathExpansion(user_id, NULL);
677 DeleteUserWallpapers(user_id, info.file); 677 DeleteUserWallpapers(user_id, info.location);
678 } 678 }
679 679
680 // static 680 // static
681 bool WallpaperManager::ResizeImage(const gfx::ImageSkia& image, 681 bool WallpaperManager::ResizeImage(const gfx::ImageSkia& image,
682 ash::WallpaperLayout layout, 682 ash::WallpaperLayout layout,
683 int preferred_width, 683 int preferred_width,
684 int preferred_height, 684 int preferred_height,
685 scoped_refptr<base::RefCountedBytes>* output, 685 scoped_refptr<base::RefCountedBytes>* output,
686 gfx::ImageSkia* output_skia) { 686 gfx::ImageSkia* output_skia) {
687 DCHECK(!BrowserThread::CurrentlyOn(BrowserThread::UI)); 687 DCHECK(!BrowserThread::CurrentlyOn(BrowserThread::UI));
(...skipping 231 matching lines...) Expand 10 before | Expand all | Expand 10 after
919 // that the user selected. 919 // that the user selected.
920 scoped_refptr<base::SequencedTaskRunner> blocking_task_runner = 920 scoped_refptr<base::SequencedTaskRunner> blocking_task_runner =
921 BrowserThread::GetBlockingPool() 921 BrowserThread::GetBlockingPool()
922 ->GetSequencedTaskRunnerWithShutdownBehavior( 922 ->GetSequencedTaskRunnerWithShutdownBehavior(
923 sequence_token_, base::SequencedWorkerPool::BLOCK_SHUTDOWN); 923 sequence_token_, base::SequencedWorkerPool::BLOCK_SHUTDOWN);
924 // TODO(bshe): This may break if RawImage becomes RefCountedMemory. 924 // TODO(bshe): This may break if RawImage becomes RefCountedMemory.
925 blocking_task_runner->PostTask( 925 blocking_task_runner->PostTask(
926 FROM_HERE, 926 FROM_HERE,
927 base::Bind(&WallpaperManager::SaveCustomWallpaper, 927 base::Bind(&WallpaperManager::SaveCustomWallpaper,
928 user_id_hash, 928 user_id_hash,
929 base::FilePath(wallpaper_info.file), 929 base::FilePath(wallpaper_info.location),
930 wallpaper_info.layout, 930 wallpaper_info.layout,
931 base::Passed(deep_copy.Pass()))); 931 base::Passed(deep_copy.Pass())));
932 } 932 }
933 933
934 std::string relative_path = base::FilePath(user_id_hash).Append(file).value(); 934 std::string relative_path = base::FilePath(user_id_hash).Append(file).value();
935 // User's custom wallpaper path is determined by relative path and the 935 // User's custom wallpaper path is determined by relative path and the
936 // appropriate wallpaper resolution in GetCustomWallpaperInternal. 936 // appropriate wallpaper resolution in GetCustomWallpaperInternal.
937 WallpaperInfo info = { 937 WallpaperInfo info = {
938 relative_path, 938 relative_path,
939 layout, 939 layout,
(...skipping 151 matching lines...) Expand 10 before | Expand all | Expand 10 after
1091 bool update_wallpaper, 1091 bool update_wallpaper,
1092 MovableOnDestroyCallbackHolder on_finish, 1092 MovableOnDestroyCallbackHolder on_finish,
1093 base::WeakPtr<WallpaperManager> weak_ptr) { 1093 base::WeakPtr<WallpaperManager> weak_ptr) {
1094 1094
1095 base::FilePath valid_path = wallpaper_path; 1095 base::FilePath valid_path = wallpaper_path;
1096 if (!base::PathExists(wallpaper_path)) { 1096 if (!base::PathExists(wallpaper_path)) {
1097 // Falls back on original file if the correct resolution file does not 1097 // Falls back on original file if the correct resolution file does not
1098 // exist. This may happen when the original custom wallpaper is small or 1098 // exist. This may happen when the original custom wallpaper is small or
1099 // browser shutdown before resized wallpaper saved. 1099 // browser shutdown before resized wallpaper saved.
1100 valid_path = GetCustomWallpaperDir(kOriginalWallpaperSubDir); 1100 valid_path = GetCustomWallpaperDir(kOriginalWallpaperSubDir);
1101 valid_path = valid_path.Append(info.file); 1101 valid_path = valid_path.Append(info.location);
1102 } 1102 }
1103 1103
1104 if (!base::PathExists(valid_path)) { 1104 if (!base::PathExists(valid_path)) {
1105 // Falls back to custom wallpaper that uses email as part of its file path. 1105 // Falls back to custom wallpaper that uses email as part of its file path.
1106 // Note that email is used instead of user_id_hash here. 1106 // Note that email is used instead of user_id_hash here.
1107 valid_path = 1107 valid_path = GetCustomWallpaperPath(kOriginalWallpaperSubDir,
1108 GetCustomWallpaperPath(kOriginalWallpaperSubDir, user_id, info.file); 1108 user_id, info.location);
1109 } 1109 }
1110 1110
1111 if (!base::PathExists(valid_path)) { 1111 if (!base::PathExists(valid_path)) {
1112 LOG(ERROR) << "Failed to load previously selected custom wallpaper. " << 1112 LOG(ERROR) << "Failed to load previously selected custom wallpaper. " <<
1113 "Fallback to default wallpaper"; 1113 "Fallback to default wallpaper";
1114 BrowserThread::PostTask(BrowserThread::UI, 1114 BrowserThread::PostTask(BrowserThread::UI,
1115 FROM_HERE, 1115 FROM_HERE,
1116 base::Bind(&WallpaperManager::DoSetDefaultWallpaper, 1116 base::Bind(&WallpaperManager::DoSetDefaultWallpaper,
1117 weak_ptr, 1117 weak_ptr,
1118 user_id, 1118 user_id,
1119 base::Passed(on_finish.Pass()))); 1119 base::Passed(on_finish.Pass())));
1120 } else { 1120 } else {
1121 BrowserThread::PostTask(BrowserThread::UI, 1121 BrowserThread::PostTask(BrowserThread::UI,
1122 FROM_HERE, 1122 FROM_HERE,
1123 base::Bind(&WallpaperManager::StartLoad, 1123 base::Bind(&WallpaperManager::StartLoad,
1124 weak_ptr, 1124 weak_ptr,
1125 user_id, 1125 user_id,
1126 info, 1126 info,
1127 update_wallpaper, 1127 update_wallpaper,
1128 valid_path, 1128 valid_path,
1129 base::Passed(on_finish.Pass()))); 1129 base::Passed(on_finish.Pass())));
1130 } 1130 }
1131 } 1131 }
1132 1132
1133 void WallpaperManager::InitInitialUserWallpaper(const std::string& user_id, 1133 void WallpaperManager::InitInitialUserWallpaper(const std::string& user_id,
1134 bool is_persistent) { 1134 bool is_persistent) {
1135 current_user_wallpaper_info_.file = ""; 1135 current_user_wallpaper_info_.location = "";
1136 current_user_wallpaper_info_.layout = ash::WALLPAPER_LAYOUT_CENTER_CROPPED; 1136 current_user_wallpaper_info_.layout = ash::WALLPAPER_LAYOUT_CENTER_CROPPED;
1137 current_user_wallpaper_info_.type = user_manager::User::DEFAULT; 1137 current_user_wallpaper_info_.type = user_manager::User::DEFAULT;
1138 current_user_wallpaper_info_.date = base::Time::Now().LocalMidnight(); 1138 current_user_wallpaper_info_.date = base::Time::Now().LocalMidnight();
1139 1139
1140 WallpaperInfo info = current_user_wallpaper_info_; 1140 WallpaperInfo info = current_user_wallpaper_info_;
1141 SetUserWallpaperInfo(user_id, info, is_persistent); 1141 SetUserWallpaperInfo(user_id, info, is_persistent);
1142 } 1142 }
1143 1143
1144 void WallpaperManager::SetUserWallpaperInfo(const std::string& user_id, 1144 void WallpaperManager::SetUserWallpaperInfo(const std::string& user_id,
1145 const WallpaperInfo& info, 1145 const WallpaperInfo& info,
1146 bool is_persistent) { 1146 bool is_persistent) {
1147 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 1147 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
1148 current_user_wallpaper_info_ = info; 1148 current_user_wallpaper_info_ = info;
1149 if (!is_persistent) 1149 if (!is_persistent)
1150 return; 1150 return;
1151 1151
1152 PrefService* local_state = g_browser_process->local_state(); 1152 PrefService* local_state = g_browser_process->local_state();
1153 DictionaryPrefUpdate wallpaper_update(local_state, 1153 DictionaryPrefUpdate wallpaper_update(local_state,
1154 prefs::kUsersWallpaperInfo); 1154 prefs::kUsersWallpaperInfo);
1155 1155
1156 base::DictionaryValue* wallpaper_info_dict = new base::DictionaryValue(); 1156 base::DictionaryValue* wallpaper_info_dict = new base::DictionaryValue();
1157 wallpaper_info_dict->SetString(kNewWallpaperDateNodeName, 1157 wallpaper_info_dict->SetString(kNewWallpaperDateNodeName,
1158 base::Int64ToString(info.date.ToInternalValue())); 1158 base::Int64ToString(info.date.ToInternalValue()));
1159 wallpaper_info_dict->SetString(kNewWallpaperFileNodeName, info.file); 1159 wallpaper_info_dict->SetString(kNewWallpaperLocationNodeName, info.location);
1160 wallpaper_info_dict->SetInteger(kNewWallpaperLayoutNodeName, info.layout); 1160 wallpaper_info_dict->SetInteger(kNewWallpaperLayoutNodeName, info.layout);
1161 wallpaper_info_dict->SetInteger(kNewWallpaperTypeNodeName, info.type); 1161 wallpaper_info_dict->SetInteger(kNewWallpaperTypeNodeName, info.type);
1162 wallpaper_update->SetWithoutPathExpansion(user_id, wallpaper_info_dict); 1162 wallpaper_update->SetWithoutPathExpansion(user_id, wallpaper_info_dict);
1163 } 1163 }
1164 1164
1165 void WallpaperManager::SetUserWallpaperDelayed(const std::string& user_id) { 1165 void WallpaperManager::SetUserWallpaperDelayed(const std::string& user_id) {
1166 ScheduleSetUserWallpaper(user_id, true); 1166 ScheduleSetUserWallpaper(user_id, true);
1167 } 1167 }
1168 1168
1169 void WallpaperManager::SetUserWallpaperNow(const std::string& user_id) { 1169 void WallpaperManager::SetUserWallpaperNow(const std::string& user_id) {
(...skipping 29 matching lines...) Expand all
1199 InitInitialUserWallpaper(user_id, true); 1199 InitInitialUserWallpaper(user_id, true);
1200 GetUserWallpaperInfo(user_id, &info); 1200 GetUserWallpaperInfo(user_id, &info);
1201 } 1201 }
1202 1202
1203 gfx::ImageSkia user_wallpaper; 1203 gfx::ImageSkia user_wallpaper;
1204 current_user_wallpaper_info_ = info; 1204 current_user_wallpaper_info_ = info;
1205 if (GetWallpaperFromCache(user_id, &user_wallpaper)) { 1205 if (GetWallpaperFromCache(user_id, &user_wallpaper)) {
1206 GetPendingWallpaper(user_id, delayed) 1206 GetPendingWallpaper(user_id, delayed)
1207 ->ResetSetWallpaperImage(user_wallpaper, info); 1207 ->ResetSetWallpaperImage(user_wallpaper, info);
1208 } else { 1208 } else {
1209 if (info.file.empty()) { 1209 if (info.location.empty()) {
1210 // Uses default built-in wallpaper when file is empty. Eventually, we 1210 // Uses default built-in wallpaper when file is empty. Eventually, we
1211 // will only ship one built-in wallpaper in ChromeOS image. 1211 // will only ship one built-in wallpaper in ChromeOS image.
1212 GetPendingWallpaper(user_id, delayed)->ResetSetDefaultWallpaper(); 1212 GetPendingWallpaper(user_id, delayed)->ResetSetDefaultWallpaper();
1213 return; 1213 return;
1214 } 1214 }
1215 1215
1216 if (info.type == user_manager::User::CUSTOMIZED || 1216 if (info.type == user_manager::User::CUSTOMIZED ||
1217 info.type == user_manager::User::POLICY) { 1217 info.type == user_manager::User::POLICY) {
1218 const char* sub_dir = GetCustomWallpaperSubdirForCurrentResolution(); 1218 const char* sub_dir = GetCustomWallpaperSubdirForCurrentResolution();
1219 // Wallpaper is not resized when layout is ash::WALLPAPER_LAYOUT_CENTER. 1219 // Wallpaper is not resized when layout is ash::WALLPAPER_LAYOUT_CENTER.
1220 // Original wallpaper should be used in this case. 1220 // Original wallpaper should be used in this case.
1221 // TODO(bshe): Generates cropped custom wallpaper for CENTER layout. 1221 // TODO(bshe): Generates cropped custom wallpaper for CENTER layout.
1222 if (info.layout == ash::WALLPAPER_LAYOUT_CENTER) 1222 if (info.layout == ash::WALLPAPER_LAYOUT_CENTER)
1223 sub_dir = kOriginalWallpaperSubDir; 1223 sub_dir = kOriginalWallpaperSubDir;
1224 base::FilePath wallpaper_path = GetCustomWallpaperDir(sub_dir); 1224 base::FilePath wallpaper_path = GetCustomWallpaperDir(sub_dir);
1225 wallpaper_path = wallpaper_path.Append(info.file); 1225 wallpaper_path = wallpaper_path.Append(info.location);
1226 if (current_wallpaper_path_ == wallpaper_path) 1226 if (current_wallpaper_path_ == wallpaper_path)
1227 return; 1227 return;
1228 current_wallpaper_path_ = wallpaper_path; 1228 current_wallpaper_path_ = wallpaper_path;
1229 loaded_wallpapers_++; 1229 loaded_wallpapers_++;
1230 1230
1231 GetPendingWallpaper(user_id, delayed) 1231 GetPendingWallpaper(user_id, delayed)
1232 ->ResetSetCustomWallpaper(info, wallpaper_path); 1232 ->ResetSetCustomWallpaper(info, wallpaper_path);
1233 return; 1233 return;
1234 } 1234 }
1235 1235
(...skipping 78 matching lines...) Expand 10 before | Expand all | Expand 10 after
1314 CacheUserWallpaper(user_id); 1314 CacheUserWallpaper(user_id);
1315 } 1315 }
1316 } 1316 }
1317 } 1317 }
1318 1318
1319 void WallpaperManager::CacheUserWallpaper(const std::string& user_id) { 1319 void WallpaperManager::CacheUserWallpaper(const std::string& user_id) {
1320 if (wallpaper_cache_.find(user_id) != wallpaper_cache_.end()) 1320 if (wallpaper_cache_.find(user_id) != wallpaper_cache_.end())
1321 return; 1321 return;
1322 WallpaperInfo info; 1322 WallpaperInfo info;
1323 if (GetUserWallpaperInfo(user_id, &info)) { 1323 if (GetUserWallpaperInfo(user_id, &info)) {
1324 if (info.file.empty()) 1324 if (info.location.empty())
1325 return; 1325 return;
1326 1326
1327 base::FilePath wallpaper_dir; 1327 base::FilePath wallpaper_dir;
1328 base::FilePath wallpaper_path; 1328 base::FilePath wallpaper_path;
1329 if (info.type == user_manager::User::CUSTOMIZED || 1329 if (info.type == user_manager::User::CUSTOMIZED ||
1330 info.type == user_manager::User::POLICY) { 1330 info.type == user_manager::User::POLICY) {
1331 const char* sub_dir = GetCustomWallpaperSubdirForCurrentResolution(); 1331 const char* sub_dir = GetCustomWallpaperSubdirForCurrentResolution();
1332 base::FilePath wallpaper_path = GetCustomWallpaperDir(sub_dir); 1332 base::FilePath wallpaper_path = GetCustomWallpaperDir(sub_dir);
1333 wallpaper_path = wallpaper_path.Append(info.file); 1333 wallpaper_path = wallpaper_path.Append(info.location);
1334 task_runner_->PostTask( 1334 task_runner_->PostTask(
1335 FROM_HERE, 1335 FROM_HERE,
1336 base::Bind(&WallpaperManager::GetCustomWallpaperInternal, 1336 base::Bind(&WallpaperManager::GetCustomWallpaperInternal,
1337 user_id, 1337 user_id,
1338 info, 1338 info,
1339 wallpaper_path, 1339 wallpaper_path,
1340 false /* do not update wallpaper */, 1340 false /* do not update wallpaper */,
1341 base::Passed(MovableOnDestroyCallbackHolder()), 1341 base::Passed(MovableOnDestroyCallbackHolder()),
1342 weak_factory_.GetWeakPtr())); 1342 weak_factory_.GetWeakPtr()));
1343 return; 1343 return;
(...skipping 92 matching lines...) Expand 10 before | Expand all | Expand 10 after
1436 void WallpaperManager::LoadWallpaper(const std::string& user_id, 1436 void WallpaperManager::LoadWallpaper(const std::string& user_id,
1437 const WallpaperInfo& info, 1437 const WallpaperInfo& info,
1438 bool update_wallpaper, 1438 bool update_wallpaper,
1439 MovableOnDestroyCallbackHolder on_finish) { 1439 MovableOnDestroyCallbackHolder on_finish) {
1440 base::FilePath wallpaper_dir; 1440 base::FilePath wallpaper_dir;
1441 base::FilePath wallpaper_path; 1441 base::FilePath wallpaper_path;
1442 1442
1443 // Do a sanity check that file path information is not empty. 1443 // Do a sanity check that file path information is not empty.
1444 if (info.type == user_manager::User::ONLINE || 1444 if (info.type == user_manager::User::ONLINE ||
1445 info.type == user_manager::User::DEFAULT) { 1445 info.type == user_manager::User::DEFAULT) {
1446 if (info.file.empty()) { 1446 if (info.location.empty()) {
1447 if (base::SysInfo::IsRunningOnChromeOS()) { 1447 if (base::SysInfo::IsRunningOnChromeOS()) {
1448 NOTREACHED() << "User wallpaper info appears to be broken: " << user_id; 1448 NOTREACHED() << "User wallpaper info appears to be broken: " << user_id;
1449 } else { 1449 } else {
1450 // Filename might be empty on debug configurations when stub users 1450 // Filename might be empty on debug configurations when stub users
1451 // were created directly in Local State (for testing). Ignore such 1451 // were created directly in Local State (for testing). Ignore such
1452 // errors i.e. allowsuch type of debug configurations on the desktop. 1452 // errors i.e. allowsuch type of debug configurations on the desktop.
1453 LOG(WARNING) << "User wallpaper info is empty: " << user_id; 1453 LOG(WARNING) << "User wallpaper info is empty: " << user_id;
1454 1454
1455 // |on_finish| callback will get called on destruction. 1455 // |on_finish| callback will get called on destruction.
1456 return; 1456 return;
1457 } 1457 }
1458 } 1458 }
1459 } 1459 }
1460 1460
1461 if (info.type == user_manager::User::ONLINE) { 1461 if (info.type == user_manager::User::ONLINE) {
1462 std::string file_name = GURL(info.file).ExtractFileName(); 1462 std::string file_name = GURL(info.location).ExtractFileName();
1463 WallpaperResolution resolution = GetAppropriateResolution(); 1463 WallpaperResolution resolution = GetAppropriateResolution();
1464 // Only solid color wallpapers have stretch layout and they have only one 1464 // Only solid color wallpapers have stretch layout and they have only one
1465 // resolution. 1465 // resolution.
1466 if (info.layout != ash::WALLPAPER_LAYOUT_STRETCH && 1466 if (info.layout != ash::WALLPAPER_LAYOUT_STRETCH &&
1467 resolution == WALLPAPER_RESOLUTION_SMALL) { 1467 resolution == WALLPAPER_RESOLUTION_SMALL) {
1468 file_name = base::FilePath(file_name).InsertBeforeExtension( 1468 file_name = base::FilePath(file_name).InsertBeforeExtension(
1469 kSmallWallpaperSuffix).value(); 1469 kSmallWallpaperSuffix).value();
1470 } 1470 }
1471 CHECK(PathService::Get(chrome::DIR_CHROMEOS_WALLPAPERS, &wallpaper_dir)); 1471 CHECK(PathService::Get(chrome::DIR_CHROMEOS_WALLPAPERS, &wallpaper_dir));
1472 wallpaper_path = wallpaper_dir.Append(file_name); 1472 wallpaper_path = wallpaper_dir.Append(file_name);
1473 if (current_wallpaper_path_ == wallpaper_path) 1473 if (current_wallpaper_path_ == wallpaper_path)
1474 return; 1474 return;
1475 1475
1476 if (update_wallpaper) 1476 if (update_wallpaper)
1477 current_wallpaper_path_ = wallpaper_path; 1477 current_wallpaper_path_ = wallpaper_path;
1478 1478
1479 loaded_wallpapers_++; 1479 loaded_wallpapers_++;
1480 StartLoad( 1480 StartLoad(
1481 user_id, info, update_wallpaper, wallpaper_path, on_finish.Pass()); 1481 user_id, info, update_wallpaper, wallpaper_path, on_finish.Pass());
1482 } else if (info.type == user_manager::User::DEFAULT) { 1482 } else if (info.type == user_manager::User::DEFAULT) {
1483 // Default wallpapers are migrated from M21 user profiles. A code refactor 1483 // Default wallpapers are migrated from M21 user profiles. A code refactor
1484 // overlooked that case and caused these wallpapers not being loaded at all. 1484 // overlooked that case and caused these wallpapers not being loaded at all.
1485 // On some slow devices, it caused login webui not visible after upgrade to 1485 // On some slow devices, it caused login webui not visible after upgrade to
1486 // M26 from M21. See crosbug.com/38429 for details. 1486 // M26 from M21. See crosbug.com/38429 for details.
1487 base::FilePath user_data_dir; 1487 base::FilePath user_data_dir;
1488 PathService::Get(chrome::DIR_USER_DATA, &user_data_dir); 1488 PathService::Get(chrome::DIR_USER_DATA, &user_data_dir);
1489 wallpaper_path = user_data_dir.Append(info.file); 1489 wallpaper_path = user_data_dir.Append(info.location);
1490 StartLoad( 1490 StartLoad(
1491 user_id, info, update_wallpaper, wallpaper_path, on_finish.Pass()); 1491 user_id, info, update_wallpaper, wallpaper_path, on_finish.Pass());
1492 } else { 1492 } else {
1493 // In unexpected cases, revert to default wallpaper to fail safely. See 1493 // In unexpected cases, revert to default wallpaper to fail safely. See
1494 // crosbug.com/38429. 1494 // crosbug.com/38429.
1495 LOG(ERROR) << "Wallpaper reverts to default unexpected."; 1495 LOG(ERROR) << "Wallpaper reverts to default unexpected.";
1496 DoSetDefaultWallpaper(user_id, on_finish.Pass()); 1496 DoSetDefaultWallpaper(user_id, on_finish.Pass());
1497 } 1497 }
1498 } 1498 }
1499 1499
(...skipping 11 matching lines...) Expand all
1511 } 1511 }
1512 1512
1513 const base::DictionaryValue* info_dict; 1513 const base::DictionaryValue* info_dict;
1514 if (!g_browser_process->local_state()-> 1514 if (!g_browser_process->local_state()->
1515 GetDictionary(prefs::kUsersWallpaperInfo)-> 1515 GetDictionary(prefs::kUsersWallpaperInfo)->
1516 GetDictionaryWithoutPathExpansion(user_id, &info_dict)) { 1516 GetDictionaryWithoutPathExpansion(user_id, &info_dict)) {
1517 return false; 1517 return false;
1518 } 1518 }
1519 1519
1520 // Use temporary variables to keep |info| untouched in the error case. 1520 // Use temporary variables to keep |info| untouched in the error case.
1521 std::string file; 1521 std::string location;
1522 if (!info_dict->GetString(kNewWallpaperFileNodeName, &file)) 1522 if (!info_dict->GetString(kNewWallpaperLocationNodeName, &location))
1523 return false; 1523 return false;
1524 int layout; 1524 int layout;
1525 if (!info_dict->GetInteger(kNewWallpaperLayoutNodeName, &layout)) 1525 if (!info_dict->GetInteger(kNewWallpaperLayoutNodeName, &layout))
1526 return false; 1526 return false;
1527 int type; 1527 int type;
1528 if (!info_dict->GetInteger(kNewWallpaperTypeNodeName, &type)) 1528 if (!info_dict->GetInteger(kNewWallpaperTypeNodeName, &type))
1529 return false; 1529 return false;
1530 std::string date_string; 1530 std::string date_string;
1531 if (!info_dict->GetString(kNewWallpaperDateNodeName, &date_string)) 1531 if (!info_dict->GetString(kNewWallpaperDateNodeName, &date_string))
1532 return false; 1532 return false;
1533 int64 date_val; 1533 int64 date_val;
1534 if (!base::StringToInt64(date_string, &date_val)) 1534 if (!base::StringToInt64(date_string, &date_val))
1535 return false; 1535 return false;
1536 1536
1537 info->file = file; 1537 info->location = location;
1538 info->layout = static_cast<ash::WallpaperLayout>(layout); 1538 info->layout = static_cast<ash::WallpaperLayout>(layout);
1539 info->type = static_cast<user_manager::User::WallpaperType>(type); 1539 info->type = static_cast<user_manager::User::WallpaperType>(type);
1540 info->date = base::Time::FromInternalValue(date_val); 1540 info->date = base::Time::FromInternalValue(date_val);
1541 return true; 1541 return true;
1542 } 1542 }
1543 1543
1544 void WallpaperManager::MoveCustomWallpapersSuccess( 1544 void WallpaperManager::MoveCustomWallpapersSuccess(
1545 const std::string& user_id, 1545 const std::string& user_id,
1546 const std::string& user_id_hash) { 1546 const std::string& user_id_hash) {
1547 WallpaperInfo info; 1547 WallpaperInfo info;
1548 GetUserWallpaperInfo(user_id, &info); 1548 GetUserWallpaperInfo(user_id, &info);
1549 if (info.type == user_manager::User::CUSTOMIZED) { 1549 if (info.type == user_manager::User::CUSTOMIZED) {
1550 // New file field should include user id hash in addition to file name. 1550 // New file field should include user id hash in addition to file name.
1551 // This is needed because at login screen, user id hash is not available. 1551 // This is needed because at login screen, user id hash is not available.
1552 std::string relative_path = 1552 info.location = base::FilePath(user_id_hash).Append(info.location).value();
1553 base::FilePath(user_id_hash).Append(info.file).value();
1554 info.file = relative_path;
1555 bool is_persistent = 1553 bool is_persistent =
1556 !UserManager::Get()->IsUserNonCryptohomeDataEphemeral(user_id); 1554 !UserManager::Get()->IsUserNonCryptohomeDataEphemeral(user_id);
1557 SetUserWallpaperInfo(user_id, info, is_persistent); 1555 SetUserWallpaperInfo(user_id, info, is_persistent);
1558 } 1556 }
1559 } 1557 }
1560 1558
1561 void WallpaperManager::MoveLoggedInUserCustomWallpaper() { 1559 void WallpaperManager::MoveLoggedInUserCustomWallpaper() {
1562 const user_manager::User* logged_in_user = 1560 const user_manager::User* logged_in_user =
1563 UserManager::Get()->GetLoggedInUser(); 1561 UserManager::Get()->GetLoggedInUser();
1564 task_runner_->PostTask( 1562 task_runner_->PostTask(
(...skipping 373 matching lines...) Expand 10 before | Expand all | Expand 10 after
1938 void WallpaperManager::CreateSolidDefaultWallpaper() { 1936 void WallpaperManager::CreateSolidDefaultWallpaper() {
1939 loaded_wallpapers_++; 1937 loaded_wallpapers_++;
1940 SkBitmap bitmap; 1938 SkBitmap bitmap;
1941 bitmap.allocN32Pixels(1, 1); 1939 bitmap.allocN32Pixels(1, 1);
1942 bitmap.eraseColor(kDefaultWallpaperColor); 1940 bitmap.eraseColor(kDefaultWallpaperColor);
1943 const gfx::ImageSkia image = gfx::ImageSkia::CreateFrom1xBitmap(bitmap); 1941 const gfx::ImageSkia image = gfx::ImageSkia::CreateFrom1xBitmap(bitmap);
1944 default_wallpaper_image_.reset(new user_manager::UserImage(image)); 1942 default_wallpaper_image_.reset(new user_manager::UserImage(image));
1945 } 1943 }
1946 1944
1947 } // namespace chromeos 1945 } // namespace chromeos
OLDNEW
« no previous file with comments | « chrome/browser/chromeos/login/users/wallpaper/wallpaper_manager.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698