| 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_update_performer.h" | 5 #include "chrome/browser/chromeos/drive/sync/entry_update_performer.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_system_util.h" | 8 #include "chrome/browser/chromeos/drive/file_system_util.h" |
| 9 #include "chrome/browser/chromeos/drive/job_scheduler.h" | 9 #include "chrome/browser/chromeos/drive/job_scheduler.h" |
| 10 #include "chrome/browser/chromeos/drive/resource_metadata.h" | 10 #include "chrome/browser/chromeos/drive/resource_metadata.h" |
| (...skipping 29 matching lines...) Expand all Loading... |
| 40 entry->set_metadata_edit_state(ResourceEntry::SYNCING); | 40 entry->set_metadata_edit_state(ResourceEntry::SYNCING); |
| 41 error = metadata->RefreshEntry(*entry); | 41 error = metadata->RefreshEntry(*entry); |
| 42 if (error != FILE_ERROR_OK) | 42 if (error != FILE_ERROR_OK) |
| 43 return error; | 43 return error; |
| 44 break; | 44 break; |
| 45 } | 45 } |
| 46 return FILE_ERROR_OK; | 46 return FILE_ERROR_OK; |
| 47 } | 47 } |
| 48 | 48 |
| 49 FileError FinishUpdate(ResourceMetadata* metadata, | 49 FileError FinishUpdate(ResourceMetadata* metadata, |
| 50 const std::string& local_id) { | 50 const std::string& local_id, |
| 51 ResourceEntry entry; | 51 ResourceEntry* entry) { |
| 52 FileError error = metadata->GetResourceEntryById(local_id, &entry); | 52 FileError error = metadata->GetResourceEntryById(local_id, entry); |
| 53 if (error != FILE_ERROR_OK) | 53 if (error != FILE_ERROR_OK) |
| 54 return error; | 54 return error; |
| 55 | 55 |
| 56 switch (entry.metadata_edit_state()) { | 56 switch (entry->metadata_edit_state()) { |
| 57 case ResourceEntry::CLEAN: // Nothing to do. | 57 case ResourceEntry::CLEAN: // Nothing to do. |
| 58 case ResourceEntry::DIRTY: // Entry was edited again during the update. | 58 case ResourceEntry::DIRTY: // Entry was edited again during the update. |
| 59 break; | 59 break; |
| 60 | 60 |
| 61 case ResourceEntry::SYNCING: | 61 case ResourceEntry::SYNCING: |
| 62 entry.set_metadata_edit_state(ResourceEntry::CLEAN); | 62 entry->set_metadata_edit_state(ResourceEntry::CLEAN); |
| 63 error = metadata->RefreshEntry(entry); | 63 error = metadata->RefreshEntry(*entry); |
| 64 if (error != FILE_ERROR_OK) | 64 if (error != FILE_ERROR_OK) |
| 65 return error; | 65 return error; |
| 66 break; | 66 break; |
| 67 } | 67 } |
| 68 return FILE_ERROR_OK; | 68 return FILE_ERROR_OK; |
| 69 } | 69 } |
| 70 | 70 |
| 71 } // namespace | 71 } // namespace |
| 72 | 72 |
| 73 EntryUpdatePerformer::EntryUpdatePerformer( | 73 EntryUpdatePerformer::EntryUpdatePerformer( |
| (...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 125 if (entry->parent_local_id() == util::kDriveTrashDirLocalId) { | 125 if (entry->parent_local_id() == util::kDriveTrashDirLocalId) { |
| 126 remove_performer_->Remove(entry->local_id(), callback); | 126 remove_performer_->Remove(entry->local_id(), callback); |
| 127 return; | 127 return; |
| 128 } | 128 } |
| 129 | 129 |
| 130 if (entry->metadata_edit_state() == ResourceEntry::CLEAN) { | 130 if (entry->metadata_edit_state() == ResourceEntry::CLEAN) { |
| 131 callback.Run(FILE_ERROR_OK); | 131 callback.Run(FILE_ERROR_OK); |
| 132 return; | 132 return; |
| 133 } | 133 } |
| 134 | 134 |
| 135 std::string parent_resource_id; |
| 136 if (!util::IsSpecialResourceId(parent_entry->resource_id())) |
| 137 parent_resource_id = parent_entry->resource_id(); |
| 138 |
| 135 base::Time last_modified = | 139 base::Time last_modified = |
| 136 base::Time::FromInternalValue(entry->file_info().last_modified()); | 140 base::Time::FromInternalValue(entry->file_info().last_modified()); |
| 137 base::Time last_accessed = | 141 base::Time last_accessed = |
| 138 base::Time::FromInternalValue(entry->file_info().last_accessed()); | 142 base::Time::FromInternalValue(entry->file_info().last_accessed()); |
| 139 scheduler_->UpdateResource( | 143 scheduler_->UpdateResource( |
| 140 entry->resource_id(), parent_entry->resource_id(), | 144 entry->resource_id(), parent_resource_id, |
| 141 entry->title(), last_modified, last_accessed, | 145 entry->title(), last_modified, last_accessed, |
| 142 base::Bind(&EntryUpdatePerformer::UpdateEntryAfterUpdateResource, | 146 base::Bind(&EntryUpdatePerformer::UpdateEntryAfterUpdateResource, |
| 143 weak_ptr_factory_.GetWeakPtr(), callback, entry->local_id())); | 147 weak_ptr_factory_.GetWeakPtr(), callback, entry->local_id())); |
| 144 } | 148 } |
| 145 | 149 |
| 146 void EntryUpdatePerformer::UpdateEntryAfterUpdateResource( | 150 void EntryUpdatePerformer::UpdateEntryAfterUpdateResource( |
| 147 const FileOperationCallback& callback, | 151 const FileOperationCallback& callback, |
| 148 const std::string& local_id, | 152 const std::string& local_id, |
| 149 google_apis::GDataErrorCode status, | 153 google_apis::GDataErrorCode status, |
| 150 scoped_ptr<google_apis::ResourceEntry> resource_entry) { | 154 scoped_ptr<google_apis::ResourceEntry> resource_entry) { |
| 151 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 155 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| 152 | 156 |
| 153 FileError error = GDataToFileError(status); | 157 FileError error = GDataToFileError(status); |
| 154 if (error != FILE_ERROR_OK) { | 158 if (error != FILE_ERROR_OK) { |
| 155 callback.Run(error); | 159 callback.Run(error); |
| 156 return; | 160 return; |
| 157 } | 161 } |
| 158 | 162 |
| 163 ResourceEntry* entry = new ResourceEntry; |
| 159 base::PostTaskAndReplyWithResult( | 164 base::PostTaskAndReplyWithResult( |
| 160 blocking_task_runner_.get(), | 165 blocking_task_runner_.get(), |
| 161 FROM_HERE, | 166 FROM_HERE, |
| 162 base::Bind(&FinishUpdate, metadata_, local_id), | 167 base::Bind(&FinishUpdate, metadata_, local_id, entry), |
| 163 callback); | 168 base::Bind(&EntryUpdatePerformer::UpdateEntryAfterFinish, |
| 169 weak_ptr_factory_.GetWeakPtr(), callback, base::Owned(entry))); |
| 170 } |
| 171 |
| 172 void EntryUpdatePerformer::UpdateEntryAfterFinish( |
| 173 const FileOperationCallback& callback, |
| 174 const ResourceEntry* entry, |
| 175 FileError error) { |
| 176 if (error != FILE_ERROR_OK) { |
| 177 callback.Run(error); |
| 178 return; |
| 179 } |
| 180 |
| 181 if (entry->metadata_edit_state() == ResourceEntry::DIRTY) { |
| 182 // The entry was edited during the update. Update again. |
| 183 UpdateEntry(entry->local_id(), callback); |
| 184 return; |
| 185 } |
| 186 |
| 187 callback.Run(FILE_ERROR_OK); |
| 164 } | 188 } |
| 165 | 189 |
| 166 } // namespace internal | 190 } // namespace internal |
| 167 } // namespace drive | 191 } // namespace drive |
| OLD | NEW |