Chromium Code Reviews| 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/drive_scheduler.h" | 5 #include "chrome/browser/chromeos/drive/drive_scheduler.h" |
| 6 | 6 |
| 7 #include <math.h> | 7 #include <math.h> |
| 8 | 8 |
| 9 #include "base/message_loop.h" | 9 #include "base/message_loop.h" |
| 10 #include "base/prefs/pref_service.h" | 10 #include "base/prefs/pref_service.h" |
| (...skipping 287 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 298 void DriveScheduler::DownloadFile( | 298 void DriveScheduler::DownloadFile( |
| 299 const base::FilePath& virtual_path, | 299 const base::FilePath& virtual_path, |
| 300 const base::FilePath& local_cache_path, | 300 const base::FilePath& local_cache_path, |
| 301 const GURL& download_url, | 301 const GURL& download_url, |
| 302 const DriveClientContext& context, | 302 const DriveClientContext& context, |
| 303 const google_apis::DownloadActionCallback& download_action_callback, | 303 const google_apis::DownloadActionCallback& download_action_callback, |
| 304 const google_apis::GetContentCallback& get_content_callback) { | 304 const google_apis::GetContentCallback& get_content_callback) { |
| 305 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 305 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| 306 | 306 |
| 307 scoped_ptr<QueueEntry> new_job(new QueueEntry); | 307 scoped_ptr<QueueEntry> new_job(new QueueEntry); |
| 308 new_job->virtual_path = virtual_path; | 308 new_job->drive_file_path = virtual_path; |
| 309 new_job->local_cache_path = local_cache_path; | 309 new_job->local_file_path = local_cache_path; |
| 310 new_job->download_url = download_url; | 310 new_job->download_url = download_url; |
| 311 new_job->context = context; | 311 new_job->context = context; |
| 312 new_job->download_action_callback = download_action_callback; | 312 new_job->download_action_callback = download_action_callback; |
| 313 new_job->get_content_callback = get_content_callback; | 313 new_job->get_content_callback = get_content_callback; |
| 314 | 314 |
| 315 StartNewJob(new_job.Pass(), TYPE_DOWNLOAD_FILE); | 315 StartNewJob(new_job.Pass(), TYPE_DOWNLOAD_FILE); |
| 316 } | 316 } |
| 317 | 317 |
| 318 void DriveScheduler::UploadNewFile( | 318 void DriveScheduler::UploadNewFile( |
| 319 const std::string& parent_resource_id, | 319 const std::string& parent_resource_id, |
| (...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 356 new_job->upload_completion_callback = upload_completion_callback; | 356 new_job->upload_completion_callback = upload_completion_callback; |
| 357 new_job->context = context; | 357 new_job->context = context; |
| 358 | 358 |
| 359 StartNewJob(new_job.Pass(), TYPE_UPLOAD_EXISTING_FILE); | 359 StartNewJob(new_job.Pass(), TYPE_UPLOAD_EXISTING_FILE); |
| 360 } | 360 } |
| 361 | 361 |
| 362 void DriveScheduler::StartNewJob(scoped_ptr<QueueEntry> job, JobType type) { | 362 void DriveScheduler::StartNewJob(scoped_ptr<QueueEntry> job, JobType type) { |
| 363 // job_info is owned by job_map_ and released when it is removed in OnJobDone. | 363 // job_info is owned by job_map_ and released when it is removed in OnJobDone. |
| 364 JobInfo* job_info = new JobInfo(type); | 364 JobInfo* job_info = new JobInfo(type); |
| 365 job->job_id = job_info->job_id = job_map_.Add(job_info); | 365 job->job_id = job_info->job_id = job_map_.Add(job_info); |
| 366 job_info->file_path = job->drive_file_path; | |
|
hidehiko
2013/04/17 06:23:21
drive_file_path is only available for Upload/Downl
kinaba
2013/04/17 06:41:01
Thanks, good catch.
I haven't deeply thought about
| |
| 366 | 367 |
| 367 QueueJob(job.Pass()); | 368 QueueJob(job.Pass()); |
| 368 StartJobLoop(GetJobQueueType(type)); | 369 StartJobLoop(GetJobQueueType(type)); |
| 369 } | 370 } |
| 370 | 371 |
| 371 void DriveScheduler::QueueJob(scoped_ptr<QueueEntry> job) { | 372 void DriveScheduler::QueueJob(scoped_ptr<QueueEntry> job) { |
| 372 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 373 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| 373 | 374 |
| 374 JobInfo* job_info = job_map_.Lookup(job->job_id); | 375 JobInfo* job_info = job_map_.Lookup(job->job_id); |
| 375 DCHECK(job_info); | 376 DCHECK(job_info); |
| (...skipping 173 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 549 entry->parent_resource_id, | 550 entry->parent_resource_id, |
| 550 entry->directory_name, | 551 entry->directory_name, |
| 551 base::Bind(&DriveScheduler::OnGetResourceEntryJobDone, | 552 base::Bind(&DriveScheduler::OnGetResourceEntryJobDone, |
| 552 weak_ptr_factory_.GetWeakPtr(), | 553 weak_ptr_factory_.GetWeakPtr(), |
| 553 base::Passed(&queue_entry))); | 554 base::Passed(&queue_entry))); |
| 554 } | 555 } |
| 555 break; | 556 break; |
| 556 | 557 |
| 557 case TYPE_DOWNLOAD_FILE: { | 558 case TYPE_DOWNLOAD_FILE: { |
| 558 drive_service_->DownloadFile( | 559 drive_service_->DownloadFile( |
| 559 entry->virtual_path, | 560 entry->drive_file_path, |
| 560 entry->local_cache_path, | 561 entry->local_file_path, |
| 561 entry->download_url, | 562 entry->download_url, |
| 562 base::Bind(&DriveScheduler::OnDownloadActionJobDone, | 563 base::Bind(&DriveScheduler::OnDownloadActionJobDone, |
| 563 weak_ptr_factory_.GetWeakPtr(), | 564 weak_ptr_factory_.GetWeakPtr(), |
| 564 base::Passed(&queue_entry)), | 565 base::Passed(&queue_entry)), |
| 565 entry->get_content_callback, | 566 entry->get_content_callback, |
| 566 google_apis::ProgressCallback()); | 567 base::Bind(&DriveScheduler::UpdateProgress, |
| 568 weak_ptr_factory_.GetWeakPtr(), | |
| 569 job_info->job_id)); | |
| 567 } | 570 } |
| 568 break; | 571 break; |
| 569 | 572 |
| 570 case TYPE_UPLOAD_NEW_FILE: { | 573 case TYPE_UPLOAD_NEW_FILE: { |
| 571 uploader_->UploadNewFile( | 574 uploader_->UploadNewFile( |
| 572 entry->resource_id, | 575 entry->resource_id, |
| 573 entry->drive_file_path, | 576 entry->drive_file_path, |
| 574 entry->local_file_path, | 577 entry->local_file_path, |
| 575 entry->title, | 578 entry->title, |
| 576 entry->content_type, | 579 entry->content_type, |
| 577 base::Bind(&DriveScheduler::OnUploadCompletionJobDone, | 580 base::Bind(&DriveScheduler::OnUploadCompletionJobDone, |
| 578 weak_ptr_factory_.GetWeakPtr(), | 581 weak_ptr_factory_.GetWeakPtr(), |
| 579 base::Passed(&queue_entry)), | 582 base::Passed(&queue_entry)), |
| 580 google_apis::ProgressCallback()); | 583 base::Bind(&DriveScheduler::UpdateProgress, |
| 584 weak_ptr_factory_.GetWeakPtr(), | |
| 585 job_info->job_id)); | |
| 581 } | 586 } |
| 582 break; | 587 break; |
| 583 | 588 |
| 584 case TYPE_UPLOAD_EXISTING_FILE: { | 589 case TYPE_UPLOAD_EXISTING_FILE: { |
| 585 uploader_->UploadExistingFile( | 590 uploader_->UploadExistingFile( |
| 586 entry->resource_id, | 591 entry->resource_id, |
| 587 entry->drive_file_path, | 592 entry->drive_file_path, |
| 588 entry->local_file_path, | 593 entry->local_file_path, |
| 589 entry->content_type, | 594 entry->content_type, |
| 590 entry->etag, | 595 entry->etag, |
| 591 base::Bind(&DriveScheduler::OnUploadCompletionJobDone, | 596 base::Bind(&DriveScheduler::OnUploadCompletionJobDone, |
| 592 weak_ptr_factory_.GetWeakPtr(), | 597 weak_ptr_factory_.GetWeakPtr(), |
| 593 base::Passed(&queue_entry)), | 598 base::Passed(&queue_entry)), |
| 594 google_apis::ProgressCallback()); | 599 base::Bind(&DriveScheduler::UpdateProgress, |
| 600 weak_ptr_factory_.GetWeakPtr(), | |
| 601 job_info->job_id)); | |
| 595 } | 602 } |
| 596 break; | 603 break; |
| 597 | 604 |
| 598 // There is no default case so that there will be a compiler error if a type | 605 // There is no default case so that there will be a compiler error if a type |
| 599 // is added but unhandled. | 606 // is added but unhandled. |
| 600 } | 607 } |
| 601 } | 608 } |
| 602 | 609 |
| 603 bool DriveScheduler::ShouldStopJobLoop(QueueType queue_type, | 610 bool DriveScheduler::ShouldStopJobLoop(QueueType queue_type, |
| 604 const DriveClientContext& context) { | 611 const DriveClientContext& context) { |
| (...skipping 238 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 843 | 850 |
| 844 if (!queue_entry) | 851 if (!queue_entry) |
| 845 return; | 852 return; |
| 846 | 853 |
| 847 // Handle the callback. | 854 // Handle the callback. |
| 848 DCHECK(!queue_entry->upload_completion_callback.is_null()); | 855 DCHECK(!queue_entry->upload_completion_callback.is_null()); |
| 849 queue_entry->upload_completion_callback.Run( | 856 queue_entry->upload_completion_callback.Run( |
| 850 error, drive_path, file_path, resource_entry.Pass()); | 857 error, drive_path, file_path, resource_entry.Pass()); |
| 851 } | 858 } |
| 852 | 859 |
| 860 void DriveScheduler::UpdateProgress(JobID job_id, int64 progress, int64 total) { | |
| 861 JobInfo* job_info = job_map_.Lookup(job_id); | |
| 862 DCHECK(job_info); | |
| 863 | |
| 864 job_info->num_completed_bytes = progress; | |
| 865 job_info->num_total_bytes = total; | |
| 866 } | |
| 867 | |
| 853 void DriveScheduler::OnConnectionTypeChanged( | 868 void DriveScheduler::OnConnectionTypeChanged( |
| 854 net::NetworkChangeNotifier::ConnectionType type) { | 869 net::NetworkChangeNotifier::ConnectionType type) { |
| 855 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 870 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| 856 | 871 |
| 857 // Resume the job loop if the network is back online. Note that we don't | 872 // Resume the job loop if the network is back online. Note that we don't |
| 858 // need to check the type of the network as it will be checked in | 873 // need to check the type of the network as it will be checked in |
| 859 // ShouldStopJobLoop() as soon as the loop is resumed. | 874 // ShouldStopJobLoop() as soon as the loop is resumed. |
| 860 if (!net::NetworkChangeNotifier::IsOffline()) { | 875 if (!net::NetworkChangeNotifier::IsOffline()) { |
| 861 for (int i = METADATA_QUEUE; i < NUM_QUEUES; ++i) { | 876 for (int i = METADATA_QUEUE; i < NUM_QUEUES; ++i) { |
| 862 StartJobLoop(static_cast<QueueType>(i)); | 877 StartJobLoop(static_cast<QueueType>(i)); |
| (...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 901 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 916 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| 902 FOR_EACH_OBSERVER(JobListObserver, observer_list_, OnJobDone(job_info)); | 917 FOR_EACH_OBSERVER(JobListObserver, observer_list_, OnJobDone(job_info)); |
| 903 } | 918 } |
| 904 | 919 |
| 905 void DriveScheduler::NotifyJobUpdated(const JobInfo& job_info) { | 920 void DriveScheduler::NotifyJobUpdated(const JobInfo& job_info) { |
| 906 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 921 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| 907 FOR_EACH_OBSERVER(JobListObserver, observer_list_, OnJobUpdated(job_info)); | 922 FOR_EACH_OBSERVER(JobListObserver, observer_list_, OnJobUpdated(job_info)); |
| 908 } | 923 } |
| 909 | 924 |
| 910 } // namespace drive | 925 } // namespace drive |
| OLD | NEW |