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.h" | |
kinaba
2013/04/19 10:05:40
fyi: if you include callback.h, the callback_forwa
calvinlo
2013/04/19 10:22:09
Done.
| |
14 #include "base/callback_forward.h" | 15 #include "base/callback_forward.h" |
15 #include "base/memory/scoped_ptr.h" | 16 #include "base/memory/scoped_ptr.h" |
16 #include "base/memory/weak_ptr.h" | 17 #include "base/memory/weak_ptr.h" |
17 #include "base/observer_list.h" | 18 #include "base/observer_list.h" |
18 #include "base/threading/non_thread_safe.h" | 19 #include "base/threading/non_thread_safe.h" |
19 #include "base/timer.h" | |
20 #include "chrome/browser/google_apis/drive_notification_observer.h" | 20 #include "chrome/browser/google_apis/drive_notification_observer.h" |
21 #include "chrome/browser/sync_file_system/drive_file_sync_client_interface.h" | 21 #include "chrome/browser/sync_file_system/drive_file_sync_client_interface.h" |
22 #include "chrome/browser/sync_file_system/drive_metadata_store.h" | 22 #include "chrome/browser/sync_file_system/drive_metadata_store.h" |
23 #include "chrome/browser/sync_file_system/local_change_processor.h" | 23 #include "chrome/browser/sync_file_system/local_change_processor.h" |
24 #include "chrome/browser/sync_file_system/remote_file_sync_service.h" | 24 #include "chrome/browser/sync_file_system/remote_file_sync_service.h" |
25 #include "webkit/fileapi/syncable/file_change.h" | 25 #include "webkit/fileapi/syncable/file_change.h" |
26 #include "webkit/fileapi/syncable/sync_action.h" | 26 #include "webkit/fileapi/syncable/sync_action.h" |
27 #include "webkit/fileapi/syncable/sync_callbacks.h" | 27 #include "webkit/fileapi/syncable/sync_callbacks.h" |
28 #include "webkit/fileapi/syncable/sync_direction.h" | 28 #include "webkit/fileapi/syncable/sync_direction.h" |
29 #include "webkit/fileapi/syncable/sync_status_code.h" | 29 #include "webkit/fileapi/syncable/sync_status_code.h" |
(...skipping 78 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
108 const base::FilePath& local_file_path, | 108 const base::FilePath& local_file_path, |
109 const SyncFileMetadata& local_file_metadata, | 109 const SyncFileMetadata& local_file_metadata, |
110 const fileapi::FileSystemURL& url, | 110 const fileapi::FileSystemURL& url, |
111 const SyncStatusCallback& callback) OVERRIDE; | 111 const SyncStatusCallback& callback) OVERRIDE; |
112 | 112 |
113 // DriveFileSyncClientObserver overrides. | 113 // DriveFileSyncClientObserver overrides. |
114 virtual void OnAuthenticated() OVERRIDE; | 114 virtual void OnAuthenticated() OVERRIDE; |
115 virtual void OnNetworkConnected() OVERRIDE; | 115 virtual void OnNetworkConnected() OVERRIDE; |
116 | 116 |
117 // google_apis::DriveNotificationObserver implementation. | 117 // google_apis::DriveNotificationObserver implementation. |
118 virtual void CheckForUpdates() OVERRIDE; | 118 virtual void OnNotificationReceived() OVERRIDE; |
119 | 119 |
120 private: | 120 private: |
121 friend class DriveFileSyncServiceMockTest; | 121 friend class DriveFileSyncServiceMockTest; |
122 friend class DriveFileSyncServiceSyncTest; | 122 friend class DriveFileSyncServiceSyncTest; |
123 class TaskToken; | 123 class TaskToken; |
124 struct ApplyLocalChangeParam; | 124 struct ApplyLocalChangeParam; |
125 struct ProcessRemoteChangeParam; | 125 struct ProcessRemoteChangeParam; |
126 | 126 |
127 enum RemoteSyncType { | 127 enum RemoteSyncType { |
128 // Smaller number indicates higher priority in ChangeQueue. | 128 // Smaller number indicates higher priority in ChangeQueue. |
(...skipping 292 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
421 // These two methods are called only from this method. | 421 // These two methods are called only from this method. |
422 void MaybeStartFetchChanges(); | 422 void MaybeStartFetchChanges(); |
423 | 423 |
424 void FetchChangesForIncrementalSync(); | 424 void FetchChangesForIncrementalSync(); |
425 void DidFetchChangesForIncrementalSync( | 425 void DidFetchChangesForIncrementalSync( |
426 scoped_ptr<TaskToken> token, | 426 scoped_ptr<TaskToken> token, |
427 bool has_new_changes, | 427 bool has_new_changes, |
428 google_apis::GDataErrorCode error, | 428 google_apis::GDataErrorCode error, |
429 scoped_ptr<google_apis::ResourceList> changes); | 429 scoped_ptr<google_apis::ResourceList> changes); |
430 bool GetOriginForEntry(const google_apis::ResourceEntry& entry, GURL* origin); | 430 bool GetOriginForEntry(const google_apis::ResourceEntry& entry, GURL* origin); |
431 void SchedulePolling(); | |
432 void OnPollingTimerFired(); | |
433 void UpdatePollingDelay(int64 new_delay_sec); | |
434 void NotifyObserversFileStatusChanged(const fileapi::FileSystemURL& url, | 431 void NotifyObserversFileStatusChanged(const fileapi::FileSystemURL& url, |
435 SyncFileStatus sync_status, | 432 SyncFileStatus sync_status, |
436 SyncAction action_taken, | 433 SyncAction action_taken, |
437 SyncDirection direction); | 434 SyncDirection direction); |
438 | 435 |
439 void HandleSyncRootDirectoryChange(const google_apis::ResourceEntry& entry); | 436 void HandleSyncRootDirectoryChange(const google_apis::ResourceEntry& entry); |
440 void HandleOriginRootDirectoryChange(const google_apis::ResourceEntry& entry); | 437 void HandleOriginRootDirectoryChange(const google_apis::ResourceEntry& entry); |
441 | 438 |
442 void EnsureSyncRootDirectory(const ResourceIdCallback& callback); | 439 void EnsureSyncRootDirectory(const ResourceIdCallback& callback); |
443 void DidEnsureSyncRoot(const ResourceIdCallback& callback, | 440 void DidEnsureSyncRoot(const ResourceIdCallback& callback, |
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
485 | 482 |
486 std::set<GURL> pending_batch_sync_origins_; | 483 std::set<GURL> pending_batch_sync_origins_; |
487 | 484 |
488 // Absence of |token_| implies a task is running. Incoming tasks should | 485 // Absence of |token_| implies a task is running. Incoming tasks should |
489 // wait for the task to finish in |pending_tasks_| if |token_| is null. | 486 // wait for the task to finish in |pending_tasks_| if |token_| is null. |
490 // Each task must take TaskToken instance from |token_| and must hold it | 487 // Each task must take TaskToken instance from |token_| and must hold it |
491 // until it finished. And the task must return the instance through | 488 // until it finished. And the task must return the instance through |
492 // NotifyTaskDone when the task finished. | 489 // NotifyTaskDone when the task finished. |
493 scoped_ptr<TaskToken> token_; | 490 scoped_ptr<TaskToken> token_; |
494 | 491 |
495 // Timer to trigger fetching changes for incremental sync. | |
496 base::OneShotTimer<DriveFileSyncService> polling_timer_; | |
497 // If polling_delay_seconds_ is negative (<0) the timer won't start. | |
498 int64 polling_delay_seconds_; | |
499 | |
500 // Is set to true when there's a fair possibility that we have some | 492 // Is set to true when there's a fair possibility that we have some |
501 // remote changes that haven't been fetched yet. | 493 // remote changes that haven't been fetched yet. |
502 // | 494 // |
503 // This flag is set when: | 495 // This flag is set when: |
504 // - This gets invalidation notification, | 496 // - This gets invalidation notification, |
505 // - The service is authenticated or becomes online, and | 497 // - The service is authenticated or becomes online, and |
506 // - The polling timer is fired. | 498 // - The polling timer is fired. |
507 // | 499 // |
508 // This flag is cleared when: | 500 // This flag is cleared when: |
509 // - A batch or incremental sync has been started, and | 501 // - A batch or incremental sync has been started, and |
(...skipping 10 matching lines...) Expand all Loading... | |
520 // Use WeakPtrFactory instead of SupportsWeakPtr to revoke the weak pointer | 512 // Use WeakPtrFactory instead of SupportsWeakPtr to revoke the weak pointer |
521 // in |token_|. | 513 // in |token_|. |
522 base::WeakPtrFactory<DriveFileSyncService> weak_factory_; | 514 base::WeakPtrFactory<DriveFileSyncService> weak_factory_; |
523 | 515 |
524 DISALLOW_COPY_AND_ASSIGN(DriveFileSyncService); | 516 DISALLOW_COPY_AND_ASSIGN(DriveFileSyncService); |
525 }; | 517 }; |
526 | 518 |
527 } // namespace sync_file_system | 519 } // namespace sync_file_system |
528 | 520 |
529 #endif // CHROME_BROWSER_SYNC_FILE_SYSTEM_DRIVE_FILE_SYNC_SERVICE_H_ | 521 #endif // CHROME_BROWSER_SYNC_FILE_SYSTEM_DRIVE_FILE_SYNC_SERVICE_H_ |
OLD | NEW |