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

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

Issue 1138883004: Revert of Revert of Drive: Let DriveUploader use batch request API. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: 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
« no previous file with comments | « chrome/browser/chromeos/drive/job_queue.cc ('k') | chrome/browser/drive/drive_uploader.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 <algorithm>
8
7 #include "base/files/file_util.h" 9 #include "base/files/file_util.h"
8 #include "base/message_loop/message_loop.h" 10 #include "base/message_loop/message_loop.h"
9 #include "base/metrics/histogram.h" 11 #include "base/metrics/histogram.h"
10 #include "base/prefs/pref_service.h" 12 #include "base/prefs/pref_service.h"
11 #include "base/rand_util.h" 13 #include "base/rand_util.h"
12 #include "base/strings/string_number_conversions.h" 14 #include "base/strings/string_number_conversions.h"
13 #include "base/strings/stringprintf.h" 15 #include "base/strings/stringprintf.h"
14 #include "chrome/browser/drive/event_logger.h" 16 #include "chrome/browser/drive/event_logger.h"
15 #include "chrome/common/pref_names.h" 17 #include "chrome/common/pref_names.h"
16 #include "content/public/browser/browser_thread.h" 18 #include "content/public/browser/browser_thread.h"
(...skipping 718 matching lines...) Expand 10 before | Expand all | Expand 10 after
735 } 737 }
736 738
737 void JobScheduler::QueueJob(JobID job_id) { 739 void JobScheduler::QueueJob(JobID job_id) {
738 DCHECK_CURRENTLY_ON(BrowserThread::UI); 740 DCHECK_CURRENTLY_ON(BrowserThread::UI);
739 741
740 JobEntry* job_entry = job_map_.Lookup(job_id); 742 JobEntry* job_entry = job_map_.Lookup(job_id);
741 DCHECK(job_entry); 743 DCHECK(job_entry);
742 const JobInfo& job_info = job_entry->job_info; 744 const JobInfo& job_info = job_entry->job_info;
743 745
744 const QueueType queue_type = GetJobQueueType(job_info.job_type); 746 const QueueType queue_type = GetJobQueueType(job_info.job_type);
745 queue_[queue_type]->Push(job_id, job_entry->context.type, false, 747 const bool batchable = job_info.job_type == TYPE_UPLOAD_EXISTING_FILE ||
748 job_info.job_type == TYPE_UPLOAD_NEW_FILE;
749 queue_[queue_type]->Push(job_id, job_entry->context.type, batchable,
746 job_info.num_total_bytes); 750 job_info.num_total_bytes);
747 751
748 // Temporary histogram for crbug.com/229650. 752 // Temporary histogram for crbug.com/229650.
749 if (job_info.job_type == TYPE_DOWNLOAD_FILE || 753 if (job_info.job_type == TYPE_DOWNLOAD_FILE ||
750 job_info.job_type == TYPE_UPLOAD_EXISTING_FILE || 754 job_info.job_type == TYPE_UPLOAD_EXISTING_FILE ||
751 job_info.job_type == TYPE_UPLOAD_NEW_FILE) { 755 job_info.job_type == TYPE_UPLOAD_NEW_FILE) {
752 std::vector<JobID> jobs_with_the_same_priority; 756 std::vector<JobID> jobs_with_the_same_priority;
753 queue_[queue_type]->GetQueuedJobs(job_entry->context.type, 757 queue_[queue_type]->GetQueuedJobs(job_entry->context.type,
754 &jobs_with_the_same_priority); 758 &jobs_with_the_same_priority);
755 DCHECK(!jobs_with_the_same_priority.empty()); 759 DCHECK(!jobs_with_the_same_priority.empty());
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after
795 wait_until_ - now); 799 wait_until_ - now);
796 return; 800 return;
797 } 801 }
798 802
799 // Run the job with the highest priority in the queue. 803 // Run the job with the highest priority in the queue.
800 std::vector<JobID> job_ids; 804 std::vector<JobID> job_ids;
801 queue_[queue_type]->PopForRun(accepted_priority, &job_ids); 805 queue_[queue_type]->PopForRun(accepted_priority, &job_ids);
802 if (job_ids.empty()) 806 if (job_ids.empty())
803 return; 807 return;
804 808
805 // TODO(hirono): Currently all requests are not batchable. So the queue always 809 if (job_ids.size() > 1)
806 // return just 1 job. 810 uploader_->StartBatchProcessing();
807 DCHECK_EQ(1u, job_ids.size());
808 JobEntry* entry = job_map_.Lookup(job_ids.front());
809 DCHECK(entry);
810 811
811 JobInfo* job_info = &entry->job_info; 812 for (JobID job_id : job_ids) {
812 job_info->state = STATE_RUNNING; 813 JobEntry* entry = job_map_.Lookup(job_id);
813 job_info->start_time = now; 814 DCHECK(entry);
814 NotifyJobUpdated(*job_info);
815 815
816 entry->cancel_callback = entry->task.Run(); 816 JobInfo* job_info = &entry->job_info;
817 job_info->state = STATE_RUNNING;
818 job_info->start_time = now;
819 NotifyJobUpdated(*job_info);
820
821 entry->cancel_callback = entry->task.Run();
822 logger_->Log(logging::LOG_INFO, "Job started: %s - %s",
823 job_info->ToString().c_str(),
824 GetQueueInfo(queue_type).c_str());
825 }
826
827 if (job_ids.size() > 1)
828 uploader_->StopBatchProcessing();
817 829
818 UpdateWait(); 830 UpdateWait();
819
820 logger_->Log(logging::LOG_INFO,
821 "Job started: %s - %s",
822 job_info->ToString().c_str(),
823 GetQueueInfo(queue_type).c_str());
824 } 831 }
825 832
826 int JobScheduler::GetCurrentAcceptedPriority(QueueType queue_type) { 833 int JobScheduler::GetCurrentAcceptedPriority(QueueType queue_type) {
827 DCHECK_CURRENTLY_ON(BrowserThread::UI); 834 DCHECK_CURRENTLY_ON(BrowserThread::UI);
828 835
829 const int kNoJobShouldRun = -1; 836 const int kNoJobShouldRun = -1;
830 837
831 // Should stop if Drive was disabled while running the fetch loop. 838 // Should stop if Drive was disabled while running the fetch loop.
832 if (pref_service_->GetBoolean(prefs::kDisableDrive)) 839 if (pref_service_->GetBoolean(prefs::kDisableDrive))
833 return kNoJobShouldRun; 840 return kNoJobShouldRun;
(...skipping 344 matching lines...) Expand 10 before | Expand all | Expand 10 after
1178 case FILE_QUEUE: 1185 case FILE_QUEUE:
1179 return "FILE_QUEUE"; 1186 return "FILE_QUEUE";
1180 case NUM_QUEUES: 1187 case NUM_QUEUES:
1181 break; // This value is just a sentinel. Should never be used. 1188 break; // This value is just a sentinel. Should never be used.
1182 } 1189 }
1183 NOTREACHED(); 1190 NOTREACHED();
1184 return ""; 1191 return "";
1185 } 1192 }
1186 1193
1187 } // namespace drive 1194 } // namespace drive
OLDNEW
« no previous file with comments | « chrome/browser/chromeos/drive/job_queue.cc ('k') | chrome/browser/drive/drive_uploader.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698