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/drive/file_system/remove_operation.h" | 5 #include "chrome/browser/chromeos/drive/file_system/remove_operation.h" |
| 6 | 6 |
| 7 #include "chrome/browser/chromeos/drive/drive.pb.h" | 7 #include "chrome/browser/chromeos/drive/drive.pb.h" |
| 8 #include "chrome/browser/chromeos/drive/file_cache.h" | 8 #include "chrome/browser/chromeos/drive/file_cache.h" |
| 9 #include "chrome/browser/chromeos/drive/file_system/operation_observer.h" | 9 #include "chrome/browser/chromeos/drive/file_system/operation_observer.h" |
| 10 #include "chrome/browser/chromeos/drive/file_system_util.h" | 10 #include "chrome/browser/chromeos/drive/file_system_util.h" |
| (...skipping 14 matching lines...) Expand all Loading... | |
| 25 metadata_(metadata), | 25 metadata_(metadata), |
| 26 cache_(cache), | 26 cache_(cache), |
| 27 weak_ptr_factory_(this) { | 27 weak_ptr_factory_(this) { |
| 28 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 28 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| 29 } | 29 } |
| 30 | 30 |
| 31 RemoveOperation::~RemoveOperation() { | 31 RemoveOperation::~RemoveOperation() { |
| 32 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 32 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| 33 } | 33 } |
| 34 | 34 |
| 35 void RemoveOperation::Remove(const base::FilePath& file_path, | 35 void RemoveOperation::Remove(const base::FilePath& path, |
| 36 bool is_recursive, | 36 bool is_recursive, |
| 37 const FileOperationCallback& callback) { | 37 const FileOperationCallback& callback) { |
| 38 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 38 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| 39 DCHECK(!callback.is_null()); | 39 DCHECK(!callback.is_null()); |
| 40 | 40 |
| 41 // Get the edit URL of an entry at |file_path|. | 41 // Get the edit URL of an entry at |path|. |
| 42 metadata_->GetResourceEntryByPathOnUIThread( | 42 metadata_->GetResourceEntryByPathOnUIThread( |
| 43 file_path, | 43 path, |
| 44 base::Bind( | 44 base::Bind( |
| 45 &RemoveOperation::RemoveAfterGetResourceEntry, | 45 &RemoveOperation::RemoveAfterGetResourceEntry, |
| 46 weak_ptr_factory_.GetWeakPtr(), | 46 weak_ptr_factory_.GetWeakPtr(), |
| 47 path, | |
| 48 is_recursive, | |
| 47 callback)); | 49 callback)); |
| 48 } | 50 } |
| 49 | 51 |
| 50 void RemoveOperation::RemoveAfterGetResourceEntry( | 52 void RemoveOperation::RemoveAfterGetResourceEntry( |
| 53 const base::FilePath& path, | |
| 54 bool is_recursive, | |
| 51 const FileOperationCallback& callback, | 55 const FileOperationCallback& callback, |
| 52 FileError error, | 56 FileError error, |
| 53 scoped_ptr<ResourceEntry> entry) { | 57 scoped_ptr<ResourceEntry> entry) { |
| 54 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 58 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| 55 DCHECK(!callback.is_null()); | 59 DCHECK(!callback.is_null()); |
| 56 | 60 |
| 57 if (error != FILE_ERROR_OK) { | 61 if (error != FILE_ERROR_OK) { |
| 58 callback.Run(error); | 62 callback.Run(error); |
| 59 return; | 63 return; |
| 60 } | 64 } |
| 61 DCHECK(entry); | 65 |
| 66 if (entry->file_info().is_directory() && !is_recursive) { | |
| 67 // Check emptiness of the directory. | |
| 68 metadata_->ReadDirectoryByPathOnUIThread( | |
| 69 path, | |
| 70 base::Bind(&RemoveOperation::RemoveAfterReadDirectory, | |
| 71 weak_ptr_factory_.GetWeakPtr(), | |
| 72 entry->resource_id(), | |
| 73 callback)); | |
| 74 return; | |
| 75 } | |
| 62 | 76 |
| 63 scheduler_->DeleteResource( | 77 scheduler_->DeleteResource( |
| 64 entry->resource_id(), | 78 entry->resource_id(), |
| 65 base::Bind(&RemoveOperation::RemoveResourceLocally, | 79 base::Bind(&RemoveOperation::RemoveResourceLocally, |
| 66 weak_ptr_factory_.GetWeakPtr(), | 80 weak_ptr_factory_.GetWeakPtr(), |
| 67 callback, | 81 callback, |
| 68 entry->resource_id())); | 82 entry->resource_id())); |
| 69 } | 83 } |
| 70 | 84 |
| 85 void RemoveOperation::RemoveAfterReadDirectory( | |
| 86 const std::string& resource_id, | |
| 87 const FileOperationCallback& callback, | |
| 88 FileError error, | |
| 89 scoped_ptr<ResourceEntryVector> entries) { | |
|
hashimoto
2013/05/28 02:34:45
nit: How about having DCHECKs for CurrentlyOn(Brow
kinaba
2013/05/28 03:31:28
Done.
| |
| 90 if (error != FILE_ERROR_OK) { | |
| 91 callback.Run(error); | |
| 92 return; | |
| 93 } | |
| 94 | |
| 95 if (!entries->empty()) { | |
| 96 callback.Run(FILE_ERROR_NOT_EMPTY); | |
| 97 return; | |
| 98 } | |
| 99 | |
| 100 scheduler_->DeleteResource( | |
| 101 resource_id, | |
| 102 base::Bind(&RemoveOperation::RemoveResourceLocally, | |
| 103 weak_ptr_factory_.GetWeakPtr(), | |
| 104 callback, | |
| 105 resource_id)); | |
| 106 } | |
| 107 | |
| 71 void RemoveOperation::RemoveResourceLocally( | 108 void RemoveOperation::RemoveResourceLocally( |
| 72 const FileOperationCallback& callback, | 109 const FileOperationCallback& callback, |
| 73 const std::string& resource_id, | 110 const std::string& resource_id, |
| 74 google_apis::GDataErrorCode status) { | 111 google_apis::GDataErrorCode status) { |
| 75 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 112 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| 76 DCHECK(!callback.is_null()); | 113 DCHECK(!callback.is_null()); |
| 77 | 114 |
| 78 FileError error = util::GDataToFileError(status); | 115 FileError error = util::GDataToFileError(status); |
| 79 if (error != FILE_ERROR_OK) { | 116 if (error != FILE_ERROR_OK) { |
| 80 callback.Run(error); | 117 callback.Run(error); |
| (...skipping 18 matching lines...) Expand all Loading... | |
| 99 DCHECK(!callback.is_null()); | 136 DCHECK(!callback.is_null()); |
| 100 | 137 |
| 101 if (error == FILE_ERROR_OK) | 138 if (error == FILE_ERROR_OK) |
| 102 observer_->OnDirectoryChangedByOperation(directory_path); | 139 observer_->OnDirectoryChangedByOperation(directory_path); |
| 103 | 140 |
| 104 callback.Run(error); | 141 callback.Run(error); |
| 105 } | 142 } |
| 106 | 143 |
| 107 } // namespace file_system | 144 } // namespace file_system |
| 108 } // namespace drive | 145 } // namespace drive |
| OLD | NEW |