OLD | NEW |
---|---|
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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/gdata/gdata_file_system_proxy.h" | 5 #include "chrome/browser/chromeos/gdata/gdata_file_system_proxy.h" |
6 | 6 |
7 #include <vector> | |
8 | |
7 #include "base/bind.h" | 9 #include "base/bind.h" |
8 #include "base/platform_file.h" | 10 #include "base/platform_file.h" |
9 #include "base/string_util.h" | 11 #include "base/string_util.h" |
10 #include "base/values.h" | 12 #include "base/values.h" |
11 #include "content/public/browser/browser_thread.h" | 13 #include "content/public/browser/browser_thread.h" |
12 #include "webkit/fileapi/file_system_file_util_proxy.h" | 14 #include "webkit/fileapi/file_system_file_util_proxy.h" |
13 #include "webkit/fileapi/file_system_types.h" | 15 #include "webkit/fileapi/file_system_types.h" |
14 #include "webkit/fileapi/file_system_util.h" | 16 #include "webkit/fileapi/file_system_util.h" |
15 | 17 |
16 using base::MessageLoopProxy; | 18 using base::MessageLoopProxy; |
17 using content::BrowserThread; | 19 using content::BrowserThread; |
18 using fileapi::FileSystemOperationInterface; | 20 using fileapi::FileSystemOperationInterface; |
19 | 21 |
20 namespace { | 22 namespace { |
21 | 23 |
22 const char kGDataRootDirectory[] = "gdata"; | 24 const char kGDataRootDirectory[] = "gdata"; |
23 const char kFeedField[] = "feed"; | 25 const char kFeedField[] = "feed"; |
24 | 26 |
25 } // namespace | 27 } // namespace |
26 | 28 |
27 namespace gdata { | 29 namespace gdata { |
28 | 30 |
29 base::FileUtilProxy::Entry GDataFileToFileUtilProxyEntry( | 31 base::FileUtilProxy::Entry GDataFileToFileUtilProxyEntry( |
30 const GDataFileBase& file) { | 32 const GDataFileBase& file) { |
31 base::FileUtilProxy::Entry entry; | 33 base::FileUtilProxy::Entry entry; |
32 entry.is_directory = file.file_info().is_directory; | 34 entry.is_directory = file.file_info().is_directory; |
33 | 35 |
34 // TODO(zelidrag): Add file name modification logic to enforce uniquness of | 36 // TODO(zelidrag): Add file name modification logic to enforce uniquness of |
35 // file paths across this file system. | 37 // file paths across this file system. |
36 entry.name = file.file_name(); | 38 entry.name = file.file_name(); |
zel
2012/03/12 20:46:46
aren't you supposed to append GDataFileBase::docum
Ben Chan
2012/03/13 00:29:21
GDataFile::file_name_ should already include the d
| |
37 | 39 |
38 entry.size = file.file_info().size; | 40 entry.size = file.file_info().size; |
39 entry.last_modified_time = file.file_info().last_modified; | 41 entry.last_modified_time = file.file_info().last_modified; |
40 return entry; | 42 return entry; |
41 } | 43 } |
42 | 44 |
43 // GetFileInfoDelegate is used to handle results of proxy's content search | 45 // GetFileInfoDelegate is used to handle results of proxy's content search |
44 // during GetFileInfo call and route reply to the calling message loop. | 46 // during GetFileInfo call and route reply to the calling message loop. |
45 class GetFileInfoDelegate : public FindFileDelegateReplyBase { | 47 class GetFileInfoDelegate : public FindFileDelegateReplyBase { |
46 public: | 48 public: |
(...skipping 17 matching lines...) Expand all Loading... | |
64 GDataDirectory* dir) OVERRIDE { | 66 GDataDirectory* dir) OVERRIDE { |
65 DCHECK(dir); | 67 DCHECK(dir); |
66 Reply(base::PLATFORM_FILE_OK, dir->file_info(), search_file_path_); | 68 Reply(base::PLATFORM_FILE_OK, dir->file_info(), search_file_path_); |
67 } | 69 } |
68 | 70 |
69 virtual void OnError(base::PlatformFileError error) OVERRIDE { | 71 virtual void OnError(base::PlatformFileError error) OVERRIDE { |
70 Reply(error, base::PlatformFileInfo(), FilePath()); | 72 Reply(error, base::PlatformFileInfo(), FilePath()); |
71 } | 73 } |
72 | 74 |
73 private: | 75 private: |
74 | |
75 // Relays reply back to the callback on calling thread. | 76 // Relays reply back to the callback on calling thread. |
76 void Reply(base::PlatformFileError result, | 77 void Reply(base::PlatformFileError result, |
77 const base::PlatformFileInfo& file_info, | 78 const base::PlatformFileInfo& file_info, |
78 const FilePath& platform_path) { | 79 const FilePath& platform_path) { |
79 if (!callback_.is_null()) { | 80 if (!callback_.is_null()) { |
80 reply_message_proxy_->PostTask(FROM_HERE, | 81 reply_message_proxy_->PostTask(FROM_HERE, |
81 Bind(&GetFileInfoDelegate::ReplyOnCallingThread, | 82 Bind(&GetFileInfoDelegate::ReplyOnCallingThread, |
82 this, | 83 this, |
83 result, | 84 result, |
84 file_info, | 85 file_info, |
(...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
144 | 145 |
145 GURL unused; | 146 GURL unused; |
146 Reply(base::PLATFORM_FILE_OK, results, directory->NeedsRefresh(&unused)); | 147 Reply(base::PLATFORM_FILE_OK, results, directory->NeedsRefresh(&unused)); |
147 } | 148 } |
148 | 149 |
149 virtual void OnError(base::PlatformFileError error) OVERRIDE { | 150 virtual void OnError(base::PlatformFileError error) OVERRIDE { |
150 Reply(error, std::vector<base::FileUtilProxy::Entry>(), false); | 151 Reply(error, std::vector<base::FileUtilProxy::Entry>(), false); |
151 } | 152 } |
152 | 153 |
153 private: | 154 private: |
154 | |
155 // Relays reply back to the callback on calling thread. | 155 // Relays reply back to the callback on calling thread. |
156 void Reply(base::PlatformFileError result, | 156 void Reply(base::PlatformFileError result, |
157 const std::vector<base::FileUtilProxy::Entry>& file_list, | 157 const std::vector<base::FileUtilProxy::Entry>& file_list, |
158 bool has_more) { | 158 bool has_more) { |
159 if (!callback_.is_null()) { | 159 if (!callback_.is_null()) { |
160 reply_message_proxy_->PostTask(FROM_HERE, | 160 reply_message_proxy_->PostTask(FROM_HERE, |
161 Bind(&ReadDirectoryDelegate::ReplyOnCallingThread, | 161 Bind(&ReadDirectoryDelegate::ReplyOnCallingThread, |
162 this, | 162 this, |
163 result, | 163 result, |
164 file_list, | 164 file_list, |
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
200 scoped_refptr<GetFileInfoDelegate> delegate( | 200 scoped_refptr<GetFileInfoDelegate> delegate( |
201 new GetFileInfoDelegate(file_system_, FilePath(), callback)); | 201 new GetFileInfoDelegate(file_system_, FilePath(), callback)); |
202 delegate->OnError(base::PLATFORM_FILE_ERROR_NOT_FOUND); | 202 delegate->OnError(base::PLATFORM_FILE_ERROR_NOT_FOUND); |
203 return; | 203 return; |
204 } | 204 } |
205 | 205 |
206 file_system_->FindFileByPath( | 206 file_system_->FindFileByPath( |
207 file_path, new GetFileInfoDelegate(file_system_, file_path, callback)); | 207 file_path, new GetFileInfoDelegate(file_system_, file_path, callback)); |
208 } | 208 } |
209 | 209 |
210 void GDataFileSystemProxy::Copy(const GURL& src_file_url, | |
211 const GURL& dest_file_url, | |
212 const FileSystemOperationInterface::StatusCallback& callback) { | |
213 FilePath src_file_path, dest_file_path; | |
214 if (!ValidateUrl(src_file_url, &src_file_path) || | |
215 !ValidateUrl(dest_file_url, &dest_file_path)) { | |
216 MessageLoopProxy::current()->PostTask(FROM_HERE, | |
217 base::Bind(callback, base::PLATFORM_FILE_ERROR_NOT_FOUND)); | |
218 return; | |
219 } | |
220 | |
221 file_system_->Copy(src_file_path, dest_file_path, callback); | |
222 } | |
223 | |
224 void GDataFileSystemProxy::Move(const GURL& src_file_url, | |
225 const GURL& dest_file_url, | |
226 const FileSystemOperationInterface::StatusCallback& callback) { | |
227 FilePath src_file_path, dest_file_path; | |
228 if (!ValidateUrl(src_file_url, &src_file_path) || | |
229 !ValidateUrl(dest_file_url, &dest_file_path)) { | |
230 MessageLoopProxy::current()->PostTask(FROM_HERE, | |
231 base::Bind(callback, base::PLATFORM_FILE_ERROR_NOT_FOUND)); | |
232 return; | |
233 } | |
234 | |
235 file_system_->Move(src_file_path, dest_file_path, callback); | |
236 } | |
210 | 237 |
211 void GDataFileSystemProxy::ReadDirectory(const GURL& file_url, | 238 void GDataFileSystemProxy::ReadDirectory(const GURL& file_url, |
212 const FileSystemOperationInterface::ReadDirectoryCallback& callback) { | 239 const FileSystemOperationInterface::ReadDirectoryCallback& callback) { |
213 FilePath file_path; | 240 FilePath file_path; |
214 if (!ValidateUrl(file_url, &file_path)) { | 241 if (!ValidateUrl(file_url, &file_path)) { |
215 scoped_refptr<ReadDirectoryDelegate> delegate( | 242 scoped_refptr<ReadDirectoryDelegate> delegate( |
216 new ReadDirectoryDelegate(file_system_, FilePath(), callback)); | 243 new ReadDirectoryDelegate(file_system_, FilePath(), callback)); |
217 delegate->OnError(base::PLATFORM_FILE_ERROR_NOT_FOUND); | 244 delegate->OnError(base::PLATFORM_FILE_ERROR_NOT_FOUND); |
218 return; | 245 return; |
219 } | 246 } |
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
255 FilePath raw_path; | 282 FilePath raw_path; |
256 fileapi::FileSystemType type = fileapi::kFileSystemTypeUnknown; | 283 fileapi::FileSystemType type = fileapi::kFileSystemTypeUnknown; |
257 if (!fileapi::CrackFileSystemURL(url, NULL, &type, file_path) || | 284 if (!fileapi::CrackFileSystemURL(url, NULL, &type, file_path) || |
258 type != fileapi::kFileSystemTypeExternal) { | 285 type != fileapi::kFileSystemTypeExternal) { |
259 return false; | 286 return false; |
260 } | 287 } |
261 return true; | 288 return true; |
262 } | 289 } |
263 | 290 |
264 } // namespace gdata | 291 } // namespace gdata |
OLD | NEW |