| 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/sync_client.h" | 5 #include "chrome/browser/chromeos/drive/sync_client.h" |
| 6 | 6 |
| 7 #include <vector> | 7 #include <vector> |
| 8 | 8 |
| 9 #include "base/bind.h" | 9 #include "base/bind.h" |
| 10 #include "base/message_loop/message_loop_proxy.h" | 10 #include "base/thread_task_runner_handle.h" |
| 11 #include "chrome/browser/chromeos/drive/drive.pb.h" | 11 #include "chrome/browser/chromeos/drive/drive.pb.h" |
| 12 #include "chrome/browser/chromeos/drive/file_cache.h" | 12 #include "chrome/browser/chromeos/drive/file_cache.h" |
| 13 #include "chrome/browser/chromeos/drive/file_system/download_operation.h" | 13 #include "chrome/browser/chromeos/drive/file_system/download_operation.h" |
| 14 #include "chrome/browser/chromeos/drive/file_system/operation_delegate.h" | 14 #include "chrome/browser/chromeos/drive/file_system/operation_delegate.h" |
| 15 #include "chrome/browser/chromeos/drive/file_system_util.h" | 15 #include "chrome/browser/chromeos/drive/file_system_util.h" |
| 16 #include "chrome/browser/chromeos/drive/job_scheduler.h" | 16 #include "chrome/browser/chromeos/drive/job_scheduler.h" |
| 17 #include "chrome/browser/chromeos/drive/sync/entry_update_performer.h" | 17 #include "chrome/browser/chromeos/drive/sync/entry_update_performer.h" |
| 18 #include "content/public/browser/browser_thread.h" | 18 #include "content/public/browser/browser_thread.h" |
| 19 #include "google_apis/drive/task_util.h" | 19 #include "google_apis/drive/task_util.h" |
| 20 | 20 |
| (...skipping 295 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 316 return; | 316 return; |
| 317 case RUNNING: | 317 case RUNNING: |
| 318 // Something has changed since the task started. Schedule rerun. | 318 // Something has changed since the task started. Schedule rerun. |
| 319 it->second.should_run_again = true; | 319 it->second.should_run_again = true; |
| 320 return; | 320 return; |
| 321 } | 321 } |
| 322 } else { | 322 } else { |
| 323 tasks_[key] = task; | 323 tasks_[key] = task; |
| 324 } | 324 } |
| 325 DCHECK_EQ(PENDING, task.state); | 325 DCHECK_EQ(PENDING, task.state); |
| 326 base::MessageLoopProxy::current()->PostDelayedTask( | 326 base::ThreadTaskRunnerHandle::Get()->PostDelayedTask( |
| 327 FROM_HERE, | 327 FROM_HERE, |
| 328 base::Bind(&SyncClient::StartTask, weak_ptr_factory_.GetWeakPtr(), key), | 328 base::Bind(&SyncClient::StartTask, weak_ptr_factory_.GetWeakPtr(), key), |
| 329 delay); | 329 delay); |
| 330 } | 330 } |
| 331 | 331 |
| 332 void SyncClient::StartTask(const SyncTasks::key_type& key) { | 332 void SyncClient::StartTask(const SyncTasks::key_type& key) { |
| 333 ResourceEntry* parent = new ResourceEntry; | 333 ResourceEntry* parent = new ResourceEntry; |
| 334 base::PostTaskAndReplyWithResult( | 334 base::PostTaskAndReplyWithResult( |
| 335 blocking_task_runner_.get(), | 335 blocking_task_runner_.get(), |
| 336 FROM_HERE, | 336 FROM_HERE, |
| (...skipping 110 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 447 file_system::DRIVE_SYNC_ERROR_SERVICE_UNAVAILABLE, local_id); | 447 file_system::DRIVE_SYNC_ERROR_SERVICE_UNAVAILABLE, local_id); |
| 448 break; | 448 break; |
| 449 default: | 449 default: |
| 450 operation_delegate_->OnDriveSyncError( | 450 operation_delegate_->OnDriveSyncError( |
| 451 file_system::DRIVE_SYNC_ERROR_MISC, local_id); | 451 file_system::DRIVE_SYNC_ERROR_MISC, local_id); |
| 452 LOG(WARNING) << "Failed: type = " << type << ", id = " << local_id | 452 LOG(WARNING) << "Failed: type = " << type << ", id = " << local_id |
| 453 << ": " << FileErrorToString(error); | 453 << ": " << FileErrorToString(error); |
| 454 } | 454 } |
| 455 | 455 |
| 456 for (size_t i = 0; i < it->second.waiting_callbacks.size(); ++i) { | 456 for (size_t i = 0; i < it->second.waiting_callbacks.size(); ++i) { |
| 457 base::MessageLoopProxy::current()->PostTask( | 457 base::ThreadTaskRunnerHandle::Get()->PostTask( |
| 458 FROM_HERE, base::Bind(it->second.waiting_callbacks[i], error)); | 458 FROM_HERE, base::Bind(it->second.waiting_callbacks[i], error)); |
| 459 } | 459 } |
| 460 it->second.waiting_callbacks.clear(); | 460 it->second.waiting_callbacks.clear(); |
| 461 | 461 |
| 462 if (it->second.should_run_again) { | 462 if (it->second.should_run_again) { |
| 463 DVLOG(1) << "Running again: type = " << type << ", id = " << local_id; | 463 DVLOG(1) << "Running again: type = " << type << ", id = " << local_id; |
| 464 it->second.state = PENDING; | 464 it->second.state = PENDING; |
| 465 it->second.should_run_again = false; | 465 it->second.should_run_again = false; |
| 466 base::MessageLoopProxy::current()->PostDelayedTask( | 466 base::ThreadTaskRunnerHandle::Get()->PostDelayedTask( |
| 467 FROM_HERE, | 467 FROM_HERE, |
| 468 base::Bind(&SyncClient::StartTask, weak_ptr_factory_.GetWeakPtr(), key), | 468 base::Bind(&SyncClient::StartTask, weak_ptr_factory_.GetWeakPtr(), key), |
| 469 retry_delay); | 469 retry_delay); |
| 470 } else { | 470 } else { |
| 471 for (size_t i = 0; i < it->second.dependent_tasks.size(); ++i) | 471 for (size_t i = 0; i < it->second.dependent_tasks.size(); ++i) |
| 472 StartTask(it->second.dependent_tasks[i]); | 472 StartTask(it->second.dependent_tasks[i]); |
| 473 tasks_.erase(it); | 473 tasks_.erase(it); |
| 474 } | 474 } |
| 475 } | 475 } |
| 476 | 476 |
| 477 void SyncClient::OnFetchFileComplete(const std::string& local_id, | 477 void SyncClient::OnFetchFileComplete(const std::string& local_id, |
| 478 FileError error, | 478 FileError error, |
| 479 const base::FilePath& local_path, | 479 const base::FilePath& local_path, |
| 480 scoped_ptr<ResourceEntry> entry) { | 480 scoped_ptr<ResourceEntry> entry) { |
| 481 DCHECK_CURRENTLY_ON(BrowserThread::UI); | 481 DCHECK_CURRENTLY_ON(BrowserThread::UI); |
| 482 OnTaskComplete(FETCH, local_id, error); | 482 OnTaskComplete(FETCH, local_id, error); |
| 483 if (error == FILE_ERROR_ABORT) { | 483 if (error == FILE_ERROR_ABORT) { |
| 484 // If user cancels download, unpin the file so that we do not sync the file | 484 // If user cancels download, unpin the file so that we do not sync the file |
| 485 // again. | 485 // again. |
| 486 base::PostTaskAndReplyWithResult( | 486 base::PostTaskAndReplyWithResult( |
| 487 blocking_task_runner_.get(), | 487 blocking_task_runner_.get(), |
| 488 FROM_HERE, | 488 FROM_HERE, |
| 489 base::Bind(&FileCache::Unpin, base::Unretained(cache_), local_id), | 489 base::Bind(&FileCache::Unpin, base::Unretained(cache_), local_id), |
| 490 base::Bind(&util::EmptyFileOperationCallback)); | 490 base::Bind(&util::EmptyFileOperationCallback)); |
| 491 } | 491 } |
| 492 } | 492 } |
| 493 | 493 |
| 494 } // namespace internal | 494 } // namespace internal |
| 495 } // namespace drive | 495 } // namespace drive |
| OLD | NEW |