Chromium Code Reviews| 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.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 Loading... | |
| 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 910 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1158 } | 1157 } |
| 1159 | 1158 |
| 1160 void GDataFileSystem::OnTransferCompleted( | 1159 void GDataFileSystem::OnTransferCompleted( |
| 1161 const FileOperationCallback& callback, | 1160 const FileOperationCallback& callback, |
| 1162 base::PlatformFileError error, | 1161 base::PlatformFileError error, |
| 1163 scoped_ptr<UploadFileInfo> upload_file_info) { | 1162 scoped_ptr<UploadFileInfo> upload_file_info) { |
| 1164 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 1163 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| 1165 DCHECK(upload_file_info.get()); | 1164 DCHECK(upload_file_info.get()); |
| 1166 | 1165 |
| 1167 if (error == base::PLATFORM_FILE_OK && upload_file_info->entry.get()) { | 1166 if (error == base::PLATFORM_FILE_OK && upload_file_info->entry.get()) { |
| 1168 // Save a local copy of the UploadFileInfo pointer. Depending on order of | |
| 1169 // argument evaluation, base::Passed() may invalidate the scoped pointer | |
| 1170 // |upload_file_info| before it can be dereferenced to access its members. | |
| 1171 const UploadFileInfo* upload_file_info_ptr = upload_file_info.get(); | |
|
satorux1
2012/07/11 19:17:16
glad to see this brittle piece to be gone.
| |
| 1172 AddUploadedFile(UPLOAD_NEW_FILE, | 1167 AddUploadedFile(UPLOAD_NEW_FILE, |
| 1173 upload_file_info_ptr->gdata_path.DirName(), | 1168 upload_file_info->gdata_path.DirName(), |
| 1174 upload_file_info_ptr->entry.get(), | 1169 upload_file_info->entry.Pass(), |
| 1175 upload_file_info_ptr->file_path, | 1170 upload_file_info->file_path, |
| 1176 GDataCache::FILE_OPERATION_COPY, | 1171 GDataCache::FILE_OPERATION_COPY, |
| 1177 base::Bind(&OnAddUploadFileCompleted, | 1172 base::Bind(&OnAddUploadFileCompleted, callback, error)); |
| 1178 callback, | |
| 1179 error, | |
| 1180 base::Passed(&upload_file_info))); | |
| 1181 } else if (!callback.is_null()) { | 1173 } else if (!callback.is_null()) { |
| 1182 callback.Run(error); | 1174 callback.Run(error); |
| 1183 } | 1175 } |
| 1184 } | 1176 } |
| 1185 | 1177 |
| 1186 void GDataFileSystem::Copy(const FilePath& src_file_path, | 1178 void GDataFileSystem::Copy(const FilePath& src_file_path, |
| 1187 const FilePath& dest_file_path, | 1179 const FilePath& dest_file_path, |
| 1188 const FileOperationCallback& callback) { | 1180 const FileOperationCallback& callback) { |
| 1189 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI) || | 1181 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI) || |
| 1190 BrowserThread::CurrentlyOn(BrowserThread::IO)); | 1182 BrowserThread::CurrentlyOn(BrowserThread::IO)); |
| (...skipping 1189 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 2380 scoped_ptr<UploadFileInfo> upload_file_info) { | 2372 scoped_ptr<UploadFileInfo> upload_file_info) { |
| 2381 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 2373 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| 2382 DCHECK(upload_file_info.get()); | 2374 DCHECK(upload_file_info.get()); |
| 2383 | 2375 |
| 2384 if (error != base::PLATFORM_FILE_OK) { | 2376 if (error != base::PLATFORM_FILE_OK) { |
| 2385 if (!callback.is_null()) | 2377 if (!callback.is_null()) |
| 2386 callback.Run(error); | 2378 callback.Run(error); |
| 2387 return; | 2379 return; |
| 2388 } | 2380 } |
| 2389 | 2381 |
| 2390 // See comments in OnTransferCompleted() for why we copy this pointer. | |
| 2391 const UploadFileInfo* upload_file_info_ptr = upload_file_info.get(); | |
|
satorux1
2012/07/11 19:17:16
this one too.
| |
| 2392 AddUploadedFile(UPLOAD_EXISTING_FILE, | 2382 AddUploadedFile(UPLOAD_EXISTING_FILE, |
| 2393 upload_file_info_ptr->gdata_path.DirName(), | 2383 upload_file_info->gdata_path.DirName(), |
| 2394 upload_file_info_ptr->entry.get(), | 2384 upload_file_info->entry.Pass(), |
| 2395 upload_file_info_ptr->file_path, | 2385 upload_file_info->file_path, |
| 2396 GDataCache::FILE_OPERATION_MOVE, | 2386 GDataCache::FILE_OPERATION_MOVE, |
| 2397 base::Bind(&OnAddUploadFileCompleted, | 2387 base::Bind(&OnAddUploadFileCompleted, callback, error)); |
| 2398 callback, | |
| 2399 error, | |
| 2400 base::Passed(&upload_file_info))); | |
| 2401 } | 2388 } |
| 2402 | 2389 |
| 2403 void GDataFileSystem::GetAvailableSpace( | 2390 void GDataFileSystem::GetAvailableSpace( |
| 2404 const GetAvailableSpaceCallback& callback) { | 2391 const GetAvailableSpaceCallback& callback) { |
| 2405 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI) || | 2392 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI) || |
| 2406 BrowserThread::CurrentlyOn(BrowserThread::IO)); | 2393 BrowserThread::CurrentlyOn(BrowserThread::IO)); |
| 2407 RunTaskOnUIThread(base::Bind(&GDataFileSystem::GetAvailableSpaceOnUIThread, | 2394 RunTaskOnUIThread(base::Bind(&GDataFileSystem::GetAvailableSpaceOnUIThread, |
| 2408 ui_weak_ptr_, | 2395 ui_weak_ptr_, |
| 2409 CreateRelayCallback(callback))); | 2396 CreateRelayCallback(callback))); |
| 2410 } | 2397 } |
| (...skipping 1085 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 3496 if (!parent_dir->RemoveEntry(entry)) | 3483 if (!parent_dir->RemoveEntry(entry)) |
| 3497 return base::PLATFORM_FILE_ERROR_NOT_FOUND; | 3484 return base::PLATFORM_FILE_ERROR_NOT_FOUND; |
| 3498 | 3485 |
| 3499 NotifyDirectoryChanged(parent_dir->GetFilePath()); | 3486 NotifyDirectoryChanged(parent_dir->GetFilePath()); |
| 3500 return base::PLATFORM_FILE_OK; | 3487 return base::PLATFORM_FILE_OK; |
| 3501 } | 3488 } |
| 3502 | 3489 |
| 3503 void GDataFileSystem::AddUploadedFile( | 3490 void GDataFileSystem::AddUploadedFile( |
| 3504 UploadMode upload_mode, | 3491 UploadMode upload_mode, |
| 3505 const FilePath& virtual_dir_path, | 3492 const FilePath& virtual_dir_path, |
| 3506 DocumentEntry* entry, | 3493 scoped_ptr<DocumentEntry> entry, |
| 3507 const FilePath& file_content_path, | 3494 const FilePath& file_content_path, |
| 3508 GDataCache::FileOperationType cache_operation, | 3495 GDataCache::FileOperationType cache_operation, |
| 3509 const base::Closure& callback) { | 3496 const base::Closure& callback) { |
| 3510 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 3497 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| 3511 | 3498 |
| 3512 // Post a task to the same thread, rather than calling it here, as | 3499 // Post a task to the same thread, rather than calling it here, as |
| 3513 // AddUploadedFile() is asynchronous. | 3500 // AddUploadedFile() is asynchronous. |
| 3514 base::MessageLoopProxy::current()->PostTask( | 3501 base::MessageLoopProxy::current()->PostTask( |
| 3515 FROM_HERE, | 3502 FROM_HERE, |
| 3516 base::Bind(&GDataFileSystem::AddUploadedFileOnUIThread, | 3503 base::Bind(&GDataFileSystem::AddUploadedFileOnUIThread, |
| 3517 ui_weak_ptr_, | 3504 ui_weak_ptr_, |
| 3518 upload_mode, | 3505 upload_mode, |
| 3519 virtual_dir_path, | 3506 virtual_dir_path, |
| 3520 entry, | 3507 base::Passed(&entry), |
| 3521 file_content_path, | 3508 file_content_path, |
| 3522 cache_operation, | 3509 cache_operation, |
| 3523 callback)); | 3510 callback)); |
| 3524 } | 3511 } |
| 3525 | 3512 |
| 3526 void GDataFileSystem::AddUploadedFileOnUIThread( | 3513 void GDataFileSystem::AddUploadedFileOnUIThread( |
| 3527 UploadMode upload_mode, | 3514 UploadMode upload_mode, |
| 3528 const FilePath& virtual_dir_path, | 3515 const FilePath& virtual_dir_path, |
| 3529 DocumentEntry* entry, | 3516 scoped_ptr<DocumentEntry> entry, |
| 3530 const FilePath& file_content_path, | 3517 const FilePath& file_content_path, |
| 3531 GDataCache::FileOperationType cache_operation, | 3518 GDataCache::FileOperationType cache_operation, |
| 3532 const base::Closure& callback) { | 3519 const base::Closure& callback) { |
| 3533 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 3520 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| 3534 DCHECK(!callback.is_null()); | 3521 DCHECK(!callback.is_null()); |
| 3535 | 3522 |
| 3536 if (!entry) { | 3523 if (!entry.get()) { |
| 3537 NOTREACHED(); | 3524 NOTREACHED(); |
| 3538 callback.Run(); | 3525 callback.Run(); |
| 3539 return; | 3526 return; |
| 3540 } | 3527 } |
| 3541 | 3528 |
| 3542 GDataEntry* dir_entry = GetGDataEntryByPath(virtual_dir_path); | 3529 GDataEntry* dir_entry = GetGDataEntryByPath(virtual_dir_path); |
| 3543 if (!dir_entry) { | 3530 if (!dir_entry) { |
| 3544 callback.Run(); | 3531 callback.Run(); |
| 3545 return; | 3532 return; |
| 3546 } | 3533 } |
| 3547 | 3534 |
| 3548 GDataDirectory* parent_dir = dir_entry->AsGDataDirectory(); | 3535 GDataDirectory* parent_dir = dir_entry->AsGDataDirectory(); |
| 3549 if (!parent_dir) { | 3536 if (!parent_dir) { |
| 3550 callback.Run(); | 3537 callback.Run(); |
| 3551 return; | 3538 return; |
| 3552 } | 3539 } |
| 3553 | 3540 |
| 3554 scoped_ptr<GDataEntry> new_entry( | 3541 scoped_ptr<GDataEntry> new_entry( |
| 3555 GDataEntry::FromDocumentEntry(parent_dir, entry, root_.get())); | 3542 GDataEntry::FromDocumentEntry(parent_dir, entry.get(), root_.get())); |
| 3556 if (!new_entry.get()) { | 3543 if (!new_entry.get()) { |
| 3557 callback.Run(); | 3544 callback.Run(); |
| 3558 return; | 3545 return; |
| 3559 } | 3546 } |
| 3560 | 3547 |
| 3561 if (upload_mode == UPLOAD_EXISTING_FILE) { | 3548 if (upload_mode == UPLOAD_EXISTING_FILE) { |
| 3562 // Remove an existing entry, which should be present. | 3549 // Remove an existing entry, which should be present. |
| 3563 GDataEntry* existing_entry = root_->GetEntryByResourceId( | 3550 GDataEntry* existing_entry = root_->GetEntryByResourceId( |
| 3564 new_entry->resource_id()); | 3551 new_entry->resource_id()); |
| 3565 if (existing_entry && | 3552 if (existing_entry && |
| (...skipping 354 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 3920 // must go through here. Removes the |file_path| from the remembered set so | 3907 // must go through here. Removes the |file_path| from the remembered set so |
| 3921 // that subsequent operations can open the file again. | 3908 // that subsequent operations can open the file again. |
| 3922 open_files_.erase(file_path); | 3909 open_files_.erase(file_path); |
| 3923 | 3910 |
| 3924 // Then invokes the user-supplied callback function. | 3911 // Then invokes the user-supplied callback function. |
| 3925 if (!callback.is_null()) | 3912 if (!callback.is_null()) |
| 3926 callback.Run(result); | 3913 callback.Run(result); |
| 3927 } | 3914 } |
| 3928 | 3915 |
| 3929 } // namespace gdata | 3916 } // namespace gdata |
| OLD | NEW |