| 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/ash_switches.h" | 9 #include "ash/ash_switches.h" |
| 10 #include "ash/desktop_background/desktop_background_controller.h" | 10 #include "ash/desktop_background/desktop_background_controller.h" |
| (...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 65 bool SaveData(int key, const std::string& file_name, const std::string& data) { | 65 bool SaveData(int key, const std::string& file_name, const std::string& data) { |
| 66 base::FilePath data_dir; | 66 base::FilePath data_dir; |
| 67 CHECK(PathService::Get(key, &data_dir)); | 67 CHECK(PathService::Get(key, &data_dir)); |
| 68 if (!base::DirectoryExists(data_dir) && | 68 if (!base::DirectoryExists(data_dir) && |
| 69 !base::CreateDirectory(data_dir)) { | 69 !base::CreateDirectory(data_dir)) { |
| 70 return false; | 70 return false; |
| 71 } | 71 } |
| 72 base::FilePath file_path = data_dir.Append(file_name); | 72 base::FilePath file_path = data_dir.Append(file_name); |
| 73 | 73 |
| 74 return base::PathExists(file_path) || | 74 return base::PathExists(file_path) || |
| 75 (file_util::WriteFile(file_path, data.c_str(), | 75 (base::WriteFile(file_path, data.c_str(), data.size()) != -1); |
| 76 data.size()) != -1); | |
| 77 } | 76 } |
| 78 | 77 |
| 79 // Gets |file_name| from directory with |key|. Return false if the directory can | 78 // Gets |file_name| from directory with |key|. Return false if the directory can |
| 80 // not be found or failed to read file to string |data|. Note if the |file_name| | 79 // not be found or failed to read file to string |data|. Note if the |file_name| |
| 81 // can not be found in the directory, return true with empty |data|. It is | 80 // can not be found in the directory, return true with empty |data|. It is |
| 82 // expected that we may try to access file which did not saved yet. | 81 // expected that we may try to access file which did not saved yet. |
| 83 bool GetData(const base::FilePath& path, std::string* data) { | 82 bool GetData(const base::FilePath& path, std::string* data) { |
| 84 base::FilePath data_dir = path.DirName(); | 83 base::FilePath data_dir = path.DirName(); |
| 85 if (!base::DirectoryExists(data_dir) && | 84 if (!base::DirectoryExists(data_dir) && |
| 86 !base::CreateDirectory(data_dir)) | 85 !base::CreateDirectory(data_dir)) |
| (...skipping 763 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 850 this, file_list)); | 849 this, file_list)); |
| 851 } | 850 } |
| 852 | 851 |
| 853 void WallpaperPrivateGetOfflineWallpaperListFunction::OnComplete( | 852 void WallpaperPrivateGetOfflineWallpaperListFunction::OnComplete( |
| 854 const std::vector<std::string>& file_list) { | 853 const std::vector<std::string>& file_list) { |
| 855 base::ListValue* results = new base::ListValue(); | 854 base::ListValue* results = new base::ListValue(); |
| 856 results->AppendStrings(file_list); | 855 results->AppendStrings(file_list); |
| 857 SetResult(results); | 856 SetResult(results); |
| 858 SendResponse(true); | 857 SendResponse(true); |
| 859 } | 858 } |
| OLD | NEW |