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