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

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 const QueueType queue_type = GetJobQueueType(job->job_info.job_type);
708 job->job_info.num_total_jobs = queue_[queue_type]->GetNumberOfJobs();
707 NotifyJobAdded(job->job_info); 709 NotifyJobAdded(job->job_info);
708 DoJobLoop(GetJobQueueType(job->job_info.job_type)); 710 DoJobLoop(GetJobQueueType(job->job_info.job_type));
709 } 711 }
710 712
711 void JobScheduler::QueueJob(JobID job_id) { 713 void JobScheduler::QueueJob(JobID job_id) {
712 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 714 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
713 715
714 JobEntry* job_entry = job_map_.Lookup(job_id); 716 JobEntry* job_entry = job_map_.Lookup(job_id);
715 DCHECK(job_entry); 717 DCHECK(job_entry);
716 const JobInfo& job_info = job_entry->job_info; 718 const JobInfo& job_info = job_entry->job_info;
717 719
718 QueueType queue_type = GetJobQueueType(job_info.job_type); 720 const QueueType queue_type = GetJobQueueType(job_info.job_type);
719 queue_[queue_type]->Push(job_id, job_entry->context.type); 721 queue_[queue_type]->Push(job_id, job_entry->context.type);
720 722
721 const std::string retry_prefix = job_entry->retry_count > 0 ? 723 const std::string retry_prefix = job_entry->retry_count > 0 ?
722 base::StringPrintf(" (retry %d)", job_entry->retry_count) : ""; 724 base::StringPrintf(" (retry %d)", job_entry->retry_count) : "";
723 logger_->Log(logging::LOG_INFO, 725 logger_->Log(logging::LOG_INFO,
724 "Job queued%s: %s - %s", 726 "Job queued%s: %s - %s",
725 retry_prefix.c_str(), 727 retry_prefix.c_str(),
726 job_info.ToString().c_str(), 728 job_info.ToString().c_str(),
727 GetQueueInfo(queue_type).c_str()); 729 GetQueueInfo(queue_type).c_str());
728 } 730 }
(...skipping 30 matching lines...) Expand all
759 JobID job_id = -1; 761 JobID job_id = -1;
760 if (!queue_[queue_type]->PopForRun(accepted_priority, &job_id)) 762 if (!queue_[queue_type]->PopForRun(accepted_priority, &job_id))
761 return; 763 return;
762 764
763 JobEntry* entry = job_map_.Lookup(job_id); 765 JobEntry* entry = job_map_.Lookup(job_id);
764 DCHECK(entry); 766 DCHECK(entry);
765 767
766 JobInfo* job_info = &entry->job_info; 768 JobInfo* job_info = &entry->job_info;
767 job_info->state = STATE_RUNNING; 769 job_info->state = STATE_RUNNING;
768 job_info->start_time = now; 770 job_info->start_time = now;
771 job_info->num_total_jobs = queue_[queue_type]->GetNumberOfJobs();
769 NotifyJobUpdated(*job_info); 772 NotifyJobUpdated(*job_info);
770 773
771 entry->cancel_callback = entry->task.Run(); 774 entry->cancel_callback = entry->task.Run();
772 775
773 UpdateWait(); 776 UpdateWait();
774 777
775 logger_->Log(logging::LOG_INFO, 778 logger_->Log(logging::LOG_INFO,
776 "Job started: %s - %s", 779 "Job started: %s - %s",
777 job_info->ToString().c_str(), 780 job_info->ToString().c_str(),
778 GetQueueInfo(queue_type).c_str()); 781 GetQueueInfo(queue_type).c_str());
(...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after
846 UpdateWait(); 849 UpdateWait();
847 } else { 850 } else {
848 throttle_count_ = 0; 851 throttle_count_ = 0;
849 } 852 }
850 853
851 const bool should_retry = 854 const bool should_retry =
852 is_server_error && job_entry->retry_count < kMaxRetryCount; 855 is_server_error && job_entry->retry_count < kMaxRetryCount;
853 if (should_retry) { 856 if (should_retry) {
854 job_entry->cancel_callback.Reset(); 857 job_entry->cancel_callback.Reset();
855 job_info->state = STATE_RETRY; 858 job_info->state = STATE_RETRY;
859 const QueueType queue_type = GetJobQueueType(job_info->job_type);
860 job_info->num_total_jobs = queue_[queue_type]->GetNumberOfJobs();
856 NotifyJobUpdated(*job_info); 861 NotifyJobUpdated(*job_info);
857 862
858 ++job_entry->retry_count; 863 ++job_entry->retry_count;
859 864
860 // Requeue the job. 865 // Requeue the job.
861 QueueJob(job_id); 866 QueueJob(job_id);
862 } else { 867 } else {
868 const QueueType queue_type = GetJobQueueType(job_info->job_type);
869 job_info->num_total_jobs = queue_[queue_type]->GetNumberOfJobs();
863 NotifyJobDone(*job_info, error); 870 NotifyJobDone(*job_info, error);
864 // The job has finished, no retry will happen in the scheduler. Now we can 871 // The job has finished, no retry will happen in the scheduler. Now we can
865 // remove the job info from the map. 872 // remove the job info from the map.
866 job_map_.Remove(job_id); 873 job_map_.Remove(job_id);
867 } 874 }
868 875
869 // Post a task to continue the job loop. This allows us to finish handling 876 // Post a task to continue the job loop. This allows us to finish handling
870 // the current job before starting the next one. 877 // the current job before starting the next one.
871 base::MessageLoopProxy::current()->PostTask(FROM_HERE, 878 base::MessageLoopProxy::current()->PostTask(FROM_HERE,
872 base::Bind(&JobScheduler::DoJobLoop, 879 base::Bind(&JobScheduler::DoJobLoop,
(...skipping 157 matching lines...) Expand 10 before | Expand all | Expand 10 after
1030 callback.Run(error, entry.Pass()); 1037 callback.Run(error, entry.Pass());
1031 } 1038 }
1032 1039
1033 void JobScheduler::UpdateProgress(JobID job_id, int64 progress, int64 total) { 1040 void JobScheduler::UpdateProgress(JobID job_id, int64 progress, int64 total) {
1034 JobEntry* job_entry = job_map_.Lookup(job_id); 1041 JobEntry* job_entry = job_map_.Lookup(job_id);
1035 DCHECK(job_entry); 1042 DCHECK(job_entry);
1036 1043
1037 job_entry->job_info.num_completed_bytes = progress; 1044 job_entry->job_info.num_completed_bytes = progress;
1038 if (total != -1) 1045 if (total != -1)
1039 job_entry->job_info.num_total_bytes = total; 1046 job_entry->job_info.num_total_bytes = total;
1047 const QueueType queue_type = GetJobQueueType(job_entry->job_info.job_type);
1048 job_entry->job_info.num_total_jobs = queue_[queue_type]->GetNumberOfJobs();
1040 NotifyJobUpdated(job_entry->job_info); 1049 NotifyJobUpdated(job_entry->job_info);
1041 } 1050 }
1042 1051
1043 void JobScheduler::OnConnectionTypeChanged( 1052 void JobScheduler::OnConnectionTypeChanged(
1044 net::NetworkChangeNotifier::ConnectionType type) { 1053 net::NetworkChangeNotifier::ConnectionType type) {
1045 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 1054 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
1046 1055
1047 // Resume the job loop. 1056 // Resume the job loop.
1048 // Note that we don't need to check the network connection status as it will 1057 // Note that we don't need to check the network connection status as it will
1049 // be checked in GetCurrentAcceptedPriority(). 1058 // be checked in GetCurrentAcceptedPriority().
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after
1091 logger_->Log(logging::LOG_INFO, 1100 logger_->Log(logging::LOG_INFO,
1092 "Job aborted: %s => %s (elapsed time: %sms) - %s", 1101 "Job aborted: %s => %s (elapsed time: %sms) - %s",
1093 job->job_info.ToString().c_str(), 1102 job->job_info.ToString().c_str(),
1094 GDataErrorCodeToString(error).c_str(), 1103 GDataErrorCodeToString(error).c_str(),
1095 base::Int64ToString(elapsed.InMilliseconds()).c_str(), 1104 base::Int64ToString(elapsed.InMilliseconds()).c_str(),
1096 GetQueueInfo(queue_type).c_str()); 1105 GetQueueInfo(queue_type).c_str());
1097 1106
1098 base::Callback<void(google_apis::GDataErrorCode)> callback = 1107 base::Callback<void(google_apis::GDataErrorCode)> callback =
1099 job->abort_callback; 1108 job->abort_callback;
1100 queue_[GetJobQueueType(job->job_info.job_type)]->Remove(job->job_info.job_id); 1109 queue_[GetJobQueueType(job->job_info.job_type)]->Remove(job->job_info.job_id);
1110 job->job_info.num_total_jobs = queue_[queue_type]->GetNumberOfJobs();
1101 NotifyJobDone(job->job_info, error); 1111 NotifyJobDone(job->job_info, error);
1102 job_map_.Remove(job->job_info.job_id); 1112 job_map_.Remove(job->job_info.job_id);
1103 base::MessageLoopProxy::current()->PostTask(FROM_HERE, 1113 base::MessageLoopProxy::current()->PostTask(FROM_HERE,
1104 base::Bind(callback, error)); 1114 base::Bind(callback, error));
1105 } 1115 }
1106 1116
1107 void JobScheduler::NotifyJobAdded(const JobInfo& job_info) { 1117 void JobScheduler::NotifyJobAdded(const JobInfo& job_info) {
1108 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 1118 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
1109 FOR_EACH_OBSERVER(JobListObserver, observer_list_, OnJobAdded(job_info)); 1119 FOR_EACH_OBSERVER(JobListObserver, observer_list_, OnJobAdded(job_info));
1110 } 1120 }
(...skipping 22 matching lines...) Expand all
1133 case FILE_QUEUE: 1143 case FILE_QUEUE:
1134 return "FILE_QUEUE"; 1144 return "FILE_QUEUE";
1135 case NUM_QUEUES: 1145 case NUM_QUEUES:
1136 break; // This value is just a sentinel. Should never be used. 1146 break; // This value is just a sentinel. Should never be used.
1137 } 1147 }
1138 NOTREACHED(); 1148 NOTREACHED();
1139 return ""; 1149 return "";
1140 } 1150 }
1141 1151
1142 } // namespace drive 1152 } // namespace drive
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698