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

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

Issue 640543002: Add histograms about files copied or movied files from or to Drive. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Fixed. Created 6 years, 2 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_scheduler.h ('k') | tools/metrics/histograms/histograms.xml » ('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 "base/files/file_util.h"
7 #include "base/message_loop/message_loop.h" 8 #include "base/message_loop/message_loop.h"
9 #include "base/metrics/histogram.h"
8 #include "base/prefs/pref_service.h" 10 #include "base/prefs/pref_service.h"
9 #include "base/rand_util.h" 11 #include "base/rand_util.h"
10 #include "base/strings/string_number_conversions.h" 12 #include "base/strings/string_number_conversions.h"
11 #include "base/strings/stringprintf.h" 13 #include "base/strings/stringprintf.h"
12 #include "chrome/browser/drive/event_logger.h" 14 #include "chrome/browser/drive/event_logger.h"
13 #include "chrome/common/pref_names.h" 15 #include "chrome/common/pref_names.h"
14 #include "content/public/browser/browser_thread.h" 16 #include "content/public/browser/browser_thread.h"
15 #include "google_apis/drive/drive_api_parser.h" 17 #include "google_apis/drive/drive_api_parser.h"
16 18
17 using content::BrowserThread; 19 using content::BrowserThread;
(...skipping 108 matching lines...) Expand 10 before | Expand all | Expand 10 after
126 google_apis::CancelCallback RunResumeUploadFile( 128 google_apis::CancelCallback RunResumeUploadFile(
127 DriveUploaderInterface* uploader, 129 DriveUploaderInterface* uploader,
128 const ResumeUploadFileParams& params) { 130 const ResumeUploadFileParams& params) {
129 return uploader->ResumeUploadFile(params.upload_location, 131 return uploader->ResumeUploadFile(params.upload_location,
130 params.local_file_path, 132 params.local_file_path,
131 params.content_type, 133 params.content_type,
132 params.callback, 134 params.callback,
133 params.progress_callback); 135 params.progress_callback);
134 } 136 }
135 137
138 // Collects information about sizes of files copied or moved from or to Drive
139 // Otherwise does nothing. Temporary for crbug.com/229650.
140 void CollectCopyHistogramSample(const std::string& histogram_name, int64 size) {
141 base::HistogramBase* const counter =
142 base::Histogram::FactoryGet(histogram_name,
143 1,
144 1024 * 1024 /* 1 GB */,
145 50,
146 base::Histogram::kUmaTargetedHistogramFlag);
147 counter->Add(size / 1024);
148 }
149
150 // Callback for GetSizeAndCollectCopyHistogramSample().
151 void OnGotSizeForCollectCopyHistogramSample(const std::string& histogram_name,
152 int64* size) {
153 if (*size != -1)
154 CollectCopyHistogramSample(histogram_name, *size);
155 }
156
157 // Collects information about sizes of files copied or moved from or to Drive
158 // Otherwise does nothing. Temporary for crbug.com/229650.
159 void GetSizeAndCollectCopyHistogramSample(
160 base::SequencedTaskRunner* blocking_task_runner,
161 const base::FilePath& local_file_path,
162 const std::string& histogram_name) {
163 int64* const size = new int64;
164 *size = -1;
165 blocking_task_runner->PostTaskAndReply(
166 FROM_HERE,
167 base::Bind(base::IgnoreResult(&base::GetFileSize),
168 local_file_path,
169 base::Unretained(size)),
170 base::Bind(&OnGotSizeForCollectCopyHistogramSample,
171 histogram_name,
172 base::Owned(size)));
173 }
174
136 } // namespace 175 } // namespace
137 176
138 // Metadata jobs are cheap, so we run them concurrently. File jobs run serially. 177 // Metadata jobs are cheap, so we run them concurrently. File jobs run serially.
139 const int JobScheduler::kMaxJobCount[] = { 178 const int JobScheduler::kMaxJobCount[] = {
140 5, // METADATA_QUEUE 179 5, // METADATA_QUEUE
141 1, // FILE_QUEUE 180 1, // FILE_QUEUE
142 }; 181 };
143 182
144 JobScheduler::JobEntry::JobEntry(JobType type) 183 JobScheduler::JobEntry::JobEntry(JobType type)
145 : job_info(type), 184 : job_info(type),
146 context(ClientContext(USER_INITIATED)), 185 context(ClientContext(USER_INITIATED)),
147 retry_count(0) { 186 retry_count(0) {
148 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 187 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
149 } 188 }
150 189
151 JobScheduler::JobEntry::~JobEntry() { 190 JobScheduler::JobEntry::~JobEntry() {
152 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 191 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
153 } 192 }
154 193
155 struct JobScheduler::ResumeUploadParams { 194 struct JobScheduler::ResumeUploadParams {
156 base::FilePath drive_file_path; 195 base::FilePath drive_file_path;
157 base::FilePath local_file_path; 196 base::FilePath local_file_path;
158 std::string content_type; 197 std::string content_type;
159 }; 198 };
160 199
161 JobScheduler::JobScheduler( 200 JobScheduler::JobScheduler(PrefService* pref_service,
162 PrefService* pref_service, 201 EventLogger* logger,
163 EventLogger* logger, 202 DriveServiceInterface* drive_service,
164 DriveServiceInterface* drive_service, 203 base::SequencedTaskRunner* blocking_task_runner)
165 base::SequencedTaskRunner* blocking_task_runner)
166 : throttle_count_(0), 204 : throttle_count_(0),
167 wait_until_(base::Time::Now()), 205 wait_until_(base::Time::Now()),
168 disable_throttling_(false), 206 disable_throttling_(false),
169 logger_(logger), 207 logger_(logger),
170 drive_service_(drive_service), 208 drive_service_(drive_service),
209 blocking_task_runner_(blocking_task_runner),
171 uploader_(new DriveUploader(drive_service, blocking_task_runner)), 210 uploader_(new DriveUploader(drive_service, blocking_task_runner)),
172 pref_service_(pref_service), 211 pref_service_(pref_service),
173 weak_ptr_factory_(this) { 212 weak_ptr_factory_(this) {
174 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 213 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
175 214
176 for (int i = 0; i < NUM_QUEUES; ++i) 215 for (int i = 0; i < NUM_QUEUES; ++i)
177 queue_[i].reset(new JobQueue(kMaxJobCount[i], NUM_CONTEXT_TYPES)); 216 queue_[i].reset(new JobQueue(kMaxJobCount[i], NUM_CONTEXT_TYPES));
178 217
179 net::NetworkChangeNotifier::AddConnectionTypeObserver(this); 218 net::NetworkChangeNotifier::AddConnectionTypeObserver(this);
180 } 219 }
(...skipping 386 matching lines...) Expand 10 before | Expand all | Expand 10 after
567 JobID JobScheduler::DownloadFile( 606 JobID JobScheduler::DownloadFile(
568 const base::FilePath& virtual_path, 607 const base::FilePath& virtual_path,
569 int64 expected_file_size, 608 int64 expected_file_size,
570 const base::FilePath& local_cache_path, 609 const base::FilePath& local_cache_path,
571 const std::string& resource_id, 610 const std::string& resource_id,
572 const ClientContext& context, 611 const ClientContext& context,
573 const google_apis::DownloadActionCallback& download_action_callback, 612 const google_apis::DownloadActionCallback& download_action_callback,
574 const google_apis::GetContentCallback& get_content_callback) { 613 const google_apis::GetContentCallback& get_content_callback) {
575 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 614 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
576 615
616 // Temporary histogram for crbug.com/229650.
617 CollectCopyHistogramSample("Drive.DownloadFromDriveFileSize",
618 expected_file_size);
619
577 JobEntry* new_job = CreateNewJob(TYPE_DOWNLOAD_FILE); 620 JobEntry* new_job = CreateNewJob(TYPE_DOWNLOAD_FILE);
578 new_job->job_info.file_path = virtual_path; 621 new_job->job_info.file_path = virtual_path;
579 new_job->job_info.num_total_bytes = expected_file_size; 622 new_job->job_info.num_total_bytes = expected_file_size;
580 new_job->context = context; 623 new_job->context = context;
581 new_job->task = base::Bind( 624 new_job->task = base::Bind(
582 &DriveServiceInterface::DownloadFile, 625 &DriveServiceInterface::DownloadFile,
583 base::Unretained(drive_service_), 626 base::Unretained(drive_service_),
584 local_cache_path, 627 local_cache_path,
585 resource_id, 628 resource_id,
586 base::Bind(&JobScheduler::OnDownloadActionJobDone, 629 base::Bind(&JobScheduler::OnDownloadActionJobDone,
(...skipping 13 matching lines...) Expand all
600 const std::string& parent_resource_id, 643 const std::string& parent_resource_id,
601 const base::FilePath& drive_file_path, 644 const base::FilePath& drive_file_path,
602 const base::FilePath& local_file_path, 645 const base::FilePath& local_file_path,
603 const std::string& title, 646 const std::string& title,
604 const std::string& content_type, 647 const std::string& content_type,
605 const DriveUploader::UploadNewFileOptions& options, 648 const DriveUploader::UploadNewFileOptions& options,
606 const ClientContext& context, 649 const ClientContext& context,
607 const google_apis::FileResourceCallback& callback) { 650 const google_apis::FileResourceCallback& callback) {
608 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 651 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
609 652
653 // Temporary histogram for crbug.com/229650.
654 GetSizeAndCollectCopyHistogramSample(
655 blocking_task_runner_, local_file_path, "Drive.UploadToDriveFileSize");
656
610 JobEntry* new_job = CreateNewJob(TYPE_UPLOAD_NEW_FILE); 657 JobEntry* new_job = CreateNewJob(TYPE_UPLOAD_NEW_FILE);
611 new_job->job_info.file_path = drive_file_path; 658 new_job->job_info.file_path = drive_file_path;
612 new_job->context = context; 659 new_job->context = context;
613 660
614 UploadNewFileParams params; 661 UploadNewFileParams params;
615 params.parent_resource_id = parent_resource_id; 662 params.parent_resource_id = parent_resource_id;
616 params.local_file_path = local_file_path; 663 params.local_file_path = local_file_path;
617 params.title = title; 664 params.title = title;
618 params.content_type = content_type; 665 params.content_type = content_type;
619 params.options = options; 666 params.options = options;
(...skipping 18 matching lines...) Expand all
638 void JobScheduler::UploadExistingFile( 685 void JobScheduler::UploadExistingFile(
639 const std::string& resource_id, 686 const std::string& resource_id,
640 const base::FilePath& drive_file_path, 687 const base::FilePath& drive_file_path,
641 const base::FilePath& local_file_path, 688 const base::FilePath& local_file_path,
642 const std::string& content_type, 689 const std::string& content_type,
643 const DriveUploader::UploadExistingFileOptions& options, 690 const DriveUploader::UploadExistingFileOptions& options,
644 const ClientContext& context, 691 const ClientContext& context,
645 const google_apis::FileResourceCallback& callback) { 692 const google_apis::FileResourceCallback& callback) {
646 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 693 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
647 694
695 // Temporary histogram for crbug.com/229650.
696 GetSizeAndCollectCopyHistogramSample(
697 blocking_task_runner_, local_file_path, "Drive.UploadToDriveFileSize");
698
648 JobEntry* new_job = CreateNewJob(TYPE_UPLOAD_EXISTING_FILE); 699 JobEntry* new_job = CreateNewJob(TYPE_UPLOAD_EXISTING_FILE);
649 new_job->job_info.file_path = drive_file_path; 700 new_job->job_info.file_path = drive_file_path;
650 new_job->context = context; 701 new_job->context = context;
651 702
652 UploadExistingFileParams params; 703 UploadExistingFileParams params;
653 params.resource_id = resource_id; 704 params.resource_id = resource_id;
654 params.local_file_path = local_file_path; 705 params.local_file_path = local_file_path;
655 params.content_type = content_type; 706 params.content_type = content_type;
656 params.options = options; 707 params.options = options;
657 708
(...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after
711 void JobScheduler::QueueJob(JobID job_id) { 762 void JobScheduler::QueueJob(JobID job_id) {
712 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 763 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
713 764
714 JobEntry* job_entry = job_map_.Lookup(job_id); 765 JobEntry* job_entry = job_map_.Lookup(job_id);
715 DCHECK(job_entry); 766 DCHECK(job_entry);
716 const JobInfo& job_info = job_entry->job_info; 767 const JobInfo& job_info = job_entry->job_info;
717 768
718 const QueueType queue_type = GetJobQueueType(job_info.job_type); 769 const QueueType queue_type = GetJobQueueType(job_info.job_type);
719 queue_[queue_type]->Push(job_id, job_entry->context.type); 770 queue_[queue_type]->Push(job_id, job_entry->context.type);
720 771
772 // Temporary histogram for crbug.com/229650.
773 if (job_info.job_type == TYPE_DOWNLOAD_FILE ||
774 job_info.job_type == TYPE_UPLOAD_EXISTING_FILE ||
775 job_info.job_type == TYPE_UPLOAD_NEW_FILE) {
776 std::vector<JobID> jobs_with_the_same_priority;
777 queue_[queue_type]->GetQueuedJobs(job_entry->context.type,
778 &jobs_with_the_same_priority);
779 DCHECK(!jobs_with_the_same_priority.empty());
780
781 const size_t blocking_jobs_count = jobs_with_the_same_priority.size() - 1;
782 UMA_HISTOGRAM_COUNTS_10000("Drive.TransferBlockedOnJobs",
783 blocking_jobs_count);
784 }
785
721 const std::string retry_prefix = job_entry->retry_count > 0 ? 786 const std::string retry_prefix = job_entry->retry_count > 0 ?
722 base::StringPrintf(" (retry %d)", job_entry->retry_count) : ""; 787 base::StringPrintf(" (retry %d)", job_entry->retry_count) : "";
723 logger_->Log(logging::LOG_INFO, 788 logger_->Log(logging::LOG_INFO,
724 "Job queued%s: %s - %s", 789 "Job queued%s: %s - %s",
725 retry_prefix.c_str(), 790 retry_prefix.c_str(),
726 job_info.ToString().c_str(), 791 job_info.ToString().c_str(),
727 GetQueueInfo(queue_type).c_str()); 792 GetQueueInfo(queue_type).c_str());
728 } 793 }
729 794
730 void JobScheduler::DoJobLoop(QueueType queue_type) { 795 void JobScheduler::DoJobLoop(QueueType queue_type) {
(...skipping 402 matching lines...) Expand 10 before | Expand all | Expand 10 after
1133 case FILE_QUEUE: 1198 case FILE_QUEUE:
1134 return "FILE_QUEUE"; 1199 return "FILE_QUEUE";
1135 case NUM_QUEUES: 1200 case NUM_QUEUES:
1136 break; // This value is just a sentinel. Should never be used. 1201 break; // This value is just a sentinel. Should never be used.
1137 } 1202 }
1138 NOTREACHED(); 1203 NOTREACHED();
1139 return ""; 1204 return "";
1140 } 1205 }
1141 1206
1142 } // namespace drive 1207 } // namespace drive
OLDNEW
« no previous file with comments | « chrome/browser/chromeos/drive/job_scheduler.h ('k') | tools/metrics/histograms/histograms.xml » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698