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 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
51 const GoogleServiceAuthError& error, | 51 const GoogleServiceAuthError& error, |
52 const std::string& token); | 52 const std::string& token); |
53 | 53 |
54 void RegisterFinished(RegisterCallback callback, | 54 void RegisterFinished(RegisterCallback callback, |
55 const std::string& registration_id, | 55 const std::string& registration_id, |
56 gcm::GCMClient::Result result); | 56 gcm::GCMClient::Result result); |
57 | 57 |
58 void OnIncomingMessage(const std::string& message, | 58 void OnIncomingMessage(const std::string& message, |
59 const std::string& echo_token); | 59 const std::string& echo_token); |
60 | 60 |
61 void OnConnectionStateChanged(ConnectionState connection_state); | 61 void OnConnectionStateChanged(bool online); |
62 | 62 |
63 private: | 63 private: |
64 base::WeakPtr<GCMInvalidationBridge> bridge_; | 64 base::WeakPtr<GCMInvalidationBridge> bridge_; |
65 scoped_refptr<base::SingleThreadTaskRunner> ui_thread_task_runner_; | 65 scoped_refptr<base::SingleThreadTaskRunner> ui_thread_task_runner_; |
66 | 66 |
67 MessageCallback message_callback_; | 67 MessageCallback message_callback_; |
68 ConnectionStateCallback connection_state_callback_; | 68 ConnectionStateCallback connection_state_callback_; |
69 | 69 |
70 base::WeakPtrFactory<Core> weak_factory_; | 70 base::WeakPtrFactory<Core> weak_factory_; |
71 | 71 |
(...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
142 callback.Run(registration_id, result); | 142 callback.Run(registration_id, result); |
143 } | 143 } |
144 | 144 |
145 void GCMInvalidationBridge::Core::OnIncomingMessage( | 145 void GCMInvalidationBridge::Core::OnIncomingMessage( |
146 const std::string& message, | 146 const std::string& message, |
147 const std::string& echo_token) { | 147 const std::string& echo_token) { |
148 DCHECK(!message_callback_.is_null()); | 148 DCHECK(!message_callback_.is_null()); |
149 message_callback_.Run(message, echo_token); | 149 message_callback_.Run(message, echo_token); |
150 } | 150 } |
151 | 151 |
152 void GCMInvalidationBridge::Core::OnConnectionStateChanged( | 152 void GCMInvalidationBridge::Core::OnConnectionStateChanged(bool online) { |
153 ConnectionState connection_state) { | |
154 if (!connection_state_callback_.is_null()) { | 153 if (!connection_state_callback_.is_null()) { |
155 connection_state_callback_.Run(connection_state); | 154 connection_state_callback_.Run(online); |
156 } | 155 } |
157 } | 156 } |
158 | 157 |
159 GCMInvalidationBridge::GCMInvalidationBridge( | 158 GCMInvalidationBridge::GCMInvalidationBridge( |
160 gcm::GCMDriver* gcm_driver, | 159 gcm::GCMDriver* gcm_driver, |
161 IdentityProvider* identity_provider) | 160 IdentityProvider* identity_provider) |
162 : OAuth2TokenService::Consumer("gcm_network_channel"), | 161 : OAuth2TokenService::Consumer("gcm_network_channel"), |
163 gcm_driver_(gcm_driver), | 162 gcm_driver_(gcm_driver), |
164 identity_provider_(identity_provider), | 163 identity_provider_(identity_provider), |
165 subscribed_for_incoming_messages_(false), | 164 subscribed_for_incoming_messages_(false), |
(...skipping 113 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
279 result)); | 278 result)); |
280 } | 279 } |
281 | 280 |
282 void GCMInvalidationBridge::SubscribeForIncomingMessages() { | 281 void GCMInvalidationBridge::SubscribeForIncomingMessages() { |
283 // No-op if GCMClient is disabled. | 282 // No-op if GCMClient is disabled. |
284 if (gcm_driver_ == NULL) | 283 if (gcm_driver_ == NULL) |
285 return; | 284 return; |
286 | 285 |
287 DCHECK(!subscribed_for_incoming_messages_); | 286 DCHECK(!subscribed_for_incoming_messages_); |
288 gcm_driver_->AddAppHandler(kInvalidationsAppId, this); | 287 gcm_driver_->AddAppHandler(kInvalidationsAppId, this); |
| 288 core_thread_task_runner_->PostTask( |
| 289 FROM_HERE, |
| 290 base::Bind(&GCMInvalidationBridge::Core::OnConnectionStateChanged, |
| 291 core_, |
| 292 gcm_driver_->IsConnected())); |
| 293 |
289 subscribed_for_incoming_messages_ = true; | 294 subscribed_for_incoming_messages_ = true; |
290 } | 295 } |
291 | 296 |
292 void GCMInvalidationBridge::ShutdownHandler() { | 297 void GCMInvalidationBridge::ShutdownHandler() { |
293 // Nothing to do. | 298 // Nothing to do. |
294 } | 299 } |
295 | 300 |
296 void GCMInvalidationBridge::OnMessage( | 301 void GCMInvalidationBridge::OnMessage( |
297 const std::string& app_id, | 302 const std::string& app_id, |
298 const gcm::GCMClient::IncomingMessage& message) { | 303 const gcm::GCMClient::IncomingMessage& message) { |
(...skipping 24 matching lines...) Expand all Loading... |
323 void GCMInvalidationBridge::OnSendError( | 328 void GCMInvalidationBridge::OnSendError( |
324 const std::string& app_id, | 329 const std::string& app_id, |
325 const gcm::GCMClient::SendErrorDetails& send_error_details) { | 330 const gcm::GCMClient::SendErrorDetails& send_error_details) { |
326 // cacheinvalidation doesn't send messages over GCM. | 331 // cacheinvalidation doesn't send messages over GCM. |
327 NOTREACHED(); | 332 NOTREACHED(); |
328 } | 333 } |
329 | 334 |
330 void GCMInvalidationBridge::OnConnected(const net::IPEndPoint& ip_endpoint) { | 335 void GCMInvalidationBridge::OnConnected(const net::IPEndPoint& ip_endpoint) { |
331 core_thread_task_runner_->PostTask( | 336 core_thread_task_runner_->PostTask( |
332 FROM_HERE, | 337 FROM_HERE, |
333 base::Bind(&GCMInvalidationBridge::Core::OnConnectionStateChanged, | 338 base::Bind( |
334 core_, | 339 &GCMInvalidationBridge::Core::OnConnectionStateChanged, core_, true)); |
335 syncer::GCMNetworkChannelDelegate::CONNECTION_STATE_ONLINE)); | |
336 } | 340 } |
337 | 341 |
338 void GCMInvalidationBridge::OnDisconnected() { | 342 void GCMInvalidationBridge::OnDisconnected() { |
339 core_thread_task_runner_->PostTask( | 343 core_thread_task_runner_->PostTask( |
340 FROM_HERE, | 344 FROM_HERE, |
341 base::Bind(&GCMInvalidationBridge::Core::OnConnectionStateChanged, | 345 base::Bind(&GCMInvalidationBridge::Core::OnConnectionStateChanged, |
342 core_, | 346 core_, |
343 syncer::GCMNetworkChannelDelegate::CONNECTION_STATE_OFFLINE)); | 347 false)); |
344 } | 348 } |
345 | 349 |
346 | 350 |
347 } // namespace invalidation | 351 } // namespace invalidation |
OLD | NEW |