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

Unified Diff: chrome/browser/chromeos/drive/job_scheduler.cc

Issue 1018853005: Files.app: Obtain total bytes of upload task before starting tasks. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 5 years, 9 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « chrome/browser/chromeos/drive/job_scheduler.h ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: chrome/browser/chromeos/drive/job_scheduler.cc
diff --git a/chrome/browser/chromeos/drive/job_scheduler.cc b/chrome/browser/chromeos/drive/job_scheduler.cc
index 491980778c94ece556d2ad4bedb36a529fa7447e..69ae8d1d30d8229160c08b479ed88dd84c943753 100644
--- a/chrome/browser/chromeos/drive/job_scheduler.cc
+++ b/chrome/browser/chromeos/drive/job_scheduler.cc
@@ -147,29 +147,16 @@ void CollectCopyHistogramSample(const std::string& histogram_name, int64 size) {
counter->Add(size / 1024);
}
-// Callback for GetSizeAndCollectCopyHistogramSample().
-void OnGotSizeForCollectCopyHistogramSample(const std::string& histogram_name,
- int64* size) {
- if (*size != -1)
- CollectCopyHistogramSample(histogram_name, *size);
-}
-
-// Collects information about sizes of files copied or moved from or to Drive
-// Otherwise does nothing. Temporary for crbug.com/229650.
-void GetSizeAndCollectCopyHistogramSample(
- base::SequencedTaskRunner* blocking_task_runner,
- const base::FilePath& local_file_path,
- const std::string& histogram_name) {
+// Obtains file size to be uploaded for seeting total bytes of JobInfo.
fukino 2015/03/20 03:27:12 nit: seeting -> setting?
hirono 2015/03/20 03:38:59 Done.
+void GetFileSizeForJob(base::SequencedTaskRunner* blocking_task_runner,
+ const base::FilePath& local_file_path,
+ const base::Callback<void(int64* size)>& callback) {
int64* const size = new int64;
*size = -1;
blocking_task_runner->PostTaskAndReply(
- FROM_HERE,
- base::Bind(base::IgnoreResult(&base::GetFileSize),
- local_file_path,
- base::Unretained(size)),
- base::Bind(&OnGotSizeForCollectCopyHistogramSample,
- histogram_name,
- base::Owned(size)));
+ FROM_HERE, base::Bind(base::IgnoreResult(&base::GetFileSize),
+ local_file_path, base::Unretained(size)),
+ base::Bind(callback, base::Owned(size)));
}
} // namespace
@@ -646,14 +633,16 @@ void JobScheduler::UploadNewFile(
const google_apis::FileResourceCallback& callback) {
DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
- // Temporary histogram for crbug.com/229650.
- GetSizeAndCollectCopyHistogramSample(
- blocking_task_runner_, local_file_path, "Drive.UploadToDriveFileSize");
-
JobEntry* new_job = CreateNewJob(TYPE_UPLOAD_NEW_FILE);
new_job->job_info.file_path = drive_file_path;
new_job->context = context;
+ GetFileSizeForJob(
+ blocking_task_runner_, local_file_path,
+ base::Bind(&JobScheduler::OnGotFileSizeForJob,
+ weak_ptr_factory_.GetWeakPtr(), new_job->job_info.job_id,
+ "Drive.UploadToDriveFileSize"));
+
UploadNewFileParams params;
params.parent_resource_id = parent_resource_id;
params.local_file_path = local_file_path;
@@ -688,14 +677,16 @@ void JobScheduler::UploadExistingFile(
const google_apis::FileResourceCallback& callback) {
DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
- // Temporary histogram for crbug.com/229650.
- GetSizeAndCollectCopyHistogramSample(
- blocking_task_runner_, local_file_path, "Drive.UploadToDriveFileSize");
-
JobEntry* new_job = CreateNewJob(TYPE_UPLOAD_EXISTING_FILE);
new_job->job_info.file_path = drive_file_path;
new_job->context = context;
+ GetFileSizeForJob(
+ blocking_task_runner_, local_file_path,
+ base::Bind(&JobScheduler::OnGotFileSizeForJob,
+ weak_ptr_factory_.GetWeakPtr(), new_job->job_info.job_id,
+ "Drive.UploadToDriveFileSize"));
+
UploadExistingFileParams params;
params.resource_id = resource_id;
params.local_file_path = local_file_path;
@@ -1113,6 +1104,24 @@ void JobScheduler::OnConnectionTypeChanged(
DoJobLoop(static_cast<QueueType>(i));
}
+void JobScheduler::OnGotFileSizeForJob(JobID job_id,
+ const std::string& histogram_name,
+ int64* size) {
+ DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
+ if (*size == -1)
+ return;
+
+ // Temporary histogram for crbug.com/229650.
+ CollectCopyHistogramSample(histogram_name, *size);
+
+ JobEntry* const job_entry = job_map_.Lookup(job_id);
+ if (!job_entry)
+ return;
+
+ job_entry->job_info.num_total_bytes = *size;
+ NotifyJobUpdated(job_entry->job_info);
+}
+
JobScheduler::QueueType JobScheduler::GetJobQueueType(JobType type) {
switch (type) {
case TYPE_GET_ABOUT_RESOURCE:
« no previous file with comments | « chrome/browser/chromeos/drive/job_scheduler.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698