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

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 Review Comments 3 : Indent 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 756 matching lines...) Expand 10 before | Expand all | Expand 10 after
780 for (size_t i = 0; i < jobs.size(); ++i) { 780 for (size_t i = 0; i < jobs.size(); ++i) {
781 JobEntry* job = job_map_.Lookup(jobs[i]); 781 JobEntry* job = job_map_.Lookup(jobs[i]);
782 DCHECK(job); 782 DCHECK(job);
783 AbortNotRunningJob(job, google_apis::DRIVE_NO_CONNECTION); 783 AbortNotRunningJob(job, google_apis::DRIVE_NO_CONNECTION);
784 } 784 }
785 } 785 }
786 786
787 // Wait when throttled. 787 // Wait when throttled.
788 const base::Time now = base::Time::Now(); 788 const base::Time now = base::Time::Now();
789 if (now < wait_until_) { 789 if (now < wait_until_) {
790 base::MessageLoopProxy::current()->PostDelayedTask( 790 base::ThreadTaskRunnerHandle::Get()->PostDelayedTask(
791 FROM_HERE, 791 FROM_HERE,
792 base::Bind(&JobScheduler::DoJobLoop, 792 base::Bind(&JobScheduler::DoJobLoop,
793 weak_ptr_factory_.GetWeakPtr(), 793 weak_ptr_factory_.GetWeakPtr(),
794 queue_type), 794 queue_type),
795 wait_until_ - now); 795 wait_until_ - now);
796 return; 796 return;
797 } 797 }
798 798
799 // Run the job with the highest priority in the queue. 799 // Run the job with the highest priority in the queue.
800 std::vector<JobID> job_ids; 800 std::vector<JobID> job_ids;
(...skipping 106 matching lines...) Expand 10 before | Expand all | Expand 10 after
907 QueueJob(job_id); 907 QueueJob(job_id);
908 } else { 908 } else {
909 NotifyJobDone(*job_info, error); 909 NotifyJobDone(*job_info, error);
910 // The job has finished, no retry will happen in the scheduler. Now we can 910 // The job has finished, no retry will happen in the scheduler. Now we can
911 // remove the job info from the map. 911 // remove the job info from the map.
912 job_map_.Remove(job_id); 912 job_map_.Remove(job_id);
913 } 913 }
914 914
915 // Post a task to continue the job loop. This allows us to finish handling 915 // Post a task to continue the job loop. This allows us to finish handling
916 // the current job before starting the next one. 916 // the current job before starting the next one.
917 base::MessageLoopProxy::current()->PostTask(FROM_HERE, 917 base::ThreadTaskRunnerHandle::Get()->PostTask(
918 FROM_HERE,
918 base::Bind(&JobScheduler::DoJobLoop, 919 base::Bind(&JobScheduler::DoJobLoop,
919 weak_ptr_factory_.GetWeakPtr(), 920 weak_ptr_factory_.GetWeakPtr(),
920 queue_type)); 921 queue_type));
921 return !should_retry; 922 return !should_retry;
922 } 923 }
923 924
924 void JobScheduler::OnGetFileListJobDone( 925 void JobScheduler::OnGetFileListJobDone(
925 JobID job_id, 926 JobID job_id,
926 const google_apis::FileListCallback& callback, 927 const google_apis::FileListCallback& callback,
927 google_apis::DriveApiErrorCode error, 928 google_apis::DriveApiErrorCode error,
(...skipping 210 matching lines...) Expand 10 before | Expand all | Expand 10 after
1138 job->job_info.ToString().c_str(), 1139 job->job_info.ToString().c_str(),
1139 DriveApiErrorCodeToString(error).c_str(), 1140 DriveApiErrorCodeToString(error).c_str(),
1140 base::Int64ToString(elapsed.InMilliseconds()).c_str(), 1141 base::Int64ToString(elapsed.InMilliseconds()).c_str(),
1141 GetQueueInfo(queue_type).c_str()); 1142 GetQueueInfo(queue_type).c_str());
1142 1143
1143 base::Callback<void(google_apis::DriveApiErrorCode)> callback = 1144 base::Callback<void(google_apis::DriveApiErrorCode)> callback =
1144 job->abort_callback; 1145 job->abort_callback;
1145 queue_[GetJobQueueType(job->job_info.job_type)]->Remove(job->job_info.job_id); 1146 queue_[GetJobQueueType(job->job_info.job_type)]->Remove(job->job_info.job_id);
1146 NotifyJobDone(job->job_info, error); 1147 NotifyJobDone(job->job_info, error);
1147 job_map_.Remove(job->job_info.job_id); 1148 job_map_.Remove(job->job_info.job_id);
1148 base::MessageLoopProxy::current()->PostTask(FROM_HERE, 1149 base::ThreadTaskRunnerHandle::Get()->PostTask(FROM_HERE,
1149 base::Bind(callback, error)); 1150 base::Bind(callback, error));
1150 } 1151 }
1151 1152
1152 void JobScheduler::NotifyJobAdded(const JobInfo& job_info) { 1153 void JobScheduler::NotifyJobAdded(const JobInfo& job_info) {
1153 DCHECK_CURRENTLY_ON(BrowserThread::UI); 1154 DCHECK_CURRENTLY_ON(BrowserThread::UI);
1154 FOR_EACH_OBSERVER(JobListObserver, observer_list_, OnJobAdded(job_info)); 1155 FOR_EACH_OBSERVER(JobListObserver, observer_list_, OnJobAdded(job_info));
1155 } 1156 }
1156 1157
1157 void JobScheduler::NotifyJobDone(const JobInfo& job_info, 1158 void JobScheduler::NotifyJobDone(const JobInfo& job_info,
1158 google_apis::DriveApiErrorCode error) { 1159 google_apis::DriveApiErrorCode error) {
1159 DCHECK_CURRENTLY_ON(BrowserThread::UI); 1160 DCHECK_CURRENTLY_ON(BrowserThread::UI);
(...skipping 18 matching lines...) Expand all
1178 case FILE_QUEUE: 1179 case FILE_QUEUE:
1179 return "FILE_QUEUE"; 1180 return "FILE_QUEUE";
1180 case NUM_QUEUES: 1181 case NUM_QUEUES:
1181 break; // This value is just a sentinel. Should never be used. 1182 break; // This value is just a sentinel. Should never be used.
1182 } 1183 }
1183 NOTREACHED(); 1184 NOTREACHED();
1184 return ""; 1185 return "";
1185 } 1186 }
1186 1187
1187 } // namespace drive 1188 } // namespace drive
OLDNEW
« no previous file with comments | « chrome/browser/chromeos/drive/fileapi/fileapi_worker.cc ('k') | chrome/browser/chromeos/drive/job_scheduler_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698