Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 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/sync/entry_revert_performer.h" | 5 #include "chrome/browser/chromeos/drive/sync/entry_revert_performer.h" |
| 6 | 6 |
| 7 #include "chrome/browser/chromeos/drive/change_list_processor.h" | 7 #include "chrome/browser/chromeos/drive/change_list_processor.h" |
| 8 #include "chrome/browser/chromeos/drive/drive.pb.h" | 8 #include "chrome/browser/chromeos/drive/drive.pb.h" |
| 9 #include "chrome/browser/chromeos/drive/file_change.h" | |
| 9 #include "chrome/browser/chromeos/drive/file_system/operation_observer.h" | 10 #include "chrome/browser/chromeos/drive/file_system/operation_observer.h" |
| 10 #include "chrome/browser/chromeos/drive/job_scheduler.h" | 11 #include "chrome/browser/chromeos/drive/job_scheduler.h" |
| 11 #include "chrome/browser/chromeos/drive/resource_entry_conversion.h" | 12 #include "chrome/browser/chromeos/drive/resource_entry_conversion.h" |
| 12 #include "chrome/browser/chromeos/drive/resource_metadata.h" | 13 #include "chrome/browser/chromeos/drive/resource_metadata.h" |
| 13 #include "chrome/browser/drive/drive_api_util.h" | 14 #include "chrome/browser/drive/drive_api_util.h" |
| 14 #include "content/public/browser/browser_thread.h" | 15 #include "content/public/browser/browser_thread.h" |
| 15 #include "google_apis/drive/drive_api_parser.h" | 16 #include "google_apis/drive/drive_api_parser.h" |
| 16 | 17 |
| 17 using content::BrowserThread; | 18 using content::BrowserThread; |
| 18 | 19 |
| 19 namespace drive { | 20 namespace drive { |
| 20 namespace internal { | 21 namespace internal { |
| 21 namespace { | 22 namespace { |
| 22 | 23 |
| 23 FileError FinishRevert(ResourceMetadata* metadata, | 24 FileError FinishRevert(ResourceMetadata* metadata, |
| 24 const std::string& local_id, | 25 const std::string& local_id, |
| 25 google_apis::GDataErrorCode status, | 26 google_apis::GDataErrorCode status, |
| 26 scoped_ptr<google_apis::FileResource> file_resource, | 27 scoped_ptr<google_apis::FileResource> file_resource, |
| 27 std::set<base::FilePath>* changed_directories) { | 28 FileChange* changed_files) { |
| 28 ResourceEntry entry; | 29 ResourceEntry entry; |
| 29 std::string parent_resource_id; | 30 std::string parent_resource_id; |
| 30 FileError error = GDataToFileError(status); | 31 FileError error = GDataToFileError(status); |
| 31 switch (error) { | 32 switch (error) { |
| 32 case FILE_ERROR_OK: | 33 case FILE_ERROR_OK: |
| 33 if (!ConvertFileResourceToResourceEntry(*file_resource, &entry, | 34 if (!ConvertFileResourceToResourceEntry(*file_resource, &entry, |
| 34 &parent_resource_id)) | 35 &parent_resource_id)) |
| 35 return FILE_ERROR_NOT_A_FILE; | 36 return FILE_ERROR_NOT_A_FILE; |
| 36 break; | 37 break; |
| 37 | 38 |
| 38 case FILE_ERROR_NOT_FOUND: | 39 case FILE_ERROR_NOT_FOUND: |
| 39 entry.set_deleted(true); | 40 entry.set_deleted(true); |
| 40 break; | 41 break; |
| 41 | 42 |
| 42 default: | 43 default: |
| 43 return error; | 44 return error; |
| 44 } | 45 } |
| 45 | 46 |
| 46 base::FilePath original_path; | 47 base::FilePath original_path; |
| 47 error = metadata->GetFilePath(local_id, &original_path); | 48 error = metadata->GetFilePath(local_id, &original_path); |
| 48 if (error != FILE_ERROR_OK) | 49 if (error != FILE_ERROR_OK) |
| 49 return error; | 50 return error; |
| 50 | 51 |
| 51 if (entry.deleted()) { | 52 if (entry.deleted()) { |
| 52 error = metadata->RemoveEntry(local_id); | 53 error = metadata->RemoveEntry(local_id); |
| 53 if (error != FILE_ERROR_OK) | 54 if (error != FILE_ERROR_OK) |
| 54 return error; | 55 return error; |
| 55 | 56 |
| 56 changed_directories->insert(original_path.DirName()); | 57 changed_files->Update(original_path, |
| 58 FileChange::FILE_TYPE_FILE, | |
|
kinaba
2014/06/23 05:37:43
File type may be FILE or DIRECTORY here.
yoshiki
2014/06/24 02:02:22
Done.
| |
| 59 FileChange::DELETE); | |
| 57 } else { | 60 } else { |
| 58 error = ChangeListProcessor::SetParentLocalIdOfEntry(metadata, &entry, | 61 error = ChangeListProcessor::SetParentLocalIdOfEntry(metadata, &entry, |
| 59 parent_resource_id); | 62 parent_resource_id); |
| 60 if (error != FILE_ERROR_OK) | 63 if (error != FILE_ERROR_OK) |
| 61 return error; | 64 return error; |
| 62 | 65 |
| 63 entry.set_local_id(local_id); | 66 entry.set_local_id(local_id); |
| 64 error = metadata->RefreshEntry(entry); | 67 error = metadata->RefreshEntry(entry); |
| 65 if (error != FILE_ERROR_OK) | 68 if (error != FILE_ERROR_OK) |
| 66 return error; | 69 return error; |
| 67 | 70 |
| 68 base::FilePath new_parent_path; | 71 base::FilePath new_path; |
| 69 error = metadata->GetFilePath(entry.parent_local_id(), &new_parent_path); | 72 error = metadata->GetFilePath(local_id, &new_path); |
| 70 if (error != FILE_ERROR_OK) | 73 if (error != FILE_ERROR_OK) |
| 71 return error; | 74 return error; |
| 72 changed_directories->insert(new_parent_path); | 75 |
| 73 changed_directories->insert(original_path.DirName()); | 76 changed_files->Update(original_path, |
| 77 FileChange::FILE_TYPE_FILE, | |
|
kinaba
2014/06/23 05:37:43
ditto
yoshiki
2014/06/24 02:02:22
Done.
| |
| 78 FileChange::DELETE); | |
| 79 changed_files->Update(new_path, | |
| 80 FileChange::FILE_TYPE_FILE, | |
| 81 FileChange::ADD_OR_UPDATE); | |
| 74 } | 82 } |
| 75 return FILE_ERROR_OK; | 83 return FILE_ERROR_OK; |
| 76 } | 84 } |
| 77 | 85 |
| 78 } // namespace | 86 } // namespace |
| 79 | 87 |
| 80 EntryRevertPerformer::EntryRevertPerformer( | 88 EntryRevertPerformer::EntryRevertPerformer( |
| 81 base::SequencedTaskRunner* blocking_task_runner, | 89 base::SequencedTaskRunner* blocking_task_runner, |
| 82 file_system::OperationObserver* observer, | 90 file_system::OperationObserver* observer, |
| 83 JobScheduler* scheduler, | 91 JobScheduler* scheduler, |
| (...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 136 } | 144 } |
| 137 | 145 |
| 138 void EntryRevertPerformer::RevertEntryAfterGetFileResource( | 146 void EntryRevertPerformer::RevertEntryAfterGetFileResource( |
| 139 const FileOperationCallback& callback, | 147 const FileOperationCallback& callback, |
| 140 const std::string& local_id, | 148 const std::string& local_id, |
| 141 google_apis::GDataErrorCode status, | 149 google_apis::GDataErrorCode status, |
| 142 scoped_ptr<google_apis::FileResource> entry) { | 150 scoped_ptr<google_apis::FileResource> entry) { |
| 143 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 151 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| 144 DCHECK(!callback.is_null()); | 152 DCHECK(!callback.is_null()); |
| 145 | 153 |
| 146 std::set<base::FilePath>* changed_directories = new std::set<base::FilePath>; | 154 FileChange* changed_files = new FileChange; |
| 147 base::PostTaskAndReplyWithResult( | 155 base::PostTaskAndReplyWithResult( |
| 148 blocking_task_runner_.get(), | 156 blocking_task_runner_.get(), |
| 149 FROM_HERE, | 157 FROM_HERE, |
| 150 base::Bind(&FinishRevert, metadata_, local_id, status, | 158 base::Bind(&FinishRevert, |
| 151 base::Passed(&entry), changed_directories), | 159 metadata_, |
| 160 local_id, | |
| 161 status, | |
| 162 base::Passed(&entry), | |
| 163 changed_files), | |
| 152 base::Bind(&EntryRevertPerformer::RevertEntryAfterFinishRevert, | 164 base::Bind(&EntryRevertPerformer::RevertEntryAfterFinishRevert, |
| 153 weak_ptr_factory_.GetWeakPtr(), callback, | 165 weak_ptr_factory_.GetWeakPtr(), |
| 154 base::Owned(changed_directories))); | 166 callback, |
| 167 base::Owned(changed_files))); | |
| 155 } | 168 } |
| 156 | 169 |
| 157 void EntryRevertPerformer::RevertEntryAfterFinishRevert( | 170 void EntryRevertPerformer::RevertEntryAfterFinishRevert( |
| 158 const FileOperationCallback& callback, | 171 const FileOperationCallback& callback, |
| 159 const std::set<base::FilePath>* changed_directories, | 172 const FileChange* changed_files, |
| 160 FileError error) { | 173 FileError error) { |
| 161 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 174 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| 162 DCHECK(!callback.is_null()); | 175 DCHECK(!callback.is_null()); |
| 163 | 176 |
| 164 for (std::set<base::FilePath>::const_iterator it = | 177 observer_->OnDirectoryChangedByOperation(*changed_files); |
| 165 changed_directories->begin(); it != changed_directories->end(); ++it) | |
| 166 observer_->OnDirectoryChangedByOperation(*it); | |
| 167 | 178 |
| 168 callback.Run(error); | 179 callback.Run(error); |
| 169 } | 180 } |
| 170 | 181 |
| 171 } // namespace internal | 182 } // namespace internal |
| 172 } // namespace drive | 183 } // namespace drive |
| OLD | NEW |