| 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 #include "sync/notifier/non_blocking_invalidation_notifier.h" | 5 #include "sync/notifier/non_blocking_invalidation_notifier.h" |
| 6 | 6 |
| 7 #include "base/location.h" | 7 #include "base/location.h" |
| 8 #include "base/logging.h" | 8 #include "base/logging.h" |
| 9 #include "base/memory/scoped_ptr.h" | 9 #include "base/memory/scoped_ptr.h" |
| 10 #include "base/single_thread_task_runner.h" | 10 #include "base/single_thread_task_runner.h" |
| 11 #include "base/thread_task_runner_handle.h" | 11 #include "base/thread_task_runner_handle.h" |
| 12 #include "base/threading/thread.h" | 12 #include "base/threading/thread.h" |
| 13 #include "jingle/notifier/listener/push_client.h" | 13 #include "jingle/notifier/listener/push_client.h" |
| 14 #include "sync/notifier/invalidation_notifier.h" | 14 #include "sync/notifier/invalidation_notifier.h" |
| 15 | 15 |
| 16 namespace csync { | 16 namespace syncer { |
| 17 | 17 |
| 18 class NonBlockingInvalidationNotifier::Core | 18 class NonBlockingInvalidationNotifier::Core |
| 19 : public base::RefCountedThreadSafe<NonBlockingInvalidationNotifier::Core>, | 19 : public base::RefCountedThreadSafe<NonBlockingInvalidationNotifier::Core>, |
| 20 // SyncNotifierObserver to observe the InvalidationNotifier we create. | 20 // SyncNotifierObserver to observe the InvalidationNotifier we create. |
| 21 public SyncNotifierObserver { | 21 public SyncNotifierObserver { |
| 22 public: | 22 public: |
| 23 // Called on parent thread. |delegate_observer| should be | 23 // Called on parent thread. |delegate_observer| should be |
| 24 // initialized. | 24 // initialized. |
| 25 explicit Core( | 25 explicit Core( |
| 26 const csync::WeakHandle<SyncNotifierObserver>& | 26 const syncer::WeakHandle<SyncNotifierObserver>& |
| 27 delegate_observer); | 27 delegate_observer); |
| 28 | 28 |
| 29 // Helpers called on I/O thread. | 29 // Helpers called on I/O thread. |
| 30 void Initialize( | 30 void Initialize( |
| 31 const notifier::NotifierOptions& notifier_options, | 31 const notifier::NotifierOptions& notifier_options, |
| 32 const InvalidationVersionMap& initial_max_invalidation_versions, | 32 const InvalidationVersionMap& initial_max_invalidation_versions, |
| 33 const std::string& initial_invalidation_state, | 33 const std::string& initial_invalidation_state, |
| 34 const csync::WeakHandle<InvalidationStateTracker>& | 34 const syncer::WeakHandle<InvalidationStateTracker>& |
| 35 invalidation_state_tracker, | 35 invalidation_state_tracker, |
| 36 const std::string& client_info); | 36 const std::string& client_info); |
| 37 void Teardown(); | 37 void Teardown(); |
| 38 void SetUniqueId(const std::string& unique_id); | 38 void SetUniqueId(const std::string& unique_id); |
| 39 void SetStateDeprecated(const std::string& state); | 39 void SetStateDeprecated(const std::string& state); |
| 40 void UpdateCredentials(const std::string& email, const std::string& token); | 40 void UpdateCredentials(const std::string& email, const std::string& token); |
| 41 void UpdateEnabledTypes(syncable::ModelTypeSet enabled_types); | 41 void UpdateEnabledTypes(syncable::ModelTypeSet enabled_types); |
| 42 | 42 |
| 43 // SyncNotifierObserver implementation (all called on I/O thread by | 43 // SyncNotifierObserver implementation (all called on I/O thread by |
| 44 // InvalidationNotifier). | 44 // InvalidationNotifier). |
| 45 virtual void OnNotificationsEnabled() OVERRIDE; | 45 virtual void OnNotificationsEnabled() OVERRIDE; |
| 46 virtual void OnNotificationsDisabled( | 46 virtual void OnNotificationsDisabled( |
| 47 NotificationsDisabledReason reason) OVERRIDE; | 47 NotificationsDisabledReason reason) OVERRIDE; |
| 48 virtual void OnIncomingNotification( | 48 virtual void OnIncomingNotification( |
| 49 const syncable::ModelTypePayloadMap& type_payloads, | 49 const syncable::ModelTypePayloadMap& type_payloads, |
| 50 IncomingNotificationSource source) OVERRIDE; | 50 IncomingNotificationSource source) OVERRIDE; |
| 51 | 51 |
| 52 private: | 52 private: |
| 53 friend class | 53 friend class |
| 54 base::RefCountedThreadSafe<NonBlockingInvalidationNotifier::Core>; | 54 base::RefCountedThreadSafe<NonBlockingInvalidationNotifier::Core>; |
| 55 // Called on parent or I/O thread. | 55 // Called on parent or I/O thread. |
| 56 ~Core(); | 56 ~Core(); |
| 57 | 57 |
| 58 // The variables below should be used only on the I/O thread. | 58 // The variables below should be used only on the I/O thread. |
| 59 const csync::WeakHandle<SyncNotifierObserver> delegate_observer_; | 59 const syncer::WeakHandle<SyncNotifierObserver> delegate_observer_; |
| 60 scoped_ptr<InvalidationNotifier> invalidation_notifier_; | 60 scoped_ptr<InvalidationNotifier> invalidation_notifier_; |
| 61 scoped_refptr<base::SingleThreadTaskRunner> network_task_runner_; | 61 scoped_refptr<base::SingleThreadTaskRunner> network_task_runner_; |
| 62 | 62 |
| 63 DISALLOW_COPY_AND_ASSIGN(Core); | 63 DISALLOW_COPY_AND_ASSIGN(Core); |
| 64 }; | 64 }; |
| 65 | 65 |
| 66 NonBlockingInvalidationNotifier::Core::Core( | 66 NonBlockingInvalidationNotifier::Core::Core( |
| 67 const csync::WeakHandle<SyncNotifierObserver>& | 67 const syncer::WeakHandle<SyncNotifierObserver>& |
| 68 delegate_observer) | 68 delegate_observer) |
| 69 : delegate_observer_(delegate_observer) { | 69 : delegate_observer_(delegate_observer) { |
| 70 DCHECK(delegate_observer_.IsInitialized()); | 70 DCHECK(delegate_observer_.IsInitialized()); |
| 71 } | 71 } |
| 72 | 72 |
| 73 NonBlockingInvalidationNotifier::Core::~Core() { | 73 NonBlockingInvalidationNotifier::Core::~Core() { |
| 74 } | 74 } |
| 75 | 75 |
| 76 void NonBlockingInvalidationNotifier::Core::Initialize( | 76 void NonBlockingInvalidationNotifier::Core::Initialize( |
| 77 const notifier::NotifierOptions& notifier_options, | 77 const notifier::NotifierOptions& notifier_options, |
| 78 const InvalidationVersionMap& initial_max_invalidation_versions, | 78 const InvalidationVersionMap& initial_max_invalidation_versions, |
| 79 const std::string& initial_invalidation_state, | 79 const std::string& initial_invalidation_state, |
| 80 const csync::WeakHandle<InvalidationStateTracker>& | 80 const syncer::WeakHandle<InvalidationStateTracker>& |
| 81 invalidation_state_tracker, | 81 invalidation_state_tracker, |
| 82 const std::string& client_info) { | 82 const std::string& client_info) { |
| 83 DCHECK(notifier_options.request_context_getter); | 83 DCHECK(notifier_options.request_context_getter); |
| 84 DCHECK_EQ(notifier::NOTIFICATION_SERVER, | 84 DCHECK_EQ(notifier::NOTIFICATION_SERVER, |
| 85 notifier_options.notification_method); | 85 notifier_options.notification_method); |
| 86 network_task_runner_ = notifier_options.request_context_getter-> | 86 network_task_runner_ = notifier_options.request_context_getter-> |
| 87 GetNetworkTaskRunner(); | 87 GetNetworkTaskRunner(); |
| 88 DCHECK(network_task_runner_->BelongsToCurrentThread()); | 88 DCHECK(network_task_runner_->BelongsToCurrentThread()); |
| 89 invalidation_notifier_.reset( | 89 invalidation_notifier_.reset( |
| 90 new InvalidationNotifier( | 90 new InvalidationNotifier( |
| (...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 148 delegate_observer_.Call(FROM_HERE, | 148 delegate_observer_.Call(FROM_HERE, |
| 149 &SyncNotifierObserver::OnIncomingNotification, | 149 &SyncNotifierObserver::OnIncomingNotification, |
| 150 type_payloads, | 150 type_payloads, |
| 151 source); | 151 source); |
| 152 } | 152 } |
| 153 | 153 |
| 154 NonBlockingInvalidationNotifier::NonBlockingInvalidationNotifier( | 154 NonBlockingInvalidationNotifier::NonBlockingInvalidationNotifier( |
| 155 const notifier::NotifierOptions& notifier_options, | 155 const notifier::NotifierOptions& notifier_options, |
| 156 const InvalidationVersionMap& initial_max_invalidation_versions, | 156 const InvalidationVersionMap& initial_max_invalidation_versions, |
| 157 const std::string& initial_invalidation_state, | 157 const std::string& initial_invalidation_state, |
| 158 const csync::WeakHandle<InvalidationStateTracker>& | 158 const syncer::WeakHandle<InvalidationStateTracker>& |
| 159 invalidation_state_tracker, | 159 invalidation_state_tracker, |
| 160 const std::string& client_info) | 160 const std::string& client_info) |
| 161 : weak_ptr_factory_(ALLOW_THIS_IN_INITIALIZER_LIST(this)), | 161 : weak_ptr_factory_(ALLOW_THIS_IN_INITIALIZER_LIST(this)), |
| 162 core_( | 162 core_( |
| 163 new Core(csync::MakeWeakHandle( | 163 new Core(syncer::MakeWeakHandle( |
| 164 weak_ptr_factory_.GetWeakPtr()))), | 164 weak_ptr_factory_.GetWeakPtr()))), |
| 165 parent_task_runner_( | 165 parent_task_runner_( |
| 166 base::ThreadTaskRunnerHandle::Get()), | 166 base::ThreadTaskRunnerHandle::Get()), |
| 167 network_task_runner_(notifier_options.request_context_getter-> | 167 network_task_runner_(notifier_options.request_context_getter-> |
| 168 GetNetworkTaskRunner()) { | 168 GetNetworkTaskRunner()) { |
| 169 if (!network_task_runner_->PostTask( | 169 if (!network_task_runner_->PostTask( |
| 170 FROM_HERE, | 170 FROM_HERE, |
| 171 base::Bind( | 171 base::Bind( |
| 172 &NonBlockingInvalidationNotifier::Core::Initialize, | 172 &NonBlockingInvalidationNotifier::Core::Initialize, |
| 173 core_.get(), | 173 core_.get(), |
| (...skipping 94 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 268 } | 268 } |
| 269 | 269 |
| 270 void NonBlockingInvalidationNotifier::OnIncomingNotification( | 270 void NonBlockingInvalidationNotifier::OnIncomingNotification( |
| 271 const syncable::ModelTypePayloadMap& type_payloads, | 271 const syncable::ModelTypePayloadMap& type_payloads, |
| 272 IncomingNotificationSource source) { | 272 IncomingNotificationSource source) { |
| 273 DCHECK(parent_task_runner_->BelongsToCurrentThread()); | 273 DCHECK(parent_task_runner_->BelongsToCurrentThread()); |
| 274 FOR_EACH_OBSERVER(SyncNotifierObserver, observers_, | 274 FOR_EACH_OBSERVER(SyncNotifierObserver, observers_, |
| 275 OnIncomingNotification(type_payloads, source)); | 275 OnIncomingNotification(type_payloads, source)); |
| 276 } | 276 } |
| 277 | 277 |
| 278 } // namespace csync | 278 } // namespace syncer |
| OLD | NEW |