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

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

Issue 10735059: gdata cleanup: Make GDataFileSystem::AddUploadedFile() take scoped_ptr<DocumentEntry>. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Rebase @ revision 146183. Created 8 years, 5 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
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.h" 5 #include "chrome/browser/chromeos/gdata/gdata_file_system.h"
6 6
7 #include <set> 7 #include <set>
8 #include <utility> 8 #include <utility>
9 9
10 #include "base/bind.h" 10 #include "base/bind.h"
(...skipping 215 matching lines...) Expand 10 before | Expand all | Expand 10 after
226 const std::string& /* md5 */) { 226 const std::string& /* md5 */) {
227 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 227 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
228 if (!callback.is_null()) 228 if (!callback.is_null())
229 callback.Run(); 229 callback.Run();
230 } 230 }
231 231
232 // Helper function called upon completion of AddUploadFile invoked by 232 // Helper function called upon completion of AddUploadFile invoked by
233 // OnTransferCompleted. 233 // OnTransferCompleted.
234 void OnAddUploadFileCompleted( 234 void OnAddUploadFileCompleted(
235 const FileOperationCallback& callback, 235 const FileOperationCallback& callback,
236 base::PlatformFileError error, 236 base::PlatformFileError error) {
237 scoped_ptr<UploadFileInfo> /* upload_file_info */) {
238 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 237 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
239 if (!callback.is_null()) 238 if (!callback.is_null())
240 callback.Run(error); 239 callback.Run(error);
241 } 240 }
242 241
243 // The class to wait for the initial load of root feed and runs the callback 242 // The class to wait for the initial load of root feed and runs the callback
244 // after the initialization. 243 // after the initialization.
245 class InitialLoadObserver : public GDataFileSystemInterface::Observer { 244 class InitialLoadObserver : public GDataFileSystemInterface::Observer {
246 public: 245 public:
247 InitialLoadObserver(GDataFileSystemInterface* file_system, 246 InitialLoadObserver(GDataFileSystemInterface* file_system,
(...skipping 948 matching lines...) Expand 10 before | Expand all | Expand 10 after
1196 } 1195 }
1197 1196
1198 void GDataFileSystem::OnTransferCompleted( 1197 void GDataFileSystem::OnTransferCompleted(
1199 const FileOperationCallback& callback, 1198 const FileOperationCallback& callback,
1200 base::PlatformFileError error, 1199 base::PlatformFileError error,
1201 scoped_ptr<UploadFileInfo> upload_file_info) { 1200 scoped_ptr<UploadFileInfo> upload_file_info) {
1202 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 1201 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
1203 DCHECK(upload_file_info.get()); 1202 DCHECK(upload_file_info.get());
1204 1203
1205 if (error == base::PLATFORM_FILE_OK && upload_file_info->entry.get()) { 1204 if (error == base::PLATFORM_FILE_OK && upload_file_info->entry.get()) {
1206 // Save a local copy of the UploadFileInfo pointer. Depending on order of
1207 // argument evaluation, base::Passed() may invalidate the scoped pointer
1208 // |upload_file_info| before it can be dereferenced to access its members.
1209 const UploadFileInfo* upload_file_info_ptr = upload_file_info.get();
1210 AddUploadedFile(UPLOAD_NEW_FILE, 1205 AddUploadedFile(UPLOAD_NEW_FILE,
1211 upload_file_info_ptr->gdata_path.DirName(), 1206 upload_file_info->gdata_path.DirName(),
1212 upload_file_info_ptr->entry.get(), 1207 upload_file_info->entry.Pass(),
1213 upload_file_info_ptr->file_path, 1208 upload_file_info->file_path,
1214 GDataCache::FILE_OPERATION_COPY, 1209 GDataCache::FILE_OPERATION_COPY,
1215 base::Bind(&OnAddUploadFileCompleted, 1210 base::Bind(&OnAddUploadFileCompleted, callback, error));
1216 callback,
1217 error,
1218 base::Passed(&upload_file_info)));
1219 } else if (!callback.is_null()) { 1211 } else if (!callback.is_null()) {
1220 callback.Run(error); 1212 callback.Run(error);
1221 } 1213 }
1222 } 1214 }
1223 1215
1224 void GDataFileSystem::Copy(const FilePath& src_file_path, 1216 void GDataFileSystem::Copy(const FilePath& src_file_path,
1225 const FilePath& dest_file_path, 1217 const FilePath& dest_file_path,
1226 const FileOperationCallback& callback) { 1218 const FileOperationCallback& callback) {
1227 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI) || 1219 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI) ||
1228 BrowserThread::CurrentlyOn(BrowserThread::IO)); 1220 BrowserThread::CurrentlyOn(BrowserThread::IO));
(...skipping 1189 matching lines...) Expand 10 before | Expand all | Expand 10 after
2418 scoped_ptr<UploadFileInfo> upload_file_info) { 2410 scoped_ptr<UploadFileInfo> upload_file_info) {
2419 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 2411 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
2420 DCHECK(upload_file_info.get()); 2412 DCHECK(upload_file_info.get());
2421 2413
2422 if (error != base::PLATFORM_FILE_OK) { 2414 if (error != base::PLATFORM_FILE_OK) {
2423 if (!callback.is_null()) 2415 if (!callback.is_null())
2424 callback.Run(error); 2416 callback.Run(error);
2425 return; 2417 return;
2426 } 2418 }
2427 2419
2428 // See comments in OnTransferCompleted() for why we copy this pointer.
2429 const UploadFileInfo* upload_file_info_ptr = upload_file_info.get();
2430 AddUploadedFile(UPLOAD_EXISTING_FILE, 2420 AddUploadedFile(UPLOAD_EXISTING_FILE,
2431 upload_file_info_ptr->gdata_path.DirName(), 2421 upload_file_info->gdata_path.DirName(),
2432 upload_file_info_ptr->entry.get(), 2422 upload_file_info->entry.Pass(),
2433 upload_file_info_ptr->file_path, 2423 upload_file_info->file_path,
2434 GDataCache::FILE_OPERATION_MOVE, 2424 GDataCache::FILE_OPERATION_MOVE,
2435 base::Bind(&OnAddUploadFileCompleted, 2425 base::Bind(&OnAddUploadFileCompleted, callback, error));
2436 callback,
2437 error,
2438 base::Passed(&upload_file_info)));
2439 } 2426 }
2440 2427
2441 void GDataFileSystem::GetAvailableSpace( 2428 void GDataFileSystem::GetAvailableSpace(
2442 const GetAvailableSpaceCallback& callback) { 2429 const GetAvailableSpaceCallback& callback) {
2443 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI) || 2430 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI) ||
2444 BrowserThread::CurrentlyOn(BrowserThread::IO)); 2431 BrowserThread::CurrentlyOn(BrowserThread::IO));
2445 RunTaskOnUIThread(base::Bind(&GDataFileSystem::GetAvailableSpaceOnUIThread, 2432 RunTaskOnUIThread(base::Bind(&GDataFileSystem::GetAvailableSpaceOnUIThread,
2446 ui_weak_ptr_, 2433 ui_weak_ptr_,
2447 CreateRelayCallback(callback))); 2434 CreateRelayCallback(callback)));
2448 } 2435 }
(...skipping 1076 matching lines...) Expand 10 before | Expand all | Expand 10 after
3525 if (!parent_dir->RemoveEntry(entry)) 3512 if (!parent_dir->RemoveEntry(entry))
3526 return base::PLATFORM_FILE_ERROR_NOT_FOUND; 3513 return base::PLATFORM_FILE_ERROR_NOT_FOUND;
3527 3514
3528 NotifyDirectoryChanged(parent_dir->GetFilePath()); 3515 NotifyDirectoryChanged(parent_dir->GetFilePath());
3529 return base::PLATFORM_FILE_OK; 3516 return base::PLATFORM_FILE_OK;
3530 } 3517 }
3531 3518
3532 void GDataFileSystem::AddUploadedFile( 3519 void GDataFileSystem::AddUploadedFile(
3533 UploadMode upload_mode, 3520 UploadMode upload_mode,
3534 const FilePath& virtual_dir_path, 3521 const FilePath& virtual_dir_path,
3535 DocumentEntry* entry, 3522 scoped_ptr<DocumentEntry> entry,
3536 const FilePath& file_content_path, 3523 const FilePath& file_content_path,
3537 GDataCache::FileOperationType cache_operation, 3524 GDataCache::FileOperationType cache_operation,
3538 const base::Closure& callback) { 3525 const base::Closure& callback) {
3539 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 3526 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
3540 3527
3541 // Post a task to the same thread, rather than calling it here, as 3528 // Post a task to the same thread, rather than calling it here, as
3542 // AddUploadedFile() is asynchronous. 3529 // AddUploadedFile() is asynchronous.
3543 base::MessageLoopProxy::current()->PostTask( 3530 base::MessageLoopProxy::current()->PostTask(
3544 FROM_HERE, 3531 FROM_HERE,
3545 base::Bind(&GDataFileSystem::AddUploadedFileOnUIThread, 3532 base::Bind(&GDataFileSystem::AddUploadedFileOnUIThread,
3546 ui_weak_ptr_, 3533 ui_weak_ptr_,
3547 upload_mode, 3534 upload_mode,
3548 virtual_dir_path, 3535 virtual_dir_path,
3549 entry, 3536 base::Passed(&entry),
3550 file_content_path, 3537 file_content_path,
3551 cache_operation, 3538 cache_operation,
3552 callback)); 3539 callback));
3553 } 3540 }
3554 3541
3555 void GDataFileSystem::AddUploadedFileOnUIThread( 3542 void GDataFileSystem::AddUploadedFileOnUIThread(
3556 UploadMode upload_mode, 3543 UploadMode upload_mode,
3557 const FilePath& virtual_dir_path, 3544 const FilePath& virtual_dir_path,
3558 DocumentEntry* entry, 3545 scoped_ptr<DocumentEntry> entry,
3559 const FilePath& file_content_path, 3546 const FilePath& file_content_path,
3560 GDataCache::FileOperationType cache_operation, 3547 GDataCache::FileOperationType cache_operation,
3561 const base::Closure& callback) { 3548 const base::Closure& callback) {
3562 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 3549 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
3563 DCHECK(!callback.is_null()); 3550 DCHECK(!callback.is_null());
3564 3551
3565 if (!entry) { 3552 if (!entry.get()) {
3566 NOTREACHED(); 3553 NOTREACHED();
3567 callback.Run(); 3554 callback.Run();
3568 return; 3555 return;
3569 } 3556 }
3570 3557
3571 GDataEntry* dir_entry = GetGDataEntryByPath(virtual_dir_path); 3558 GDataEntry* dir_entry = GetGDataEntryByPath(virtual_dir_path);
3572 if (!dir_entry) { 3559 if (!dir_entry) {
3573 callback.Run(); 3560 callback.Run();
3574 return; 3561 return;
3575 } 3562 }
3576 3563
3577 GDataDirectory* parent_dir = dir_entry->AsGDataDirectory(); 3564 GDataDirectory* parent_dir = dir_entry->AsGDataDirectory();
3578 if (!parent_dir) { 3565 if (!parent_dir) {
3579 callback.Run(); 3566 callback.Run();
3580 return; 3567 return;
3581 } 3568 }
3582 3569
3583 scoped_ptr<GDataEntry> new_entry( 3570 scoped_ptr<GDataEntry> new_entry(
3584 GDataEntry::FromDocumentEntry(parent_dir, entry, root_.get())); 3571 GDataEntry::FromDocumentEntry(parent_dir, entry.get(), root_.get()));
3585 if (!new_entry.get()) { 3572 if (!new_entry.get()) {
3586 callback.Run(); 3573 callback.Run();
3587 return; 3574 return;
3588 } 3575 }
3589 3576
3590 if (upload_mode == UPLOAD_EXISTING_FILE) { 3577 if (upload_mode == UPLOAD_EXISTING_FILE) {
3591 // Remove an existing entry, which should be present. 3578 // Remove an existing entry, which should be present.
3592 const std::string& resource_id = new_entry->resource_id(); 3579 const std::string& resource_id = new_entry->resource_id();
3593 root_->GetEntryByResourceIdAsync(resource_id, 3580 root_->GetEntryByResourceIdAsync(resource_id,
3594 base::Bind(&RemoveStaleEntryOnUpload, resource_id, parent_dir)); 3581 base::Bind(&RemoveStaleEntryOnUpload, resource_id, parent_dir));
(...skipping 347 matching lines...) Expand 10 before | Expand all | Expand 10 after
3942 // must go through here. Removes the |file_path| from the remembered set so 3929 // must go through here. Removes the |file_path| from the remembered set so
3943 // that subsequent operations can open the file again. 3930 // that subsequent operations can open the file again.
3944 open_files_.erase(file_path); 3931 open_files_.erase(file_path);
3945 3932
3946 // Then invokes the user-supplied callback function. 3933 // Then invokes the user-supplied callback function.
3947 if (!callback.is_null()) 3934 if (!callback.is_null())
3948 callback.Run(result); 3935 callback.Run(result);
3949 } 3936 }
3950 3937
3951 } // namespace gdata 3938 } // namespace gdata
OLDNEW
« no previous file with comments | « chrome/browser/chromeos/gdata/gdata_file_system.h ('k') | chrome/browser/chromeos/gdata/mock_gdata_file_system.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698