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

Unified 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | chrome/browser/chromeos/drive/drive_scheduler.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: chrome/browser/chromeos/drive/drive_scheduler.h
diff --git a/chrome/browser/chromeos/drive/drive_scheduler.h b/chrome/browser/chromeos/drive/drive_scheduler.h
index b791d17a8d7e29348e02066e3027087adffd226a..b3285382b532e598531568a6453f913948489f1e 100644
--- a/chrome/browser/chromeos/drive/drive_scheduler.h
+++ b/chrome/browser/chromeos/drive/drive_scheduler.h
@@ -6,10 +6,13 @@
#define CHROME_BROWSER_CHROMEOS_DRIVE_DRIVE_SCHEDULER_H_
#include <list>
+#include <vector>
#include "base/id_map.h"
#include "base/memory/scoped_ptr.h"
+#include "base/observer_list.h"
#include "chrome/browser/chromeos/drive/drive_file_system_interface.h"
+#include "chrome/browser/chromeos/drive/job_list_interface.h"
#include "chrome/browser/google_apis/drive_service_interface.h"
#include "chrome/browser/google_apis/drive_uploader.h"
#include "net/base/network_change_notifier.h"
@@ -25,68 +28,9 @@ namespace drive {
// TODO(zork): Provide an interface for querying the number of jobs, and state
// 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.
class DriveScheduler
- : public net::NetworkChangeNotifier::ConnectionTypeObserver {
+ : public net::NetworkChangeNotifier::ConnectionTypeObserver,
+ public JobListInterface {
public:
- // Enum representing the type of job.
- enum JobType {
- TYPE_GET_ABOUT_RESOURCE,
- TYPE_GET_ACCOUNT_METADATA,
- TYPE_GET_APP_LIST,
- TYPE_GET_ALL_RESOURCE_LIST,
- TYPE_GET_RESOURCE_LIST_IN_DIRECTORY,
- TYPE_SEARCH,
- TYPE_GET_CHANGE_LIST,
- TYPE_CONTINUE_GET_RESOURCE_LIST,
- TYPE_GET_RESOURCE_ENTRY,
- TYPE_DELETE_RESOURCE,
- TYPE_COPY_HOSTED_DOCUMENT,
- TYPE_RENAME_RESOURCE,
- TYPE_ADD_RESOURCE_TO_DIRECTORY,
- TYPE_REMOVE_RESOURCE_FROM_DIRECTORY,
- TYPE_ADD_NEW_DIRECTORY,
- TYPE_DOWNLOAD_FILE,
- TYPE_UPLOAD_NEW_FILE,
- TYPE_UPLOAD_EXISTING_FILE,
- };
-
- // Current state of the job.
- enum JobState {
- // The job is queued, but not yet executed.
- STATE_NONE,
-
- // The job is in the process of being handled.
- STATE_RUNNING,
-
- // The job failed, but has been re-added to the queue.
- STATE_RETRY,
- };
-
- // Unique ID assigned to each job. It is base::IDMap<JobInfo>::KeyType.
- typedef int32 JobID;
-
- // Information about a specific job that is visible to other systems.
- struct JobInfo {
- explicit JobInfo(JobType in_job_type);
-
- // Type of the job.
- JobType job_type;
-
- // Id of the job, which can be used to query or modify it.
- JobID job_id;
-
- // Number of bytes completed, if applicable.
- int completed_bytes;
-
- // Total bytes of this operation, if applicable.
- int total_bytes;
-
- // Drive path of the file that this job acts on.
- base::FilePath file_path;
-
- // Current state of the operation.
- JobState state;
- };
-
DriveScheduler(Profile* profile,
google_apis::DriveServiceInterface* drive_service);
virtual ~DriveScheduler();
@@ -95,6 +39,11 @@ class DriveScheduler
// other functions.
void Initialize();
+ // JobListInterface overrides.
+ virtual std::vector<JobInfo> GetJobInfoList() OVERRIDE;
+ virtual void AddObserver(JobListObserver* observer) OVERRIDE;
+ virtual void RemoveObserver(JobListObserver* observer) OVERRIDE;
+
// Adds a GetAccountMetadata operation to the queue.
// |callback| must not be null.
void GetAccountMetadata(
@@ -428,12 +377,14 @@ class DriveScheduler
// For testing only. Disables throttling so that testing is faster.
void SetDisableThrottling(bool disable) { disable_throttling_ = disable; }
+ // Notifies updates to observers.
+ void NotifyJobAdded(const JobInfo& job_id);
+ void NotifyJobDone(const JobInfo& job_id);
+ void NotifyJobUpdated(const JobInfo& job_id);
+
// Number of jobs in flight for each queue.
int jobs_running_[NUM_QUEUES];
- // Next value that should be assigned as a job id.
- int next_job_id_;
-
// The number of times operations have failed in a row, capped at
// kMaxThrottleCount. This is used to calculate the delay before running the
// next task.
@@ -449,6 +400,9 @@ class DriveScheduler
typedef IDMap<JobInfo, IDMapOwnPointer> JobIDMap;
JobIDMap job_map_;
+ // The list of observers for the scheduler.
+ ObserverList<JobListObserver> observer_list_;
+
google_apis::DriveServiceInterface* drive_service_;
scoped_ptr<google_apis::DriveUploaderInterface> uploader_;
« 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