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 <string> | 7 #include <string> |
8 #include <vector> | 8 #include <vector> |
9 | 9 |
10 #include "base/bind.h" | 10 #include "base/bind.h" |
11 #include "base/platform_file.h" | 11 #include "base/platform_file.h" |
12 #include "base/string_util.h" | 12 #include "base/string_util.h" |
13 #include "base/values.h" | 13 #include "base/values.h" |
14 #include "content/public/browser/browser_thread.h" | 14 #include "content/public/browser/browser_thread.h" |
| 15 #include "chrome/browser/chromeos/gdata/gdata.pb.h" |
15 #include "chrome/browser/chromeos/gdata/gdata_system_service.h" | 16 #include "chrome/browser/chromeos/gdata/gdata_system_service.h" |
16 #include "chrome/browser/chromeos/gdata/gdata_file_system.h" | 17 #include "chrome/browser/chromeos/gdata/gdata_file_system.h" |
17 #include "webkit/blob/shareable_file_reference.h" | 18 #include "webkit/blob/shareable_file_reference.h" |
18 #include "webkit/fileapi/file_system_file_util_proxy.h" | 19 #include "webkit/fileapi/file_system_file_util_proxy.h" |
19 #include "webkit/fileapi/file_system_types.h" | 20 #include "webkit/fileapi/file_system_types.h" |
20 #include "webkit/fileapi/file_system_util.h" | 21 #include "webkit/fileapi/file_system_util.h" |
21 | 22 |
22 using base::MessageLoopProxy; | 23 using base::MessageLoopProxy; |
23 using content::BrowserThread; | 24 using content::BrowserThread; |
24 using fileapi::FileSystemOperationInterface; | 25 using fileapi::FileSystemOperationInterface; |
(...skipping 24 matching lines...) Expand all Loading... |
49 BrowserThread::GetMessageLoopProxyForThread(BrowserThread::FILE)); | 50 BrowserThread::GetMessageLoopProxyForThread(BrowserThread::FILE)); |
50 } | 51 } |
51 | 52 |
52 callback.Run(error, file_info, local_path, file_ref); | 53 callback.Run(error, file_info, local_path, file_ref); |
53 } | 54 } |
54 | 55 |
55 } // namespace | 56 } // namespace |
56 | 57 |
57 namespace gdata { | 58 namespace gdata { |
58 | 59 |
59 base::FileUtilProxy::Entry GDataEntryToFileUtilProxyEntry( | 60 base::FileUtilProxy::Entry GDataEntryProtoToFileUtilProxyEntry( |
60 const GDataEntry& gdata_entry) { | 61 const GDataEntryProto& proto) { |
| 62 base::PlatformFileInfo file_info; |
| 63 GDataEntry::ConvertProtoToPlatformFileInfo(proto.file_info(), &file_info); |
| 64 |
61 base::FileUtilProxy::Entry entry; | 65 base::FileUtilProxy::Entry entry; |
62 entry.is_directory = gdata_entry.file_info().is_directory; | 66 entry.name = proto.file_name(); |
63 | 67 entry.is_directory = file_info.is_directory; |
64 // TODO(zelidrag): Add file name modification logic to enforce uniquness of | 68 entry.size = file_info.size; |
65 // file paths across this file system. | 69 entry.last_modified_time = file_info.last_modified; |
66 entry.name = gdata_entry.file_name(); | |
67 | |
68 entry.size = gdata_entry.file_info().size; | |
69 entry.last_modified_time = gdata_entry.file_info().last_modified; | |
70 return entry; | 70 return entry; |
71 } | 71 } |
72 | 72 |
73 // GDataFileSystemProxy class implementation. | 73 // GDataFileSystemProxy class implementation. |
74 | 74 |
75 GDataFileSystemProxy::GDataFileSystemProxy( | 75 GDataFileSystemProxy::GDataFileSystemProxy( |
76 GDataFileSystemInterface* file_system) | 76 GDataFileSystemInterface* file_system) |
77 : file_system_(file_system) { | 77 : file_system_(file_system) { |
78 // Should be created from the file browser extension API (AddMountFunction) | 78 // Should be created from the file browser extension API (AddMountFunction) |
79 // on UI thread. | 79 // on UI thread. |
(...skipping 11 matching lines...) Expand all Loading... |
91 if (!ValidateUrl(file_url, &file_path)) { | 91 if (!ValidateUrl(file_url, &file_path)) { |
92 base::MessageLoopProxy::current()->PostTask( | 92 base::MessageLoopProxy::current()->PostTask( |
93 FROM_HERE, | 93 FROM_HERE, |
94 base::Bind(callback, | 94 base::Bind(callback, |
95 base::PLATFORM_FILE_ERROR_NOT_FOUND, | 95 base::PLATFORM_FILE_ERROR_NOT_FOUND, |
96 base::PlatformFileInfo(), | 96 base::PlatformFileInfo(), |
97 FilePath())); | 97 FilePath())); |
98 return; | 98 return; |
99 } | 99 } |
100 | 100 |
101 file_system_->FindEntryByPathAsync( | 101 file_system_->GetEntryInfoByPathAsync( |
102 file_path, | 102 file_path, |
103 base::Bind(&GDataFileSystemProxy::OnGetMetadata, | 103 base::Bind(&GDataFileSystemProxy::OnGetMetadata, |
104 this, | 104 this, |
105 file_path, | 105 file_path, |
106 callback)); | 106 callback)); |
107 } | 107 } |
108 | 108 |
109 void GDataFileSystemProxy::Copy(const GURL& src_file_url, | 109 void GDataFileSystemProxy::Copy(const GURL& src_file_url, |
110 const GURL& dest_file_url, | 110 const GURL& dest_file_url, |
111 const FileSystemOperationInterface::StatusCallback& callback) { | 111 const FileSystemOperationInterface::StatusCallback& callback) { |
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
145 if (!ValidateUrl(file_url, &file_path)) { | 145 if (!ValidateUrl(file_url, &file_path)) { |
146 base::MessageLoopProxy::current()->PostTask( | 146 base::MessageLoopProxy::current()->PostTask( |
147 FROM_HERE, | 147 FROM_HERE, |
148 base::Bind(callback, | 148 base::Bind(callback, |
149 base::PLATFORM_FILE_ERROR_NOT_FOUND, | 149 base::PLATFORM_FILE_ERROR_NOT_FOUND, |
150 std::vector<base::FileUtilProxy::Entry>(), | 150 std::vector<base::FileUtilProxy::Entry>(), |
151 false)); | 151 false)); |
152 return; | 152 return; |
153 } | 153 } |
154 | 154 |
155 file_system_->FindEntryByPathAsync( | 155 file_system_->ReadDirectoryByPathAsync( |
156 file_path, | 156 file_path, |
157 base::Bind(&GDataFileSystemProxy::OnReadDirectory, | 157 base::Bind(&GDataFileSystemProxy::OnReadDirectory, |
158 this, | 158 this, |
159 file_system_->hide_hosted_documents(), | 159 file_system_->hide_hosted_documents(), |
160 callback)); | 160 callback)); |
161 } | 161 } |
162 | 162 |
163 void GDataFileSystemProxy::Remove(const GURL& file_url, bool recursive, | 163 void GDataFileSystemProxy::Remove(const GURL& file_url, bool recursive, |
164 const FileSystemOperationInterface::StatusCallback& callback) { | 164 const FileSystemOperationInterface::StatusCallback& callback) { |
165 FilePath file_path; | 165 FilePath file_path; |
(...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
220 type != fileapi::kFileSystemTypeExternal) { | 220 type != fileapi::kFileSystemTypeExternal) { |
221 return false; | 221 return false; |
222 } | 222 } |
223 return true; | 223 return true; |
224 } | 224 } |
225 | 225 |
226 void GDataFileSystemProxy::OnGetMetadata( | 226 void GDataFileSystemProxy::OnGetMetadata( |
227 const FilePath& file_path, | 227 const FilePath& file_path, |
228 const FileSystemOperationInterface::GetMetadataCallback& callback, | 228 const FileSystemOperationInterface::GetMetadataCallback& callback, |
229 base::PlatformFileError error, | 229 base::PlatformFileError error, |
230 const FilePath& directory_path, | 230 scoped_ptr<gdata::GDataEntryProto> entry_proto) { |
231 GDataEntry* entry) { | |
232 if (error != base::PLATFORM_FILE_OK) { | 231 if (error != base::PLATFORM_FILE_OK) { |
233 callback.Run(error, base::PlatformFileInfo(), FilePath()); | 232 callback.Run(error, base::PlatformFileInfo(), FilePath()); |
234 return; | 233 return; |
235 } | 234 } |
| 235 DCHECK(entry_proto.get()); |
236 | 236 |
237 callback.Run(base::PLATFORM_FILE_OK, entry->file_info(), file_path); | 237 base::PlatformFileInfo file_info; |
| 238 GDataEntry::ConvertProtoToPlatformFileInfo( |
| 239 entry_proto->file_info(), |
| 240 &file_info); |
| 241 |
| 242 callback.Run(base::PLATFORM_FILE_OK, file_info, file_path); |
238 } | 243 } |
239 | 244 |
240 void GDataFileSystemProxy::OnReadDirectory( | 245 void GDataFileSystemProxy::OnReadDirectory( |
241 bool hide_hosted_documents, | 246 bool hide_hosted_documents, |
242 const FileSystemOperationInterface::ReadDirectoryCallback& | 247 const FileSystemOperationInterface::ReadDirectoryCallback& |
243 callback, | 248 callback, |
244 base::PlatformFileError error, | 249 base::PlatformFileError error, |
245 const FilePath& directory_path, | 250 scoped_ptr<gdata::GDataDirectoryProto> directory_proto) { |
246 GDataEntry* entry) { | 251 DCHECK(error != base::PLATFORM_FILE_OK); |
247 DCHECK(entry || error != base::PLATFORM_FILE_OK); | |
248 | |
249 GDataDirectory* directory = entry ? entry->AsGDataDirectory() : NULL; | |
250 if (!directory && error == base::PLATFORM_FILE_OK) | |
251 error = base::PLATFORM_FILE_ERROR_NOT_A_DIRECTORY; | |
252 | 252 |
253 if (error != base::PLATFORM_FILE_OK) { | 253 if (error != base::PLATFORM_FILE_OK) { |
254 callback.Run(error, std::vector<base::FileUtilProxy::Entry>(), false); | 254 callback.Run(error, std::vector<base::FileUtilProxy::Entry>(), false); |
255 return; | 255 return; |
256 } | 256 } |
257 std::vector<base::FileUtilProxy::Entry> entries; | 257 std::vector<base::FileUtilProxy::Entry> entries; |
258 // Convert gdata files to something File API stack can understand. | 258 // Convert gdata files to something File API stack can understand. |
259 for (GDataDirectoryCollection::const_iterator iter = | 259 for (int i = 0; i < directory_proto->child_directories_size(); ++i) { |
260 directory->child_directories().begin(); | 260 const GDataDirectoryProto& proto = directory_proto->child_directories(i); |
261 iter != directory->child_directories().end(); ++iter) { | 261 entries.push_back( |
262 entries.push_back(GDataEntryToFileUtilProxyEntry(*(iter->second))); | 262 GDataEntryProtoToFileUtilProxyEntry(proto.gdata_entry())); |
263 } | 263 } |
264 for (GDataFileCollection::const_iterator iter = | 264 for (int i = 0; i < directory_proto->child_files_size(); ++i) { |
265 directory->child_files().begin(); | 265 const GDataFileProto& proto = directory_proto->child_files(i); |
266 iter != directory->child_files().end(); ++iter) { | 266 if (hide_hosted_documents && proto.is_hosted_document()) |
267 if (hide_hosted_documents) { | |
268 GDataFile* file = iter->second; | |
269 if (file->is_hosted_document()) | |
270 continue; | 267 continue; |
271 } | 268 entries.push_back( |
272 entries.push_back(GDataEntryToFileUtilProxyEntry(*(iter->second))); | 269 GDataEntryProtoToFileUtilProxyEntry(proto.gdata_entry())); |
273 } | 270 } |
274 | 271 |
275 callback.Run(base::PLATFORM_FILE_OK, entries, false); | 272 callback.Run(base::PLATFORM_FILE_OK, entries, false); |
276 } | 273 } |
277 | 274 |
278 } // namespace gdata | 275 } // namespace gdata |
OLD | NEW |