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

Side by Side Diff: chrome/browser/sync_file_system/drive_file_sync_service.h

Issue 13866037: Ports XMPP Invalidation code from drive_file_sync_service in /sync_file_system to /google_apis/driv… (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Fix DriveFileSyncServiceMockTest.RegisterNewOrigin test Created 7 years, 8 months 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_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 "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 "sync/notifier/invalidation_handler.h"
26 #include "webkit/fileapi/syncable/file_change.h" 25 #include "webkit/fileapi/syncable/file_change.h"
27 #include "webkit/fileapi/syncable/sync_action.h" 26 #include "webkit/fileapi/syncable/sync_action.h"
28 #include "webkit/fileapi/syncable/sync_callbacks.h" 27 #include "webkit/fileapi/syncable/sync_callbacks.h"
29 #include "webkit/fileapi/syncable/sync_direction.h" 28 #include "webkit/fileapi/syncable/sync_direction.h"
30 #include "webkit/fileapi/syncable/sync_status_code.h" 29 #include "webkit/fileapi/syncable/sync_status_code.h"
31 30
32 class ExtensionService; 31 class ExtensionService;
33 32
34 namespace google_apis { 33 namespace google_apis {
35 class ResourceList; 34 class ResourceList;
36 } 35 }
37 36
38 namespace tracked_objects { 37 namespace tracked_objects {
39 class Location; 38 class Location;
40 } 39 }
41 40
42 namespace sync_file_system { 41 namespace sync_file_system {
43 42
44 // Maintains remote file changes. 43 // Maintains remote file changes.
45 // Owned by SyncFileSystemService (which is a per-profile object). 44 // Owned by SyncFileSystemService (which is a per-profile object).
46 class DriveFileSyncService 45 class DriveFileSyncService
47 : public RemoteFileSyncService, 46 : public RemoteFileSyncService,
48 public LocalChangeProcessor, 47 public LocalChangeProcessor,
49 public DriveFileSyncClientObserver, 48 public DriveFileSyncClientObserver,
50 public base::NonThreadSafe, 49 public base::NonThreadSafe,
51 public syncer::InvalidationHandler,
52 public google_apis::DriveNotificationObserver { 50 public google_apis::DriveNotificationObserver {
53 public: 51 public:
54 static const char kServiceName[]; 52 static const char kServiceName[];
55 static ConflictResolutionPolicy kDefaultPolicy; 53 static ConflictResolutionPolicy kDefaultPolicy;
56 54
57 explicit DriveFileSyncService(Profile* profile); 55 explicit DriveFileSyncService(Profile* profile);
58 virtual ~DriveFileSyncService(); 56 virtual ~DriveFileSyncService();
59 57
60 // Creates DriveFileSyncClient instance for testing. 58 // Creates DriveFileSyncClient instance for testing.
61 // |metadata_store| must be initialized beforehand. 59 // |metadata_store| must be initialized beforehand.
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after
109 const FileChange& change, 107 const FileChange& change,
110 const base::FilePath& local_file_path, 108 const base::FilePath& local_file_path,
111 const SyncFileMetadata& local_file_metadata, 109 const SyncFileMetadata& local_file_metadata,
112 const fileapi::FileSystemURL& url, 110 const fileapi::FileSystemURL& url,
113 const SyncStatusCallback& callback) OVERRIDE; 111 const SyncStatusCallback& callback) OVERRIDE;
114 112
115 // DriveFileSyncClientObserver overrides. 113 // DriveFileSyncClientObserver overrides.
116 virtual void OnAuthenticated() OVERRIDE; 114 virtual void OnAuthenticated() OVERRIDE;
117 virtual void OnNetworkConnected() OVERRIDE; 115 virtual void OnNetworkConnected() OVERRIDE;
118 116
119 // syncer::InvalidationHandler implementation.
120 virtual void OnInvalidatorStateChange(
121 syncer::InvalidatorState state) OVERRIDE;
122 virtual void OnIncomingInvalidation(
123 const syncer::ObjectIdInvalidationMap& invalidation_map) OVERRIDE;
124
125 // google_apis::DriveNotificationObserver implementation. 117 // google_apis::DriveNotificationObserver implementation.
126 virtual void CheckForUpdates() OVERRIDE; 118 virtual void CheckForUpdates() OVERRIDE;
127 119
128 private: 120 private:
129 friend class DriveFileSyncServiceMockTest; 121 friend class DriveFileSyncServiceMockTest;
130 friend class DriveFileSyncServiceSyncTest; 122 friend class DriveFileSyncServiceSyncTest;
131 class TaskToken; 123 class TaskToken;
132 struct ApplyLocalChangeParam; 124 struct ApplyLocalChangeParam;
133 struct ProcessRemoteChangeParam; 125 struct ProcessRemoteChangeParam;
134 126
(...skipping 296 matching lines...) Expand 10 before | Expand all | Expand 10 after
431 void FetchChangesForIncrementalSync(); 423 void FetchChangesForIncrementalSync();
432 void DidFetchChangesForIncrementalSync( 424 void DidFetchChangesForIncrementalSync(
433 scoped_ptr<TaskToken> token, 425 scoped_ptr<TaskToken> token,
434 bool has_new_changes, 426 bool has_new_changes,
435 google_apis::GDataErrorCode error, 427 google_apis::GDataErrorCode error,
436 scoped_ptr<google_apis::ResourceList> changes); 428 scoped_ptr<google_apis::ResourceList> changes);
437 bool GetOriginForEntry(const google_apis::ResourceEntry& entry, GURL* origin); 429 bool GetOriginForEntry(const google_apis::ResourceEntry& entry, GURL* origin);
438 void SchedulePolling(); 430 void SchedulePolling();
439 void OnPollingTimerFired(); 431 void OnPollingTimerFired();
440 void UpdatePollingDelay(int64 new_delay_sec); 432 void UpdatePollingDelay(int64 new_delay_sec);
441 void RegisterDriveNotifications();
442 bool IsDriveNotificationSupported();
443 void SetPushNotificationEnabled(syncer::InvalidatorState state);
444 void NotifyObserversFileStatusChanged(const fileapi::FileSystemURL& url, 433 void NotifyObserversFileStatusChanged(const fileapi::FileSystemURL& url,
445 SyncFileStatus sync_status, 434 SyncFileStatus sync_status,
446 SyncAction action_taken, 435 SyncAction action_taken,
447 SyncDirection direction); 436 SyncDirection direction);
448 437
449 void HandleSyncRootDirectoryChange(const google_apis::ResourceEntry& entry); 438 void HandleSyncRootDirectoryChange(const google_apis::ResourceEntry& entry);
450 void HandleOriginRootDirectoryChange(const google_apis::ResourceEntry& entry); 439 void HandleOriginRootDirectoryChange(const google_apis::ResourceEntry& entry);
451 440
452 void EnsureSyncRootDirectory(const ResourceIdCallback& callback); 441 void EnsureSyncRootDirectory(const ResourceIdCallback& callback);
453 void DidEnsureSyncRoot(const ResourceIdCallback& callback, 442 void DidEnsureSyncRoot(const ResourceIdCallback& callback,
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after
495 484
496 std::set<GURL> pending_batch_sync_origins_; 485 std::set<GURL> pending_batch_sync_origins_;
497 486
498 // Absence of |token_| implies a task is running. Incoming tasks should 487 // Absence of |token_| implies a task is running. Incoming tasks should
499 // wait for the task to finish in |pending_tasks_| if |token_| is null. 488 // wait for the task to finish in |pending_tasks_| if |token_| is null.
500 // Each task must take TaskToken instance from |token_| and must hold it 489 // Each task must take TaskToken instance from |token_| and must hold it
501 // until it finished. And the task must return the instance through 490 // until it finished. And the task must return the instance through
502 // NotifyTaskDone when the task finished. 491 // NotifyTaskDone when the task finished.
503 scoped_ptr<TaskToken> token_; 492 scoped_ptr<TaskToken> token_;
504 493
505 // True when Drive File Sync Service is registered for Drive notifications.
506 bool push_notification_registered_;
507 // True once the first drive notification is received with OK state.
508 bool push_notification_enabled_;
509 // Timer to trigger fetching changes for incremental sync. 494 // Timer to trigger fetching changes for incremental sync.
510 base::OneShotTimer<DriveFileSyncService> polling_timer_; 495 base::OneShotTimer<DriveFileSyncService> polling_timer_;
511 // If polling_delay_seconds_ is negative (<0) the timer won't start. 496 // If polling_delay_seconds_ is negative (<0) the timer won't start.
512 int64 polling_delay_seconds_; 497 int64 polling_delay_seconds_;
513 498
514 // Is set to true when there's a fair possibility that we have some 499 // Is set to true when there's a fair possibility that we have some
515 // remote changes that haven't been fetched yet. 500 // remote changes that haven't been fetched yet.
516 // 501 //
517 // This flag is set when: 502 // This flag is set when:
518 // - This gets invalidation notification, 503 // - This gets invalidation notification,
(...skipping 15 matching lines...) Expand all
534 // Use WeakPtrFactory instead of SupportsWeakPtr to revoke the weak pointer 519 // Use WeakPtrFactory instead of SupportsWeakPtr to revoke the weak pointer
535 // in |token_|. 520 // in |token_|.
536 base::WeakPtrFactory<DriveFileSyncService> weak_factory_; 521 base::WeakPtrFactory<DriveFileSyncService> weak_factory_;
537 522
538 DISALLOW_COPY_AND_ASSIGN(DriveFileSyncService); 523 DISALLOW_COPY_AND_ASSIGN(DriveFileSyncService);
539 }; 524 };
540 525
541 } // namespace sync_file_system 526 } // namespace sync_file_system
542 527
543 #endif // CHROME_BROWSER_SYNC_FILE_SYSTEM_DRIVE_FILE_SYNC_SERVICE_H_ 528 #endif // CHROME_BROWSER_SYNC_FILE_SYSTEM_DRIVE_FILE_SYNC_SERVICE_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698