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

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: 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
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 UMA_HISTOGRAM_CUSTOM_COUNTS(
142 histogram_name, size / 1024, 1, 1024 * 1024 /* 1 GB */, 50);
143 }
144
145 // Callback for GetSizeAndCollectCopyHistogramSample().
146 void OnGotSizeForCollectCopyHistogramSample(const std::string& histogram_name,
147 int64* size) {
148 if (*size != -1)
149 CollectCopyHistogramSample(histogram_name, *size);
150 }
151
152 // Collects information about sizes of files copied or moved from or to Drive
153 // Otherwise does nothing. Temporary for crbug.com/229650.
154 void GetSizeAndCollectCopyHistogramSample(
155 base::SequencedTaskRunner* blocking_task_runner,
156 const base::FilePath& local_file_path,
157 const std::string& histogram_name) {
158 int64* const size = new int64;
159 *size = -1;
160 blocking_task_runner->PostTaskAndReply(
161 FROM_HERE,
162 base::Bind(base::IgnoreResult(&base::GetFileSize),
163 local_file_path,
164 base::Unretained(size)),
165 base::Bind(&OnGotSizeForCollectCopyHistogramSample,
166 histogram_name,
167 base::Owned(size)));
168 }
169
136 } // namespace 170 } // namespace
137 171
138 // Metadata jobs are cheap, so we run them concurrently. File jobs run serially. 172 // Metadata jobs are cheap, so we run them concurrently. File jobs run serially.
139 const int JobScheduler::kMaxJobCount[] = { 173 const int JobScheduler::kMaxJobCount[] = {
140 5, // METADATA_QUEUE 174 5, // METADATA_QUEUE
141 1, // FILE_QUEUE 175 1, // FILE_QUEUE
142 }; 176 };
143 177
144 JobScheduler::JobEntry::JobEntry(JobType type) 178 JobScheduler::JobEntry::JobEntry(JobType type)
145 : job_info(type), 179 : job_info(type),
146 context(ClientContext(USER_INITIATED)), 180 context(ClientContext(USER_INITIATED)),
147 retry_count(0) { 181 retry_count(0) {
148 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 182 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
149 } 183 }
150 184
151 JobScheduler::JobEntry::~JobEntry() { 185 JobScheduler::JobEntry::~JobEntry() {
152 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 186 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
153 } 187 }
154 188
155 struct JobScheduler::ResumeUploadParams { 189 struct JobScheduler::ResumeUploadParams {
156 base::FilePath drive_file_path; 190 base::FilePath drive_file_path;
157 base::FilePath local_file_path; 191 base::FilePath local_file_path;
158 std::string content_type; 192 std::string content_type;
159 }; 193 };
160 194
161 JobScheduler::JobScheduler( 195 JobScheduler::JobScheduler(PrefService* pref_service,
162 PrefService* pref_service, 196 EventLogger* logger,
163 EventLogger* logger, 197 DriveServiceInterface* drive_service,
164 DriveServiceInterface* drive_service, 198 base::SequencedTaskRunner* blocking_task_runner)
165 base::SequencedTaskRunner* blocking_task_runner)
166 : throttle_count_(0), 199 : throttle_count_(0),
167 wait_until_(base::Time::Now()), 200 wait_until_(base::Time::Now()),
168 disable_throttling_(false), 201 disable_throttling_(false),
169 logger_(logger), 202 logger_(logger),
170 drive_service_(drive_service), 203 drive_service_(drive_service),
204 blocking_task_runner_(blocking_task_runner),
171 uploader_(new DriveUploader(drive_service, blocking_task_runner)), 205 uploader_(new DriveUploader(drive_service, blocking_task_runner)),
172 pref_service_(pref_service), 206 pref_service_(pref_service),
173 weak_ptr_factory_(this) { 207 weak_ptr_factory_(this) {
174 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 208 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
175 209
176 for (int i = 0; i < NUM_QUEUES; ++i) 210 for (int i = 0; i < NUM_QUEUES; ++i)
177 queue_[i].reset(new JobQueue(kMaxJobCount[i], NUM_CONTEXT_TYPES)); 211 queue_[i].reset(new JobQueue(kMaxJobCount[i], NUM_CONTEXT_TYPES));
178 212
179 net::NetworkChangeNotifier::AddConnectionTypeObserver(this); 213 net::NetworkChangeNotifier::AddConnectionTypeObserver(this);
180 } 214 }
(...skipping 386 matching lines...) Expand 10 before | Expand all | Expand 10 after
567 JobID JobScheduler::DownloadFile( 601 JobID JobScheduler::DownloadFile(
568 const base::FilePath& virtual_path, 602 const base::FilePath& virtual_path,
569 int64 expected_file_size, 603 int64 expected_file_size,
570 const base::FilePath& local_cache_path, 604 const base::FilePath& local_cache_path,
571 const std::string& resource_id, 605 const std::string& resource_id,
572 const ClientContext& context, 606 const ClientContext& context,
573 const google_apis::DownloadActionCallback& download_action_callback, 607 const google_apis::DownloadActionCallback& download_action_callback,
574 const google_apis::GetContentCallback& get_content_callback) { 608 const google_apis::GetContentCallback& get_content_callback) {
575 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 609 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
576 610
611 // Temporary histogram for crbug.com/229650.
612 CollectCopyHistogramSample("Drive.CopyFromDriveFileSizeKB",
kinaba 2014/10/08 14:13:28 Strictly speaking, this counts not only copying to
mtomasz 2014/10/09 02:24:45 SGTM. Done.
613 expected_file_size);
614
577 JobEntry* new_job = CreateNewJob(TYPE_DOWNLOAD_FILE); 615 JobEntry* new_job = CreateNewJob(TYPE_DOWNLOAD_FILE);
578 new_job->job_info.file_path = virtual_path; 616 new_job->job_info.file_path = virtual_path;
579 new_job->job_info.num_total_bytes = expected_file_size; 617 new_job->job_info.num_total_bytes = expected_file_size;
580 new_job->context = context; 618 new_job->context = context;
581 new_job->task = base::Bind( 619 new_job->task = base::Bind(
582 &DriveServiceInterface::DownloadFile, 620 &DriveServiceInterface::DownloadFile,
583 base::Unretained(drive_service_), 621 base::Unretained(drive_service_),
584 local_cache_path, 622 local_cache_path,
585 resource_id, 623 resource_id,
586 base::Bind(&JobScheduler::OnDownloadActionJobDone, 624 base::Bind(&JobScheduler::OnDownloadActionJobDone,
(...skipping 13 matching lines...) Expand all
600 const std::string& parent_resource_id, 638 const std::string& parent_resource_id,
601 const base::FilePath& drive_file_path, 639 const base::FilePath& drive_file_path,
602 const base::FilePath& local_file_path, 640 const base::FilePath& local_file_path,
603 const std::string& title, 641 const std::string& title,
604 const std::string& content_type, 642 const std::string& content_type,
605 const DriveUploader::UploadNewFileOptions& options, 643 const DriveUploader::UploadNewFileOptions& options,
606 const ClientContext& context, 644 const ClientContext& context,
607 const google_apis::FileResourceCallback& callback) { 645 const google_apis::FileResourceCallback& callback) {
608 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 646 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
609 647
648 // Temporary histogram for crbug.com/229650.
649 GetSizeAndCollectCopyHistogramSample(
650 blocking_task_runner_, local_file_path, "Drive.CopyToDriveFileSizeKB");
651
610 JobEntry* new_job = CreateNewJob(TYPE_UPLOAD_NEW_FILE); 652 JobEntry* new_job = CreateNewJob(TYPE_UPLOAD_NEW_FILE);
611 new_job->job_info.file_path = drive_file_path; 653 new_job->job_info.file_path = drive_file_path;
612 new_job->context = context; 654 new_job->context = context;
613 655
614 UploadNewFileParams params; 656 UploadNewFileParams params;
615 params.parent_resource_id = parent_resource_id; 657 params.parent_resource_id = parent_resource_id;
616 params.local_file_path = local_file_path; 658 params.local_file_path = local_file_path;
617 params.title = title; 659 params.title = title;
618 params.content_type = content_type; 660 params.content_type = content_type;
619 params.options = options; 661 params.options = options;
(...skipping 18 matching lines...) Expand all
638 void JobScheduler::UploadExistingFile( 680 void JobScheduler::UploadExistingFile(
639 const std::string& resource_id, 681 const std::string& resource_id,
640 const base::FilePath& drive_file_path, 682 const base::FilePath& drive_file_path,
641 const base::FilePath& local_file_path, 683 const base::FilePath& local_file_path,
642 const std::string& content_type, 684 const std::string& content_type,
643 const DriveUploader::UploadExistingFileOptions& options, 685 const DriveUploader::UploadExistingFileOptions& options,
644 const ClientContext& context, 686 const ClientContext& context,
645 const google_apis::FileResourceCallback& callback) { 687 const google_apis::FileResourceCallback& callback) {
646 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 688 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
647 689
690 // Temporary histogram for crbug.com/229650.
691 GetSizeAndCollectCopyHistogramSample(
692 blocking_task_runner_, local_file_path, "Drive.CopyToDriveFileSizeKB");
693
648 JobEntry* new_job = CreateNewJob(TYPE_UPLOAD_EXISTING_FILE); 694 JobEntry* new_job = CreateNewJob(TYPE_UPLOAD_EXISTING_FILE);
649 new_job->job_info.file_path = drive_file_path; 695 new_job->job_info.file_path = drive_file_path;
650 new_job->context = context; 696 new_job->context = context;
651 697
652 UploadExistingFileParams params; 698 UploadExistingFileParams params;
653 params.resource_id = resource_id; 699 params.resource_id = resource_id;
654 params.local_file_path = local_file_path; 700 params.local_file_path = local_file_path;
655 params.content_type = content_type; 701 params.content_type = content_type;
656 params.options = options; 702 params.options = options;
657 703
(...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after
711 void JobScheduler::QueueJob(JobID job_id) { 757 void JobScheduler::QueueJob(JobID job_id) {
712 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 758 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
713 759
714 JobEntry* job_entry = job_map_.Lookup(job_id); 760 JobEntry* job_entry = job_map_.Lookup(job_id);
715 DCHECK(job_entry); 761 DCHECK(job_entry);
716 const JobInfo& job_info = job_entry->job_info; 762 const JobInfo& job_info = job_entry->job_info;
717 763
718 const QueueType queue_type = GetJobQueueType(job_info.job_type); 764 const QueueType queue_type = GetJobQueueType(job_info.job_type);
719 queue_[queue_type]->Push(job_id, job_entry->context.type); 765 queue_[queue_type]->Push(job_id, job_entry->context.type);
720 766
767 // Temporary histogram for crbug.com/229650.
768 if (job_info.job_type == TYPE_DOWNLOAD_FILE ||
769 job_info.job_type == TYPE_UPLOAD_EXISTING_FILE ||
770 job_info.job_type == TYPE_UPLOAD_NEW_FILE) {
771 std::vector<JobID> jobs_with_the_same_priority;
772 queue_[queue_type]->GetQueuedJobs(job_entry->context.type,
773 &jobs_with_the_same_priority);
774 DCHECK(!jobs_with_the_same_priority.empty());
775
776 const size_t blocking_jobs_count = jobs_with_the_same_priority.size() - 1;
777 UMA_HISTOGRAM_COUNTS_10000("Drive.CopyBlockedOnJobs", blocking_jobs_count);
778 }
779
721 const std::string retry_prefix = job_entry->retry_count > 0 ? 780 const std::string retry_prefix = job_entry->retry_count > 0 ?
722 base::StringPrintf(" (retry %d)", job_entry->retry_count) : ""; 781 base::StringPrintf(" (retry %d)", job_entry->retry_count) : "";
723 logger_->Log(logging::LOG_INFO, 782 logger_->Log(logging::LOG_INFO,
724 "Job queued%s: %s - %s", 783 "Job queued%s: %s - %s",
725 retry_prefix.c_str(), 784 retry_prefix.c_str(),
726 job_info.ToString().c_str(), 785 job_info.ToString().c_str(),
727 GetQueueInfo(queue_type).c_str()); 786 GetQueueInfo(queue_type).c_str());
728 } 787 }
729 788
730 void JobScheduler::DoJobLoop(QueueType queue_type) { 789 void JobScheduler::DoJobLoop(QueueType queue_type) {
(...skipping 402 matching lines...) Expand 10 before | Expand all | Expand 10 after
1133 case FILE_QUEUE: 1192 case FILE_QUEUE:
1134 return "FILE_QUEUE"; 1193 return "FILE_QUEUE";
1135 case NUM_QUEUES: 1194 case NUM_QUEUES:
1136 break; // This value is just a sentinel. Should never be used. 1195 break; // This value is just a sentinel. Should never be used.
1137 } 1196 }
1138 NOTREACHED(); 1197 NOTREACHED();
1139 return ""; 1198 return "";
1140 } 1199 }
1141 1200
1142 } // namespace drive 1201 } // namespace drive
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698