| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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 "net/quic/quic_stream_factory.h" | 5 #include "net/quic/quic_stream_factory.h" |
| 6 | 6 |
| 7 #include <set> | 7 #include <set> |
| 8 | 8 |
| 9 #include "base/message_loop.h" | 9 #include "base/message_loop.h" |
| 10 #include "base/message_loop_proxy.h" | 10 #include "base/message_loop_proxy.h" |
| (...skipping 138 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 149 io_state_ = STATE_CONNECT; | 149 io_state_ = STATE_CONNECT; |
| 150 return OK; | 150 return OK; |
| 151 } | 151 } |
| 152 | 152 |
| 153 QuicStreamRequest::QuicStreamRequest(QuicStreamFactory* factory) | 153 QuicStreamRequest::QuicStreamRequest(QuicStreamFactory* factory) |
| 154 : factory_(factory), | 154 : factory_(factory), |
| 155 stream_(NULL){ | 155 stream_(NULL){ |
| 156 } | 156 } |
| 157 | 157 |
| 158 QuicStreamRequest::~QuicStreamRequest() { | 158 QuicStreamRequest::~QuicStreamRequest() { |
| 159 if (factory_) | 159 if (factory_ && !callback_.is_null()) |
| 160 factory_->CancelRequest(this); | 160 factory_->CancelRequest(this); |
| 161 } | 161 } |
| 162 | 162 |
| 163 int QuicStreamRequest::Request( | 163 int QuicStreamRequest::Request( |
| 164 const HostPortProxyPair& host_port_proxy_pair, | 164 const HostPortProxyPair& host_port_proxy_pair, |
| 165 const BoundNetLog& net_log, | 165 const BoundNetLog& net_log, |
| 166 const CompletionCallback& callback) { | 166 const CompletionCallback& callback) { |
| 167 DCHECK(!stream_); | 167 DCHECK(!stream_); |
| 168 DCHECK(callback_.is_null()); | 168 DCHECK(callback_.is_null()); |
| 169 int rv = factory_->Create(host_port_proxy_pair, net_log, this); | 169 int rv = factory_->Create(host_port_proxy_pair, net_log, this); |
| (...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 209 DCHECK(!factory_->HasActiveSession(host_port_proxy_pair_)); | 209 DCHECK(!factory_->HasActiveSession(host_port_proxy_pair_)); |
| 210 factory_->ActivateSession(host_port_proxy_pair_, session_); | 210 factory_->ActivateSession(host_port_proxy_pair_, session_); |
| 211 | 211 |
| 212 return OK; | 212 return OK; |
| 213 } | 213 } |
| 214 | 214 |
| 215 QuicStreamFactory::QuicStreamFactory( | 215 QuicStreamFactory::QuicStreamFactory( |
| 216 HostResolver* host_resolver, | 216 HostResolver* host_resolver, |
| 217 ClientSocketFactory* client_socket_factory, | 217 ClientSocketFactory* client_socket_factory, |
| 218 const RandomUint64Callback& random_uint64_callback, | 218 const RandomUint64Callback& random_uint64_callback, |
| 219 const QuicClock* clock) | 219 QuicClock* clock) |
| 220 : host_resolver_(host_resolver), | 220 : host_resolver_(host_resolver), |
| 221 client_socket_factory_(client_socket_factory), | 221 client_socket_factory_(client_socket_factory), |
| 222 random_uint64_callback_(random_uint64_callback), | 222 random_uint64_callback_(random_uint64_callback), |
| 223 clock_(clock), | 223 clock_(clock), |
| 224 ALLOW_THIS_IN_INITIALIZER_LIST(weak_factory_(this)) { | 224 ALLOW_THIS_IN_INITIALIZER_LIST(weak_factory_(this)) { |
| 225 } | 225 } |
| 226 | 226 |
| 227 QuicStreamFactory::~QuicStreamFactory() { | 227 QuicStreamFactory::~QuicStreamFactory() { |
| 228 STLDeleteElements(&all_sessions_); | 228 STLDeleteElements(&all_sessions_); |
| 229 STLDeleteValues(&active_jobs_); | 229 STLDeleteValues(&active_jobs_); |
| (...skipping 105 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 335 IPEndPoint addr = *address_list_.begin(); | 335 IPEndPoint addr = *address_list_.begin(); |
| 336 DatagramClientSocket* socket = | 336 DatagramClientSocket* socket = |
| 337 client_socket_factory_->CreateDatagramClientSocket( | 337 client_socket_factory_->CreateDatagramClientSocket( |
| 338 DatagramSocket::DEFAULT_BIND, base::Bind(&base::RandInt), | 338 DatagramSocket::DEFAULT_BIND, base::Bind(&base::RandInt), |
| 339 net_log.net_log(), net_log.source()); | 339 net_log.net_log(), net_log.source()); |
| 340 socket->Connect(addr); | 340 socket->Connect(addr); |
| 341 socket->GetLocalAddress(&addr); | 341 socket->GetLocalAddress(&addr); |
| 342 | 342 |
| 343 QuicConnectionHelper* helper = new QuicConnectionHelper( | 343 QuicConnectionHelper* helper = new QuicConnectionHelper( |
| 344 MessageLoop::current()->message_loop_proxy(), | 344 MessageLoop::current()->message_loop_proxy(), |
| 345 clock_, socket); | 345 clock_.get(), socket); |
| 346 | 346 |
| 347 QuicConnection* connection = new QuicConnection(guid, addr, helper); | 347 QuicConnection* connection = new QuicConnection(guid, addr, helper); |
| 348 QuicClientSession* session = new QuicClientSession(connection, helper, this); | 348 QuicClientSession* session = new QuicClientSession(connection, helper, this); |
| 349 all_sessions_.insert(session); // owning pointer | 349 all_sessions_.insert(session); // owning pointer |
| 350 return session; | 350 return session; |
| 351 } | 351 } |
| 352 | 352 |
| 353 bool QuicStreamFactory::HasActiveJob( | 353 bool QuicStreamFactory::HasActiveJob( |
| 354 const HostPortProxyPair& host_port_proxy_pair) { | 354 const HostPortProxyPair& host_port_proxy_pair) { |
| 355 return ContainsKey(active_jobs_, host_port_proxy_pair); | 355 return ContainsKey(active_jobs_, host_port_proxy_pair); |
| 356 } | 356 } |
| 357 | 357 |
| 358 void QuicStreamFactory::ActivateSession( | 358 void QuicStreamFactory::ActivateSession( |
| 359 const HostPortProxyPair& host_port_proxy_pair, | 359 const HostPortProxyPair& host_port_proxy_pair, |
| 360 QuicClientSession* session) { | 360 QuicClientSession* session) { |
| 361 DCHECK(!HasActiveSession(host_port_proxy_pair)); | 361 DCHECK(!HasActiveSession(host_port_proxy_pair)); |
| 362 active_sessions_[host_port_proxy_pair] = session; | 362 active_sessions_[host_port_proxy_pair] = session; |
| 363 session_aliases_[session].insert(host_port_proxy_pair); | 363 session_aliases_[session].insert(host_port_proxy_pair); |
| 364 } | 364 } |
| 365 | 365 |
| 366 | 366 |
| 367 } // namespace net | 367 } // namespace net |
| OLD | NEW |