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

Side by Side Diff: chrome/browser/chromeos/drive/drive_scheduler.h

Issue 14148006: Add an observer interface for DriveScheduler. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Review fix/ Created 7 years, 8 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 | Annotate | Revision Log
« no previous file with comments | « no previous file | chrome/browser/chromeos/drive/drive_scheduler.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 #ifndef CHROME_BROWSER_CHROMEOS_DRIVE_DRIVE_SCHEDULER_H_ 5 #ifndef CHROME_BROWSER_CHROMEOS_DRIVE_DRIVE_SCHEDULER_H_
6 #define CHROME_BROWSER_CHROMEOS_DRIVE_DRIVE_SCHEDULER_H_ 6 #define CHROME_BROWSER_CHROMEOS_DRIVE_DRIVE_SCHEDULER_H_
7 7
8 #include <list> 8 #include <list>
9 #include <vector>
9 10
10 #include "base/id_map.h" 11 #include "base/id_map.h"
11 #include "base/memory/scoped_ptr.h" 12 #include "base/memory/scoped_ptr.h"
13 #include "base/observer_list.h"
12 #include "chrome/browser/chromeos/drive/drive_file_system_interface.h" 14 #include "chrome/browser/chromeos/drive/drive_file_system_interface.h"
15 #include "chrome/browser/chromeos/drive/job_list_interface.h"
13 #include "chrome/browser/google_apis/drive_service_interface.h" 16 #include "chrome/browser/google_apis/drive_service_interface.h"
14 #include "chrome/browser/google_apis/drive_uploader.h" 17 #include "chrome/browser/google_apis/drive_uploader.h"
15 #include "net/base/network_change_notifier.h" 18 #include "net/base/network_change_notifier.h"
16 19
17 class Profile; 20 class Profile;
18 21
19 namespace drive { 22 namespace drive {
20 23
21 // The DriveScheduler is responsible for queuing and scheduling drive 24 // The DriveScheduler is responsible for queuing and scheduling drive
22 // operations. It is responsible for handling retry logic, rate limiting, as 25 // operations. It is responsible for handling retry logic, rate limiting, as
23 // concurrency as appropriate. 26 // concurrency as appropriate.
24 // 27 //
25 // TODO(zork): Provide an interface for querying the number of jobs, and state 28 // TODO(zork): Provide an interface for querying the number of jobs, and state
26 // of each. See: crbug.com/154243 29 // of each. See: crbug.com/154243
satorux1 2013/04/17 00:53:57 remove the TODO, now you are adding such an interf
kinaba 2013/04/17 01:03:54 Done. Good catch.
27 class DriveScheduler 30 class DriveScheduler
28 : public net::NetworkChangeNotifier::ConnectionTypeObserver { 31 : public net::NetworkChangeNotifier::ConnectionTypeObserver,
32 public JobListInterface {
29 public: 33 public:
30 // Enum representing the type of job.
31 enum JobType {
32 TYPE_GET_ABOUT_RESOURCE,
33 TYPE_GET_ACCOUNT_METADATA,
34 TYPE_GET_APP_LIST,
35 TYPE_GET_ALL_RESOURCE_LIST,
36 TYPE_GET_RESOURCE_LIST_IN_DIRECTORY,
37 TYPE_SEARCH,
38 TYPE_GET_CHANGE_LIST,
39 TYPE_CONTINUE_GET_RESOURCE_LIST,
40 TYPE_GET_RESOURCE_ENTRY,
41 TYPE_DELETE_RESOURCE,
42 TYPE_COPY_HOSTED_DOCUMENT,
43 TYPE_RENAME_RESOURCE,
44 TYPE_ADD_RESOURCE_TO_DIRECTORY,
45 TYPE_REMOVE_RESOURCE_FROM_DIRECTORY,
46 TYPE_ADD_NEW_DIRECTORY,
47 TYPE_DOWNLOAD_FILE,
48 TYPE_UPLOAD_NEW_FILE,
49 TYPE_UPLOAD_EXISTING_FILE,
50 };
51
52 // Current state of the job.
53 enum JobState {
54 // The job is queued, but not yet executed.
55 STATE_NONE,
56
57 // The job is in the process of being handled.
58 STATE_RUNNING,
59
60 // The job failed, but has been re-added to the queue.
61 STATE_RETRY,
62 };
63
64 // Unique ID assigned to each job. It is base::IDMap<JobInfo>::KeyType.
65 typedef int32 JobID;
66
67 // Information about a specific job that is visible to other systems.
68 struct JobInfo {
69 explicit JobInfo(JobType in_job_type);
70
71 // Type of the job.
72 JobType job_type;
73
74 // Id of the job, which can be used to query or modify it.
75 JobID job_id;
76
77 // Number of bytes completed, if applicable.
78 int completed_bytes;
79
80 // Total bytes of this operation, if applicable.
81 int total_bytes;
82
83 // Drive path of the file that this job acts on.
84 base::FilePath file_path;
85
86 // Current state of the operation.
87 JobState state;
88 };
89
90 DriveScheduler(Profile* profile, 34 DriveScheduler(Profile* profile,
91 google_apis::DriveServiceInterface* drive_service); 35 google_apis::DriveServiceInterface* drive_service);
92 virtual ~DriveScheduler(); 36 virtual ~DriveScheduler();
93 37
94 // Initializes the object. This function should be called before any 38 // Initializes the object. This function should be called before any
95 // other functions. 39 // other functions.
96 void Initialize(); 40 void Initialize();
97 41
42 // JobListInterface overrides.
43 virtual std::vector<JobInfo> GetJobInfoList() OVERRIDE;
44 virtual void AddObserver(JobListObserver* observer) OVERRIDE;
45 virtual void RemoveObserver(JobListObserver* observer) OVERRIDE;
46
98 // Adds a GetAccountMetadata operation to the queue. 47 // Adds a GetAccountMetadata operation to the queue.
99 // |callback| must not be null. 48 // |callback| must not be null.
100 void GetAccountMetadata( 49 void GetAccountMetadata(
101 const google_apis::GetAccountMetadataCallback& callback); 50 const google_apis::GetAccountMetadataCallback& callback);
102 51
103 // Adds a GetAppList operation to the queue. 52 // Adds a GetAppList operation to the queue.
104 // |callback| must not be null. 53 // |callback| must not be null.
105 void GetAppList(const google_apis::GetAppListCallback& callback); 54 void GetAppList(const google_apis::GetAppListCallback& callback);
106 55
107 // Adds a GetAboutResource operation to the queue. 56 // Adds a GetAboutResource operation to the queue.
(...skipping 313 matching lines...) Expand 10 before | Expand all | Expand 10 after
421 // net::NetworkChangeNotifier::ConnectionTypeObserver override. 370 // net::NetworkChangeNotifier::ConnectionTypeObserver override.
422 virtual void OnConnectionTypeChanged( 371 virtual void OnConnectionTypeChanged(
423 net::NetworkChangeNotifier::ConnectionType type) OVERRIDE; 372 net::NetworkChangeNotifier::ConnectionType type) OVERRIDE;
424 373
425 // Get the type of queue the specified job should be put in. 374 // Get the type of queue the specified job should be put in.
426 QueueType GetJobQueueType(JobType type); 375 QueueType GetJobQueueType(JobType type);
427 376
428 // For testing only. Disables throttling so that testing is faster. 377 // For testing only. Disables throttling so that testing is faster.
429 void SetDisableThrottling(bool disable) { disable_throttling_ = disable; } 378 void SetDisableThrottling(bool disable) { disable_throttling_ = disable; }
430 379
380 // Notifies updates to observers.
381 void NotifyJobAdded(const JobInfo& job_id);
382 void NotifyJobDone(const JobInfo& job_id);
383 void NotifyJobUpdated(const JobInfo& job_id);
384
431 // Number of jobs in flight for each queue. 385 // Number of jobs in flight for each queue.
432 int jobs_running_[NUM_QUEUES]; 386 int jobs_running_[NUM_QUEUES];
433 387
434 // Next value that should be assigned as a job id.
435 int next_job_id_;
436
437 // The number of times operations have failed in a row, capped at 388 // The number of times operations have failed in a row, capped at
438 // kMaxThrottleCount. This is used to calculate the delay before running the 389 // kMaxThrottleCount. This is used to calculate the delay before running the
439 // next task. 390 // next task.
440 int throttle_count_; 391 int throttle_count_;
441 392
442 // Disables throttling for testing. 393 // Disables throttling for testing.
443 bool disable_throttling_; 394 bool disable_throttling_;
444 395
445 // The queues of jobs. 396 // The queues of jobs.
446 std::list<QueueEntry*> queue_[NUM_QUEUES]; 397 std::list<QueueEntry*> queue_[NUM_QUEUES];
447 398
448 // The list of unfinished (= queued or running) job info indexed by job IDs. 399 // The list of unfinished (= queued or running) job info indexed by job IDs.
449 typedef IDMap<JobInfo, IDMapOwnPointer> JobIDMap; 400 typedef IDMap<JobInfo, IDMapOwnPointer> JobIDMap;
450 JobIDMap job_map_; 401 JobIDMap job_map_;
451 402
403 // The list of observers for the scheduler.
404 ObserverList<JobListObserver> observer_list_;
405
452 google_apis::DriveServiceInterface* drive_service_; 406 google_apis::DriveServiceInterface* drive_service_;
453 scoped_ptr<google_apis::DriveUploaderInterface> uploader_; 407 scoped_ptr<google_apis::DriveUploaderInterface> uploader_;
454 408
455 Profile* profile_; 409 Profile* profile_;
456 410
457 // Whether this instance is initialized or not. 411 // Whether this instance is initialized or not.
458 bool initialized_; 412 bool initialized_;
459 413
460 // Note: This should remain the last member so it'll be destroyed and 414 // Note: This should remain the last member so it'll be destroyed and
461 // invalidate its weak pointers before any other members are destroyed. 415 // invalidate its weak pointers before any other members are destroyed.
462 base::WeakPtrFactory<DriveScheduler> weak_ptr_factory_; 416 base::WeakPtrFactory<DriveScheduler> weak_ptr_factory_;
463 DISALLOW_COPY_AND_ASSIGN(DriveScheduler); 417 DISALLOW_COPY_AND_ASSIGN(DriveScheduler);
464 }; 418 };
465 419
466 } // namespace drive 420 } // namespace drive
467 421
468 #endif // CHROME_BROWSER_CHROMEOS_DRIVE_DRIVE_SCHEDULER_H_ 422 #endif // CHROME_BROWSER_CHROMEOS_DRIVE_DRIVE_SCHEDULER_H_
OLDNEW
« no previous file with comments | « no previous file | chrome/browser/chromeos/drive/drive_scheduler.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698