| 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 141 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 152 const browser_sync::WeakHandle<InvalidationVersionTracker>& | 152 const browser_sync::WeakHandle<InvalidationVersionTracker>& |
| 153 invalidation_version_tracker, | 153 invalidation_version_tracker, |
| 154 const std::string& client_info) | 154 const std::string& client_info) |
| 155 : core_(new Core), | 155 : core_(new Core), |
| 156 parent_message_loop_proxy_( | 156 parent_message_loop_proxy_( |
| 157 base::MessageLoopProxy::current()), | 157 base::MessageLoopProxy::current()), |
| 158 io_message_loop_proxy_(notifier_options.request_context_getter-> | 158 io_message_loop_proxy_(notifier_options.request_context_getter-> |
| 159 GetIOMessageLoopProxy()) { | 159 GetIOMessageLoopProxy()) { |
| 160 if (!io_message_loop_proxy_->PostTask( | 160 if (!io_message_loop_proxy_->PostTask( |
| 161 FROM_HERE, | 161 FROM_HERE, |
| 162 NewRunnableMethod( | 162 base::Bind( |
| 163 &NonBlockingInvalidationNotifier::Core::Initialize, |
| 163 core_.get(), | 164 core_.get(), |
| 164 &NonBlockingInvalidationNotifier::Core::Initialize, | |
| 165 notifier_options, | 165 notifier_options, |
| 166 initial_max_invalidation_versions, | 166 initial_max_invalidation_versions, |
| 167 invalidation_version_tracker, | 167 invalidation_version_tracker, |
| 168 client_info))) { | 168 client_info))) { |
| 169 NOTREACHED(); | 169 NOTREACHED(); |
| 170 } | 170 } |
| 171 } | 171 } |
| 172 | 172 |
| 173 NonBlockingInvalidationNotifier::~NonBlockingInvalidationNotifier() { | 173 NonBlockingInvalidationNotifier::~NonBlockingInvalidationNotifier() { |
| 174 DCHECK(parent_message_loop_proxy_->BelongsToCurrentThread()); | 174 DCHECK(parent_message_loop_proxy_->BelongsToCurrentThread()); |
| 175 if (!io_message_loop_proxy_->PostTask( | 175 if (!io_message_loop_proxy_->PostTask( |
| 176 FROM_HERE, | 176 FROM_HERE, |
| 177 NewRunnableMethod( | 177 base::Bind(&NonBlockingInvalidationNotifier::Core::Teardown, |
| 178 core_.get(), | 178 core_.get()))) { |
| 179 &NonBlockingInvalidationNotifier::Core::Teardown))) { | |
| 180 NOTREACHED(); | 179 NOTREACHED(); |
| 181 } | 180 } |
| 182 } | 181 } |
| 183 | 182 |
| 184 void NonBlockingInvalidationNotifier::AddObserver( | 183 void NonBlockingInvalidationNotifier::AddObserver( |
| 185 SyncNotifierObserver* observer) { | 184 SyncNotifierObserver* observer) { |
| 186 DCHECK(parent_message_loop_proxy_->BelongsToCurrentThread()); | 185 DCHECK(parent_message_loop_proxy_->BelongsToCurrentThread()); |
| 187 core_->AddObserver(observer); | 186 core_->AddObserver(observer); |
| 188 } | 187 } |
| 189 | 188 |
| 190 void NonBlockingInvalidationNotifier::RemoveObserver( | 189 void NonBlockingInvalidationNotifier::RemoveObserver( |
| 191 SyncNotifierObserver* observer) { | 190 SyncNotifierObserver* observer) { |
| 192 DCHECK(parent_message_loop_proxy_->BelongsToCurrentThread()); | 191 DCHECK(parent_message_loop_proxy_->BelongsToCurrentThread()); |
| 193 core_->RemoveObserver(observer); | 192 core_->RemoveObserver(observer); |
| 194 } | 193 } |
| 195 | 194 |
| 196 void NonBlockingInvalidationNotifier::SetUniqueId( | 195 void NonBlockingInvalidationNotifier::SetUniqueId( |
| 197 const std::string& unique_id) { | 196 const std::string& unique_id) { |
| 198 DCHECK(parent_message_loop_proxy_->BelongsToCurrentThread()); | 197 DCHECK(parent_message_loop_proxy_->BelongsToCurrentThread()); |
| 199 if (!io_message_loop_proxy_->PostTask( | 198 if (!io_message_loop_proxy_->PostTask( |
| 200 FROM_HERE, | 199 FROM_HERE, |
| 201 NewRunnableMethod( | 200 base::Bind(&NonBlockingInvalidationNotifier::Core::SetUniqueId, |
| 202 core_.get(), | 201 core_.get(), unique_id))) { |
| 203 &NonBlockingInvalidationNotifier::Core::SetUniqueId, | |
| 204 unique_id))) { | |
| 205 NOTREACHED(); | 202 NOTREACHED(); |
| 206 } | 203 } |
| 207 } | 204 } |
| 208 | 205 |
| 209 void NonBlockingInvalidationNotifier::SetState(const std::string& state) { | 206 void NonBlockingInvalidationNotifier::SetState(const std::string& state) { |
| 210 DCHECK(parent_message_loop_proxy_->BelongsToCurrentThread()); | 207 DCHECK(parent_message_loop_proxy_->BelongsToCurrentThread()); |
| 211 if (!io_message_loop_proxy_->PostTask( | 208 if (!io_message_loop_proxy_->PostTask( |
| 212 FROM_HERE, | 209 FROM_HERE, |
| 213 NewRunnableMethod( | 210 base::Bind(&NonBlockingInvalidationNotifier::Core::SetState, |
| 214 core_.get(), | 211 core_.get(), state))) { |
| 215 &NonBlockingInvalidationNotifier::Core::SetState, | |
| 216 state))) { | |
| 217 NOTREACHED(); | 212 NOTREACHED(); |
| 218 } | 213 } |
| 219 } | 214 } |
| 220 | 215 |
| 221 void NonBlockingInvalidationNotifier::UpdateCredentials( | 216 void NonBlockingInvalidationNotifier::UpdateCredentials( |
| 222 const std::string& email, const std::string& token) { | 217 const std::string& email, const std::string& token) { |
| 223 DCHECK(parent_message_loop_proxy_->BelongsToCurrentThread()); | 218 DCHECK(parent_message_loop_proxy_->BelongsToCurrentThread()); |
| 224 if (!io_message_loop_proxy_->PostTask( | 219 if (!io_message_loop_proxy_->PostTask( |
| 225 FROM_HERE, | 220 FROM_HERE, |
| 226 NewRunnableMethod( | 221 base::Bind(&NonBlockingInvalidationNotifier::Core::UpdateCredentials, |
| 227 core_.get(), | 222 core_.get(), email, token))) { |
| 228 &NonBlockingInvalidationNotifier::Core::UpdateCredentials, | |
| 229 email, token))) { | |
| 230 NOTREACHED(); | 223 NOTREACHED(); |
| 231 } | 224 } |
| 232 } | 225 } |
| 233 | 226 |
| 234 void NonBlockingInvalidationNotifier::UpdateEnabledTypes( | 227 void NonBlockingInvalidationNotifier::UpdateEnabledTypes( |
| 235 const syncable::ModelTypeSet& enabled_types) { | 228 const syncable::ModelTypeSet& enabled_types) { |
| 236 DCHECK(parent_message_loop_proxy_->BelongsToCurrentThread()); | 229 DCHECK(parent_message_loop_proxy_->BelongsToCurrentThread()); |
| 237 if (!io_message_loop_proxy_->PostTask( | 230 if (!io_message_loop_proxy_->PostTask( |
| 238 FROM_HERE, | 231 FROM_HERE, |
| 239 NewRunnableMethod( | 232 base::Bind(&NonBlockingInvalidationNotifier::Core::UpdateEnabledTypes, |
| 240 core_.get(), | 233 core_.get(), enabled_types))) { |
| 241 &NonBlockingInvalidationNotifier::Core::UpdateEnabledTypes, | |
| 242 enabled_types))) { | |
| 243 NOTREACHED(); | 234 NOTREACHED(); |
| 244 } | 235 } |
| 245 } | 236 } |
| 246 | 237 |
| 247 void NonBlockingInvalidationNotifier::SendNotification( | 238 void NonBlockingInvalidationNotifier::SendNotification( |
| 248 const syncable::ModelTypeSet& changed_types) { | 239 const syncable::ModelTypeSet& changed_types) { |
| 249 DCHECK(parent_message_loop_proxy_->BelongsToCurrentThread()); | 240 DCHECK(parent_message_loop_proxy_->BelongsToCurrentThread()); |
| 250 // InvalidationClient doesn't implement SendNotification(), so no | 241 // InvalidationClient doesn't implement SendNotification(), so no |
| 251 // need to forward on the call. | 242 // need to forward on the call. |
| 252 } | 243 } |
| 253 | 244 |
| 254 } // namespace sync_notifier | 245 } // namespace sync_notifier |
| OLD | NEW |