| OLD | NEW |
| 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 <math.h> | 7 #include <math.h> |
| 8 | 8 |
| 9 #include "base/message_loop.h" | 9 #include "base/message_loop.h" |
| 10 #include "base/prefs/pref_service.h" | 10 #include "base/prefs/pref_service.h" |
| (...skipping 151 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 162 } | 162 } |
| 163 | 163 |
| 164 void JobScheduler::RemoveObserver(JobListObserver* observer) { | 164 void JobScheduler::RemoveObserver(JobListObserver* observer) { |
| 165 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 165 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| 166 observer_list_.RemoveObserver(observer); | 166 observer_list_.RemoveObserver(observer); |
| 167 } | 167 } |
| 168 | 168 |
| 169 void JobScheduler::CancelJob(JobID job_id) { | 169 void JobScheduler::CancelJob(JobID job_id) { |
| 170 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 170 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| 171 | 171 |
| 172 // TODO(kinaba): Completely remove drive_service_->CancelForFilePath | |
| 173 // once DriveUploader supported cancellation callback: crbug.com/257012. | |
| 174 JobEntry* job = job_map_.Lookup(job_id); | 172 JobEntry* job = job_map_.Lookup(job_id); |
| 175 if (job) { | 173 if (job) { |
| 174 // TODO(kinaba): crbug.com/251116 Support cancelling jobs not yet started. |
| 176 if (!job->cancel_callback.is_null()) | 175 if (!job->cancel_callback.is_null()) |
| 177 job->cancel_callback.Run(); | 176 job->cancel_callback.Run(); |
| 178 else | |
| 179 drive_service_->CancelForFilePath(job->job_info.file_path); | |
| 180 } | 177 } |
| 181 } | 178 } |
| 182 | 179 |
| 183 void JobScheduler::CancelAllJobs() { | 180 void JobScheduler::CancelAllJobs() { |
| 184 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 181 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| 185 | 182 |
| 186 // TODO(kinaba): Move the cancellation feature from DriveService | 183 // CancelJob may remove the entry from |job_map_|. That's OK. IDMap supports |
| 187 // to JobScheduler. | 184 // removable during iteration. |
| 188 drive_service_->CancelAll(); | 185 for (JobIDMap::iterator iter(&job_map_); !iter.IsAtEnd(); iter.Advance()) |
| 186 CancelJob(iter.GetCurrentKey()); |
| 189 } | 187 } |
| 190 | 188 |
| 191 void JobScheduler::GetAboutResource( | 189 void JobScheduler::GetAboutResource( |
| 192 const google_apis::GetAboutResourceCallback& callback) { | 190 const google_apis::GetAboutResourceCallback& callback) { |
| 193 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 191 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| 194 DCHECK(!callback.is_null()); | 192 DCHECK(!callback.is_null()); |
| 195 | 193 |
| 196 JobEntry* new_job = CreateNewJob(TYPE_GET_ABOUT_RESOURCE); | 194 JobEntry* new_job = CreateNewJob(TYPE_GET_ABOUT_RESOURCE); |
| 197 new_job->task = base::Bind( | 195 new_job->task = base::Bind( |
| 198 &google_apis::DriveServiceInterface::GetAboutResource, | 196 &google_apis::DriveServiceInterface::GetAboutResource, |
| (...skipping 787 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 986 case FILE_QUEUE: | 984 case FILE_QUEUE: |
| 987 return "FILE_QUEUE"; | 985 return "FILE_QUEUE"; |
| 988 case NUM_QUEUES: | 986 case NUM_QUEUES: |
| 989 break; // This value is just a sentinel. Should never be used. | 987 break; // This value is just a sentinel. Should never be used. |
| 990 } | 988 } |
| 991 NOTREACHED(); | 989 NOTREACHED(); |
| 992 return ""; | 990 return ""; |
| 993 } | 991 } |
| 994 | 992 |
| 995 } // namespace drive | 993 } // namespace drive |
| OLD | NEW |