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

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

Issue 23480087: Use username_hash instead of email (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: rebase Created 7 years, 3 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 | Annotate | Revision Log
OLDNEW
1 // Copyright (c) 2013 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2013 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/wallpaper_manager.h" 5 #include "chrome/browser/chromeos/login/wallpaper_manager.h"
6 6
7 #include <vector> 7 #include <vector>
8 8
9 #include "ash/shell.h" 9 #include "ash/shell.h"
10 #include "base/command_line.h" 10 #include "base/command_line.h"
(...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after
75 const char kOriginalCustomWallpaperSuffix[] = "_wallpaper"; 75 const char kOriginalCustomWallpaperSuffix[] = "_wallpaper";
76 76
77 // Maximum number of wallpapers cached by CacheUsersWallpapers(). 77 // Maximum number of wallpapers cached by CacheUsersWallpapers().
78 const int kMaxWallpapersToCache = 3; 78 const int kMaxWallpapersToCache = 3;
79 79
80 // For our scaling ratios we need to round positive numbers. 80 // For our scaling ratios we need to round positive numbers.
81 int RoundPositive(double x) { 81 int RoundPositive(double x) {
82 return static_cast<int>(floor(x + 0.5)); 82 return static_cast<int>(floor(x + 0.5));
83 } 83 }
84 84
85 // Returns custom wallpaper directory by appending |sub_dir| and |email| as sub 85 // Returns custom wallpaper directory by appending corresponding |sub_dir|.
86 // directories. 86 base::FilePath GetCustomWallpaperDir(const char* sub_dir) {
87 base::FilePath GetCustomWallpaperDir(const char* sub_dir,
88 const std::string& email) {
89 base::FilePath custom_wallpaper_dir; 87 base::FilePath custom_wallpaper_dir;
90 CHECK(PathService::Get(chrome::DIR_CHROMEOS_CUSTOM_WALLPAPERS, 88 CHECK(PathService::Get(chrome::DIR_CHROMEOS_CUSTOM_WALLPAPERS,
91 &custom_wallpaper_dir)); 89 &custom_wallpaper_dir));
92 return custom_wallpaper_dir.Append(sub_dir).Append(email); 90 return custom_wallpaper_dir.Append(sub_dir);
91 }
92
93 bool MoveCustomWallpaperDirectory(const char* sub_dir,
94 const std::string& email,
95 const std::string& username_hash) {
96 base::FilePath base_path = GetCustomWallpaperDir(sub_dir);
97 base::FilePath to_path = base_path.Append(username_hash);
98 base::FilePath from_path = base_path.Append(email);
99 if (base::PathExists(from_path))
100 return base::Move(from_path, to_path);
101 return false;
93 } 102 }
94 103
95 } // namespace 104 } // namespace
96 105
97 namespace chromeos { 106 namespace chromeos {
98 107
99 const char kWallpaperSequenceTokenName[] = "wallpaper-sequence"; 108 const char kWallpaperSequenceTokenName[] = "wallpaper-sequence";
100 109
101 const char kSmallWallpaperSuffix[] = "_small"; 110 const char kSmallWallpaperSuffix[] = "_small";
102 const char kLargeWallpaperSuffix[] = "_large"; 111 const char kLargeWallpaperSuffix[] = "_large";
(...skipping 94 matching lines...) Expand 10 before | Expand all | Expand 10 after
197 } 206 }
198 207
199 void WallpaperManager::ClearWallpaperCache() { 208 void WallpaperManager::ClearWallpaperCache() {
200 // Cancel callback for previous cache requests. 209 // Cancel callback for previous cache requests.
201 weak_factory_.InvalidateWeakPtrs(); 210 weak_factory_.InvalidateWeakPtrs();
202 wallpaper_cache_.clear(); 211 wallpaper_cache_.clear();
203 } 212 }
204 213
205 base::FilePath WallpaperManager::GetCustomWallpaperPath( 214 base::FilePath WallpaperManager::GetCustomWallpaperPath(
206 const char* sub_dir, 215 const char* sub_dir,
207 const std::string& email, 216 const std::string& username_hash,
208 const std::string& file) { 217 const std::string& file) {
209 base::FilePath custom_wallpaper_path = GetCustomWallpaperDir(sub_dir, email); 218 base::FilePath custom_wallpaper_path = GetCustomWallpaperDir(sub_dir);
210 return custom_wallpaper_path.Append(file); 219 return custom_wallpaper_path.Append(username_hash).Append(file);
211 } 220 }
212 221
213 bool WallpaperManager::GetWallpaperFromCache(const std::string& email, 222 bool WallpaperManager::GetWallpaperFromCache(const std::string& email,
214 gfx::ImageSkia* wallpaper) { 223 gfx::ImageSkia* wallpaper) {
215 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 224 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
216 CustomWallpaperMap::const_iterator it = wallpaper_cache_.find(email); 225 CustomWallpaperMap::const_iterator it = wallpaper_cache_.find(email);
217 if (it != wallpaper_cache_.end()) { 226 if (it != wallpaper_cache_.end()) {
218 *wallpaper = (*it).second; 227 *wallpaper = (*it).second;
219 return true; 228 return true;
220 } 229 }
(...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after
277 SetUserWallpaper(user_manager->GetLoggedInUser()->email()); 286 SetUserWallpaper(user_manager->GetLoggedInUser()->email());
278 } 287 }
279 288
280 void WallpaperManager::Observe(int type, 289 void WallpaperManager::Observe(int type,
281 const content::NotificationSource& source, 290 const content::NotificationSource& source,
282 const content::NotificationDetails& details) { 291 const content::NotificationDetails& details) {
283 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 292 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
284 switch (type) { 293 switch (type) {
285 case chrome::NOTIFICATION_LOGIN_USER_CHANGED: { 294 case chrome::NOTIFICATION_LOGIN_USER_CHANGED: {
286 ClearWallpaperCache(); 295 ClearWallpaperCache();
296 MoveLoggedInUserCustomWallpaper();
287 break; 297 break;
288 } 298 }
289 case chrome::NOTIFICATION_LOGIN_OR_LOCK_WEBUI_VISIBLE: { 299 case chrome::NOTIFICATION_LOGIN_OR_LOCK_WEBUI_VISIBLE: {
290 if (!GetComandLine()->HasSwitch(switches::kDisableBootAnimation)) { 300 if (!GetComandLine()->HasSwitch(switches::kDisableBootAnimation)) {
291 BrowserThread::PostDelayedTask( 301 BrowserThread::PostDelayedTask(
292 BrowserThread::UI, FROM_HERE, 302 BrowserThread::UI, FROM_HERE,
293 base::Bind(&WallpaperManager::CacheUsersWallpapers, 303 base::Bind(&WallpaperManager::CacheUsersWallpapers,
294 weak_factory_.GetWeakPtr()), 304 weak_factory_.GetWeakPtr()),
295 base::TimeDelta::FromMilliseconds(kCacheWallpaperDelayMs)); 305 base::TimeDelta::FromMilliseconds(kCacheWallpaperDelayMs));
296 } else { 306 } else {
(...skipping 11 matching lines...) Expand all
308 should_cache_wallpaper_ = false; 318 should_cache_wallpaper_ = false;
309 } 319 }
310 break; 320 break;
311 } 321 }
312 default: 322 default:
313 NOTREACHED() << "Unexpected notification " << type; 323 NOTREACHED() << "Unexpected notification " << type;
314 } 324 }
315 } 325 }
316 326
317 void WallpaperManager::RemoveUserWallpaperInfo(const std::string& email) { 327 void WallpaperManager::RemoveUserWallpaperInfo(const std::string& email) {
328 WallpaperInfo info;
329 GetUserWallpaperInfo(email, &info);
318 PrefService* prefs = g_browser_process->local_state(); 330 PrefService* prefs = g_browser_process->local_state();
319 DictionaryPrefUpdate prefs_wallpapers_info_update(prefs, 331 DictionaryPrefUpdate prefs_wallpapers_info_update(prefs,
320 prefs::kUsersWallpaperInfo); 332 prefs::kUsersWallpaperInfo);
321 prefs_wallpapers_info_update->RemoveWithoutPathExpansion(email, NULL); 333 prefs_wallpapers_info_update->RemoveWithoutPathExpansion(email, NULL);
322 334 DeleteUserWallpapers(email, info.file);
323 DeleteUserWallpapers(email);
324 } 335 }
325 336
326 bool WallpaperManager::ResizeWallpaper( 337 bool WallpaperManager::ResizeWallpaper(
327 const UserImage& wallpaper, 338 const UserImage& wallpaper,
328 ash::WallpaperLayout layout, 339 ash::WallpaperLayout layout,
329 int preferred_width, 340 int preferred_width,
330 int preferred_height, 341 int preferred_height,
331 scoped_refptr<base::RefCountedBytes>* output) { 342 scoped_refptr<base::RefCountedBytes>* output) {
332 DCHECK(BrowserThread::GetBlockingPool()-> 343 DCHECK(BrowserThread::GetBlockingPool()->
333 IsRunningSequenceOnCurrentThread(sequence_token_)); 344 IsRunningSequenceOnCurrentThread(sequence_token_));
(...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after
392 scoped_refptr<base::RefCountedBytes> data; 403 scoped_refptr<base::RefCountedBytes> data;
393 if (ResizeWallpaper(wallpaper, layout, preferred_width, preferred_height, 404 if (ResizeWallpaper(wallpaper, layout, preferred_width, preferred_height,
394 &data)) { 405 &data)) {
395 SaveWallpaperInternal(path, 406 SaveWallpaperInternal(path,
396 reinterpret_cast<const char*>(data->front()), 407 reinterpret_cast<const char*>(data->front()),
397 data->size()); 408 data->size());
398 } 409 }
399 } 410 }
400 411
401 void WallpaperManager::SetCustomWallpaper(const std::string& username, 412 void WallpaperManager::SetCustomWallpaper(const std::string& username,
413 const std::string& username_hash,
402 const std::string& file, 414 const std::string& file,
403 ash::WallpaperLayout layout, 415 ash::WallpaperLayout layout,
404 User::WallpaperType type, 416 User::WallpaperType type,
405 const UserImage& wallpaper) { 417 const UserImage& wallpaper) {
406 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 418 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
407 419
408 base::FilePath wallpaper_path = GetCustomWallpaperPath( 420 base::FilePath wallpaper_path =
409 kOriginalWallpaperSubDir, 421 GetCustomWallpaperPath(kOriginalWallpaperSubDir, username_hash, file);
410 username,
411 file);
412 422
413 // If decoded wallpaper is empty, we are probably failed to decode the file. 423 // If decoded wallpaper is empty, we are probably failed to decode the file.
414 // Use default wallpaper in this case. 424 // Use default wallpaper in this case.
415 if (wallpaper.image().isNull()) { 425 if (wallpaper.image().isNull()) {
416 SetDefaultWallpaper(); 426 SetDefaultWallpaper();
417 return; 427 return;
418 } 428 }
419 429
420 bool is_persistent = 430 bool is_persistent =
421 !UserManager::Get()->IsUserNonCryptohomeDataEphemeral(username); 431 !UserManager::Get()->IsUserNonCryptohomeDataEphemeral(username);
(...skipping 11 matching lines...) Expand all
433 // Block shutdown on this task. Otherwise, we may lost the custom wallpaper 443 // Block shutdown on this task. Otherwise, we may lost the custom wallpaper
434 // user selected. 444 // user selected.
435 scoped_refptr<base::SequencedTaskRunner> blocking_task_runner = 445 scoped_refptr<base::SequencedTaskRunner> blocking_task_runner =
436 BrowserThread::GetBlockingPool()-> 446 BrowserThread::GetBlockingPool()->
437 GetSequencedTaskRunnerWithShutdownBehavior(sequence_token_, 447 GetSequencedTaskRunnerWithShutdownBehavior(sequence_token_,
438 base::SequencedWorkerPool::BLOCK_SHUTDOWN); 448 base::SequencedWorkerPool::BLOCK_SHUTDOWN);
439 // TODO(bshe): This may break if RawImage becomes RefCountedMemory. 449 // TODO(bshe): This may break if RawImage becomes RefCountedMemory.
440 blocking_task_runner->PostTask(FROM_HERE, 450 blocking_task_runner->PostTask(FROM_HERE,
441 base::Bind(&WallpaperManager::ProcessCustomWallpaper, 451 base::Bind(&WallpaperManager::ProcessCustomWallpaper,
442 base::Unretained(this), 452 base::Unretained(this),
443 username, 453 username_hash,
444 is_persistent, 454 is_persistent,
445 wallpaper_info, 455 wallpaper_info,
446 base::Passed(&deep_copy), 456 base::Passed(&deep_copy),
447 wallpaper.raw_image())); 457 wallpaper.raw_image()));
448 ash::Shell::GetInstance()->desktop_background_controller()-> 458 ash::Shell::GetInstance()->desktop_background_controller()->
449 SetCustomWallpaper(wallpaper.image(), layout); 459 SetCustomWallpaper(wallpaper.image(), layout);
450 460
451 // User's custom wallpaper path is determined by username/email and the 461 // User's custom wallpaper path is determined by relative path and the
452 // appropriate wallpaper resolution in GetCustomWallpaperInternal. 462 // appropriate wallpaper resolution in GetCustomWallpaperInternal.
453 WallpaperInfo info = { 463 WallpaperInfo info = {
454 file, 464 username_hash + '/' + file,
Nikita (slow) 2013/09/25 16:23:12 nit: Use separator constant.
bshe 2013/09/26 16:49:57 Not sure if you mean base::FilePath::kSeparators[0
455 layout, 465 layout,
456 User::CUSTOMIZED, 466 User::CUSTOMIZED,
457 base::Time::Now().LocalMidnight() 467 base::Time::Now().LocalMidnight()
458 }; 468 };
459 SetUserWallpaperInfo(username, info, is_persistent); 469 SetUserWallpaperInfo(username, info, is_persistent);
460 } 470 }
461 471
462 void WallpaperManager::SetDefaultWallpaper() { 472 void WallpaperManager::SetDefaultWallpaper() {
463 current_wallpaper_path_.clear(); 473 current_wallpaper_path_.clear();
464 if (ash::Shell::GetInstance()->desktop_background_controller()-> 474 if (ash::Shell::GetInstance()->desktop_background_controller()->
(...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after
534 if (info.type == User::CUSTOMIZED) { 544 if (info.type == User::CUSTOMIZED) {
535 ash::WallpaperResolution resolution = ash::Shell::GetInstance()-> 545 ash::WallpaperResolution resolution = ash::Shell::GetInstance()->
536 desktop_background_controller()->GetAppropriateResolution(); 546 desktop_background_controller()->GetAppropriateResolution();
537 const char* sub_dir = (resolution == ash::WALLPAPER_RESOLUTION_SMALL) ? 547 const char* sub_dir = (resolution == ash::WALLPAPER_RESOLUTION_SMALL) ?
538 kSmallWallpaperSubDir : kLargeWallpaperSubDir; 548 kSmallWallpaperSubDir : kLargeWallpaperSubDir;
539 // Wallpaper is not resized when layout is ash::WALLPAPER_LAYOUT_CENTER. 549 // Wallpaper is not resized when layout is ash::WALLPAPER_LAYOUT_CENTER.
540 // Original wallpaper should be used in this case. 550 // Original wallpaper should be used in this case.
541 // TODO(bshe): Generates cropped custom wallpaper for CENTER layout. 551 // TODO(bshe): Generates cropped custom wallpaper for CENTER layout.
542 if (info.layout == ash::WALLPAPER_LAYOUT_CENTER) 552 if (info.layout == ash::WALLPAPER_LAYOUT_CENTER)
543 sub_dir = kOriginalWallpaperSubDir; 553 sub_dir = kOriginalWallpaperSubDir;
544 base::FilePath wallpaper_path = GetCustomWallpaperPath(sub_dir, email, 554 base::FilePath wallpaper_path = GetCustomWallpaperDir(sub_dir);
545 info.file); 555 wallpaper_path = wallpaper_path.Append(info.file);
546 if (current_wallpaper_path_ == wallpaper_path) 556 if (current_wallpaper_path_ == wallpaper_path)
547 return; 557 return;
548 current_wallpaper_path_ = wallpaper_path; 558 current_wallpaper_path_ = wallpaper_path;
549 loaded_wallpapers_++; 559 loaded_wallpapers_++;
550 560
551 task_runner_->PostTask(FROM_HERE, 561 task_runner_->PostTask(FROM_HERE,
552 base::Bind(&WallpaperManager::GetCustomWallpaperInternal, 562 base::Bind(&WallpaperManager::GetCustomWallpaperInternal,
553 base::Unretained(this), email, info, wallpaper_path, 563 base::Unretained(this), email, info, wallpaper_path,
554 true /* update wallpaper */)); 564 true /* update wallpaper */));
555 return; 565 return;
(...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after
615 return; 625 return;
616 WallpaperInfo info; 626 WallpaperInfo info;
617 if (GetUserWallpaperInfo(email, &info)) { 627 if (GetUserWallpaperInfo(email, &info)) {
618 base::FilePath wallpaper_dir; 628 base::FilePath wallpaper_dir;
619 base::FilePath wallpaper_path; 629 base::FilePath wallpaper_path;
620 if (info.type == User::CUSTOMIZED) { 630 if (info.type == User::CUSTOMIZED) {
621 ash::WallpaperResolution resolution = ash::Shell::GetInstance()-> 631 ash::WallpaperResolution resolution = ash::Shell::GetInstance()->
622 desktop_background_controller()->GetAppropriateResolution(); 632 desktop_background_controller()->GetAppropriateResolution();
623 const char* sub_dir = (resolution == ash::WALLPAPER_RESOLUTION_SMALL) ? 633 const char* sub_dir = (resolution == ash::WALLPAPER_RESOLUTION_SMALL) ?
624 kSmallWallpaperSubDir : kLargeWallpaperSubDir; 634 kSmallWallpaperSubDir : kLargeWallpaperSubDir;
625 base::FilePath wallpaper_path = GetCustomWallpaperPath(sub_dir, email, 635 base::FilePath wallpaper_path = GetCustomWallpaperDir(sub_dir);
626 info.file); 636 wallpaper_path = wallpaper_path.Append(info.file);
627 task_runner_->PostTask(FROM_HERE, 637 task_runner_->PostTask(FROM_HERE,
628 base::Bind(&WallpaperManager::GetCustomWallpaperInternal, 638 base::Bind(&WallpaperManager::GetCustomWallpaperInternal,
629 base::Unretained(this), email, info, wallpaper_path, 639 base::Unretained(this), email, info, wallpaper_path,
630 false /* do not update wallpaper */)); 640 false /* do not update wallpaper */));
631 return; 641 return;
632 } 642 }
633 LoadWallpaper(email, info, false /* do not update wallpaper */); 643 LoadWallpaper(email, info, false /* do not update wallpaper */);
634 } 644 }
635 } 645 }
636 646
(...skipping 25 matching lines...) Expand all
662 base::FilePath path = *it; 672 base::FilePath path = *it;
663 // Some users may still have legacy wallpapers with png extension. We need 673 // Some users may still have legacy wallpapers with png extension. We need
664 // to delete these wallpapers too. 674 // to delete these wallpapers too.
665 if (!base::DeleteFile(path, true) && 675 if (!base::DeleteFile(path, true) &&
666 !base::DeleteFile(path.AddExtension(".png"), false)) { 676 !base::DeleteFile(path.AddExtension(".png"), false)) {
667 LOG(ERROR) << "Failed to remove user wallpaper at " << path.value(); 677 LOG(ERROR) << "Failed to remove user wallpaper at " << path.value();
668 } 678 }
669 } 679 }
670 } 680 }
671 681
672 void WallpaperManager::DeleteUserWallpapers(const std::string& email) { 682 void WallpaperManager::DeleteUserWallpapers(const std::string& email,
683 const std::string& path_to_file) {
673 std::vector<base::FilePath> file_to_remove; 684 std::vector<base::FilePath> file_to_remove;
674 // Remove small user wallpaper. 685 // Remove small user wallpaper.
675 base::FilePath wallpaper_path = 686 base::FilePath wallpaper_path =
676 GetCustomWallpaperDir(kSmallWallpaperSubDir, email); 687 GetCustomWallpaperDir(kSmallWallpaperSubDir);
688 // Remove old directory if exists
689 file_to_remove.push_back(wallpaper_path.Append(email));
690 wallpaper_path = wallpaper_path.Append(path_to_file).DirName();
677 file_to_remove.push_back(wallpaper_path); 691 file_to_remove.push_back(wallpaper_path);
678 692
679 // Remove large user wallpaper. 693 // Remove large user wallpaper.
680 wallpaper_path = GetCustomWallpaperDir(kLargeWallpaperSubDir, email); 694 wallpaper_path = GetCustomWallpaperDir(kLargeWallpaperSubDir);
695 file_to_remove.push_back(wallpaper_path.Append(email));
696 wallpaper_path = wallpaper_path.Append(path_to_file);
681 file_to_remove.push_back(wallpaper_path); 697 file_to_remove.push_back(wallpaper_path);
682 698
683 // Remove user wallpaper thumbnail. 699 // Remove user wallpaper thumbnail.
684 wallpaper_path = GetCustomWallpaperDir(kThumbnailWallpaperSubDir, email); 700 wallpaper_path = GetCustomWallpaperDir(kThumbnailWallpaperSubDir);
701 file_to_remove.push_back(wallpaper_path.Append(email));
702 wallpaper_path = wallpaper_path.Append(path_to_file);
685 file_to_remove.push_back(wallpaper_path); 703 file_to_remove.push_back(wallpaper_path);
686 704
687 // Remove original user wallpaper. 705 // Remove original user wallpaper.
688 wallpaper_path = GetCustomWallpaperDir(kOriginalWallpaperSubDir, email); 706 wallpaper_path = GetCustomWallpaperDir(kOriginalWallpaperSubDir);
707 file_to_remove.push_back(wallpaper_path.Append(email));
708 wallpaper_path = wallpaper_path.Append(path_to_file);
689 file_to_remove.push_back(wallpaper_path); 709 file_to_remove.push_back(wallpaper_path);
690 710
691 base::WorkerPool::PostTask( 711 base::WorkerPool::PostTask(
692 FROM_HERE, 712 FROM_HERE,
693 base::Bind(&WallpaperManager::DeleteWallpaperInList, 713 base::Bind(&WallpaperManager::DeleteWallpaperInList,
694 base::Unretained(this), 714 base::Unretained(this),
695 file_to_remove), 715 file_to_remove),
696 false); 716 false);
697 } 717 }
698 718
699 void WallpaperManager::EnsureCustomWallpaperDirectories( 719 void WallpaperManager::EnsureCustomWallpaperDirectories(
700 const std::string& email) { 720 const std::string& username_hash) {
701 base::FilePath dir; 721 base::FilePath dir;
702 dir = GetCustomWallpaperDir(kSmallWallpaperSubDir, email); 722 dir = GetCustomWallpaperDir(kSmallWallpaperSubDir);
723 dir = dir.Append(username_hash);
703 if (!base::PathExists(dir)) 724 if (!base::PathExists(dir))
704 file_util::CreateDirectory(dir); 725 file_util::CreateDirectory(dir);
705 dir = GetCustomWallpaperDir(kLargeWallpaperSubDir, email); 726 dir = GetCustomWallpaperDir(kLargeWallpaperSubDir);
727 dir = dir.Append(username_hash);
706 if (!base::PathExists(dir)) 728 if (!base::PathExists(dir))
707 file_util::CreateDirectory(dir); 729 file_util::CreateDirectory(dir);
708 dir = GetCustomWallpaperDir(kOriginalWallpaperSubDir, email); 730 dir = GetCustomWallpaperDir(kOriginalWallpaperSubDir);
731 dir = dir.Append(username_hash);
709 if (!base::PathExists(dir)) 732 if (!base::PathExists(dir))
710 file_util::CreateDirectory(dir); 733 file_util::CreateDirectory(dir);
711 dir = GetCustomWallpaperDir(kThumbnailWallpaperSubDir, email); 734 dir = GetCustomWallpaperDir(kThumbnailWallpaperSubDir);
735 dir = dir.Append(username_hash);
712 if (!base::PathExists(dir)) 736 if (!base::PathExists(dir))
713 file_util::CreateDirectory(dir); 737 file_util::CreateDirectory(dir);
714 } 738 }
715 739
716 CommandLine* WallpaperManager::GetComandLine() { 740 CommandLine* WallpaperManager::GetComandLine() {
717 CommandLine* command_line = command_line_for_testing_ ? 741 CommandLine* command_line = command_line_for_testing_ ?
718 command_line_for_testing_ : CommandLine::ForCurrentProcess(); 742 command_line_for_testing_ : CommandLine::ForCurrentProcess();
719 return command_line; 743 return command_line;
720 } 744 }
721 745
(...skipping 98 matching lines...) Expand 10 before | Expand all | Expand 10 after
820 &date_string) && 844 &date_string) &&
821 base::StringToInt64(date_string, &val))) 845 base::StringToInt64(date_string, &val)))
822 val = 0; 846 val = 0;
823 info->date = base::Time::FromInternalValue(val); 847 info->date = base::Time::FromInternalValue(val);
824 return true; 848 return true;
825 } 849 }
826 850
827 return false; 851 return false;
828 } 852 }
829 853
854 void WallpaperManager::MoveCustomWallpapersOnWorker(const std::string& email,
855 const std::string& username_hash) {
Nikita (slow) 2013/09/25 16:23:12 nit: Either align this parameter with previous or
bshe 2013/09/26 16:49:57 Done.
856 DCHECK(BrowserThread::GetBlockingPool()->
857 IsRunningSequenceOnCurrentThread(sequence_token_));
858 if (MoveCustomWallpaperDirectory(kOriginalWallpaperSubDir, email,
Nikita (slow) 2013/09/25 16:23:12 nit: Move second parameter on separate line.
bshe 2013/09/26 16:49:57 Done.
859 username_hash)) {
860 // Consider success if the original wallpaper is moved to the new directory.
861 // Original wallpaper is the fallback if the correct resolution wallpaper
862 // can not be found.
863 BrowserThread::PostTask(
864 BrowserThread::UI, FROM_HERE,
865 base::Bind(&WallpaperManager::MoveCustomWallpapersSuccess,
866 base::Unretained(this),
867 email, username_hash));
Nikita (slow) 2013/09/25 16:23:12 nit: Move to next line.
bshe 2013/09/26 16:49:57 Done.
868 }
869 MoveCustomWallpaperDirectory(kLargeWallpaperSubDir, email, username_hash);
870 MoveCustomWallpaperDirectory(kSmallWallpaperSubDir, email, username_hash);
871 MoveCustomWallpaperDirectory(kThumbnailWallpaperSubDir, email, username_hash);
872 }
873
874 void WallpaperManager::MoveCustomWallpapersSuccess(const std::string& email,
Nikita (slow) 2013/09/25 16:23:12 nit: same here
bshe 2013/09/26 16:49:57 Done.
875 const std::string& username_hash) {
876 WallpaperInfo info;
877 GetUserWallpaperInfo(email, &info);
878 if (info.type == User::CUSTOMIZED) {
879 // New file field should include username hash in addition to file name.
880 // This is needed because at login screen, username hash is not available.
881 info.file = username_hash + "/" + info.file;
882 bool is_persistent =
883 !UserManager::Get()->IsUserNonCryptohomeDataEphemeral(email);
884 SetUserWallpaperInfo(email, info, is_persistent);
885 }
886 }
887
888 void WallpaperManager::MoveLoggedInUserCustomWallpaper() {
889 const User* logged_in_user = UserManager::Get()->GetLoggedInUser();
890 task_runner_->PostTask(FROM_HERE,
Nikita (slow) 2013/09/25 16:23:12 Please postpone this task since when NOTIFICATION_
bshe 2013/09/26 16:49:57 Postponed it after receiving NOTIFICATION_SESSION_
Nikita (slow) 2013/09/26 17:46:18 I'm proposing to add reasonable delay - in seconds
bshe 2013/09/26 21:02:12 I see. Added a 30 seconds delay for the task. On
891 base::Bind(&WallpaperManager::MoveCustomWallpapersOnWorker,
892 base::Unretained(this),
893 logged_in_user->email(),
894 logged_in_user->username_hash()));
895 }
896
830 void WallpaperManager::GetCustomWallpaperInternal( 897 void WallpaperManager::GetCustomWallpaperInternal(
831 const std::string& email, 898 const std::string& email,
832 const WallpaperInfo& info, 899 const WallpaperInfo& info,
833 const base::FilePath& wallpaper_path, 900 const base::FilePath& wallpaper_path,
834 bool update_wallpaper) { 901 bool update_wallpaper) {
835 DCHECK(BrowserThread::GetBlockingPool()-> 902 DCHECK(BrowserThread::GetBlockingPool()->
836 IsRunningSequenceOnCurrentThread(sequence_token_)); 903 IsRunningSequenceOnCurrentThread(sequence_token_));
837 904
838 base::FilePath valid_path = wallpaper_path; 905 base::FilePath valid_path = wallpaper_path;
839 if (!base::PathExists(wallpaper_path)) { 906 if (!base::PathExists(wallpaper_path)) {
840 // Falls back on original file if the correct resoltuion file does not 907 // Falls back on original file if the correct resoltuion file does not
841 // exist. This may happen when the original custom wallpaper is small or 908 // exist. This may happen when the original custom wallpaper is small or
842 // browser shutdown before resized wallpaper saved. 909 // browser shutdown before resized wallpaper saved.
910 valid_path = GetCustomWallpaperDir(kOriginalWallpaperSubDir);
911 valid_path = valid_path.Append(info.file);
912 }
913
914 if (!base::PathExists(valid_path)) {
915 // Falls back to custom wallpaper that uses email as part of its file path.
916 // Note that email is used instead of username_hash here.
843 valid_path = GetCustomWallpaperPath(kOriginalWallpaperSubDir, email, 917 valid_path = GetCustomWallpaperPath(kOriginalWallpaperSubDir, email,
844 info.file); 918 info.file);
845 } 919 }
846 920
847 if (!base::PathExists(valid_path)) { 921 if (!base::PathExists(valid_path)) {
848 LOG(ERROR) << "Failed to load previously selected custom wallpaper. " << 922 LOG(ERROR) << "Failed to load previously selected custom wallpaper. " <<
849 "Fallback to default wallpaper"; 923 "Fallback to default wallpaper";
850 BrowserThread::PostTask(BrowserThread::UI, 924 BrowserThread::PostTask(BrowserThread::UI,
851 FROM_HERE, 925 FROM_HERE,
852 base::Bind(&WallpaperManager::SetDefaultWallpaper, 926 base::Bind(&WallpaperManager::SetDefaultWallpaper,
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after
891 if (!UserManager::Get()->IsUserLoggedIn()) { 965 if (!UserManager::Get()->IsUserLoggedIn()) {
892 wallpaper_cache_.insert(std::make_pair(email, wallpaper.image())); 966 wallpaper_cache_.insert(std::make_pair(email, wallpaper.image()));
893 } 967 }
894 if (update_wallpaper) { 968 if (update_wallpaper) {
895 ash::Shell::GetInstance()->desktop_background_controller()-> 969 ash::Shell::GetInstance()->desktop_background_controller()->
896 SetCustomWallpaper(wallpaper.image(), layout); 970 SetCustomWallpaper(wallpaper.image(), layout);
897 } 971 }
898 } 972 }
899 973
900 void WallpaperManager::ProcessCustomWallpaper( 974 void WallpaperManager::ProcessCustomWallpaper(
901 const std::string& email, 975 const std::string& username_hash,
902 bool persistent, 976 bool persistent,
903 const WallpaperInfo& info, 977 const WallpaperInfo& info,
904 scoped_ptr<gfx::ImageSkia> image, 978 scoped_ptr<gfx::ImageSkia> image,
905 const UserImage::RawImage& raw_image) { 979 const UserImage::RawImage& raw_image) {
906 DCHECK(BrowserThread::GetBlockingPool()-> 980 DCHECK(BrowserThread::GetBlockingPool()->
907 IsRunningSequenceOnCurrentThread(sequence_token_)); 981 IsRunningSequenceOnCurrentThread(sequence_token_));
908 UserImage wallpaper(*image.get(), raw_image); 982 UserImage wallpaper(*image.get(), raw_image);
909 if (persistent) { 983 if (persistent) {
910 SaveCustomWallpaper(email, base::FilePath(info.file), info.layout, 984 SaveCustomWallpaper(username_hash, base::FilePath(info.file), info.layout,
911 wallpaper); 985 wallpaper);
912 } 986 }
913 } 987 }
914 988
915 void WallpaperManager::SaveCustomWallpaper(const std::string& email, 989 void WallpaperManager::SaveCustomWallpaper(const std::string& username_hash,
916 const base::FilePath& original_path, 990 const base::FilePath& original_path,
917 ash::WallpaperLayout layout, 991 ash::WallpaperLayout layout,
918 const UserImage& wallpaper) { 992 const UserImage& wallpaper) {
919 DCHECK(BrowserThread::GetBlockingPool()-> 993 DCHECK(BrowserThread::GetBlockingPool()->
920 IsRunningSequenceOnCurrentThread(sequence_token_)); 994 IsRunningSequenceOnCurrentThread(sequence_token_));
921 EnsureCustomWallpaperDirectories(email); 995 EnsureCustomWallpaperDirectories(username_hash);
922 std::string file_name = original_path.BaseName().value(); 996 std::string file_name = original_path.BaseName().value();
923 base::FilePath small_wallpaper_path = 997 base::FilePath small_wallpaper_path =
924 GetCustomWallpaperPath(kSmallWallpaperSubDir, email, file_name); 998 GetCustomWallpaperPath(kSmallWallpaperSubDir, username_hash, file_name);
925 base::FilePath large_wallpaper_path = 999 base::FilePath large_wallpaper_path =
926 GetCustomWallpaperPath(kLargeWallpaperSubDir, email, file_name); 1000 GetCustomWallpaperPath(kLargeWallpaperSubDir, username_hash, file_name);
927 1001
928 // Re-encode orginal file to jpeg format and saves the result in case that 1002 // Re-encode orginal file to jpeg format and saves the result in case that
929 // resized wallpaper is not generated (i.e. chrome shutdown before resized 1003 // resized wallpaper is not generated (i.e. chrome shutdown before resized
930 // wallpaper is saved). 1004 // wallpaper is saved).
931 ResizeAndSaveWallpaper(wallpaper, original_path, 1005 ResizeAndSaveWallpaper(wallpaper, original_path,
932 ash::WALLPAPER_LAYOUT_STRETCH, 1006 ash::WALLPAPER_LAYOUT_STRETCH,
933 wallpaper.image().width(), 1007 wallpaper.image().width(),
934 wallpaper.image().height()); 1008 wallpaper.image().height());
935 DeleteAllExcept(original_path); 1009 DeleteAllExcept(original_path);
936 1010
(...skipping 30 matching lines...) Expand all
967 // |sequence_token_| here. 1041 // |sequence_token_| here.
968 wallpaper_loader_->Start(wallpaper_path.value(), 0, sequence_token_, 1042 wallpaper_loader_->Start(wallpaper_path.value(), 0, sequence_token_,
969 base::Bind(&WallpaperManager::OnWallpaperDecoded, 1043 base::Bind(&WallpaperManager::OnWallpaperDecoded,
970 base::Unretained(this), 1044 base::Unretained(this),
971 email, 1045 email,
972 info.layout, 1046 info.layout,
973 update_wallpaper)); 1047 update_wallpaper));
974 } 1048 }
975 1049
976 } // namespace chromeos 1050 } // namespace chromeos
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698