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

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

Issue 18286004: Move PathExists to base namespace. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 7 years, 5 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 375 matching lines...) Expand 10 before | Expand all | Expand 10 after
386 return true; 386 return true;
387 } 387 }
388 388
389 void WallpaperManager::ResizeAndSaveWallpaper(const UserImage& wallpaper, 389 void WallpaperManager::ResizeAndSaveWallpaper(const UserImage& wallpaper,
390 const base::FilePath& path, 390 const base::FilePath& path,
391 ash::WallpaperLayout layout, 391 ash::WallpaperLayout layout,
392 int preferred_width, 392 int preferred_width,
393 int preferred_height) { 393 int preferred_height) {
394 if (layout == ash::WALLPAPER_LAYOUT_CENTER) { 394 if (layout == ash::WALLPAPER_LAYOUT_CENTER) {
395 // TODO(bshe): Generates cropped custom wallpaper for CENTER layout. 395 // TODO(bshe): Generates cropped custom wallpaper for CENTER layout.
396 if (file_util::PathExists(path)) 396 if (base::PathExists(path))
397 base::Delete(path, false); 397 base::Delete(path, false);
398 return; 398 return;
399 } 399 }
400 scoped_refptr<base::RefCountedBytes> data; 400 scoped_refptr<base::RefCountedBytes> data;
401 if (ResizeWallpaper(wallpaper, layout, preferred_width, preferred_height, 401 if (ResizeWallpaper(wallpaper, layout, preferred_width, preferred_height,
402 &data)) { 402 &data)) {
403 SaveWallpaperInternal(path, 403 SaveWallpaperInternal(path,
404 reinterpret_cast<const char*>(data->front()), 404 reinterpret_cast<const char*>(data->front()),
405 data->size()); 405 data->size());
406 } 406 }
(...skipping 317 matching lines...) Expand 10 before | Expand all | Expand 10 after
724 base::Bind(&WallpaperManager::DeleteWallpaperInList, 724 base::Bind(&WallpaperManager::DeleteWallpaperInList,
725 base::Unretained(this), 725 base::Unretained(this),
726 file_to_remove), 726 file_to_remove),
727 false); 727 false);
728 } 728 }
729 729
730 void WallpaperManager::EnsureCustomWallpaperDirectories( 730 void WallpaperManager::EnsureCustomWallpaperDirectories(
731 const std::string& email) { 731 const std::string& email) {
732 base::FilePath dir; 732 base::FilePath dir;
733 dir = GetCustomWallpaperDir(kSmallWallpaperSubDir, email); 733 dir = GetCustomWallpaperDir(kSmallWallpaperSubDir, email);
734 if (!file_util::PathExists(dir)) 734 if (!base::PathExists(dir))
735 file_util::CreateDirectory(dir); 735 file_util::CreateDirectory(dir);
736 dir = GetCustomWallpaperDir(kLargeWallpaperSubDir, email); 736 dir = GetCustomWallpaperDir(kLargeWallpaperSubDir, email);
737 if (!file_util::PathExists(dir)) 737 if (!base::PathExists(dir))
738 file_util::CreateDirectory(dir); 738 file_util::CreateDirectory(dir);
739 dir = GetCustomWallpaperDir(kOriginalWallpaperSubDir, email); 739 dir = GetCustomWallpaperDir(kOriginalWallpaperSubDir, email);
740 if (!file_util::PathExists(dir)) 740 if (!base::PathExists(dir))
741 file_util::CreateDirectory(dir); 741 file_util::CreateDirectory(dir);
742 dir = GetCustomWallpaperDir(kThumbnailWallpaperSubDir, email); 742 dir = GetCustomWallpaperDir(kThumbnailWallpaperSubDir, email);
743 if (!file_util::PathExists(dir)) 743 if (!base::PathExists(dir))
744 file_util::CreateDirectory(dir); 744 file_util::CreateDirectory(dir);
745 } 745 }
746 746
747 void WallpaperManager::FallbackToOldCustomWallpaper(const std::string& email, 747 void WallpaperManager::FallbackToOldCustomWallpaper(const std::string& email,
748 const WallpaperInfo& info, 748 const WallpaperInfo& info,
749 bool update_wallpaper){ 749 bool update_wallpaper){
750 ash::WallpaperResolution resolution = ash::Shell::GetInstance()-> 750 ash::WallpaperResolution resolution = ash::Shell::GetInstance()->
751 desktop_background_controller()->GetAppropriateResolution(); 751 desktop_background_controller()->GetAppropriateResolution();
752 bool is_small = resolution == ash::WALLPAPER_RESOLUTION_SMALL; 752 bool is_small = resolution == ash::WALLPAPER_RESOLUTION_SMALL;
753 base::FilePath wallpaper_path = GetWallpaperPathForUser(email, is_small); 753 base::FilePath wallpaper_path = GetWallpaperPathForUser(email, is_small);
(...skipping 85 matching lines...) Expand 10 before | Expand all | Expand 10 after
839 IsRunningSequenceOnCurrentThread(sequence_token_)); 839 IsRunningSequenceOnCurrentThread(sequence_token_));
840 840
841 base::FilePath from_path; 841 base::FilePath from_path;
842 base::FilePath to_path; 842 base::FilePath to_path;
843 // Move old custom wallpapers to new place for all existing users. 843 // Move old custom wallpapers to new place for all existing users.
844 for (UserList::const_iterator it = users.begin(); it != users.end(); ++it) { 844 for (UserList::const_iterator it = users.begin(); it != users.end(); ++it) {
845 std::string email = (*it)->email(); 845 std::string email = (*it)->email();
846 EnsureCustomWallpaperDirectories(email); 846 EnsureCustomWallpaperDirectories(email);
847 from_path = GetWallpaperPathForUser(email, true); 847 from_path = GetWallpaperPathForUser(email, true);
848 // Old wallpaper with extension name may still exist. 848 // Old wallpaper with extension name may still exist.
849 if (!file_util::PathExists(from_path)) 849 if (!base::PathExists(from_path))
850 from_path = from_path.AddExtension(".png"); 850 from_path = from_path.AddExtension(".png");
851 if (file_util::PathExists(from_path)) { 851 if (base::PathExists(from_path)) {
852 // Appends DUMMY to the file name of moved custom wallpaper. This way we 852 // Appends DUMMY to the file name of moved custom wallpaper. This way we
853 // do not need to update WallpaperInfo for user. 853 // do not need to update WallpaperInfo for user.
854 to_path = GetCustomWallpaperPath(kSmallWallpaperSubDir, email, "DUMMY"); 854 to_path = GetCustomWallpaperPath(kSmallWallpaperSubDir, email, "DUMMY");
855 base::Move(from_path, to_path); 855 base::Move(from_path, to_path);
856 } 856 }
857 from_path = GetWallpaperPathForUser(email, false); 857 from_path = GetWallpaperPathForUser(email, false);
858 if (!file_util::PathExists(from_path)) 858 if (!base::PathExists(from_path))
859 from_path = from_path.AddExtension(".png"); 859 from_path = from_path.AddExtension(".png");
860 if (file_util::PathExists(from_path)) { 860 if (base::PathExists(from_path)) {
861 to_path = GetCustomWallpaperPath(kLargeWallpaperSubDir, email, "DUMMY"); 861 to_path = GetCustomWallpaperPath(kLargeWallpaperSubDir, email, "DUMMY");
862 base::Move(from_path, to_path); 862 base::Move(from_path, to_path);
863 } 863 }
864 from_path = GetOriginalWallpaperPathForUser(email); 864 from_path = GetOriginalWallpaperPathForUser(email);
865 if (!file_util::PathExists(from_path)) 865 if (!base::PathExists(from_path))
866 from_path = from_path.AddExtension(".png"); 866 from_path = from_path.AddExtension(".png");
867 if (file_util::PathExists(from_path)) { 867 if (base::PathExists(from_path)) {
868 to_path = GetCustomWallpaperPath(kOriginalWallpaperSubDir, email, 868 to_path = GetCustomWallpaperPath(kOriginalWallpaperSubDir, email,
869 "DUMMY"); 869 "DUMMY");
870 base::Move(from_path, to_path); 870 base::Move(from_path, to_path);
871 } 871 }
872 } 872 }
873 } 873 }
874 874
875 bool WallpaperManager::GetUserWallpaperInfo(const std::string& email, 875 bool WallpaperManager::GetUserWallpaperInfo(const std::string& email,
876 WallpaperInfo* info){ 876 WallpaperInfo* info){
877 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 877 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after
915 915
916 void WallpaperManager::GetCustomWallpaperInternalOld( 916 void WallpaperManager::GetCustomWallpaperInternalOld(
917 const std::string& email, 917 const std::string& email,
918 const WallpaperInfo& info, 918 const WallpaperInfo& info,
919 const base::FilePath& wallpaper_path, 919 const base::FilePath& wallpaper_path,
920 bool update_wallpaper) { 920 bool update_wallpaper) {
921 DCHECK(BrowserThread::GetBlockingPool()-> 921 DCHECK(BrowserThread::GetBlockingPool()->
922 IsRunningSequenceOnCurrentThread(sequence_token_)); 922 IsRunningSequenceOnCurrentThread(sequence_token_));
923 std::string file_name = wallpaper_path.BaseName().value(); 923 std::string file_name = wallpaper_path.BaseName().value();
924 924
925 if (!file_util::PathExists(wallpaper_path)) { 925 if (!base::PathExists(wallpaper_path)) {
926 if (file_util::PathExists(wallpaper_path.AddExtension(".png"))) { 926 if (base::PathExists(wallpaper_path.AddExtension(".png"))) {
927 // Old wallpaper may have a png extension. 927 // Old wallpaper may have a png extension.
928 file_name += ".png"; 928 file_name += ".png";
929 } else { 929 } else {
930 // Falls back on original file if the correct resoltuion file does not 930 // Falls back on original file if the correct resoltuion file does not
931 // exist. This may happen when the original custom wallpaper is small or 931 // exist. This may happen when the original custom wallpaper is small or
932 // browser shutdown before resized wallpaper saved. 932 // browser shutdown before resized wallpaper saved.
933 file_name = GetOriginalWallpaperPathForUser(email).BaseName().value(); 933 file_name = GetOriginalWallpaperPathForUser(email).BaseName().value();
934 } 934 }
935 } 935 }
936 936
937 base::FilePath valid_path = wallpaper_path.DirName().Append(file_name); 937 base::FilePath valid_path = wallpaper_path.DirName().Append(file_name);
938 if (!file_util::PathExists(valid_path)) 938 if (!base::PathExists(valid_path))
939 valid_path = valid_path.AddExtension(".png"); 939 valid_path = valid_path.AddExtension(".png");
940 BrowserThread::PostTask( 940 BrowserThread::PostTask(
941 BrowserThread::UI, FROM_HERE, 941 BrowserThread::UI, FROM_HERE,
942 base::Bind(&WallpaperManager::StartLoad, base::Unretained(this), email, 942 base::Bind(&WallpaperManager::StartLoad, base::Unretained(this), email,
943 info, update_wallpaper, valid_path)); 943 info, update_wallpaper, valid_path));
944 BrowserThread::PostTask( 944 BrowserThread::PostTask(
945 BrowserThread::UI, FROM_HERE, 945 BrowserThread::UI, FROM_HERE,
946 base::Bind(&WallpaperManager::MoveCustomWallpapers, 946 base::Bind(&WallpaperManager::MoveCustomWallpapers,
947 base::Unretained(this))); 947 base::Unretained(this)));
948 } 948 }
949 949
950 void WallpaperManager::GetCustomWallpaperInternal( 950 void WallpaperManager::GetCustomWallpaperInternal(
951 const std::string& email, 951 const std::string& email,
952 const WallpaperInfo& info, 952 const WallpaperInfo& info,
953 const base::FilePath& wallpaper_path, 953 const base::FilePath& wallpaper_path,
954 bool update_wallpaper) { 954 bool update_wallpaper) {
955 DCHECK(BrowserThread::GetBlockingPool()-> 955 DCHECK(BrowserThread::GetBlockingPool()->
956 IsRunningSequenceOnCurrentThread(sequence_token_)); 956 IsRunningSequenceOnCurrentThread(sequence_token_));
957 957
958 base::FilePath valid_path = wallpaper_path; 958 base::FilePath valid_path = wallpaper_path;
959 if (!file_util::PathExists(wallpaper_path)) { 959 if (!base::PathExists(wallpaper_path)) {
960 // Falls back on original file if the correct resoltuion file does not 960 // Falls back on original file if the correct resoltuion file does not
961 // exist. This may happen when the original custom wallpaper is small or 961 // exist. This may happen when the original custom wallpaper is small or
962 // browser shutdown before resized wallpaper saved. 962 // browser shutdown before resized wallpaper saved.
963 valid_path = GetCustomWallpaperPath(kOriginalWallpaperSubDir, email, 963 valid_path = GetCustomWallpaperPath(kOriginalWallpaperSubDir, email,
964 info.file); 964 info.file);
965 } 965 }
966 966
967 if (!file_util::PathExists(valid_path)) { 967 if (!base::PathExists(valid_path)) {
968 BrowserThread::PostTask( 968 BrowserThread::PostTask(
969 BrowserThread::UI, 969 BrowserThread::UI,
970 FROM_HERE, 970 FROM_HERE,
971 base::Bind(&WallpaperManager::FallbackToOldCustomWallpaper, 971 base::Bind(&WallpaperManager::FallbackToOldCustomWallpaper,
972 base::Unretained(this), 972 base::Unretained(this),
973 email, 973 email,
974 info, 974 info,
975 update_wallpaper)); 975 update_wallpaper));
976 } else { 976 } else {
977 BrowserThread::PostTask(BrowserThread::UI, 977 BrowserThread::PostTask(BrowserThread::UI,
(...skipping 120 matching lines...) Expand 10 before | Expand all | Expand 10 after
1098 1098
1099 void WallpaperManager::SystemResumed(const base::TimeDelta& sleep_duration) { 1099 void WallpaperManager::SystemResumed(const base::TimeDelta& sleep_duration) {
1100 BatchUpdateWallpaper(); 1100 BatchUpdateWallpaper();
1101 } 1101 }
1102 1102
1103 void WallpaperManager::TimezoneChanged(const icu::TimeZone& timezone) { 1103 void WallpaperManager::TimezoneChanged(const icu::TimeZone& timezone) {
1104 RestartTimer(); 1104 RestartTimer();
1105 } 1105 }
1106 1106
1107 } // namespace chromeos 1107 } // namespace chromeos
OLDNEW
« no previous file with comments | « chrome/browser/chromeos/login/startup_utils.cc ('k') | chrome/browser/chromeos/login/wallpaper_manager_browsertest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698