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

Side by Side Diff: chrome/browser/chromeos/gdata/gdata_file_system_proxy.cc

Issue 10268023: gdata: Remove use of FindEntryByPathAsync() from gdata_file_system_proxy.cc (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: use GetEntryInfoByPathAsync instead Created 8 years, 7 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
« no previous file with comments | « chrome/browser/chromeos/gdata/gdata_file_system_proxy.h ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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
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 void GDataGDataEntryProtoToFileUtilProxyEntry(
achuithb 2012/05/01 09:21:44 GDataGData? I think one GData is sufficient? This
satorux1 2012/05/01 17:24:31 Good catch! Fixed.
60 const GDataEntry& gdata_entry) { 61 const GDataEntryProto& proto,
62 base::FileUtilProxy::Entry* entry) {
63 entry->name = proto.file_name();
64
65 base::PlatformFileInfo file_info;
66 GDataEntry::ConvertProtoToPlatformFileInfo(proto.file_info(), &file_info);
67 entry->size = file_info.size;
68 entry->last_modified_time = file_info.last_modified;
achuithb 2012/05/01 09:21:44 You should just set entry->is_directory here from
satorux1 2012/05/01 17:24:31 The code was so bad. Good to have a great code rev
69 }
70
71 base::FileUtilProxy::Entry GDataDirectoryProtoToFileUtilProxyEntry(
72 const GDataDirectoryProto& proto) {
61 base::FileUtilProxy::Entry entry; 73 base::FileUtilProxy::Entry entry;
62 entry.is_directory = gdata_entry.file_info().is_directory; 74 entry.is_directory = true;
63 75
64 // TODO(zelidrag): Add file name modification logic to enforce uniquness of 76 GDataGDataEntryProtoToFileUtilProxyEntry(proto.gdata_entry(), &entry);
65 // file paths across this file system.
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; 77 return entry;
71 } 78 }
72 79
80 base::FileUtilProxy::Entry GDataFileProtoToFileUtilProxyEntry(
81 const GDataFileProto & proto) {
82 base::FileUtilProxy::Entry entry;
83 entry.is_directory = false;
84
85 GDataGDataEntryProtoToFileUtilProxyEntry(proto.gdata_entry(), &entry);
86 return entry;
87 }
88
73 // GDataFileSystemProxy class implementation. 89 // GDataFileSystemProxy class implementation.
74 90
75 GDataFileSystemProxy::GDataFileSystemProxy( 91 GDataFileSystemProxy::GDataFileSystemProxy(
76 GDataFileSystemInterface* file_system) 92 GDataFileSystemInterface* file_system)
77 : file_system_(file_system) { 93 : file_system_(file_system) {
78 // Should be created from the file browser extension API (AddMountFunction) 94 // Should be created from the file browser extension API (AddMountFunction)
79 // on UI thread. 95 // on UI thread.
80 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 96 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
81 } 97 }
82 98
83 GDataFileSystemProxy::~GDataFileSystemProxy() { 99 GDataFileSystemProxy::~GDataFileSystemProxy() {
84 // Should be deleted from the CrosMountPointProvider on IO thread. 100 // Should be deleted from the CrosMountPointProvider on IO thread.
85 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); 101 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
86 } 102 }
87 103
88 void GDataFileSystemProxy::GetFileInfo(const GURL& file_url, 104 void GDataFileSystemProxy::GetFileInfo(const GURL& file_url,
89 const FileSystemOperationInterface::GetMetadataCallback& callback) { 105 const FileSystemOperationInterface::GetMetadataCallback& callback) {
90 FilePath file_path; 106 FilePath file_path;
91 if (!ValidateUrl(file_url, &file_path)) { 107 if (!ValidateUrl(file_url, &file_path)) {
92 base::MessageLoopProxy::current()->PostTask( 108 base::MessageLoopProxy::current()->PostTask(
93 FROM_HERE, 109 FROM_HERE,
94 base::Bind(callback, 110 base::Bind(callback,
95 base::PLATFORM_FILE_ERROR_NOT_FOUND, 111 base::PLATFORM_FILE_ERROR_NOT_FOUND,
96 base::PlatformFileInfo(), 112 base::PlatformFileInfo(),
97 FilePath())); 113 FilePath()));
98 return; 114 return;
99 } 115 }
100 116
101 file_system_->FindEntryByPathAsync( 117 file_system_->GetEntryInfoByPathAsync(
102 file_path, 118 file_path,
103 base::Bind(&GDataFileSystemProxy::OnGetMetadata, 119 base::Bind(&GDataFileSystemProxy::OnGetMetadata,
104 this, 120 this,
105 file_path, 121 file_path,
106 callback)); 122 callback));
107 } 123 }
108 124
109 void GDataFileSystemProxy::Copy(const GURL& src_file_url, 125 void GDataFileSystemProxy::Copy(const GURL& src_file_url,
110 const GURL& dest_file_url, 126 const GURL& dest_file_url,
111 const FileSystemOperationInterface::StatusCallback& callback) { 127 const FileSystemOperationInterface::StatusCallback& callback) {
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after
145 if (!ValidateUrl(file_url, &file_path)) { 161 if (!ValidateUrl(file_url, &file_path)) {
146 base::MessageLoopProxy::current()->PostTask( 162 base::MessageLoopProxy::current()->PostTask(
147 FROM_HERE, 163 FROM_HERE,
148 base::Bind(callback, 164 base::Bind(callback,
149 base::PLATFORM_FILE_ERROR_NOT_FOUND, 165 base::PLATFORM_FILE_ERROR_NOT_FOUND,
150 std::vector<base::FileUtilProxy::Entry>(), 166 std::vector<base::FileUtilProxy::Entry>(),
151 false)); 167 false));
152 return; 168 return;
153 } 169 }
154 170
155 file_system_->FindEntryByPathAsync( 171 file_system_->ReadDirectoryByPathAsync(
156 file_path, 172 file_path,
157 base::Bind(&GDataFileSystemProxy::OnReadDirectory, 173 base::Bind(&GDataFileSystemProxy::OnReadDirectory,
158 this, 174 this,
159 file_system_->hide_hosted_documents(), 175 file_system_->hide_hosted_documents(),
160 callback)); 176 callback));
161 } 177 }
162 178
163 void GDataFileSystemProxy::Remove(const GURL& file_url, bool recursive, 179 void GDataFileSystemProxy::Remove(const GURL& file_url, bool recursive,
164 const FileSystemOperationInterface::StatusCallback& callback) { 180 const FileSystemOperationInterface::StatusCallback& callback) {
165 FilePath file_path; 181 FilePath file_path;
(...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after
220 type != fileapi::kFileSystemTypeExternal) { 236 type != fileapi::kFileSystemTypeExternal) {
221 return false; 237 return false;
222 } 238 }
223 return true; 239 return true;
224 } 240 }
225 241
226 void GDataFileSystemProxy::OnGetMetadata( 242 void GDataFileSystemProxy::OnGetMetadata(
227 const FilePath& file_path, 243 const FilePath& file_path,
228 const FileSystemOperationInterface::GetMetadataCallback& callback, 244 const FileSystemOperationInterface::GetMetadataCallback& callback,
229 base::PlatformFileError error, 245 base::PlatformFileError error,
230 const FilePath& directory_path, 246 scoped_ptr<gdata::GDataEntryProto> entry_proto) {
231 GDataEntry* entry) {
232 if (error != base::PLATFORM_FILE_OK) { 247 if (error != base::PLATFORM_FILE_OK) {
233 callback.Run(error, base::PlatformFileInfo(), FilePath()); 248 callback.Run(error, base::PlatformFileInfo(), FilePath());
234 return; 249 return;
235 } 250 }
251 DCHECK(entry_proto.get());
236 252
237 callback.Run(base::PLATFORM_FILE_OK, entry->file_info(), file_path); 253 base::PlatformFileInfo file_info;
254 GDataEntry::ConvertProtoToPlatformFileInfo(
255 entry_proto->file_info(),
256 &file_info);
257
258 callback.Run(base::PLATFORM_FILE_OK, file_info, file_path);
238 } 259 }
239 260
240 void GDataFileSystemProxy::OnReadDirectory( 261 void GDataFileSystemProxy::OnReadDirectory(
241 bool hide_hosted_documents, 262 bool hide_hosted_documents,
242 const FileSystemOperationInterface::ReadDirectoryCallback& 263 const FileSystemOperationInterface::ReadDirectoryCallback&
243 callback, 264 callback,
244 base::PlatformFileError error, 265 base::PlatformFileError error,
245 const FilePath& directory_path, 266 scoped_ptr<gdata::GDataDirectoryProto> directory_proto) {
246 GDataEntry* entry) { 267 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 268
253 if (error != base::PLATFORM_FILE_OK) { 269 if (error != base::PLATFORM_FILE_OK) {
254 callback.Run(error, std::vector<base::FileUtilProxy::Entry>(), false); 270 callback.Run(error, std::vector<base::FileUtilProxy::Entry>(), false);
255 return; 271 return;
256 } 272 }
257 std::vector<base::FileUtilProxy::Entry> entries; 273 std::vector<base::FileUtilProxy::Entry> entries;
258 // Convert gdata files to something File API stack can understand. 274 // Convert gdata files to something File API stack can understand.
259 for (GDataDirectoryCollection::const_iterator iter = 275 for (int i = 0; i < directory_proto->child_directories_size(); ++i) {
260 directory->child_directories().begin(); 276 const GDataDirectoryProto& proto = directory_proto->child_directories(i);
261 iter != directory->child_directories().end(); ++iter) { 277 entries.push_back(GDataDirectoryProtoToFileUtilProxyEntry(proto));
262 entries.push_back(GDataEntryToFileUtilProxyEntry(*(iter->second)));
263 } 278 }
264 for (GDataFileCollection::const_iterator iter = 279 for (int i = 0; i < directory_proto->child_files_size(); ++i) {
265 directory->child_files().begin(); 280 const GDataFileProto& proto = directory_proto->child_files(i);
266 iter != directory->child_files().end(); ++iter) { 281 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; 282 continue;
271 } 283 entries.push_back(GDataFileProtoToFileUtilProxyEntry(proto));
272 entries.push_back(GDataEntryToFileUtilProxyEntry(*(iter->second)));
273 } 284 }
274 285
275 callback.Run(base::PLATFORM_FILE_OK, entries, false); 286 callback.Run(base::PLATFORM_FILE_OK, entries, false);
276 } 287 }
277 288
278 } // namespace gdata 289 } // namespace gdata
OLDNEW
« no previous file with comments | « chrome/browser/chromeos/gdata/gdata_file_system_proxy.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698