| 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 // An implementation of SyncNotifier that wraps InvalidationNotifier | 5 // An implementation of SyncNotifier that wraps InvalidationNotifier |
| 6 // on its own thread. | 6 // on its own thread. |
| 7 | 7 |
| 8 #ifndef SYNC_NOTIFIER_NON_BLOCKING_INVALIDATION_NOTIFIER_H_ | 8 #ifndef SYNC_NOTIFIER_NON_BLOCKING_INVALIDATION_NOTIFIER_H_ |
| 9 #define SYNC_NOTIFIER_NON_BLOCKING_INVALIDATION_NOTIFIER_H_ | 9 #define SYNC_NOTIFIER_NON_BLOCKING_INVALIDATION_NOTIFIER_H_ |
| 10 | 10 |
| 11 #include <string> | 11 #include <string> |
| 12 | 12 |
| 13 #include "base/basictypes.h" | 13 #include "base/basictypes.h" |
| 14 #include "base/compiler_specific.h" | 14 #include "base/compiler_specific.h" |
| 15 #include "base/memory/ref_counted.h" | 15 #include "base/memory/ref_counted.h" |
| 16 #include "base/memory/weak_ptr.h" | 16 #include "base/memory/weak_ptr.h" |
| 17 #include "base/observer_list.h" | |
| 18 #include "jingle/notifier/base/notifier_options.h" | 17 #include "jingle/notifier/base/notifier_options.h" |
| 19 #include "sync/internal_api/public/util/weak_handle.h" | 18 #include "sync/internal_api/public/util/weak_handle.h" |
| 20 #include "sync/notifier/invalidation_state_tracker.h" | 19 #include "sync/notifier/invalidation_state_tracker.h" |
| 21 #include "sync/notifier/sync_notifier.h" | 20 #include "sync/notifier/sync_notifier.h" |
| 21 #include "sync/notifier/sync_notifier_helper.h" |
| 22 #include "sync/notifier/sync_notifier_observer.h" | 22 #include "sync/notifier/sync_notifier_observer.h" |
| 23 | 23 |
| 24 namespace base { | 24 namespace base { |
| 25 class SingleThreadTaskRunner; | 25 class SingleThreadTaskRunner; |
| 26 } // namespace base | 26 } // namespace base |
| 27 | 27 |
| 28 namespace syncer { | 28 namespace syncer { |
| 29 | 29 |
| 30 class NonBlockingInvalidationNotifier | 30 class NonBlockingInvalidationNotifier |
| 31 : public SyncNotifier, | 31 : public SyncNotifier, |
| 32 // SyncNotifierObserver to "observe" our Core via WeakHandle. | 32 // SyncNotifierObserver to "observe" our Core via WeakHandle. |
| 33 public SyncNotifierObserver { | 33 public SyncNotifierObserver { |
| 34 public: | 34 public: |
| 35 // |invalidation_state_tracker| must be initialized. | 35 // |invalidation_state_tracker| must be initialized. |
| 36 NonBlockingInvalidationNotifier( | 36 NonBlockingInvalidationNotifier( |
| 37 const notifier::NotifierOptions& notifier_options, | 37 const notifier::NotifierOptions& notifier_options, |
| 38 const InvalidationVersionMap& initial_max_invalidation_versions, | 38 const InvalidationVersionMap& initial_max_invalidation_versions, |
| 39 const std::string& initial_invalidation_state, | 39 const std::string& initial_invalidation_state, |
| 40 const syncer::WeakHandle<InvalidationStateTracker>& | 40 const syncer::WeakHandle<InvalidationStateTracker>& |
| 41 invalidation_state_tracker, | 41 invalidation_state_tracker, |
| 42 const std::string& client_info); | 42 const std::string& client_info); |
| 43 | 43 |
| 44 virtual ~NonBlockingInvalidationNotifier(); | 44 virtual ~NonBlockingInvalidationNotifier(); |
| 45 | 45 |
| 46 // SyncNotifier implementation. | 46 // SyncNotifier implementation. |
| 47 virtual void AddObserver(SyncNotifierObserver* observer) OVERRIDE; | 47 virtual void UpdateRegisteredIds(SyncNotifierObserver* handler, |
| 48 virtual void RemoveObserver(SyncNotifierObserver* observer) OVERRIDE; | 48 const ObjectIdSet& ids) OVERRIDE; |
| 49 virtual void SetUniqueId(const std::string& unique_id) OVERRIDE; | 49 virtual void SetUniqueId(const std::string& unique_id) OVERRIDE; |
| 50 virtual void SetStateDeprecated(const std::string& state) OVERRIDE; | 50 virtual void SetStateDeprecated(const std::string& state) OVERRIDE; |
| 51 virtual void UpdateCredentials( | 51 virtual void UpdateCredentials( |
| 52 const std::string& email, const std::string& token) OVERRIDE; | 52 const std::string& email, const std::string& token) OVERRIDE; |
| 53 virtual void UpdateEnabledTypes( | |
| 54 syncer::ModelTypeSet enabled_types) OVERRIDE; | |
| 55 virtual void SendNotification( | 53 virtual void SendNotification( |
| 56 syncer::ModelTypeSet changed_types) OVERRIDE; | 54 syncer::ModelTypeSet changed_types) OVERRIDE; |
| 57 | 55 |
| 58 // SyncNotifierObserver implementation. | 56 // SyncNotifierObserver implementation. |
| 59 virtual void OnNotificationsEnabled() OVERRIDE; | 57 virtual void OnNotificationsEnabled() OVERRIDE; |
| 60 virtual void OnNotificationsDisabled( | 58 virtual void OnNotificationsDisabled( |
| 61 NotificationsDisabledReason reason) OVERRIDE; | 59 NotificationsDisabledReason reason) OVERRIDE; |
| 62 virtual void OnIncomingNotification( | 60 virtual void OnIncomingNotification( |
| 63 const syncer::ModelTypePayloadMap& type_payloads, | 61 const ObjectIdPayloadMap& id_payloads, |
| 64 IncomingNotificationSource source) OVERRIDE; | 62 IncomingNotificationSource source) OVERRIDE; |
| 65 | 63 |
| 66 private: | 64 private: |
| 67 class Core; | 65 class Core; |
| 68 | 66 |
| 69 base::WeakPtrFactory<NonBlockingInvalidationNotifier> weak_ptr_factory_; | 67 base::WeakPtrFactory<NonBlockingInvalidationNotifier> weak_ptr_factory_; |
| 70 | 68 |
| 71 // Our observers (which must live on the parent thread). | 69 SyncNotifierHelper helper_; |
| 72 ObserverList<SyncNotifierObserver> observers_; | |
| 73 | 70 |
| 74 // The real guts of NonBlockingInvalidationNotifier, which allows | 71 // The real guts of NonBlockingInvalidationNotifier, which allows |
| 75 // this class to live completely on the parent thread. | 72 // this class to live completely on the parent thread. |
| 76 scoped_refptr<Core> core_; | 73 scoped_refptr<Core> core_; |
| 77 scoped_refptr<base::SingleThreadTaskRunner> parent_task_runner_; | 74 scoped_refptr<base::SingleThreadTaskRunner> parent_task_runner_; |
| 78 scoped_refptr<base::SingleThreadTaskRunner> network_task_runner_; | 75 scoped_refptr<base::SingleThreadTaskRunner> network_task_runner_; |
| 79 | 76 |
| 80 DISALLOW_COPY_AND_ASSIGN(NonBlockingInvalidationNotifier); | 77 DISALLOW_COPY_AND_ASSIGN(NonBlockingInvalidationNotifier); |
| 81 }; | 78 }; |
| 82 | 79 |
| 83 } // namespace syncer | 80 } // namespace syncer |
| 84 | 81 |
| 85 #endif // SYNC_NOTIFIER_NON_BLOCKING_INVALIDATION_NOTIFIER_H_ | 82 #endif // SYNC_NOTIFIER_NON_BLOCKING_INVALIDATION_NOTIFIER_H_ |
| OLD | NEW |