Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(312)

Side by Side Diff: chrome/browser/chromeos/drive/job_scheduler.cc

Issue 507293002: Enrich fileBrowserPrivate.onFileTransfersUpdated event to support displaying total number of jobs. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 6 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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/job_scheduler.h" 5 #include "chrome/browser/chromeos/drive/job_scheduler.h"
6 6
7 #include "base/message_loop/message_loop.h" 7 #include "base/message_loop/message_loop.h"
8 #include "base/prefs/pref_service.h" 8 #include "base/prefs/pref_service.h"
9 #include "base/rand_util.h" 9 #include "base/rand_util.h"
10 #include "base/strings/string_number_conversions.h" 10 #include "base/strings/string_number_conversions.h"
(...skipping 686 matching lines...) Expand 10 before | Expand all | Expand 10 after
697 JobScheduler::JobEntry* JobScheduler::CreateNewJob(JobType type) { 697 JobScheduler::JobEntry* JobScheduler::CreateNewJob(JobType type) {
698 JobEntry* job = new JobEntry(type); 698 JobEntry* job = new JobEntry(type);
699 job->job_info.job_id = job_map_.Add(job); // Takes the ownership of |job|. 699 job->job_info.job_id = job_map_.Add(job); // Takes the ownership of |job|.
700 return job; 700 return job;
701 } 701 }
702 702
703 void JobScheduler::StartJob(JobEntry* job) { 703 void JobScheduler::StartJob(JobEntry* job) {
704 DCHECK(!job->task.is_null()); 704 DCHECK(!job->task.is_null());
705 705
706 QueueJob(job->job_info.job_id); 706 QueueJob(job->job_info.job_id);
707 QueueType queue_type = GetJobQueueType(job->job_info.job_type);
708 job->job_info.num_total_jobs = queue_[queue_type]->GetNumberOfJobs();
709 if (queue_type == FILE_QUEUE) {
710 job->job_info.state = STATE_NEW;
711 }
707 NotifyJobAdded(job->job_info); 712 NotifyJobAdded(job->job_info);
708 DoJobLoop(GetJobQueueType(job->job_info.job_type)); 713 DoJobLoop(GetJobQueueType(job->job_info.job_type));
709 } 714 }
710 715
711 void JobScheduler::QueueJob(JobID job_id) { 716 void JobScheduler::QueueJob(JobID job_id) {
712 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 717 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
713 718
714 JobEntry* job_entry = job_map_.Lookup(job_id); 719 JobEntry* job_entry = job_map_.Lookup(job_id);
715 DCHECK(job_entry); 720 DCHECK(job_entry);
716 const JobInfo& job_info = job_entry->job_info; 721 const JobInfo& job_info = job_entry->job_info;
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after
759 JobID job_id = -1; 764 JobID job_id = -1;
760 if (!queue_[queue_type]->PopForRun(accepted_priority, &job_id)) 765 if (!queue_[queue_type]->PopForRun(accepted_priority, &job_id))
761 return; 766 return;
762 767
763 JobEntry* entry = job_map_.Lookup(job_id); 768 JobEntry* entry = job_map_.Lookup(job_id);
764 DCHECK(entry); 769 DCHECK(entry);
765 770
766 JobInfo* job_info = &entry->job_info; 771 JobInfo* job_info = &entry->job_info;
767 job_info->state = STATE_RUNNING; 772 job_info->state = STATE_RUNNING;
768 job_info->start_time = now; 773 job_info->start_time = now;
774 job_info->num_total_jobs = queue_[queue_type]->GetNumberOfJobs();
769 NotifyJobUpdated(*job_info); 775 NotifyJobUpdated(*job_info);
770 776
771 entry->cancel_callback = entry->task.Run(); 777 entry->cancel_callback = entry->task.Run();
772 778
773 UpdateWait(); 779 UpdateWait();
774 780
775 logger_->Log(logging::LOG_INFO, 781 logger_->Log(logging::LOG_INFO,
776 "Job started: %s - %s", 782 "Job started: %s - %s",
777 job_info->ToString().c_str(), 783 job_info->ToString().c_str(),
778 GetQueueInfo(queue_type).c_str()); 784 GetQueueInfo(queue_type).c_str());
(...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after
846 UpdateWait(); 852 UpdateWait();
847 } else { 853 } else {
848 throttle_count_ = 0; 854 throttle_count_ = 0;
849 } 855 }
850 856
851 const bool should_retry = 857 const bool should_retry =
852 is_server_error && job_entry->retry_count < kMaxRetryCount; 858 is_server_error && job_entry->retry_count < kMaxRetryCount;
853 if (should_retry) { 859 if (should_retry) {
854 job_entry->cancel_callback.Reset(); 860 job_entry->cancel_callback.Reset();
855 job_info->state = STATE_RETRY; 861 job_info->state = STATE_RETRY;
862 QueueType queue_type = GetJobQueueType(job_info->job_type);
863 job_info->num_total_jobs = queue_[queue_type]->GetNumberOfJobs();
856 NotifyJobUpdated(*job_info); 864 NotifyJobUpdated(*job_info);
857 865
858 ++job_entry->retry_count; 866 ++job_entry->retry_count;
859 867
860 // Requeue the job. 868 // Requeue the job.
861 QueueJob(job_id); 869 QueueJob(job_id);
862 } else { 870 } else {
871 QueueType queue_type = GetJobQueueType(job_info->job_type);
872 job_info->num_total_jobs = queue_[queue_type]->GetNumberOfJobs();
863 NotifyJobDone(*job_info, error); 873 NotifyJobDone(*job_info, error);
864 // The job has finished, no retry will happen in the scheduler. Now we can 874 // The job has finished, no retry will happen in the scheduler. Now we can
865 // remove the job info from the map. 875 // remove the job info from the map.
866 job_map_.Remove(job_id); 876 job_map_.Remove(job_id);
867 } 877 }
868 878
869 // Post a task to continue the job loop. This allows us to finish handling 879 // Post a task to continue the job loop. This allows us to finish handling
870 // the current job before starting the next one. 880 // the current job before starting the next one.
871 base::MessageLoopProxy::current()->PostTask(FROM_HERE, 881 base::MessageLoopProxy::current()->PostTask(FROM_HERE,
872 base::Bind(&JobScheduler::DoJobLoop, 882 base::Bind(&JobScheduler::DoJobLoop,
(...skipping 157 matching lines...) Expand 10 before | Expand all | Expand 10 after
1030 callback.Run(error, entry.Pass()); 1040 callback.Run(error, entry.Pass());
1031 } 1041 }
1032 1042
1033 void JobScheduler::UpdateProgress(JobID job_id, int64 progress, int64 total) { 1043 void JobScheduler::UpdateProgress(JobID job_id, int64 progress, int64 total) {
1034 JobEntry* job_entry = job_map_.Lookup(job_id); 1044 JobEntry* job_entry = job_map_.Lookup(job_id);
1035 DCHECK(job_entry); 1045 DCHECK(job_entry);
1036 1046
1037 job_entry->job_info.num_completed_bytes = progress; 1047 job_entry->job_info.num_completed_bytes = progress;
1038 if (total != -1) 1048 if (total != -1)
1039 job_entry->job_info.num_total_bytes = total; 1049 job_entry->job_info.num_total_bytes = total;
1050 QueueType queue_type = GetJobQueueType(job_entry->job_info.job_type);
1051 job_entry->job_info.num_total_jobs = queue_[queue_type]->GetNumberOfJobs();
1040 NotifyJobUpdated(job_entry->job_info); 1052 NotifyJobUpdated(job_entry->job_info);
1041 } 1053 }
1042 1054
1043 void JobScheduler::OnConnectionTypeChanged( 1055 void JobScheduler::OnConnectionTypeChanged(
1044 net::NetworkChangeNotifier::ConnectionType type) { 1056 net::NetworkChangeNotifier::ConnectionType type) {
1045 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 1057 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
1046 1058
1047 // Resume the job loop. 1059 // Resume the job loop.
1048 // Note that we don't need to check the network connection status as it will 1060 // Note that we don't need to check the network connection status as it will
1049 // be checked in GetCurrentAcceptedPriority(). 1061 // be checked in GetCurrentAcceptedPriority().
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after
1091 logger_->Log(logging::LOG_INFO, 1103 logger_->Log(logging::LOG_INFO,
1092 "Job aborted: %s => %s (elapsed time: %sms) - %s", 1104 "Job aborted: %s => %s (elapsed time: %sms) - %s",
1093 job->job_info.ToString().c_str(), 1105 job->job_info.ToString().c_str(),
1094 GDataErrorCodeToString(error).c_str(), 1106 GDataErrorCodeToString(error).c_str(),
1095 base::Int64ToString(elapsed.InMilliseconds()).c_str(), 1107 base::Int64ToString(elapsed.InMilliseconds()).c_str(),
1096 GetQueueInfo(queue_type).c_str()); 1108 GetQueueInfo(queue_type).c_str());
1097 1109
1098 base::Callback<void(google_apis::GDataErrorCode)> callback = 1110 base::Callback<void(google_apis::GDataErrorCode)> callback =
1099 job->abort_callback; 1111 job->abort_callback;
1100 queue_[GetJobQueueType(job->job_info.job_type)]->Remove(job->job_info.job_id); 1112 queue_[GetJobQueueType(job->job_info.job_type)]->Remove(job->job_info.job_id);
1113 job->job_info.num_total_jobs = queue_[queue_type]->GetNumberOfJobs();
1101 NotifyJobDone(job->job_info, error); 1114 NotifyJobDone(job->job_info, error);
1102 job_map_.Remove(job->job_info.job_id); 1115 job_map_.Remove(job->job_info.job_id);
1103 base::MessageLoopProxy::current()->PostTask(FROM_HERE, 1116 base::MessageLoopProxy::current()->PostTask(FROM_HERE,
1104 base::Bind(callback, error)); 1117 base::Bind(callback, error));
1105 } 1118 }
1106 1119
1107 void JobScheduler::NotifyJobAdded(const JobInfo& job_info) { 1120 void JobScheduler::NotifyJobAdded(const JobInfo& job_info) {
1108 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 1121 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
1109 FOR_EACH_OBSERVER(JobListObserver, observer_list_, OnJobAdded(job_info)); 1122 FOR_EACH_OBSERVER(JobListObserver, observer_list_, OnJobAdded(job_info));
1110 } 1123 }
(...skipping 22 matching lines...) Expand all
1133 case FILE_QUEUE: 1146 case FILE_QUEUE:
1134 return "FILE_QUEUE"; 1147 return "FILE_QUEUE";
1135 case NUM_QUEUES: 1148 case NUM_QUEUES:
1136 break; // This value is just a sentinel. Should never be used. 1149 break; // This value is just a sentinel. Should never be used.
1137 } 1150 }
1138 NOTREACHED(); 1151 NOTREACHED();
1139 return ""; 1152 return "";
1140 } 1153 }
1141 1154
1142 } // namespace drive 1155 } // namespace drive
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698