Commit db6a4aac authored by kinaba@chromium.org's avatar kinaba@chromium.org

Fill JobInfo in DriveScheduler.

BUG=128079

Review URL: https://chromiumcodereview.appspot.com/14235015

git-svn-id: svn://svn.chromium.org/chrome/trunk/src@194786 0039d316-1c4b-4281-b951-d872f2087c98
parent 5394a410
......@@ -305,8 +305,8 @@ void DriveScheduler::DownloadFile(
DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
scoped_ptr<QueueEntry> new_job(new QueueEntry);
new_job->virtual_path = virtual_path;
new_job->local_cache_path = local_cache_path;
new_job->drive_file_path = virtual_path;
new_job->local_file_path = local_cache_path;
new_job->download_url = download_url;
new_job->context = context;
new_job->download_action_callback = download_action_callback;
......@@ -363,6 +363,7 @@ void DriveScheduler::StartNewJob(scoped_ptr<QueueEntry> job, JobType type) {
// job_info is owned by job_map_ and released when it is removed in OnJobDone.
JobInfo* job_info = new JobInfo(type);
job->job_id = job_info->job_id = job_map_.Add(job_info);
job_info->file_path = job->drive_file_path;
QueueJob(job.Pass());
StartJobLoop(GetJobQueueType(type));
......@@ -556,14 +557,16 @@ void DriveScheduler::DoJobLoop(QueueType queue_type) {
case TYPE_DOWNLOAD_FILE: {
drive_service_->DownloadFile(
entry->virtual_path,
entry->local_cache_path,
entry->drive_file_path,
entry->local_file_path,
entry->download_url,
base::Bind(&DriveScheduler::OnDownloadActionJobDone,
weak_ptr_factory_.GetWeakPtr(),
base::Passed(&queue_entry)),
entry->get_content_callback,
google_apis::ProgressCallback());
base::Bind(&DriveScheduler::UpdateProgress,
weak_ptr_factory_.GetWeakPtr(),
job_info->job_id));
}
break;
......@@ -577,7 +580,9 @@ void DriveScheduler::DoJobLoop(QueueType queue_type) {
base::Bind(&DriveScheduler::OnUploadCompletionJobDone,
weak_ptr_factory_.GetWeakPtr(),
base::Passed(&queue_entry)),
google_apis::ProgressCallback());
base::Bind(&DriveScheduler::UpdateProgress,
weak_ptr_factory_.GetWeakPtr(),
job_info->job_id));
}
break;
......@@ -591,7 +596,9 @@ void DriveScheduler::DoJobLoop(QueueType queue_type) {
base::Bind(&DriveScheduler::OnUploadCompletionJobDone,
weak_ptr_factory_.GetWeakPtr(),
base::Passed(&queue_entry)),
google_apis::ProgressCallback());
base::Bind(&DriveScheduler::UpdateProgress,
weak_ptr_factory_.GetWeakPtr(),
job_info->job_id));
}
break;
......@@ -850,6 +857,14 @@ void DriveScheduler::OnUploadCompletionJobDone(
error, drive_path, file_path, resource_entry.Pass());
}
void DriveScheduler::UpdateProgress(JobID job_id, int64 progress, int64 total) {
JobInfo* job_info = job_map_.Lookup(job_id);
DCHECK(job_info);
job_info->num_completed_bytes = progress;
job_info->num_total_bytes = total;
}
void DriveScheduler::OnConnectionTypeChanged(
net::NetworkChangeNotifier::ConnectionType type) {
DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
......
......@@ -182,8 +182,10 @@ class DriveScheduler
// Online and cache path of the operation's target.
// Used by:
// TYPE_DOWNLOAD_FILE
base::FilePath virtual_path;
base::FilePath local_cache_path;
// TYPE_UPLOAD_NEW_FILE
// TYPE_UPLOAD_EXISTING_FILE
base::FilePath drive_file_path;
base::FilePath local_file_path;
// Parameter to get change list.
// Used by:
......@@ -272,8 +274,6 @@ class DriveScheduler
// Used by:
// TYPE_UPLOAD_NEW_FILE
// TYPE_UPLOAD_EXISTING_FILE
base::FilePath drive_file_path;
base::FilePath local_file_path;
std::string content_type;
std::string etag;
std::string title;
......@@ -360,6 +360,9 @@ class DriveScheduler
const base::FilePath& file_path,
scoped_ptr<google_apis::ResourceEntry> resource_entry);
// Updates the progress status of the specified job.
void UpdateProgress(JobID job_id, int64 progress, int64 total);
// net::NetworkChangeNotifier::ConnectionTypeObserver override.
virtual void OnConnectionTypeChanged(
net::NetworkChangeNotifier::ConnectionType type) OVERRIDE;
......
......@@ -462,7 +462,7 @@ TEST_F(DriveSchedulerTest, DownloadFileCellularDisabled) {
google_apis::GDataErrorCode download_error = google_apis::GDATA_OTHER_ERROR;
base::FilePath output_file_path;
scheduler_->DownloadFile(
base::FilePath::FromUTF8Unsafe("/drive/whatever.txt"), // virtual path
base::FilePath::FromUTF8Unsafe("drive/whatever.txt"), // virtual path
kOutputFilePath,
kContentUrl,
DriveClientContext(BACKGROUND),
......@@ -516,7 +516,7 @@ TEST_F(DriveSchedulerTest, DownloadFileWimaxDisabled) {
google_apis::GDataErrorCode download_error = google_apis::GDATA_OTHER_ERROR;
base::FilePath output_file_path;
scheduler_->DownloadFile(
base::FilePath::FromUTF8Unsafe("/drive/whatever.txt"), // virtual path
base::FilePath::FromUTF8Unsafe("drive/whatever.txt"), // virtual path
kOutputFilePath,
kContentUrl,
DriveClientContext(BACKGROUND),
......@@ -570,7 +570,7 @@ TEST_F(DriveSchedulerTest, DownloadFileCellularEnabled) {
google_apis::GDataErrorCode download_error = google_apis::GDATA_OTHER_ERROR;
base::FilePath output_file_path;
scheduler_->DownloadFile(
base::FilePath::FromUTF8Unsafe("/drive/whatever.txt"), // virtual path
base::FilePath::FromUTF8Unsafe("drive/whatever.txt"), // virtual path
kOutputFilePath,
kContentUrl,
DriveClientContext(BACKGROUND),
......@@ -616,7 +616,7 @@ TEST_F(DriveSchedulerTest, DownloadFileWimaxEnabled) {
google_apis::GDataErrorCode download_error = google_apis::GDATA_OTHER_ERROR;
base::FilePath output_file_path;
scheduler_->DownloadFile(
base::FilePath::FromUTF8Unsafe("/drive/whatever.txt"), // virtual path
base::FilePath::FromUTF8Unsafe("drive/whatever.txt"), // virtual path
kOutputFilePath,
kContentUrl,
DriveClientContext(BACKGROUND),
......@@ -678,7 +678,7 @@ TEST_F(DriveSchedulerTest, JobInfo) {
google_apis::test_util::CreateCopyResultCallback(&error));
expected_types.insert(TYPE_DOWNLOAD_FILE);
scheduler_->DownloadFile(
base::FilePath::FromUTF8Unsafe("/drive/whatever.txt"), // virtual path
base::FilePath::FromUTF8Unsafe("drive/whatever.txt"), // virtual path
temp_dir.path().AppendASCII("whatever.txt"),
GURL("https://file_content_url/"),
DriveClientContext(BACKGROUND),
......
......@@ -52,9 +52,9 @@ struct JobInfo {
explicit JobInfo(JobType in_job_type)
: job_type(in_job_type),
job_id(-1),
state(STATE_NONE),
num_completed_bytes(0),
num_total_bytes(0),
state(STATE_NONE) {
num_total_bytes(0) {
}
// Type of the job.
......@@ -63,17 +63,20 @@ struct JobInfo {
// Id of the job, which can be used to query or modify it.
JobID job_id;
// Number of bytes completed, if applicable.
// Current state of the operation.
JobState state;
// The fields below are available only for jobs with job_type:
// TYPE_DOWNLOAD_FILE, TYPE_UPLOAD_NEW_FILE, or TYPE_UPLOAD_EXISTING_FILE.
// Number of bytes completed.
int64 num_completed_bytes;
// Total bytes of this operation, if applicable.
// Total bytes of this operation.
int64 num_total_bytes;
// Drive path of the file that this job acts on.
base::FilePath file_path;
// Current state of the operation.
JobState state;
};
// The interface for observing JobListInterface.
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment