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/base64.h" | 5 #include "base/base64.h" |
6 #include "base/i18n/time_formatting.h" | 6 #include "base/i18n/time_formatting.h" |
7 #include "base/metrics/histogram.h" | 7 #include "base/metrics/histogram.h" |
8 #include "base/sha1.h" | 8 #include "base/sha1.h" |
9 #include "base/strings/string_number_conversions.h" | 9 #include "base/strings/string_number_conversions.h" |
10 #include "base/strings/string_util.h" | 10 #include "base/strings/string_util.h" |
(...skipping 92 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
103 | 103 |
104 GCMNetworkChannel::GCMNetworkChannel( | 104 GCMNetworkChannel::GCMNetworkChannel( |
105 scoped_refptr<net::URLRequestContextGetter> request_context_getter, | 105 scoped_refptr<net::URLRequestContextGetter> request_context_getter, |
106 scoped_ptr<GCMNetworkChannelDelegate> delegate) | 106 scoped_ptr<GCMNetworkChannelDelegate> delegate) |
107 : request_context_getter_(request_context_getter), | 107 : request_context_getter_(request_context_getter), |
108 delegate_(delegate.Pass()), | 108 delegate_(delegate.Pass()), |
109 register_backoff_entry_(new net::BackoffEntry(&kRegisterBackoffPolicy)), | 109 register_backoff_entry_(new net::BackoffEntry(&kRegisterBackoffPolicy)), |
110 diagnostic_info_(this), | 110 diagnostic_info_(this), |
111 weak_factory_(this) { | 111 weak_factory_(this) { |
112 net::NetworkChangeNotifier::AddNetworkChangeObserver(this); | 112 net::NetworkChangeNotifier::AddNetworkChangeObserver(this); |
113 delegate_->Initialize(); | 113 delegate_->Initialize(base::Bind(&GCMNetworkChannel::OnConnectionStateChanged, |
| 114 weak_factory_.GetWeakPtr())); |
114 Register(); | 115 Register(); |
115 } | 116 } |
116 | 117 |
117 GCMNetworkChannel::~GCMNetworkChannel() { | 118 GCMNetworkChannel::~GCMNetworkChannel() { |
118 net::NetworkChangeNotifier::RemoveNetworkChangeObserver(this); | 119 net::NetworkChangeNotifier::RemoveNetworkChangeObserver(this); |
119 } | 120 } |
120 | 121 |
121 void GCMNetworkChannel::Register() { | 122 void GCMNetworkChannel::Register() { |
122 delegate_->Register(base::Bind(&GCMNetworkChannel::OnRegisterComplete, | 123 delegate_->Register(base::Bind(&GCMNetworkChannel::OnRegisterComplete, |
123 weak_factory_.GetWeakPtr())); | 124 weak_factory_.GetWeakPtr())); |
(...skipping 152 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
276 } | 277 } |
277 DVLOG(2) << "Deliver incoming message"; | 278 DVLOG(2) << "Deliver incoming message"; |
278 RecordIncomingMessageStatus(INCOMING_MESSAGE_SUCCESS); | 279 RecordIncomingMessageStatus(INCOMING_MESSAGE_SUCCESS); |
279 DeliverIncomingMessage(android_message.message()); | 280 DeliverIncomingMessage(android_message.message()); |
280 #else | 281 #else |
281 // This code shouldn't be invoked on Android. | 282 // This code shouldn't be invoked on Android. |
282 NOTREACHED(); | 283 NOTREACHED(); |
283 #endif | 284 #endif |
284 } | 285 } |
285 | 286 |
| 287 void GCMNetworkChannel::OnConnectionStateChanged( |
| 288 GCMNetworkChannelDelegate::ConnectionState connection_state) { |
| 289 switch (connection_state) { |
| 290 case GCMNetworkChannelDelegate::CONNECTION_STATE_OFFLINE: { |
| 291 NotifyStateChange(TRANSIENT_INVALIDATION_ERROR); |
| 292 break; |
| 293 } |
| 294 case GCMNetworkChannelDelegate::CONNECTION_STATE_ONLINE: { |
| 295 NotifyStateChange(INVALIDATIONS_ENABLED); |
| 296 break; |
| 297 } |
| 298 default: { |
| 299 NOTREACHED(); |
| 300 break; |
| 301 } |
| 302 } |
| 303 } |
| 304 |
286 void GCMNetworkChannel::OnNetworkChanged( | 305 void GCMNetworkChannel::OnNetworkChanged( |
287 net::NetworkChangeNotifier::ConnectionType connection_type) { | 306 net::NetworkChangeNotifier::ConnectionType connection_type) { |
288 // Network connection is restored. Let's notify cacheinvalidations so it has | 307 // Network connection is restored. Let's notify cacheinvalidations so it has |
289 // chance to retry. | 308 // chance to retry. |
290 if (connection_type != net::NetworkChangeNotifier::CONNECTION_NONE) | 309 if (connection_type != net::NetworkChangeNotifier::CONNECTION_NONE) |
291 NotifyStateChange(INVALIDATIONS_ENABLED); | 310 NotifyStateChange(INVALIDATIONS_ENABLED); |
292 } | 311 } |
293 | 312 |
294 GURL GCMNetworkChannel::BuildUrl(const std::string& registration_id) { | 313 GURL GCMNetworkChannel::BuildUrl(const std::string& registration_id) { |
295 DCHECK(!registration_id.empty()); | 314 DCHECK(!registration_id.empty()); |
(...skipping 125 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
421 ENUM_CASE(gcm::GCMClient::NOT_SIGNED_IN); | 440 ENUM_CASE(gcm::GCMClient::NOT_SIGNED_IN); |
422 ENUM_CASE(gcm::GCMClient::INVALID_PARAMETER); | 441 ENUM_CASE(gcm::GCMClient::INVALID_PARAMETER); |
423 ENUM_CASE(gcm::GCMClient::ASYNC_OPERATION_PENDING); | 442 ENUM_CASE(gcm::GCMClient::ASYNC_OPERATION_PENDING); |
424 ENUM_CASE(gcm::GCMClient::GCM_DISABLED); | 443 ENUM_CASE(gcm::GCMClient::GCM_DISABLED); |
425 } | 444 } |
426 NOTREACHED(); | 445 NOTREACHED(); |
427 return ""; | 446 return ""; |
428 } | 447 } |
429 | 448 |
430 } // namespace syncer | 449 } // namespace syncer |
OLD | NEW |