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

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

Issue 1124813003: [chrome/browser/chromeos/drive] Avoid use of MessageLoopProxy by use of TTRH (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Fixed nits Created 5 years, 7 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/files/file_util.h" 7 #include "base/files/file_util.h"
8 #include "base/message_loop/message_loop.h"
9 #include "base/metrics/histogram.h" 8 #include "base/metrics/histogram.h"
10 #include "base/prefs/pref_service.h" 9 #include "base/prefs/pref_service.h"
11 #include "base/rand_util.h" 10 #include "base/rand_util.h"
12 #include "base/strings/string_number_conversions.h" 11 #include "base/strings/string_number_conversions.h"
13 #include "base/strings/stringprintf.h" 12 #include "base/strings/stringprintf.h"
13 #include "base/thread_task_runner_handle.h"
14 #include "chrome/browser/drive/event_logger.h" 14 #include "chrome/browser/drive/event_logger.h"
15 #include "chrome/common/pref_names.h" 15 #include "chrome/common/pref_names.h"
16 #include "content/public/browser/browser_thread.h" 16 #include "content/public/browser/browser_thread.h"
17 #include "google_apis/drive/drive_api_parser.h" 17 #include "google_apis/drive/drive_api_parser.h"
18 18
19 using content::BrowserThread; 19 using content::BrowserThread;
20 20
21 namespace drive { 21 namespace drive {
22 22
23 namespace { 23 namespace {
(...skipping 753 matching lines...) Expand 10 before | Expand all | Expand 10 after
777 for (size_t i = 0; i < jobs.size(); ++i) { 777 for (size_t i = 0; i < jobs.size(); ++i) {
778 JobEntry* job = job_map_.Lookup(jobs[i]); 778 JobEntry* job = job_map_.Lookup(jobs[i]);
779 DCHECK(job); 779 DCHECK(job);
780 AbortNotRunningJob(job, google_apis::DRIVE_NO_CONNECTION); 780 AbortNotRunningJob(job, google_apis::DRIVE_NO_CONNECTION);
781 } 781 }
782 } 782 }
783 783
784 // Wait when throttled. 784 // Wait when throttled.
785 const base::Time now = base::Time::Now(); 785 const base::Time now = base::Time::Now();
786 if (now < wait_until_) { 786 if (now < wait_until_) {
787 base::MessageLoopProxy::current()->PostDelayedTask( 787 base::ThreadTaskRunnerHandle::Get()->PostDelayedTask(
788 FROM_HERE, 788 FROM_HERE,
789 base::Bind(&JobScheduler::DoJobLoop, 789 base::Bind(&JobScheduler::DoJobLoop,
790 weak_ptr_factory_.GetWeakPtr(), 790 weak_ptr_factory_.GetWeakPtr(),
791 queue_type), 791 queue_type),
792 wait_until_ - now); 792 wait_until_ - now);
793 return; 793 return;
794 } 794 }
795 795
796 // Run the job with the highest priority in the queue. 796 // Run the job with the highest priority in the queue.
797 JobID job_id = -1; 797 JobID job_id = -1;
(...skipping 102 matching lines...) Expand 10 before | Expand all | Expand 10 after
900 QueueJob(job_id); 900 QueueJob(job_id);
901 } else { 901 } else {
902 NotifyJobDone(*job_info, error); 902 NotifyJobDone(*job_info, error);
903 // The job has finished, no retry will happen in the scheduler. Now we can 903 // The job has finished, no retry will happen in the scheduler. Now we can
904 // remove the job info from the map. 904 // remove the job info from the map.
905 job_map_.Remove(job_id); 905 job_map_.Remove(job_id);
906 } 906 }
907 907
908 // Post a task to continue the job loop. This allows us to finish handling 908 // Post a task to continue the job loop. This allows us to finish handling
909 // the current job before starting the next one. 909 // the current job before starting the next one.
910 base::MessageLoopProxy::current()->PostTask(FROM_HERE, 910 base::ThreadTaskRunnerHandle::Get()->PostTask(
911 FROM_HERE,
911 base::Bind(&JobScheduler::DoJobLoop, 912 base::Bind(&JobScheduler::DoJobLoop,
912 weak_ptr_factory_.GetWeakPtr(), 913 weak_ptr_factory_.GetWeakPtr(),
913 queue_type)); 914 queue_type));
914 return !should_retry; 915 return !should_retry;
915 } 916 }
916 917
917 void JobScheduler::OnGetFileListJobDone( 918 void JobScheduler::OnGetFileListJobDone(
918 JobID job_id, 919 JobID job_id,
919 const google_apis::FileListCallback& callback, 920 const google_apis::FileListCallback& callback,
920 google_apis::DriveApiErrorCode error, 921 google_apis::DriveApiErrorCode error,
921 scoped_ptr<google_apis::FileList> file_list) { 922 scoped_ptr<google_apis::FileList> file_list) {
922 DCHECK_CURRENTLY_ON(BrowserThread::UI); 923 DCHECK_CURRENTLY_ON(BrowserThread::UI);
923 DCHECK(!callback.is_null()); 924 DCHECK(!callback.is_null());
(...skipping 207 matching lines...) Expand 10 before | Expand all | Expand 10 after
1131 job->job_info.ToString().c_str(), 1132 job->job_info.ToString().c_str(),
1132 DriveApiErrorCodeToString(error).c_str(), 1133 DriveApiErrorCodeToString(error).c_str(),
1133 base::Int64ToString(elapsed.InMilliseconds()).c_str(), 1134 base::Int64ToString(elapsed.InMilliseconds()).c_str(),
1134 GetQueueInfo(queue_type).c_str()); 1135 GetQueueInfo(queue_type).c_str());
1135 1136
1136 base::Callback<void(google_apis::DriveApiErrorCode)> callback = 1137 base::Callback<void(google_apis::DriveApiErrorCode)> callback =
1137 job->abort_callback; 1138 job->abort_callback;
1138 queue_[GetJobQueueType(job->job_info.job_type)]->Remove(job->job_info.job_id); 1139 queue_[GetJobQueueType(job->job_info.job_type)]->Remove(job->job_info.job_id);
1139 NotifyJobDone(job->job_info, error); 1140 NotifyJobDone(job->job_info, error);
1140 job_map_.Remove(job->job_info.job_id); 1141 job_map_.Remove(job->job_info.job_id);
1141 base::MessageLoopProxy::current()->PostTask(FROM_HERE, 1142 base::ThreadTaskRunnerHandle::Get()->PostTask(FROM_HERE,
1142 base::Bind(callback, error)); 1143 base::Bind(callback, error));
1143 } 1144 }
1144 1145
1145 void JobScheduler::NotifyJobAdded(const JobInfo& job_info) { 1146 void JobScheduler::NotifyJobAdded(const JobInfo& job_info) {
1146 DCHECK_CURRENTLY_ON(BrowserThread::UI); 1147 DCHECK_CURRENTLY_ON(BrowserThread::UI);
1147 FOR_EACH_OBSERVER(JobListObserver, observer_list_, OnJobAdded(job_info)); 1148 FOR_EACH_OBSERVER(JobListObserver, observer_list_, OnJobAdded(job_info));
1148 } 1149 }
1149 1150
1150 void JobScheduler::NotifyJobDone(const JobInfo& job_info, 1151 void JobScheduler::NotifyJobDone(const JobInfo& job_info,
1151 google_apis::DriveApiErrorCode error) { 1152 google_apis::DriveApiErrorCode error) {
1152 DCHECK_CURRENTLY_ON(BrowserThread::UI); 1153 DCHECK_CURRENTLY_ON(BrowserThread::UI);
(...skipping 18 matching lines...) Expand all
1171 case FILE_QUEUE: 1172 case FILE_QUEUE:
1172 return "FILE_QUEUE"; 1173 return "FILE_QUEUE";
1173 case NUM_QUEUES: 1174 case NUM_QUEUES:
1174 break; // This value is just a sentinel. Should never be used. 1175 break; // This value is just a sentinel. Should never be used.
1175 } 1176 }
1176 NOTREACHED(); 1177 NOTREACHED();
1177 return ""; 1178 return "";
1178 } 1179 }
1179 1180
1180 } // namespace drive 1181 } // namespace drive
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698