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