| 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/extensions/wallpaper_private_api.h" | 5 #include "chrome/browser/chromeos/extensions/wallpaper_private_api.h" |
| 6 | 6 |
| 7 #include <vector> | 7 #include <vector> |
| 8 | 8 |
| 9 #include "ash/shell.h" | 9 #include "ash/shell.h" |
| 10 #include "ash/wm/window_cycle_controller.h" | 10 #include "ash/wm/window_cycle_controller.h" |
| (...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 70 } | 70 } |
| 71 // Default to use CENTER layout. | 71 // Default to use CENTER layout. |
| 72 return ash::WALLPAPER_LAYOUT_CENTER; | 72 return ash::WALLPAPER_LAYOUT_CENTER; |
| 73 } | 73 } |
| 74 | 74 |
| 75 // Saves |data| as |file_name| to directory with |key|. Return false if the | 75 // Saves |data| as |file_name| to directory with |key|. Return false if the |
| 76 // directory can not be found/created or failed to write file. | 76 // directory can not be found/created or failed to write file. |
| 77 bool SaveData(int key, const std::string& file_name, const std::string& data) { | 77 bool SaveData(int key, const std::string& file_name, const std::string& data) { |
| 78 base::FilePath data_dir; | 78 base::FilePath data_dir; |
| 79 CHECK(PathService::Get(key, &data_dir)); | 79 CHECK(PathService::Get(key, &data_dir)); |
| 80 if (!file_util::DirectoryExists(data_dir) && | 80 if (!base::DirectoryExists(data_dir) && |
| 81 !file_util::CreateDirectory(data_dir)) { | 81 !file_util::CreateDirectory(data_dir)) { |
| 82 return false; | 82 return false; |
| 83 } | 83 } |
| 84 base::FilePath file_path = data_dir.Append(file_name); | 84 base::FilePath file_path = data_dir.Append(file_name); |
| 85 | 85 |
| 86 return base::PathExists(file_path) || | 86 return base::PathExists(file_path) || |
| 87 (file_util::WriteFile(file_path, data.c_str(), | 87 (file_util::WriteFile(file_path, data.c_str(), |
| 88 data.size()) != -1); | 88 data.size()) != -1); |
| 89 } | 89 } |
| 90 | 90 |
| 91 // Gets |file_name| from directory with |key|. Return false if the directory can | 91 // Gets |file_name| from directory with |key|. Return false if the directory can |
| 92 // not be found or failed to read file to string |data|. Note if the |file_name| | 92 // not be found or failed to read file to string |data|. Note if the |file_name| |
| 93 // can not be found in the directory, return true with empty |data|. It is | 93 // can not be found in the directory, return true with empty |data|. It is |
| 94 // expected that we may try to access file which did not saved yet. | 94 // expected that we may try to access file which did not saved yet. |
| 95 bool GetData(const base::FilePath& path, std::string* data) { | 95 bool GetData(const base::FilePath& path, std::string* data) { |
| 96 base::FilePath data_dir = path.DirName(); | 96 base::FilePath data_dir = path.DirName(); |
| 97 if (!file_util::DirectoryExists(data_dir) && | 97 if (!base::DirectoryExists(data_dir) && |
| 98 !file_util::CreateDirectory(data_dir)) | 98 !file_util::CreateDirectory(data_dir)) |
| 99 return false; | 99 return false; |
| 100 | 100 |
| 101 return !base::PathExists(path) || | 101 return !base::PathExists(path) || |
| 102 file_util::ReadFileToString(path, data); | 102 file_util::ReadFileToString(path, data); |
| 103 } | 103 } |
| 104 | 104 |
| 105 class WindowStateManager; | 105 class WindowStateManager; |
| 106 | 106 |
| 107 // static | 107 // static |
| (...skipping 778 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 886 const std::string& email, | 886 const std::string& email, |
| 887 const std::string& source) { | 887 const std::string& source) { |
| 888 DCHECK(BrowserThread::GetBlockingPool()->IsRunningSequenceOnCurrentThread( | 888 DCHECK(BrowserThread::GetBlockingPool()->IsRunningSequenceOnCurrentThread( |
| 889 sequence_token_)); | 889 sequence_token_)); |
| 890 std::vector<std::string> file_list; | 890 std::vector<std::string> file_list; |
| 891 // TODO(bshe): This api function is only used for ONLINE wallpapers. Remove | 891 // TODO(bshe): This api function is only used for ONLINE wallpapers. Remove |
| 892 // source. | 892 // source. |
| 893 if (source == kOnlineSource) { | 893 if (source == kOnlineSource) { |
| 894 base::FilePath wallpaper_dir; | 894 base::FilePath wallpaper_dir; |
| 895 CHECK(PathService::Get(chrome::DIR_CHROMEOS_WALLPAPERS, &wallpaper_dir)); | 895 CHECK(PathService::Get(chrome::DIR_CHROMEOS_WALLPAPERS, &wallpaper_dir)); |
| 896 if (file_util::DirectoryExists(wallpaper_dir)) { | 896 if (base::DirectoryExists(wallpaper_dir)) { |
| 897 base::FileEnumerator files(wallpaper_dir, false, | 897 base::FileEnumerator files(wallpaper_dir, false, |
| 898 base::FileEnumerator::FILES); | 898 base::FileEnumerator::FILES); |
| 899 for (base::FilePath current = files.Next(); !current.empty(); | 899 for (base::FilePath current = files.Next(); !current.empty(); |
| 900 current = files.Next()) { | 900 current = files.Next()) { |
| 901 std::string file_name = current.BaseName().RemoveExtension().value(); | 901 std::string file_name = current.BaseName().RemoveExtension().value(); |
| 902 // Do not add file name of small resolution wallpaper to the list. | 902 // Do not add file name of small resolution wallpaper to the list. |
| 903 if (!EndsWith(file_name, chromeos::kSmallWallpaperSuffix, true)) | 903 if (!EndsWith(file_name, chromeos::kSmallWallpaperSuffix, true)) |
| 904 file_list.push_back(current.BaseName().value()); | 904 file_list.push_back(current.BaseName().value()); |
| 905 } | 905 } |
| 906 } | 906 } |
| 907 } | 907 } |
| 908 BrowserThread::PostTask( | 908 BrowserThread::PostTask( |
| 909 BrowserThread::UI, FROM_HERE, | 909 BrowserThread::UI, FROM_HERE, |
| 910 base::Bind(&WallpaperPrivateGetOfflineWallpaperListFunction::OnComplete, | 910 base::Bind(&WallpaperPrivateGetOfflineWallpaperListFunction::OnComplete, |
| 911 this, file_list)); | 911 this, file_list)); |
| 912 } | 912 } |
| 913 | 913 |
| 914 void WallpaperPrivateGetOfflineWallpaperListFunction::OnComplete( | 914 void WallpaperPrivateGetOfflineWallpaperListFunction::OnComplete( |
| 915 const std::vector<std::string>& file_list) { | 915 const std::vector<std::string>& file_list) { |
| 916 ListValue* results = new ListValue(); | 916 ListValue* results = new ListValue(); |
| 917 results->AppendStrings(file_list); | 917 results->AppendStrings(file_list); |
| 918 SetResult(results); | 918 SetResult(results); |
| 919 SendResponse(true); | 919 SendResponse(true); |
| 920 } | 920 } |
| OLD | NEW |