| 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.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" | |
| 20 #include "chrome/browser/google_apis/drive_notification_observer.h" | 19 #include "chrome/browser/google_apis/drive_notification_observer.h" |
| 21 #include "chrome/browser/sync_file_system/drive_file_sync_client_interface.h" | 20 #include "chrome/browser/sync_file_system/drive_file_sync_client_interface.h" |
| 22 #include "chrome/browser/sync_file_system/drive_metadata_store.h" | 21 #include "chrome/browser/sync_file_system/drive_metadata_store.h" |
| 23 #include "chrome/browser/sync_file_system/local_change_processor.h" | 22 #include "chrome/browser/sync_file_system/local_change_processor.h" |
| 24 #include "chrome/browser/sync_file_system/remote_file_sync_service.h" | 23 #include "chrome/browser/sync_file_system/remote_file_sync_service.h" |
| 25 #include "webkit/fileapi/syncable/file_change.h" | 24 #include "webkit/fileapi/syncable/file_change.h" |
| 26 #include "webkit/fileapi/syncable/sync_action.h" | 25 #include "webkit/fileapi/syncable/sync_action.h" |
| 27 #include "webkit/fileapi/syncable/sync_callbacks.h" | 26 #include "webkit/fileapi/syncable/sync_callbacks.h" |
| 28 #include "webkit/fileapi/syncable/sync_direction.h" | 27 #include "webkit/fileapi/syncable/sync_direction.h" |
| 29 #include "webkit/fileapi/syncable/sync_status_code.h" | 28 #include "webkit/fileapi/syncable/sync_status_code.h" |
| (...skipping 75 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 105 const base::FilePath& local_file_path, | 104 const base::FilePath& local_file_path, |
| 106 const SyncFileMetadata& local_file_metadata, | 105 const SyncFileMetadata& local_file_metadata, |
| 107 const fileapi::FileSystemURL& url, | 106 const fileapi::FileSystemURL& url, |
| 108 const SyncStatusCallback& callback) OVERRIDE; | 107 const SyncStatusCallback& callback) OVERRIDE; |
| 109 | 108 |
| 110 // DriveFileSyncClientObserver overrides. | 109 // DriveFileSyncClientObserver overrides. |
| 111 virtual void OnAuthenticated() OVERRIDE; | 110 virtual void OnAuthenticated() OVERRIDE; |
| 112 virtual void OnNetworkConnected() OVERRIDE; | 111 virtual void OnNetworkConnected() OVERRIDE; |
| 113 | 112 |
| 114 // google_apis::DriveNotificationObserver implementation. | 113 // google_apis::DriveNotificationObserver implementation. |
| 115 virtual void CheckForUpdates() OVERRIDE; | 114 virtual void OnNotificationReceived() OVERRIDE; |
| 116 | 115 |
| 117 private: | 116 private: |
| 118 friend class DriveFileSyncServiceMockTest; | 117 friend class DriveFileSyncServiceMockTest; |
| 119 friend class DriveFileSyncServiceSyncTest; | 118 friend class DriveFileSyncServiceSyncTest; |
| 120 class TaskToken; | 119 class TaskToken; |
| 121 struct ApplyLocalChangeParam; | 120 struct ApplyLocalChangeParam; |
| 122 struct ProcessRemoteChangeParam; | 121 struct ProcessRemoteChangeParam; |
| 123 | 122 |
| 124 enum RemoteSyncType { | 123 enum RemoteSyncType { |
| 125 // Smaller number indicates higher priority in ChangeQueue. | 124 // Smaller number indicates higher priority in ChangeQueue. |
| (...skipping 311 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 437 // These two methods are called only from this method. | 436 // These two methods are called only from this method. |
| 438 void MaybeStartFetchChanges(); | 437 void MaybeStartFetchChanges(); |
| 439 | 438 |
| 440 void FetchChangesForIncrementalSync(); | 439 void FetchChangesForIncrementalSync(); |
| 441 void DidFetchChangesForIncrementalSync( | 440 void DidFetchChangesForIncrementalSync( |
| 442 scoped_ptr<TaskToken> token, | 441 scoped_ptr<TaskToken> token, |
| 443 bool has_new_changes, | 442 bool has_new_changes, |
| 444 google_apis::GDataErrorCode error, | 443 google_apis::GDataErrorCode error, |
| 445 scoped_ptr<google_apis::ResourceList> changes); | 444 scoped_ptr<google_apis::ResourceList> changes); |
| 446 bool GetOriginForEntry(const google_apis::ResourceEntry& entry, GURL* origin); | 445 bool GetOriginForEntry(const google_apis::ResourceEntry& entry, GURL* origin); |
| 447 void SchedulePolling(); | |
| 448 void OnPollingTimerFired(); | |
| 449 void UpdatePollingDelay(int64 new_delay_sec); | |
| 450 void NotifyObserversFileStatusChanged(const fileapi::FileSystemURL& url, | 446 void NotifyObserversFileStatusChanged(const fileapi::FileSystemURL& url, |
| 451 SyncFileStatus sync_status, | 447 SyncFileStatus sync_status, |
| 452 SyncAction action_taken, | 448 SyncAction action_taken, |
| 453 SyncDirection direction); | 449 SyncDirection direction); |
| 454 | 450 |
| 455 void HandleSyncRootDirectoryChange(const google_apis::ResourceEntry& entry); | 451 void HandleSyncRootDirectoryChange(const google_apis::ResourceEntry& entry); |
| 456 void HandleOriginRootDirectoryChange(const google_apis::ResourceEntry& entry); | 452 void HandleOriginRootDirectoryChange(const google_apis::ResourceEntry& entry); |
| 457 | 453 |
| 458 void EnsureSyncRootDirectory(const ResourceIdCallback& callback); | 454 void EnsureSyncRootDirectory(const ResourceIdCallback& callback); |
| 459 void DidEnsureSyncRoot(const ResourceIdCallback& callback, | 455 void DidEnsureSyncRoot(const ResourceIdCallback& callback, |
| (...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 501 | 497 |
| 502 std::set<GURL> pending_batch_sync_origins_; | 498 std::set<GURL> pending_batch_sync_origins_; |
| 503 | 499 |
| 504 // Absence of |token_| implies a task is running. Incoming tasks should | 500 // Absence of |token_| implies a task is running. Incoming tasks should |
| 505 // wait for the task to finish in |pending_tasks_| if |token_| is null. | 501 // wait for the task to finish in |pending_tasks_| if |token_| is null. |
| 506 // Each task must take TaskToken instance from |token_| and must hold it | 502 // Each task must take TaskToken instance from |token_| and must hold it |
| 507 // until it finished. And the task must return the instance through | 503 // until it finished. And the task must return the instance through |
| 508 // NotifyTaskDone when the task finished. | 504 // NotifyTaskDone when the task finished. |
| 509 scoped_ptr<TaskToken> token_; | 505 scoped_ptr<TaskToken> token_; |
| 510 | 506 |
| 511 // Timer to trigger fetching changes for incremental sync. | |
| 512 base::OneShotTimer<DriveFileSyncService> polling_timer_; | |
| 513 // If polling_delay_seconds_ is negative (<0) the timer won't start. | |
| 514 int64 polling_delay_seconds_; | |
| 515 | |
| 516 // Is set to true when there's a fair possibility that we have some | 507 // Is set to true when there's a fair possibility that we have some |
| 517 // remote changes that haven't been fetched yet. | 508 // remote changes that haven't been fetched yet. |
| 518 // | 509 // |
| 519 // This flag is set when: | 510 // This flag is set when: |
| 520 // - This gets invalidation notification, | 511 // - This gets invalidation notification, |
| 521 // - The service is authenticated or becomes online, and | 512 // - The service is authenticated or becomes online, and |
| 522 // - The polling timer is fired. | 513 // - The polling timer is fired. |
| 523 // | 514 // |
| 524 // This flag is cleared when: | 515 // This flag is cleared when: |
| 525 // - A batch or incremental sync has been started, and | 516 // - A batch or incremental sync has been started, and |
| (...skipping 10 matching lines...) Expand all Loading... |
| 536 // Use WeakPtrFactory instead of SupportsWeakPtr to revoke the weak pointer | 527 // Use WeakPtrFactory instead of SupportsWeakPtr to revoke the weak pointer |
| 537 // in |token_|. | 528 // in |token_|. |
| 538 base::WeakPtrFactory<DriveFileSyncService> weak_factory_; | 529 base::WeakPtrFactory<DriveFileSyncService> weak_factory_; |
| 539 | 530 |
| 540 DISALLOW_COPY_AND_ASSIGN(DriveFileSyncService); | 531 DISALLOW_COPY_AND_ASSIGN(DriveFileSyncService); |
| 541 }; | 532 }; |
| 542 | 533 |
| 543 } // namespace sync_file_system | 534 } // namespace sync_file_system |
| 544 | 535 |
| 545 #endif // CHROME_BROWSER_SYNC_FILE_SYSTEM_DRIVE_FILE_SYNC_SERVICE_H_ | 536 #endif // CHROME_BROWSER_SYNC_FILE_SYSTEM_DRIVE_FILE_SYNC_SERVICE_H_ |
| OLD | NEW |