| OLD | NEW |
| 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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 "chrome/browser/sync/notifier/non_blocking_invalidation_notifier.h" | 5 #include "chrome/browser/sync/notifier/non_blocking_invalidation_notifier.h" |
| 6 | 6 |
| 7 #include "base/logging.h" | 7 #include "base/logging.h" |
| 8 #include "base/memory/scoped_ptr.h" | 8 #include "base/memory/scoped_ptr.h" |
| 9 #include "base/message_loop.h" | 9 #include "base/message_loop.h" |
| 10 #include "base/observer_list_threadsafe.h" | 10 #include "base/observer_list_threadsafe.h" |
| (...skipping 14 matching lines...) Expand all Loading... |
| 25 void AddObserver(SyncNotifierObserver* observer); | 25 void AddObserver(SyncNotifierObserver* observer); |
| 26 void RemoveObserver(SyncNotifierObserver* observer); | 26 void RemoveObserver(SyncNotifierObserver* observer); |
| 27 | 27 |
| 28 // Helpers called on I/O thread. | 28 // Helpers called on I/O thread. |
| 29 void Initialize(const notifier::NotifierOptions& notifier_options, | 29 void Initialize(const notifier::NotifierOptions& notifier_options, |
| 30 const std::string& client_info); | 30 const std::string& client_info); |
| 31 void Teardown(); | 31 void Teardown(); |
| 32 void SetUniqueId(const std::string& unique_id); | 32 void SetUniqueId(const std::string& unique_id); |
| 33 void SetState(const std::string& state); | 33 void SetState(const std::string& state); |
| 34 void UpdateCredentials(const std::string& email, const std::string& token); | 34 void UpdateCredentials(const std::string& email, const std::string& token); |
| 35 void UpdateEnabledTypes(const syncable::ModelTypeSet& types); | 35 void UpdateEnabledTypes(const syncable::ModelTypeSet& enabled_types); |
| 36 void SendNotification(); | |
| 37 | 36 |
| 38 // SyncNotifierObserver implementation (all called on I/O thread). | 37 // SyncNotifierObserver implementation (all called on I/O thread). |
| 39 virtual void OnIncomingNotification( | 38 virtual void OnIncomingNotification( |
| 40 const syncable::ModelTypePayloadMap& type_payloads); | 39 const syncable::ModelTypePayloadMap& type_payloads); |
| 41 virtual void OnNotificationStateChange(bool notifications_enabled); | 40 virtual void OnNotificationStateChange(bool notifications_enabled); |
| 42 virtual void StoreState(const std::string& state); | 41 virtual void StoreState(const std::string& state); |
| 43 | 42 |
| 44 private: | 43 private: |
| 45 friend class | 44 friend class |
| 46 base::RefCountedThreadSafe<NonBlockingInvalidationNotifier::Core>; | 45 base::RefCountedThreadSafe<NonBlockingInvalidationNotifier::Core>; |
| (...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 104 invalidation_notifier_->SetState(state); | 103 invalidation_notifier_->SetState(state); |
| 105 } | 104 } |
| 106 | 105 |
| 107 void NonBlockingInvalidationNotifier::Core::UpdateCredentials( | 106 void NonBlockingInvalidationNotifier::Core::UpdateCredentials( |
| 108 const std::string& email, const std::string& token) { | 107 const std::string& email, const std::string& token) { |
| 109 DCHECK(io_message_loop_proxy_->BelongsToCurrentThread()); | 108 DCHECK(io_message_loop_proxy_->BelongsToCurrentThread()); |
| 110 invalidation_notifier_->UpdateCredentials(email, token); | 109 invalidation_notifier_->UpdateCredentials(email, token); |
| 111 } | 110 } |
| 112 | 111 |
| 113 void NonBlockingInvalidationNotifier::Core::UpdateEnabledTypes( | 112 void NonBlockingInvalidationNotifier::Core::UpdateEnabledTypes( |
| 114 const syncable::ModelTypeSet& types) { | 113 const syncable::ModelTypeSet& enabled_types) { |
| 115 DCHECK(io_message_loop_proxy_->BelongsToCurrentThread()); | 114 DCHECK(io_message_loop_proxy_->BelongsToCurrentThread()); |
| 116 invalidation_notifier_->UpdateEnabledTypes(types); | 115 invalidation_notifier_->UpdateEnabledTypes(enabled_types); |
| 117 } | 116 } |
| 118 | 117 |
| 119 void NonBlockingInvalidationNotifier::Core::OnIncomingNotification( | 118 void NonBlockingInvalidationNotifier::Core::OnIncomingNotification( |
| 120 const syncable::ModelTypePayloadMap& type_payloads) { | 119 const syncable::ModelTypePayloadMap& type_payloads) { |
| 121 DCHECK(io_message_loop_proxy_->BelongsToCurrentThread()); | 120 DCHECK(io_message_loop_proxy_->BelongsToCurrentThread()); |
| 122 observers_->Notify(&SyncNotifierObserver::OnIncomingNotification, | 121 observers_->Notify(&SyncNotifierObserver::OnIncomingNotification, |
| 123 type_payloads); | 122 type_payloads); |
| 124 } | 123 } |
| 125 | 124 |
| 126 void NonBlockingInvalidationNotifier::Core::OnNotificationStateChange( | 125 void NonBlockingInvalidationNotifier::Core::OnNotificationStateChange( |
| (...skipping 82 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 209 FROM_HERE, | 208 FROM_HERE, |
| 210 NewRunnableMethod( | 209 NewRunnableMethod( |
| 211 core_.get(), | 210 core_.get(), |
| 212 &NonBlockingInvalidationNotifier::Core::UpdateCredentials, | 211 &NonBlockingInvalidationNotifier::Core::UpdateCredentials, |
| 213 email, token))) { | 212 email, token))) { |
| 214 NOTREACHED(); | 213 NOTREACHED(); |
| 215 } | 214 } |
| 216 } | 215 } |
| 217 | 216 |
| 218 void NonBlockingInvalidationNotifier::UpdateEnabledTypes( | 217 void NonBlockingInvalidationNotifier::UpdateEnabledTypes( |
| 219 const syncable::ModelTypeSet& types) { | 218 const syncable::ModelTypeSet& enabled_types) { |
| 220 DCHECK(parent_message_loop_proxy_->BelongsToCurrentThread()); | 219 DCHECK(parent_message_loop_proxy_->BelongsToCurrentThread()); |
| 221 if (!io_message_loop_proxy_->PostTask( | 220 if (!io_message_loop_proxy_->PostTask( |
| 222 FROM_HERE, | 221 FROM_HERE, |
| 223 NewRunnableMethod( | 222 NewRunnableMethod( |
| 224 core_.get(), | 223 core_.get(), |
| 225 &NonBlockingInvalidationNotifier::Core::UpdateEnabledTypes, | 224 &NonBlockingInvalidationNotifier::Core::UpdateEnabledTypes, |
| 226 types))) { | 225 enabled_types))) { |
| 227 NOTREACHED(); | 226 NOTREACHED(); |
| 228 } | 227 } |
| 229 } | 228 } |
| 230 | 229 |
| 231 void NonBlockingInvalidationNotifier::SendNotification() { | 230 void NonBlockingInvalidationNotifier::SendNotification( |
| 231 const syncable::ModelTypeSet& changed_types) { |
| 232 DCHECK(parent_message_loop_proxy_->BelongsToCurrentThread()); | 232 DCHECK(parent_message_loop_proxy_->BelongsToCurrentThread()); |
| 233 // InvalidationClient doesn't implement SendNotification(), so no | 233 // InvalidationClient doesn't implement SendNotification(), so no |
| 234 // need to forward on the call. | 234 // need to forward on the call. |
| 235 } | 235 } |
| 236 | 236 |
| 237 } // namespace sync_notifier | 237 } // namespace sync_notifier |
| OLD | NEW |