| 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 <set> | 7 #include <set> |
| 8 | 8 |
| 9 #include "base/callback_helpers.h" | 9 #include "base/callback_helpers.h" |
| 10 #include "base/files/file_util.h" | 10 #include "base/files/file_util.h" |
| (...skipping 236 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 247 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 247 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| 248 } | 248 } |
| 249 | 249 |
| 250 void EntryUpdatePerformer::UpdateEntry(const std::string& local_id, | 250 void EntryUpdatePerformer::UpdateEntry(const std::string& local_id, |
| 251 const ClientContext& context, | 251 const ClientContext& context, |
| 252 const FileOperationCallback& callback) { | 252 const FileOperationCallback& callback) { |
| 253 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 253 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| 254 DCHECK(!callback.is_null()); | 254 DCHECK(!callback.is_null()); |
| 255 | 255 |
| 256 scoped_ptr<LocalState> local_state(new LocalState); | 256 scoped_ptr<LocalState> local_state(new LocalState); |
| 257 LocalState* local_state_ptr = local_state.get(); | 257 LocalState* const local_state_ptr = local_state.get(); |
| 258 base::PostTaskAndReplyWithResult( | 258 base::PostTaskAndReplyWithResult( |
| 259 blocking_task_runner_.get(), | 259 blocking_task_runner_.get(), |
| 260 FROM_HERE, | 260 FROM_HERE, |
| 261 base::Bind(&PrepareUpdate, metadata_, cache_, local_id, local_state_ptr), | 261 base::Bind(&PrepareUpdate, metadata_, cache_, local_id, local_state_ptr), |
| 262 base::Bind(&EntryUpdatePerformer::UpdateEntryAfterPrepare, | 262 base::Bind(&EntryUpdatePerformer::UpdateEntryAfterPrepare, |
| 263 weak_ptr_factory_.GetWeakPtr(), context, callback, | 263 weak_ptr_factory_.GetWeakPtr(), context, callback, |
| 264 base::Passed(&local_state))); | 264 base::Passed(&local_state))); |
| 265 } | 265 } |
| 266 | 266 |
| 267 void EntryUpdatePerformer::UpdateEntryAfterPrepare( | 267 void EntryUpdatePerformer::UpdateEntryAfterPrepare( |
| (...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 320 if (local_state->entry.resource_id().empty()) { | 320 if (local_state->entry.resource_id().empty()) { |
| 321 // Not locking the loader intentionally here to avoid making the UI | 321 // Not locking the loader intentionally here to avoid making the UI |
| 322 // unresponsive while uploading large files. | 322 // unresponsive while uploading large files. |
| 323 // FinishUpdate() is responsible to resolve conflicts caused by this. | 323 // FinishUpdate() is responsible to resolve conflicts caused by this. |
| 324 scoped_ptr<base::ScopedClosureRunner> null_loader_lock; | 324 scoped_ptr<base::ScopedClosureRunner> null_loader_lock; |
| 325 | 325 |
| 326 DriveUploader::UploadNewFileOptions options; | 326 DriveUploader::UploadNewFileOptions options; |
| 327 options.modified_date = last_modified; | 327 options.modified_date = last_modified; |
| 328 options.last_viewed_by_me_date = last_accessed; | 328 options.last_viewed_by_me_date = last_accessed; |
| 329 options.properties = properties; | 329 options.properties = properties; |
| 330 LocalState* const local_state_ptr = local_state.get(); |
| 330 scheduler_->UploadNewFile( | 331 scheduler_->UploadNewFile( |
| 331 local_state->parent_entry.resource_id(), local_state->drive_file_path, | 332 local_state_ptr->parent_entry.resource_id(), |
| 332 local_state->cache_file_path, local_state->entry.title(), | 333 local_state_ptr->drive_file_path, local_state_ptr->cache_file_path, |
| 333 local_state->entry.file_specific_info().content_mime_type(), options, | 334 local_state_ptr->entry.title(), |
| 334 context, | 335 local_state_ptr->entry.file_specific_info().content_mime_type(), |
| 336 options, context, |
| 335 base::Bind(&EntryUpdatePerformer::UpdateEntryAfterUpdateResource, | 337 base::Bind(&EntryUpdatePerformer::UpdateEntryAfterUpdateResource, |
| 336 weak_ptr_factory_.GetWeakPtr(), context, callback, | 338 weak_ptr_factory_.GetWeakPtr(), context, callback, |
| 337 base::Passed(&local_state), | 339 base::Passed(&local_state), |
| 338 base::Passed(&null_loader_lock))); | 340 base::Passed(&null_loader_lock))); |
| 339 } else { | 341 } else { |
| 340 DriveUploader::UploadExistingFileOptions options; | 342 DriveUploader::UploadExistingFileOptions options; |
| 341 options.title = local_state->entry.title(); | 343 options.title = local_state->entry.title(); |
| 342 options.parent_resource_id = local_state->parent_entry.resource_id(); | 344 options.parent_resource_id = local_state->parent_entry.resource_id(); |
| 343 options.modified_date = last_modified; | 345 options.modified_date = last_modified; |
| 344 options.last_viewed_by_me_date = last_accessed; | 346 options.last_viewed_by_me_date = last_accessed; |
| 345 options.properties = properties; | 347 options.properties = properties; |
| 348 LocalState* const local_state_ptr = local_state.get(); |
| 346 scheduler_->UploadExistingFile( | 349 scheduler_->UploadExistingFile( |
| 347 local_state->entry.resource_id(), local_state->drive_file_path, | 350 local_state_ptr->entry.resource_id(), |
| 348 local_state->cache_file_path, | 351 local_state_ptr->drive_file_path, local_state_ptr->cache_file_path, |
| 349 local_state->entry.file_specific_info().content_mime_type(), options, | 352 local_state_ptr->entry.file_specific_info().content_mime_type(), |
| 350 context, | 353 options, context, |
| 351 base::Bind(&EntryUpdatePerformer::UpdateEntryAfterUpdateResource, | 354 base::Bind(&EntryUpdatePerformer::UpdateEntryAfterUpdateResource, |
| 352 weak_ptr_factory_.GetWeakPtr(), context, callback, | 355 weak_ptr_factory_.GetWeakPtr(), context, callback, |
| 353 base::Passed(&local_state), | 356 base::Passed(&local_state), |
| 354 base::Passed(scoped_ptr<base::ScopedClosureRunner>()))); | 357 base::Passed(scoped_ptr<base::ScopedClosureRunner>()))); |
| 355 } | 358 } |
| 356 return; | 359 return; |
| 357 } | 360 } |
| 358 | 361 |
| 359 // Create directory. | 362 // Create directory. |
| 360 if (local_state->entry.file_info().is_directory() && | 363 if (local_state->entry.file_info().is_directory() && |
| 361 local_state->entry.resource_id().empty()) { | 364 local_state->entry.resource_id().empty()) { |
| 362 // Lock the loader to avoid race conditions. | 365 // Lock the loader to avoid race conditions. |
| 363 scoped_ptr<base::ScopedClosureRunner> loader_lock = | 366 scoped_ptr<base::ScopedClosureRunner> loader_lock = |
| 364 loader_controller_->GetLock(); | 367 loader_controller_->GetLock(); |
| 365 | 368 |
| 366 DriveServiceInterface::AddNewDirectoryOptions options; | 369 DriveServiceInterface::AddNewDirectoryOptions options; |
| 367 options.modified_date = last_modified; | 370 options.modified_date = last_modified; |
| 368 options.last_viewed_by_me_date = last_accessed; | 371 options.last_viewed_by_me_date = last_accessed; |
| 369 options.properties = properties; | 372 options.properties = properties; |
| 373 LocalState* const local_state_ptr = local_state.get(); |
| 370 scheduler_->AddNewDirectory( | 374 scheduler_->AddNewDirectory( |
| 371 local_state->parent_entry.resource_id(), local_state->entry.title(), | 375 local_state_ptr->parent_entry.resource_id(), |
| 372 options, context, | 376 local_state_ptr->entry.title(), options, context, |
| 373 base::Bind(&EntryUpdatePerformer::UpdateEntryAfterUpdateResource, | 377 base::Bind(&EntryUpdatePerformer::UpdateEntryAfterUpdateResource, |
| 374 weak_ptr_factory_.GetWeakPtr(), context, callback, | 378 weak_ptr_factory_.GetWeakPtr(), context, callback, |
| 375 base::Passed(&local_state), base::Passed(&loader_lock))); | 379 base::Passed(&local_state), base::Passed(&loader_lock))); |
| 376 return; | 380 return; |
| 377 } | 381 } |
| 378 | 382 |
| 379 // No need to perform update. | 383 // No need to perform update. |
| 380 if (local_state->entry.metadata_edit_state() == ResourceEntry::CLEAN || | 384 if (local_state->entry.metadata_edit_state() == ResourceEntry::CLEAN || |
| 381 local_state->entry.resource_id().empty()) { | 385 local_state->entry.resource_id().empty()) { |
| 382 callback.Run(FILE_ERROR_OK); | 386 callback.Run(FILE_ERROR_OK); |
| 383 return; | 387 return; |
| 384 } | 388 } |
| 385 | 389 |
| 386 // Perform metadata update. | 390 // Perform metadata update. |
| 391 LocalState* const local_state_ptr = local_state.get(); |
| 387 scheduler_->UpdateResource( | 392 scheduler_->UpdateResource( |
| 388 local_state->entry.resource_id(), local_state->parent_entry.resource_id(), | 393 local_state_ptr->entry.resource_id(), |
| 389 local_state->entry.title(), last_modified, last_accessed, properties, | 394 local_state_ptr->parent_entry.resource_id(), |
| 395 local_state_ptr->entry.title(), last_modified, last_accessed, properties, |
| 390 context, | 396 context, |
| 391 base::Bind(&EntryUpdatePerformer::UpdateEntryAfterUpdateResource, | 397 base::Bind(&EntryUpdatePerformer::UpdateEntryAfterUpdateResource, |
| 392 weak_ptr_factory_.GetWeakPtr(), context, callback, | 398 weak_ptr_factory_.GetWeakPtr(), context, callback, |
| 393 base::Passed(&local_state), | 399 base::Passed(&local_state), |
| 394 base::Passed(scoped_ptr<base::ScopedClosureRunner>()))); | 400 base::Passed(scoped_ptr<base::ScopedClosureRunner>()))); |
| 395 } | 401 } |
| 396 | 402 |
| 397 void EntryUpdatePerformer::UpdateEntryAfterUpdateResource( | 403 void EntryUpdatePerformer::UpdateEntryAfterUpdateResource( |
| 398 const ClientContext& context, | 404 const ClientContext& context, |
| 399 const FileOperationCallback& callback, | 405 const FileOperationCallback& callback, |
| (...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 433 FileError error) { | 439 FileError error) { |
| 434 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 440 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| 435 DCHECK(!callback.is_null()); | 441 DCHECK(!callback.is_null()); |
| 436 | 442 |
| 437 delegate_->OnFileChangedByOperation(*changed_files); | 443 delegate_->OnFileChangedByOperation(*changed_files); |
| 438 callback.Run(error); | 444 callback.Run(error); |
| 439 } | 445 } |
| 440 | 446 |
| 441 } // namespace internal | 447 } // namespace internal |
| 442 } // namespace drive | 448 } // namespace drive |
| OLD | NEW |