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 #ifndef CHROME_BROWSER_CHROMEOS_DRIVE_JOB_SCHEDULER_H_ | 5 #ifndef CHROME_BROWSER_CHROMEOS_DRIVE_JOB_SCHEDULER_H_ |
6 #define CHROME_BROWSER_CHROMEOS_DRIVE_JOB_SCHEDULER_H_ | 6 #define CHROME_BROWSER_CHROMEOS_DRIVE_JOB_SCHEDULER_H_ |
7 | 7 |
8 #include <vector> | 8 #include <vector> |
9 | 9 |
10 #include "base/id_map.h" | 10 #include "base/id_map.h" |
(...skipping 218 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
229 int retry_count; | 229 int retry_count; |
230 | 230 |
231 // The callback to start the job. Called each time it is retry. | 231 // The callback to start the job. Called each time it is retry. |
232 base::Callback<google_apis::CancelCallback()> task; | 232 base::Callback<google_apis::CancelCallback()> task; |
233 | 233 |
234 // The callback to cancel the running job. It is returned from task.Run(). | 234 // The callback to cancel the running job. It is returned from task.Run(). |
235 google_apis::CancelCallback cancel_callback; | 235 google_apis::CancelCallback cancel_callback; |
236 | 236 |
237 // The callback to notify an error to the client of JobScheduler. | 237 // The callback to notify an error to the client of JobScheduler. |
238 // This is used to notify cancel of a job that is not running yet. | 238 // This is used to notify cancel of a job that is not running yet. |
239 base::Callback<void(google_apis::GDataErrorCode)> abort_callback; | 239 base::Callback<void(google_apis::DriveApiErrorCode)> abort_callback; |
240 }; | 240 }; |
241 | 241 |
242 // Parameters for DriveUploader::ResumeUploadFile. | 242 // Parameters for DriveUploader::ResumeUploadFile. |
243 struct ResumeUploadParams; | 243 struct ResumeUploadParams; |
244 | 244 |
245 // Creates a new job and add it to the job map. | 245 // Creates a new job and add it to the job map. |
246 JobEntry* CreateNewJob(JobType type); | 246 JobEntry* CreateNewJob(JobType type); |
247 | 247 |
248 // Adds the specified job to the queue and starts the job loop for the queue | 248 // Adds the specified job to the queue and starts the job loop for the queue |
249 // if needed. | 249 // if needed. |
250 void StartJob(JobEntry* job); | 250 void StartJob(JobEntry* job); |
251 | 251 |
252 // Adds the specified job to the queue. | 252 // Adds the specified job to the queue. |
253 void QueueJob(JobID job_id); | 253 void QueueJob(JobID job_id); |
254 | 254 |
255 // Determines the next job that should run, and starts it. | 255 // Determines the next job that should run, and starts it. |
256 void DoJobLoop(QueueType queue_type); | 256 void DoJobLoop(QueueType queue_type); |
257 | 257 |
258 // Returns the lowest acceptable priority level of the operations that is | 258 // Returns the lowest acceptable priority level of the operations that is |
259 // currently allowed to start for the |queue_type|. | 259 // currently allowed to start for the |queue_type|. |
260 int GetCurrentAcceptedPriority(QueueType queue_type); | 260 int GetCurrentAcceptedPriority(QueueType queue_type); |
261 | 261 |
262 // Updates |wait_until_| to throttle requests. | 262 // Updates |wait_until_| to throttle requests. |
263 void UpdateWait(); | 263 void UpdateWait(); |
264 | 264 |
265 // Retries the job if needed and returns false. Otherwise returns true. | 265 // Retries the job if needed and returns false. Otherwise returns true. |
266 bool OnJobDone(JobID job_id, google_apis::GDataErrorCode error); | 266 bool OnJobDone(JobID job_id, google_apis::DriveApiErrorCode error); |
267 | 267 |
268 // Callback for job finishing with a FileListCallback. | 268 // Callback for job finishing with a FileListCallback. |
269 void OnGetFileListJobDone( | 269 void OnGetFileListJobDone( |
270 JobID job_id, | 270 JobID job_id, |
271 const google_apis::FileListCallback& callback, | 271 const google_apis::FileListCallback& callback, |
272 google_apis::GDataErrorCode error, | 272 google_apis::DriveApiErrorCode error, |
273 scoped_ptr<google_apis::FileList> file_list); | 273 scoped_ptr<google_apis::FileList> file_list); |
274 | 274 |
275 // Callback for job finishing with a ChangeListCallback. | 275 // Callback for job finishing with a ChangeListCallback. |
276 void OnGetChangeListJobDone( | 276 void OnGetChangeListJobDone( |
277 JobID job_id, | 277 JobID job_id, |
278 const google_apis::ChangeListCallback& callback, | 278 const google_apis::ChangeListCallback& callback, |
279 google_apis::GDataErrorCode error, | 279 google_apis::DriveApiErrorCode error, |
280 scoped_ptr<google_apis::ChangeList> change_list); | 280 scoped_ptr<google_apis::ChangeList> change_list); |
281 | 281 |
282 // Callback for job finishing with a FileResourceCallback. | 282 // Callback for job finishing with a FileResourceCallback. |
283 void OnGetFileResourceJobDone( | 283 void OnGetFileResourceJobDone( |
284 JobID job_id, | 284 JobID job_id, |
285 const google_apis::FileResourceCallback& callback, | 285 const google_apis::FileResourceCallback& callback, |
286 google_apis::GDataErrorCode error, | 286 google_apis::DriveApiErrorCode error, |
287 scoped_ptr<google_apis::FileResource> entry); | 287 scoped_ptr<google_apis::FileResource> entry); |
288 | 288 |
289 // Callback for job finishing with a AboutResourceCallback. | 289 // Callback for job finishing with a AboutResourceCallback. |
290 void OnGetAboutResourceJobDone( | 290 void OnGetAboutResourceJobDone( |
291 JobID job_id, | 291 JobID job_id, |
292 const google_apis::AboutResourceCallback& callback, | 292 const google_apis::AboutResourceCallback& callback, |
293 google_apis::GDataErrorCode error, | 293 google_apis::DriveApiErrorCode error, |
294 scoped_ptr<google_apis::AboutResource> about_resource); | 294 scoped_ptr<google_apis::AboutResource> about_resource); |
295 | 295 |
296 // Callback for job finishing with a GetShareUrlCallback. | 296 // Callback for job finishing with a GetShareUrlCallback. |
297 void OnGetShareUrlJobDone( | 297 void OnGetShareUrlJobDone( |
298 JobID job_id, | 298 JobID job_id, |
299 const google_apis::GetShareUrlCallback& callback, | 299 const google_apis::GetShareUrlCallback& callback, |
300 google_apis::GDataErrorCode error, | 300 google_apis::DriveApiErrorCode error, |
301 const GURL& share_url); | 301 const GURL& share_url); |
302 | 302 |
303 // Callback for job finishing with a AppListCallback. | 303 // Callback for job finishing with a AppListCallback. |
304 void OnGetAppListJobDone( | 304 void OnGetAppListJobDone( |
305 JobID job_id, | 305 JobID job_id, |
306 const google_apis::AppListCallback& callback, | 306 const google_apis::AppListCallback& callback, |
307 google_apis::GDataErrorCode error, | 307 google_apis::DriveApiErrorCode error, |
308 scoped_ptr<google_apis::AppList> app_list); | 308 scoped_ptr<google_apis::AppList> app_list); |
309 | 309 |
310 // Callback for job finishing with a EntryActionCallback. | 310 // Callback for job finishing with a EntryActionCallback. |
311 void OnEntryActionJobDone(JobID job_id, | 311 void OnEntryActionJobDone(JobID job_id, |
312 const google_apis::EntryActionCallback& callback, | 312 const google_apis::EntryActionCallback& callback, |
313 google_apis::GDataErrorCode error); | 313 google_apis::DriveApiErrorCode error); |
314 | 314 |
315 // Callback for job finishing with a DownloadActionCallback. | 315 // Callback for job finishing with a DownloadActionCallback. |
316 void OnDownloadActionJobDone( | 316 void OnDownloadActionJobDone( |
317 JobID job_id, | 317 JobID job_id, |
318 const google_apis::DownloadActionCallback& callback, | 318 const google_apis::DownloadActionCallback& callback, |
319 google_apis::GDataErrorCode error, | 319 google_apis::DriveApiErrorCode error, |
320 const base::FilePath& temp_file); | 320 const base::FilePath& temp_file); |
321 | 321 |
322 // Callback for job finishing with a UploadCompletionCallback. | 322 // Callback for job finishing with a UploadCompletionCallback. |
323 void OnUploadCompletionJobDone( | 323 void OnUploadCompletionJobDone( |
324 JobID job_id, | 324 JobID job_id, |
325 const ResumeUploadParams& resume_params, | 325 const ResumeUploadParams& resume_params, |
326 const google_apis::FileResourceCallback& callback, | 326 const google_apis::FileResourceCallback& callback, |
327 google_apis::GDataErrorCode error, | 327 google_apis::DriveApiErrorCode error, |
328 const GURL& upload_location, | 328 const GURL& upload_location, |
329 scoped_ptr<google_apis::FileResource> entry); | 329 scoped_ptr<google_apis::FileResource> entry); |
330 | 330 |
331 // Callback for DriveUploader::ResumeUploadFile(). | 331 // Callback for DriveUploader::ResumeUploadFile(). |
332 void OnResumeUploadFileDone( | 332 void OnResumeUploadFileDone( |
333 JobID job_id, | 333 JobID job_id, |
334 const base::Callback<google_apis::CancelCallback()>& original_task, | 334 const base::Callback<google_apis::CancelCallback()>& original_task, |
335 const google_apis::FileResourceCallback& callback, | 335 const google_apis::FileResourceCallback& callback, |
336 google_apis::GDataErrorCode error, | 336 google_apis::DriveApiErrorCode error, |
337 const GURL& upload_location, | 337 const GURL& upload_location, |
338 scoped_ptr<google_apis::FileResource> entry); | 338 scoped_ptr<google_apis::FileResource> entry); |
339 | 339 |
340 // Updates the progress status of the specified job. | 340 // Updates the progress status of the specified job. |
341 void UpdateProgress(JobID job_id, int64 progress, int64 total); | 341 void UpdateProgress(JobID job_id, int64 progress, int64 total); |
342 | 342 |
343 // net::NetworkChangeNotifier::ConnectionTypeObserver override. | 343 // net::NetworkChangeNotifier::ConnectionTypeObserver override. |
344 void OnConnectionTypeChanged( | 344 void OnConnectionTypeChanged( |
345 net::NetworkChangeNotifier::ConnectionType type) override; | 345 net::NetworkChangeNotifier::ConnectionType type) override; |
346 | 346 |
347 // Get the type of queue the specified job should be put in. | 347 // Get the type of queue the specified job should be put in. |
348 QueueType GetJobQueueType(JobType type); | 348 QueueType GetJobQueueType(JobType type); |
349 | 349 |
350 // For testing only. Disables throttling so that testing is faster. | 350 // For testing only. Disables throttling so that testing is faster. |
351 void SetDisableThrottling(bool disable) { disable_throttling_ = disable; } | 351 void SetDisableThrottling(bool disable) { disable_throttling_ = disable; } |
352 | 352 |
353 // Aborts a job which is not in STATE_RUNNING. | 353 // Aborts a job which is not in STATE_RUNNING. |
354 void AbortNotRunningJob(JobEntry* job, google_apis::GDataErrorCode error); | 354 void AbortNotRunningJob(JobEntry* job, google_apis::DriveApiErrorCode error); |
355 | 355 |
356 // Notifies updates to observers. | 356 // Notifies updates to observers. |
357 void NotifyJobAdded(const JobInfo& job_info); | 357 void NotifyJobAdded(const JobInfo& job_info); |
358 void NotifyJobDone(const JobInfo& job_info, | 358 void NotifyJobDone(const JobInfo& job_info, |
359 google_apis::GDataErrorCode error); | 359 google_apis::DriveApiErrorCode error); |
360 void NotifyJobUpdated(const JobInfo& job_info); | 360 void NotifyJobUpdated(const JobInfo& job_info); |
361 | 361 |
362 // Gets information of the queue of the given type as string. | 362 // Gets information of the queue of the given type as string. |
363 std::string GetQueueInfo(QueueType type) const; | 363 std::string GetQueueInfo(QueueType type) const; |
364 | 364 |
365 // Returns a string representation of QueueType. | 365 // Returns a string representation of QueueType. |
366 static std::string QueueTypeToString(QueueType type); | 366 static std::string QueueTypeToString(QueueType type); |
367 | 367 |
368 // The number of times operations have failed in a row, capped at | 368 // The number of times operations have failed in a row, capped at |
369 // kMaxThrottleCount. This is used to calculate the delay before running the | 369 // kMaxThrottleCount. This is used to calculate the delay before running the |
(...skipping 25 matching lines...) Expand all Loading... |
395 | 395 |
396 // Note: This should remain the last member so it'll be destroyed and | 396 // Note: This should remain the last member so it'll be destroyed and |
397 // invalidate its weak pointers before any other members are destroyed. | 397 // invalidate its weak pointers before any other members are destroyed. |
398 base::WeakPtrFactory<JobScheduler> weak_ptr_factory_; | 398 base::WeakPtrFactory<JobScheduler> weak_ptr_factory_; |
399 DISALLOW_COPY_AND_ASSIGN(JobScheduler); | 399 DISALLOW_COPY_AND_ASSIGN(JobScheduler); |
400 }; | 400 }; |
401 | 401 |
402 } // namespace drive | 402 } // namespace drive |
403 | 403 |
404 #endif // CHROME_BROWSER_CHROMEOS_DRIVE_JOB_SCHEDULER_H_ | 404 #endif // CHROME_BROWSER_CHROMEOS_DRIVE_JOB_SCHEDULER_H_ |
OLD | NEW |