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_SYNC_FILE_SYSTEM_DRIVE_FILE_SYNC_SERVICE_H_ | 5 #ifndef CHROME_BROWSER_SYNC_FILE_SYSTEM_DRIVE_FILE_SYNC_SERVICE_H_ |
6 #define CHROME_BROWSER_SYNC_FILE_SYSTEM_DRIVE_FILE_SYNC_SERVICE_H_ | 6 #define CHROME_BROWSER_SYNC_FILE_SYSTEM_DRIVE_FILE_SYNC_SERVICE_H_ |
7 | 7 |
8 #include <deque> | 8 #include <deque> |
9 #include <map> | 9 #include <map> |
10 #include <set> | 10 #include <set> |
11 #include <string> | 11 #include <string> |
12 #include <vector> | 12 #include <vector> |
13 | 13 |
14 #include "base/callback_forward.h" | 14 #include "base/callback_forward.h" |
15 #include "base/memory/scoped_ptr.h" | 15 #include "base/memory/scoped_ptr.h" |
16 #include "base/memory/weak_ptr.h" | 16 #include "base/memory/weak_ptr.h" |
17 #include "base/observer_list.h" | 17 #include "base/observer_list.h" |
18 #include "base/threading/non_thread_safe.h" | 18 #include "base/threading/non_thread_safe.h" |
| 19 #include "base/timer.h" |
19 #include "chrome/browser/google_apis/drive_service_interface.h" | 20 #include "chrome/browser/google_apis/drive_service_interface.h" |
20 #include "chrome/browser/google_apis/gdata_wapi_parser.h" | 21 #include "chrome/browser/google_apis/gdata_wapi_parser.h" |
21 #include "chrome/browser/sync_file_system/local_change_processor.h" | 22 #include "chrome/browser/sync_file_system/local_change_processor.h" |
22 #include "chrome/browser/sync_file_system/remote_file_sync_service.h" | 23 #include "chrome/browser/sync_file_system/remote_file_sync_service.h" |
23 #include "webkit/fileapi/syncable/file_change.h" | 24 #include "webkit/fileapi/syncable/file_change.h" |
24 #include "webkit/fileapi/syncable/sync_callbacks.h" | 25 #include "webkit/fileapi/syncable/sync_callbacks.h" |
25 #include "webkit/fileapi/syncable/sync_operation_type.h" | 26 #include "webkit/fileapi/syncable/sync_operation_type.h" |
26 | 27 |
27 namespace google_apis { | 28 namespace google_apis { |
28 class DocumentFeed; | 29 class DocumentFeed; |
(...skipping 241 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
270 scoped_ptr<ProcessRemoteChangeParam> param, | 271 scoped_ptr<ProcessRemoteChangeParam> param, |
271 fileapi::SyncStatusCode status); | 272 fileapi::SyncStatusCode status); |
272 void AbortRemoteSync( | 273 void AbortRemoteSync( |
273 scoped_ptr<ProcessRemoteChangeParam> param, | 274 scoped_ptr<ProcessRemoteChangeParam> param, |
274 fileapi::SyncStatusCode status); | 275 fileapi::SyncStatusCode status); |
275 void FinalizeRemoteSync( | 276 void FinalizeRemoteSync( |
276 scoped_ptr<ProcessRemoteChangeParam> param, | 277 scoped_ptr<ProcessRemoteChangeParam> param, |
277 fileapi::SyncStatusCode status); | 278 fileapi::SyncStatusCode status); |
278 | 279 |
279 void AppendNewRemoteChange(const GURL& origin, | 280 void AppendNewRemoteChange(const GURL& origin, |
280 google_apis::DocumentEntry* entry, | 281 const google_apis::DocumentEntry& entry, |
281 int64 changestamp, | 282 int64 changestamp, |
282 RemoteSyncType sync_type); | 283 RemoteSyncType sync_type); |
283 void CancelRemoteChange(const fileapi::FileSystemURL& url); | 284 void RemoveRemoteChange(const fileapi::FileSystemURL& url); |
284 void MaybeMarkAsIncrementalSyncOrigin(const GURL& origin); | 285 void MaybeMarkAsIncrementalSyncOrigin(const GURL& origin); |
285 | 286 |
286 // This returns false if no change is found for the |url|. | 287 // This returns false if no change is found for the |url|. |
287 bool GetPendingChangeForFileSystemURL(const fileapi::FileSystemURL& url, | 288 bool GetPendingChangeForFileSystemURL(const fileapi::FileSystemURL& url, |
288 RemoteChange* change) const; | 289 RemoteChange* change) const; |
289 | 290 |
290 // A wrapper implementation to GDataErrorCodeToSyncStatusCode which returns | 291 // A wrapper implementation to GDataErrorCodeToSyncStatusCode which returns |
291 // authentication error if the user is not signed in. | 292 // authentication error if the user is not signed in. |
292 fileapi::SyncStatusCode GDataErrorCodeToSyncStatusCodeWrapper( | 293 fileapi::SyncStatusCode GDataErrorCodeToSyncStatusCodeWrapper( |
293 google_apis::GDataErrorCode error) const; | 294 google_apis::GDataErrorCode error) const; |
294 | 295 |
295 FilePath temporary_file_dir_; | 296 FilePath temporary_file_dir_; |
296 | 297 |
| 298 void FetchChangesForIncrementalSync(); |
| 299 void DidFetchChangesForIncrementalSync( |
| 300 scoped_ptr<TaskToken> token, |
| 301 google_apis::GDataErrorCode error, |
| 302 scoped_ptr<google_apis::DocumentFeed> changes); |
| 303 bool GetOriginForEntry(const google_apis::DocumentEntry& entry, GURL* origin); |
| 304 void SchedulePolling(); |
| 305 |
297 scoped_ptr<DriveMetadataStore> metadata_store_; | 306 scoped_ptr<DriveMetadataStore> metadata_store_; |
298 scoped_ptr<DriveFileSyncClient> sync_client_; | 307 scoped_ptr<DriveFileSyncClient> sync_client_; |
299 | 308 |
300 fileapi::SyncStatusCode last_operation_status_; | 309 fileapi::SyncStatusCode last_operation_status_; |
301 RemoteServiceState state_; | 310 RemoteServiceState state_; |
302 std::deque<base::Closure> pending_tasks_; | 311 std::deque<base::Closure> pending_tasks_; |
303 | 312 |
304 int64 largest_changestamp_; | 313 int64 largest_fetched_changestamp_; |
| 314 |
305 PendingChangeQueue pending_changes_; | 315 PendingChangeQueue pending_changes_; |
306 URLToChange url_to_change_; | 316 URLToChange url_to_change_; |
307 | 317 |
308 std::set<GURL> pending_batch_sync_origins_; | 318 std::set<GURL> pending_batch_sync_origins_; |
309 | 319 |
310 // Absence of |token_| implies a task is running. Incoming tasks should | 320 // Absence of |token_| implies a task is running. Incoming tasks should |
311 // wait for the task to finish in |pending_tasks_| if |token_| is null. | 321 // wait for the task to finish in |pending_tasks_| if |token_| is null. |
312 // Each task must take TaskToken instance from |token_| and must hold it | 322 // Each task must take TaskToken instance from |token_| and must hold it |
313 // until it finished. And the task must return the instance through | 323 // until it finished. And the task must return the instance through |
314 // NotifyTaskDone when the task finished. | 324 // NotifyTaskDone when the task finished. |
315 scoped_ptr<TaskToken> token_; | 325 scoped_ptr<TaskToken> token_; |
316 | 326 |
| 327 base::OneShotTimer<DriveFileSyncService> polling_timer_; |
| 328 base::TimeDelta polling_delay_; |
| 329 bool polling_enabled_; |
| 330 |
317 ObserverList<Observer> observers_; | 331 ObserverList<Observer> observers_; |
318 | 332 |
319 // Use WeakPtrFactory instead of SupportsWeakPtr to revoke the weak pointer | 333 // Use WeakPtrFactory instead of SupportsWeakPtr to revoke the weak pointer |
320 // in |token_|. | 334 // in |token_|. |
321 base::WeakPtrFactory<DriveFileSyncService> weak_factory_; | 335 base::WeakPtrFactory<DriveFileSyncService> weak_factory_; |
322 | 336 |
323 DISALLOW_COPY_AND_ASSIGN(DriveFileSyncService); | 337 DISALLOW_COPY_AND_ASSIGN(DriveFileSyncService); |
324 }; | 338 }; |
325 | 339 |
326 } // namespace sync_file_system | 340 } // namespace sync_file_system |
327 | 341 |
328 #endif // CHROME_BROWSER_SYNC_FILE_SYSTEM_DRIVE_FILE_SYNC_SERVICE_H_ | 342 #endif // CHROME_BROWSER_SYNC_FILE_SYSTEM_DRIVE_FILE_SYNC_SERVICE_H_ |
OLD | NEW |