OLD | NEW |
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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 "base/bind.h" | 5 #include "base/bind.h" |
6 #include "base/location.h" | 6 #include "base/location.h" |
7 #include "base/single_thread_task_runner.h" | 7 #include "base/single_thread_task_runner.h" |
8 #include "base/thread_task_runner_handle.h" | 8 #include "base/thread_task_runner_handle.h" |
9 #include "components/gcm_driver/gcm_driver.h" | 9 #include "components/gcm_driver/gcm_driver.h" |
10 #include "components/invalidation/gcm_invalidation_bridge.h" | 10 #include "components/invalidation/gcm_invalidation_bridge.h" |
(...skipping 147 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
158 GCMInvalidationBridge::GCMInvalidationBridge( | 158 GCMInvalidationBridge::GCMInvalidationBridge( |
159 gcm::GCMDriver* gcm_driver, | 159 gcm::GCMDriver* gcm_driver, |
160 IdentityProvider* identity_provider) | 160 IdentityProvider* identity_provider) |
161 : OAuth2TokenService::Consumer("gcm_network_channel"), | 161 : OAuth2TokenService::Consumer("gcm_network_channel"), |
162 gcm_driver_(gcm_driver), | 162 gcm_driver_(gcm_driver), |
163 identity_provider_(identity_provider), | 163 identity_provider_(identity_provider), |
164 subscribed_for_incoming_messages_(false), | 164 subscribed_for_incoming_messages_(false), |
165 weak_factory_(this) {} | 165 weak_factory_(this) {} |
166 | 166 |
167 GCMInvalidationBridge::~GCMInvalidationBridge() { | 167 GCMInvalidationBridge::~GCMInvalidationBridge() { |
168 if (subscribed_for_incoming_messages_) | 168 if (subscribed_for_incoming_messages_) { |
169 gcm_driver_->RemoveAppHandler(kInvalidationsAppId); | 169 gcm_driver_->RemoveAppHandler(kInvalidationsAppId); |
| 170 gcm_driver_->RemoveConnectionObserver(this); |
| 171 } |
170 } | 172 } |
171 | 173 |
172 scoped_ptr<syncer::GCMNetworkChannelDelegate> | 174 scoped_ptr<syncer::GCMNetworkChannelDelegate> |
173 GCMInvalidationBridge::CreateDelegate() { | 175 GCMInvalidationBridge::CreateDelegate() { |
174 DCHECK(CalledOnValidThread()); | 176 DCHECK(CalledOnValidThread()); |
175 scoped_ptr<syncer::GCMNetworkChannelDelegate> core(new Core( | 177 scoped_ptr<syncer::GCMNetworkChannelDelegate> core(new Core( |
176 weak_factory_.GetWeakPtr(), base::ThreadTaskRunnerHandle::Get())); | 178 weak_factory_.GetWeakPtr(), base::ThreadTaskRunnerHandle::Get())); |
177 return core.Pass(); | 179 return core.Pass(); |
178 } | 180 } |
179 | 181 |
(...skipping 98 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
278 result)); | 280 result)); |
279 } | 281 } |
280 | 282 |
281 void GCMInvalidationBridge::SubscribeForIncomingMessages() { | 283 void GCMInvalidationBridge::SubscribeForIncomingMessages() { |
282 // No-op if GCMClient is disabled. | 284 // No-op if GCMClient is disabled. |
283 if (gcm_driver_ == NULL) | 285 if (gcm_driver_ == NULL) |
284 return; | 286 return; |
285 | 287 |
286 DCHECK(!subscribed_for_incoming_messages_); | 288 DCHECK(!subscribed_for_incoming_messages_); |
287 gcm_driver_->AddAppHandler(kInvalidationsAppId, this); | 289 gcm_driver_->AddAppHandler(kInvalidationsAppId, this); |
| 290 gcm_driver_->AddConnectionObserver(this); |
288 core_thread_task_runner_->PostTask( | 291 core_thread_task_runner_->PostTask( |
289 FROM_HERE, | 292 FROM_HERE, |
290 base::Bind(&GCMInvalidationBridge::Core::OnConnectionStateChanged, | 293 base::Bind(&GCMInvalidationBridge::Core::OnConnectionStateChanged, |
291 core_, | 294 core_, |
292 gcm_driver_->IsConnected())); | 295 gcm_driver_->IsConnected())); |
293 | 296 |
294 subscribed_for_incoming_messages_ = true; | 297 subscribed_for_incoming_messages_ = true; |
295 } | 298 } |
296 | 299 |
297 void GCMInvalidationBridge::ShutdownHandler() { | 300 void GCMInvalidationBridge::ShutdownHandler() { |
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
349 void GCMInvalidationBridge::OnDisconnected() { | 352 void GCMInvalidationBridge::OnDisconnected() { |
350 core_thread_task_runner_->PostTask( | 353 core_thread_task_runner_->PostTask( |
351 FROM_HERE, | 354 FROM_HERE, |
352 base::Bind(&GCMInvalidationBridge::Core::OnConnectionStateChanged, | 355 base::Bind(&GCMInvalidationBridge::Core::OnConnectionStateChanged, |
353 core_, | 356 core_, |
354 false)); | 357 false)); |
355 } | 358 } |
356 | 359 |
357 | 360 |
358 } // namespace invalidation | 361 } // namespace invalidation |
OLD | NEW |