| 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 "base/callback_helpers.h" | 7 #include "base/callback_helpers.h" | 
| 8 #include "base/file_util.h" | 8 #include "base/file_util.h" | 
| 9 #include "chrome/browser/chromeos/drive/change_list_loader.h" | 9 #include "chrome/browser/chromeos/drive/change_list_loader.h" | 
| 10 #include "chrome/browser/chromeos/drive/drive.pb.h" | 10 #include "chrome/browser/chromeos/drive/drive.pb.h" | 
| (...skipping 135 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
| 146 } | 146 } | 
| 147 | 147 | 
| 148 }  // namespace | 148 }  // namespace | 
| 149 | 149 | 
| 150 EntryUpdatePerformer::EntryUpdatePerformer( | 150 EntryUpdatePerformer::EntryUpdatePerformer( | 
| 151     base::SequencedTaskRunner* blocking_task_runner, | 151     base::SequencedTaskRunner* blocking_task_runner, | 
| 152     file_system::OperationObserver* observer, | 152     file_system::OperationObserver* observer, | 
| 153     JobScheduler* scheduler, | 153     JobScheduler* scheduler, | 
| 154     ResourceMetadata* metadata, | 154     ResourceMetadata* metadata, | 
| 155     FileCache* cache, | 155     FileCache* cache, | 
| 156     ChangeListLoader* change_list_loader) | 156     LoaderController* loader_controller) | 
| 157     : blocking_task_runner_(blocking_task_runner), | 157     : blocking_task_runner_(blocking_task_runner), | 
| 158       scheduler_(scheduler), | 158       scheduler_(scheduler), | 
| 159       metadata_(metadata), | 159       metadata_(metadata), | 
| 160       cache_(cache), | 160       cache_(cache), | 
| 161       change_list_loader_(change_list_loader), | 161       loader_controller_(loader_controller), | 
| 162       remove_performer_(new RemovePerformer(blocking_task_runner, | 162       remove_performer_(new RemovePerformer(blocking_task_runner, | 
| 163                                             observer, | 163                                             observer, | 
| 164                                             scheduler, | 164                                             scheduler, | 
| 165                                             metadata)), | 165                                             metadata)), | 
| 166       entry_revert_performer_(new EntryRevertPerformer(blocking_task_runner, | 166       entry_revert_performer_(new EntryRevertPerformer(blocking_task_runner, | 
| 167                                                        observer, | 167                                                        observer, | 
| 168                                                        scheduler, | 168                                                        scheduler, | 
| 169                                                        metadata)), | 169                                                        metadata)), | 
| 170       weak_ptr_factory_(this) { | 170       weak_ptr_factory_(this) { | 
| 171   DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 171   DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 
| (...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
| 212   } | 212   } | 
| 213 | 213 | 
| 214   base::Time last_modified = base::Time::FromInternalValue( | 214   base::Time last_modified = base::Time::FromInternalValue( | 
| 215       local_state->entry.file_info().last_modified()); | 215       local_state->entry.file_info().last_modified()); | 
| 216   base::Time last_accessed = base::Time::FromInternalValue( | 216   base::Time last_accessed = base::Time::FromInternalValue( | 
| 217       local_state->entry.file_info().last_accessed()); | 217       local_state->entry.file_info().last_accessed()); | 
| 218 | 218 | 
| 219   // Perform content update. | 219   // Perform content update. | 
| 220   if (local_state->should_content_update) { | 220   if (local_state->should_content_update) { | 
| 221     if (local_state->entry.resource_id().empty()) { | 221     if (local_state->entry.resource_id().empty()) { | 
|  | 222       // Lock the loader to avoid race conditions. | 
|  | 223       scoped_ptr<base::ScopedClosureRunner> loader_lock = | 
|  | 224           loader_controller_->GetLock(); | 
|  | 225 | 
| 222       drive::DriveUploader::UploadNewFileOptions options; | 226       drive::DriveUploader::UploadNewFileOptions options; | 
| 223       options.modified_date = last_modified; | 227       options.modified_date = last_modified; | 
| 224       options.last_viewed_by_me_date = last_accessed; | 228       options.last_viewed_by_me_date = last_accessed; | 
| 225       scheduler_->UploadNewFile( | 229       scheduler_->UploadNewFile( | 
| 226           local_state->parent_entry.resource_id(), | 230           local_state->parent_entry.resource_id(), | 
| 227           local_state->drive_file_path, | 231           local_state->drive_file_path, | 
| 228           local_state->cache_file_path, | 232           local_state->cache_file_path, | 
| 229           local_state->entry.title(), | 233           local_state->entry.title(), | 
| 230           local_state->entry.file_specific_info().content_mime_type(), | 234           local_state->entry.file_specific_info().content_mime_type(), | 
| 231           options, | 235           options, | 
| 232           context, | 236           context, | 
| 233           base::Bind(&EntryUpdatePerformer::UpdateEntryAfterUpdateResource, | 237           base::Bind(&EntryUpdatePerformer::UpdateEntryAfterUpdateResource, | 
| 234                      weak_ptr_factory_.GetWeakPtr(), | 238                      weak_ptr_factory_.GetWeakPtr(), | 
| 235                      context, | 239                      context, | 
| 236                      callback, | 240                      callback, | 
| 237                      local_state->entry.local_id(), | 241                      local_state->entry.local_id(), | 
| 238                      base::Passed(change_list_loader_->GetLock()))); | 242                      base::Passed(&loader_lock))); | 
| 239     } else { | 243     } else { | 
| 240       drive::DriveUploader::UploadExistingFileOptions options; | 244       drive::DriveUploader::UploadExistingFileOptions options; | 
| 241       options.title = local_state->entry.title(); | 245       options.title = local_state->entry.title(); | 
| 242       options.parent_resource_id = local_state->parent_entry.resource_id(); | 246       options.parent_resource_id = local_state->parent_entry.resource_id(); | 
| 243       options.modified_date = last_modified; | 247       options.modified_date = last_modified; | 
| 244       options.last_viewed_by_me_date = last_accessed; | 248       options.last_viewed_by_me_date = last_accessed; | 
| 245       scheduler_->UploadExistingFile( | 249       scheduler_->UploadExistingFile( | 
| 246           local_state->entry.resource_id(), | 250           local_state->entry.resource_id(), | 
| 247           local_state->drive_file_path, | 251           local_state->drive_file_path, | 
| 248           local_state->cache_file_path, | 252           local_state->cache_file_path, | 
| (...skipping 24 matching lines...) Expand all  Loading... | 
| 273       base::Bind(&EntryUpdatePerformer::UpdateEntryAfterUpdateResource, | 277       base::Bind(&EntryUpdatePerformer::UpdateEntryAfterUpdateResource, | 
| 274                  weak_ptr_factory_.GetWeakPtr(), | 278                  weak_ptr_factory_.GetWeakPtr(), | 
| 275                  context, callback, local_state->entry.local_id(), | 279                  context, callback, local_state->entry.local_id(), | 
| 276                  base::Passed(scoped_ptr<base::ScopedClosureRunner>()))); | 280                  base::Passed(scoped_ptr<base::ScopedClosureRunner>()))); | 
| 277 } | 281 } | 
| 278 | 282 | 
| 279 void EntryUpdatePerformer::UpdateEntryAfterUpdateResource( | 283 void EntryUpdatePerformer::UpdateEntryAfterUpdateResource( | 
| 280     const ClientContext& context, | 284     const ClientContext& context, | 
| 281     const FileOperationCallback& callback, | 285     const FileOperationCallback& callback, | 
| 282     const std::string& local_id, | 286     const std::string& local_id, | 
| 283     scoped_ptr<base::ScopedClosureRunner> change_list_loader_lock, | 287     scoped_ptr<base::ScopedClosureRunner> loader_lock, | 
| 284     google_apis::GDataErrorCode status, | 288     google_apis::GDataErrorCode status, | 
| 285     scoped_ptr<google_apis::ResourceEntry> resource_entry) { | 289     scoped_ptr<google_apis::ResourceEntry> resource_entry) { | 
| 286   DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 290   DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 
| 287 | 291 | 
| 288   if (status == google_apis::HTTP_FORBIDDEN) { | 292   if (status == google_apis::HTTP_FORBIDDEN) { | 
| 289     // Editing this entry is not allowed, revert local changes. | 293     // Editing this entry is not allowed, revert local changes. | 
| 290     entry_revert_performer_->RevertEntry(local_id, context, callback); | 294     entry_revert_performer_->RevertEntry(local_id, context, callback); | 
| 291     return; | 295     return; | 
| 292   } | 296   } | 
| 293 | 297 | 
| 294   FileError error = GDataToFileError(status); | 298   FileError error = GDataToFileError(status); | 
| 295   if (error != FILE_ERROR_OK) { | 299   if (error != FILE_ERROR_OK) { | 
| 296     callback.Run(error); | 300     callback.Run(error); | 
| 297     return; | 301     return; | 
| 298   } | 302   } | 
| 299 | 303 | 
| 300   base::PostTaskAndReplyWithResult( | 304   base::PostTaskAndReplyWithResult( | 
| 301       blocking_task_runner_.get(), | 305       blocking_task_runner_.get(), | 
| 302       FROM_HERE, | 306       FROM_HERE, | 
| 303       base::Bind(&FinishUpdate, | 307       base::Bind(&FinishUpdate, | 
| 304                  metadata_, cache_, local_id, base::Passed(&resource_entry)), | 308                  metadata_, cache_, local_id, base::Passed(&resource_entry)), | 
| 305       callback); | 309       callback); | 
| 306 } | 310 } | 
| 307 | 311 | 
| 308 }  // namespace internal | 312 }  // namespace internal | 
| 309 }  // namespace drive | 313 }  // namespace drive | 
| OLD | NEW | 
|---|