| OLD | NEW |
| 1 // Copyright (c) 2013 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2013 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 "google_apis/gcm/engine/connection_factory_impl.h" | 5 #include "google_apis/gcm/engine/connection_factory_impl.h" |
| 6 | 6 |
| 7 #include "base/message_loop/message_loop.h" | 7 #include "base/message_loop/message_loop.h" |
| 8 #include "base/metrics/histogram.h" | 8 #include "base/metrics/histogram.h" |
| 9 #include "base/metrics/sparse_histogram.h" | 9 #include "base/metrics/sparse_histogram.h" |
| 10 #include "google_apis/gcm/engine/connection_handler_impl.h" | 10 #include "google_apis/gcm/engine/connection_handler_impl.h" |
| (...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 77 gcm_network_session_->proxy_service()->CancelPacRequest(pac_request_); | 77 gcm_network_session_->proxy_service()->CancelPacRequest(pac_request_); |
| 78 pac_request_ = NULL; | 78 pac_request_ = NULL; |
| 79 } | 79 } |
| 80 } | 80 } |
| 81 | 81 |
| 82 void ConnectionFactoryImpl::Initialize( | 82 void ConnectionFactoryImpl::Initialize( |
| 83 const BuildLoginRequestCallback& request_builder, | 83 const BuildLoginRequestCallback& request_builder, |
| 84 const ConnectionHandler::ProtoReceivedCallback& read_callback, | 84 const ConnectionHandler::ProtoReceivedCallback& read_callback, |
| 85 const ConnectionHandler::ProtoSentCallback& write_callback) { | 85 const ConnectionHandler::ProtoSentCallback& write_callback) { |
| 86 DCHECK(!connection_handler_); | 86 DCHECK(!connection_handler_); |
| 87 DCHECK(read_callback_.is_null()); |
| 88 DCHECK(write_callback_.is_null()); |
| 87 | 89 |
| 88 previous_backoff_ = CreateBackoffEntry(&backoff_policy_); | 90 previous_backoff_ = CreateBackoffEntry(&backoff_policy_); |
| 89 backoff_entry_ = CreateBackoffEntry(&backoff_policy_); | 91 backoff_entry_ = CreateBackoffEntry(&backoff_policy_); |
| 90 request_builder_ = request_builder; | 92 request_builder_ = request_builder; |
| 93 read_callback_ = read_callback; |
| 94 write_callback_ = write_callback; |
| 91 | 95 |
| 92 net::NetworkChangeNotifier::AddNetworkChangeObserver(this); | 96 net::NetworkChangeNotifier::AddNetworkChangeObserver(this); |
| 93 waiting_for_network_online_ = net::NetworkChangeNotifier::IsOffline(); | 97 waiting_for_network_online_ = net::NetworkChangeNotifier::IsOffline(); |
| 94 connection_handler_ = CreateConnectionHandler( | |
| 95 base::TimeDelta::FromMilliseconds(kReadTimeoutMs), | |
| 96 read_callback, | |
| 97 write_callback, | |
| 98 base::Bind(&ConnectionFactoryImpl::ConnectionHandlerCallback, | |
| 99 weak_ptr_factory_.GetWeakPtr())).Pass(); | |
| 100 } | 98 } |
| 101 | 99 |
| 102 ConnectionHandler* ConnectionFactoryImpl::GetConnectionHandler() const { | 100 ConnectionHandler* ConnectionFactoryImpl::GetConnectionHandler() const { |
| 103 return connection_handler_.get(); | 101 return connection_handler_.get(); |
| 104 } | 102 } |
| 105 | 103 |
| 106 void ConnectionFactoryImpl::Connect() { | 104 void ConnectionFactoryImpl::Connect() { |
| 107 DCHECK(connection_handler_); | 105 if (!connection_handler_) { |
| 106 connection_handler_ = CreateConnectionHandler( |
| 107 base::TimeDelta::FromMilliseconds(kReadTimeoutMs), |
| 108 read_callback_, |
| 109 write_callback_, |
| 110 base::Bind(&ConnectionFactoryImpl::ConnectionHandlerCallback, |
| 111 weak_ptr_factory_.GetWeakPtr())).Pass(); |
| 112 } |
| 108 | 113 |
| 109 if (connecting_ || waiting_for_backoff_) | 114 if (connecting_ || waiting_for_backoff_) |
| 110 return; // Connection attempt already in progress or pending. | 115 return; // Connection attempt already in progress or pending. |
| 111 | 116 |
| 112 if (IsEndpointReachable()) | 117 if (IsEndpointReachable()) |
| 113 return; // Already connected. | 118 return; // Already connected. |
| 114 | 119 |
| 115 ConnectWithBackoff(); | 120 ConnectWithBackoff(); |
| 116 } | 121 } |
| 117 | 122 |
| (...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 156 return "CONNECTING"; | 161 return "CONNECTING"; |
| 157 if (waiting_for_backoff_) | 162 if (waiting_for_backoff_) |
| 158 return "WAITING FOR BACKOFF"; | 163 return "WAITING FOR BACKOFF"; |
| 159 if (waiting_for_network_online_) | 164 if (waiting_for_network_online_) |
| 160 return "WAITING FOR NETWORK CHANGE"; | 165 return "WAITING FOR NETWORK CHANGE"; |
| 161 return "NOT CONNECTED"; | 166 return "NOT CONNECTED"; |
| 162 } | 167 } |
| 163 | 168 |
| 164 void ConnectionFactoryImpl::SignalConnectionReset( | 169 void ConnectionFactoryImpl::SignalConnectionReset( |
| 165 ConnectionResetReason reason) { | 170 ConnectionResetReason reason) { |
| 171 if (!connection_handler_) { |
| 172 // No initial connection has been made. No need to do anything. |
| 173 return; |
| 174 } |
| 175 |
| 166 // A failure can trigger multiple resets, so no need to do anything if a | 176 // A failure can trigger multiple resets, so no need to do anything if a |
| 167 // connection is already in progress. | 177 // connection is already in progress. |
| 168 if (connecting_) { | 178 if (connecting_) { |
| 169 DVLOG(1) << "Connection in progress, ignoring reset."; | 179 DVLOG(1) << "Connection in progress, ignoring reset."; |
| 170 return; | 180 return; |
| 171 } | 181 } |
| 172 | 182 |
| 173 if (listener_) | 183 if (listener_) |
| 174 listener_->OnDisconnected(); | 184 listener_->OnDisconnected(); |
| 175 | 185 |
| (...skipping 376 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 552 | 562 |
| 553 void ConnectionFactoryImpl::RebuildNetworkSessionAuthCache() { | 563 void ConnectionFactoryImpl::RebuildNetworkSessionAuthCache() { |
| 554 if (!http_network_session_.get() || !http_network_session_->http_auth_cache()) | 564 if (!http_network_session_.get() || !http_network_session_->http_auth_cache()) |
| 555 return; | 565 return; |
| 556 | 566 |
| 557 gcm_network_session_->http_auth_cache()->UpdateAllFrom( | 567 gcm_network_session_->http_auth_cache()->UpdateAllFrom( |
| 558 *http_network_session_->http_auth_cache()); | 568 *http_network_session_->http_auth_cache()); |
| 559 } | 569 } |
| 560 | 570 |
| 561 } // namespace gcm | 571 } // namespace gcm |
| OLD | NEW |