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

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

Issue 11418127: Pass calls to GetDocuments through the scheduler (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Rebase Created 8 years 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
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 "base/memory/linked_ptr.h" 8 #include "base/memory/linked_ptr.h"
9 #include "base/memory/scoped_ptr.h" 9 #include "base/memory/scoped_ptr.h"
10 #include "chrome/browser/chromeos/drive/drive_file_system_interface.h" 10 #include "chrome/browser/chromeos/drive/drive_file_system_interface.h"
11 #include "chrome/browser/google_apis/drive_service_interface.h"
11 #include "net/base/network_change_notifier.h" 12 #include "net/base/network_change_notifier.h"
12 13
13 #include <deque> 14 #include <deque>
14 15
15 class Profile; 16 class Profile;
16 17
17 namespace drive { 18 namespace drive {
18 19
19 namespace file_system { 20 namespace file_system {
20 class DriveOperations; 21 class DriveOperations;
21 } 22 }
22 23
23 // The DriveScheduler is responsible for queuing and scheduling drive 24 // The DriveScheduler is responsible for queuing and scheduling drive
24 // operations. It is responsible for handling retry logic, rate limiting, as 25 // operations. It is responsible for handling retry logic, rate limiting, as
25 // concurrency as appropriate. 26 // concurrency as appropriate.
26 // 27 //
27 // 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
28 // of each. See: crbug.com/154243 29 // of each. See: crbug.com/154243
29 class DriveScheduler 30 class DriveScheduler
30 : public net::NetworkChangeNotifier::ConnectionTypeObserver { 31 : public net::NetworkChangeNotifier::ConnectionTypeObserver {
31 public: 32 public:
32 33
33 // Enum representing the type of job. 34 // Enum representing the type of job.
34 enum JobType { 35 enum JobType {
35 TYPE_COPY, 36 TYPE_COPY,
37 TYPE_GET_DOCUMENTS,
36 TYPE_MOVE, 38 TYPE_MOVE,
37 TYPE_REMOVE, 39 TYPE_REMOVE,
38 TYPE_TRANSFER_LOCAL_TO_REMOTE, 40 TYPE_TRANSFER_LOCAL_TO_REMOTE,
39 TYPE_TRANSFER_REGULAR_FILE, 41 TYPE_TRANSFER_REGULAR_FILE,
40 TYPE_TRANSFER_REMOTE_TO_LOCAL, 42 TYPE_TRANSFER_REMOTE_TO_LOCAL,
41 }; 43 };
42 44
43 // Current state of the job. 45 // Current state of the job.
44 enum JobState { 46 enum JobState {
45 // The job is queued, but not yet executed. 47 // The job is queued, but not yet executed.
(...skipping 23 matching lines...) Expand all
69 int total_bytes; 71 int total_bytes;
70 72
71 // Drive path of the file that this job acts on. 73 // Drive path of the file that this job acts on.
72 FilePath file_path; 74 FilePath file_path;
73 75
74 // Current state of the operation. 76 // Current state of the operation.
75 JobState state; 77 JobState state;
76 }; 78 };
77 79
78 DriveScheduler(Profile* profile, 80 DriveScheduler(Profile* profile,
81 google_apis::DriveServiceInterface* drive_service,
79 file_system::DriveOperations* drive_operations); 82 file_system::DriveOperations* drive_operations);
80 virtual ~DriveScheduler(); 83 virtual ~DriveScheduler();
81 84
82 // Initializes the object. This function should be called before any 85 // Initializes the object. This function should be called before any
83 // other functions. 86 // other functions.
84 void Initialize(); 87 void Initialize();
85 88
86 // Adds a copy operation to the queue. 89 // Adds a copy operation to the queue.
87 void Copy(const FilePath& src_file_path, 90 void Copy(const FilePath& src_file_path,
88 const FilePath& dest_file_path, 91 const FilePath& dest_file_path,
89 const FileOperationCallback& callback); 92 const FileOperationCallback& callback);
90 93
94 // Adds a GetDocuments operation to the queue.
95 void GetDocuments(const GURL& feed_url,
96 int64 start_changestamp,
97 const std::string& search_query,
98 bool shared_with_me,
99 const std::string& directory_resource_id,
100 const google_apis::GetDataCallback& callback);
101
91 // Adds a transfer operation to the queue. 102 // Adds a transfer operation to the queue.
92 void TransferFileFromRemoteToLocal(const FilePath& remote_src_file_path, 103 void TransferFileFromRemoteToLocal(const FilePath& remote_src_file_path,
93 const FilePath& local_dest_file_path, 104 const FilePath& local_dest_file_path,
94 const FileOperationCallback& callback); 105 const FileOperationCallback& callback);
95 106
96 // Adds a transfer operation to the queue. 107 // Adds a transfer operation to the queue.
97 void TransferFileFromLocalToRemote(const FilePath& local_src_file_path, 108 void TransferFileFromLocalToRemote(const FilePath& local_src_file_path,
98 const FilePath& remote_dest_file_path, 109 const FilePath& remote_dest_file_path,
99 const FileOperationCallback& callback); 110 const FileOperationCallback& callback);
100 111
(...skipping 11 matching lines...) Expand all
112 void Remove(const FilePath& file_path, 123 void Remove(const FilePath& file_path,
113 bool is_recursive, 124 bool is_recursive,
114 const FileOperationCallback& callback); 125 const FileOperationCallback& callback);
115 126
116 private: 127 private:
117 friend class DriveSchedulerTest; 128 friend class DriveSchedulerTest;
118 129
119 // Represents a single entry in the job queue. 130 // Represents a single entry in the job queue.
120 struct QueueEntry { 131 struct QueueEntry {
121 QueueEntry(JobType in_job_type, 132 QueueEntry(JobType in_job_type,
122 FilePath in_file_path, 133 FilePath in_file_path);
123 FileOperationCallback in_callback);
124 ~QueueEntry(); 134 ~QueueEntry();
125 135
126 JobInfo job_info; 136 JobInfo job_info;
127 137
128 // Callback for when the operation completes. 138 // Callback for when the operation completes.
129 // Used by: 139 // Used by:
130 // TYPE_COPY, 140 // TYPE_COPY,
131 // TYPE_MOVE, 141 // TYPE_MOVE,
132 // TYPE_REMOVE, 142 // TYPE_REMOVE,
133 // TYPE_TRANSFER_LOCAL_TO_REMOTE, 143 // TYPE_TRANSFER_LOCAL_TO_REMOTE,
134 // TYPE_TRANSFER_REGULAR_FILE, 144 // TYPE_TRANSFER_REGULAR_FILE,
135 // TYPE_TRANSFER_REMOTE_TO_LOCAL 145 // TYPE_TRANSFER_REMOTE_TO_LOCAL
136 FileOperationCallback callback; 146 FileOperationCallback file_operation_callback;
137 147
138 // Destination of the operation. 148 // Destination of the operation.
139 // Used by: 149 // Used by:
140 // TYPE_COPY, 150 // TYPE_COPY,
141 // TYPE_MOVE, 151 // TYPE_MOVE,
142 // TYPE_TRANSFER_LOCAL_TO_REMOTE, 152 // TYPE_TRANSFER_LOCAL_TO_REMOTE,
143 // TYPE_TRANSFER_REGULAR_FILE, 153 // TYPE_TRANSFER_REGULAR_FILE,
144 // TYPE_TRANSFER_REMOTE_TO_LOCAL 154 // TYPE_TRANSFER_REMOTE_TO_LOCAL
145 FilePath dest_file_path; 155 FilePath dest_file_path;
146 156
147 // Whether the operation is recursive. Used by: TYPE_REMOVE 157 // Whether the operation is recursive. Used by:
158 // TYPE_REMOVE
148 bool is_recursive; 159 bool is_recursive;
160
161 // Parameters for GetDocuments(). Used by:
162 // TYPE_GET_DOCUMENTS
163 GURL feed_url;
164 int64 start_changestamp;
165 std::string search_query;
166 bool shared_with_me;
167 std::string directory_resource_id;
168 google_apis::GetDataCallback get_data_callback;
149 }; 169 };
150 170
151 // Adds the specified job to the queue. Takes ownership of |job| 171 // Adds the specified job to the queue. Takes ownership of |job|
152 int QueueJob(scoped_ptr<QueueEntry> job); 172 int QueueJob(scoped_ptr<QueueEntry> job);
153 173
154 // Starts the job loop, if it is not already running. 174 // Starts the job loop, if it is not already running.
155 void StartJobLoop(); 175 void StartJobLoop();
156 176
157 // Determines the next job that should run, and starts it. 177 // Determines the next job that should run, and starts it.
158 void DoJobLoop(); 178 void DoJobLoop();
159 179
160 // Checks if operations should be suspended, such as if the network is 180 // Checks if operations should be suspended, such as if the network is
161 // disconnected. 181 // disconnected.
162 // 182 //
163 // Returns true when it should stop, and false if it should continue. 183 // Returns true when it should stop, and false if it should continue.
164 bool ShouldStopJobLoop(); 184 bool ShouldStopJobLoop();
165 185
166 // Increases the throttle delay if it's below the maximum value, and posts a 186 // Increases the throttle delay if it's below the maximum value, and posts a
167 // task to continue the loop after the delay. 187 // task to continue the loop after the delay.
168 void ThrottleAndContinueJobLoop(); 188 void ThrottleAndContinueJobLoop();
169 189
170 // Resets the throttle delay to the initial value, and continues the job loop. 190 // Resets the throttle delay to the initial value, and continues the job loop.
171 void ResetThrottleAndContinueJobLoop(); 191 void ResetThrottleAndContinueJobLoop();
172 192
173 // Callback for job finishing. Retries the job if needed, otherwise cleans up 193 // Retries the job if needed, otherwise cleans up the job, invokes the
174 // the job, invokes the callback, and continues the job loop. 194 // callback, and continues the job loop.
175 void OnJobDone(int job_id, DriveFileError error); 195 scoped_ptr<QueueEntry> OnJobDone(int job_id, DriveFileError error);
196
197 // Callback for job finishing with a FileOperationCallback.
198 void OnFileOperationJobDone(int job_id, DriveFileError error);
199
200 // Callback for job finishing with a GetDataCallback.
201 void OnGetDataJobDone(int job_id,
202 google_apis::GDataErrorCode error,
203 scoped_ptr<base::Value> feed_data);
176 204
177 // net::NetworkChangeNotifier::ConnectionTypeObserver override. 205 // net::NetworkChangeNotifier::ConnectionTypeObserver override.
178 virtual void OnConnectionTypeChanged( 206 virtual void OnConnectionTypeChanged(
179 net::NetworkChangeNotifier::ConnectionType type) OVERRIDE; 207 net::NetworkChangeNotifier::ConnectionType type) OVERRIDE;
180 208
181 // For testing only. Disables throttling so that testing is faster. 209 // For testing only. Disables throttling so that testing is faster.
182 void SetDisableThrottling(bool disable) { disable_throttling_ = disable; } 210 void SetDisableThrottling(bool disable) { disable_throttling_ = disable; }
183 211
184 // True when there is a job running. Indicates that new jobs should wait to 212 // True when there is a job running. Indicates that new jobs should wait to
185 // be executed. 213 // be executed.
(...skipping 13 matching lines...) Expand all
199 // Mapping of id to QueueEntry. 227 // Mapping of id to QueueEntry.
200 typedef std::map<int, linked_ptr<QueueEntry> > JobMap; 228 typedef std::map<int, linked_ptr<QueueEntry> > JobMap;
201 JobMap job_info_map_; 229 JobMap job_info_map_;
202 230
203 // The queue of jobs id. Sorted by priority. 231 // The queue of jobs id. Sorted by priority.
204 std::deque<int> queue_; 232 std::deque<int> queue_;
205 233
206 // Drive operations. 234 // Drive operations.
207 file_system::DriveOperations* drive_operations_; 235 file_system::DriveOperations* drive_operations_;
208 236
237 google_apis::DriveServiceInterface* drive_service_;
238
209 Profile* profile_; 239 Profile* profile_;
210 240
211 // Note: This should remain the last member so it'll be destroyed and 241 // Note: This should remain the last member so it'll be destroyed and
212 // invalidate its weak pointers before any other members are destroyed. 242 // invalidate its weak pointers before any other members are destroyed.
213 base::WeakPtrFactory<DriveScheduler> weak_ptr_factory_; 243 base::WeakPtrFactory<DriveScheduler> weak_ptr_factory_;
214 244
215 // Whether this instance is initialized or not. 245 // Whether this instance is initialized or not.
216 bool initialized_; 246 bool initialized_;
217 247
218 DISALLOW_COPY_AND_ASSIGN(DriveScheduler); 248 DISALLOW_COPY_AND_ASSIGN(DriveScheduler);
219 }; 249 };
220 250
221 } // namespace drive 251 } // namespace drive
222 252
223 #endif // CHROME_BROWSER_CHROMEOS_DRIVE_DRIVE_SCHEDULER_H_ 253 #endif // CHROME_BROWSER_CHROMEOS_DRIVE_DRIVE_SCHEDULER_H_
OLDNEW
« no previous file with comments | « chrome/browser/chromeos/drive/drive_file_system.cc ('k') | chrome/browser/chromeos/drive/drive_scheduler.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698