| OLD | NEW |
| 1 // Copyright (c) 2009 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2009 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/flip/flip_session.h" | 5 #include "net/flip/flip_session.h" |
| 6 | 6 |
| 7 #include "base/basictypes.h" | 7 #include "base/basictypes.h" |
| 8 #include "base/logging.h" | 8 #include "base/logging.h" |
| 9 #include "base/message_loop.h" | 9 #include "base/message_loop.h" |
| 10 #include "base/rand_util.h" | 10 #include "base/rand_util.h" |
| 11 #include "base/stats_counters.h" | 11 #include "base/stats_counters.h" |
| 12 #include "base/string_util.h" | 12 #include "base/string_util.h" |
| 13 #include "net/base/load_flags.h" | 13 #include "net/base/load_flags.h" |
| 14 #include "net/base/net_util.h" | 14 #include "net/base/net_util.h" |
| 15 #include "net/flip/flip_frame_builder.h" | 15 #include "net/flip/flip_frame_builder.h" |
| 16 #include "net/flip/flip_protocol.h" | 16 #include "net/flip/flip_protocol.h" |
| 17 #include "net/flip/flip_stream.h" | 17 #include "net/flip/flip_stream.h" |
| 18 #include "net/http/http_network_session.h" | 18 #include "net/http/http_network_session.h" |
| 19 #include "net/http/http_request_info.h" | 19 #include "net/http/http_request_info.h" |
| 20 #include "net/http/http_response_headers.h" | 20 #include "net/http/http_response_headers.h" |
| 21 #include "net/http/http_response_info.h" | 21 #include "net/http/http_response_info.h" |
| 22 #include "net/socket/client_socket_factory.h" | 22 #include "net/socket/client_socket_factory.h" |
| 23 #include "net/socket/ssl_client_socket.h" | 23 #include "net/socket/ssl_client_socket.h" |
| 24 #include "net/tools/dump_cache/url_to_filename_encoder.h" | 24 #include "net/tools/dump_cache/url_to_filename_encoder.h" |
| 25 | 25 |
| 26 namespace net { | 26 namespace net { |
| 27 | 27 |
| 28 // static | 28 // static |
| 29 scoped_ptr<FlipSessionPool> FlipSession::session_pool_; | |
| 30 bool FlipSession::use_ssl_ = true; | 29 bool FlipSession::use_ssl_ = true; |
| 31 int PrioritizedIOBuffer::order_ = 0; | 30 int PrioritizedIOBuffer::order_ = 0; |
| 32 | 31 |
| 33 FlipSession* FlipSession::GetFlipSession( | |
| 34 const HostResolver::RequestInfo& info, | |
| 35 HttpNetworkSession* session) { | |
| 36 if (!session_pool_.get()) | |
| 37 session_pool_.reset(new FlipSessionPool()); | |
| 38 return session_pool_->Get(info, session); | |
| 39 } | |
| 40 | |
| 41 FlipSession::FlipSession(std::string host, HttpNetworkSession* session) | 32 FlipSession::FlipSession(std::string host, HttpNetworkSession* session) |
| 42 : ALLOW_THIS_IN_INITIALIZER_LIST( | 33 : ALLOW_THIS_IN_INITIALIZER_LIST( |
| 43 connect_callback_(this, &FlipSession::OnTCPConnect)), | 34 connect_callback_(this, &FlipSession::OnTCPConnect)), |
| 44 ALLOW_THIS_IN_INITIALIZER_LIST( | 35 ALLOW_THIS_IN_INITIALIZER_LIST( |
| 45 ssl_connect_callback_(this, &FlipSession::OnSSLConnect)), | 36 ssl_connect_callback_(this, &FlipSession::OnSSLConnect)), |
| 46 ALLOW_THIS_IN_INITIALIZER_LIST( | 37 ALLOW_THIS_IN_INITIALIZER_LIST( |
| 47 read_callback_(this, &FlipSession::OnReadComplete)), | 38 read_callback_(this, &FlipSession::OnReadComplete)), |
| 48 ALLOW_THIS_IN_INITIALIZER_LIST( | 39 ALLOW_THIS_IN_INITIALIZER_LIST( |
| 49 write_callback_(this, &FlipSession::OnWriteComplete)), | 40 write_callback_(this, &FlipSession::OnWriteComplete)), |
| 50 domain_(host), | 41 domain_(host), |
| (...skipping 13 matching lines...) Expand all Loading... |
| 64 } | 55 } |
| 65 | 56 |
| 66 FlipSession::~FlipSession() { | 57 FlipSession::~FlipSession() { |
| 67 // Cleanup all the streams. | 58 // Cleanup all the streams. |
| 68 CloseAllStreams(net::ERR_ABORTED); | 59 CloseAllStreams(net::ERR_ABORTED); |
| 69 | 60 |
| 70 if (connection_.is_initialized()) { | 61 if (connection_.is_initialized()) { |
| 71 // With Flip we can't recycle sockets. | 62 // With Flip we can't recycle sockets. |
| 72 connection_.socket()->Disconnect(); | 63 connection_.socket()->Disconnect(); |
| 73 } | 64 } |
| 74 if (session_pool_.get()) | 65 |
| 75 session_pool_->Remove(this); | 66 session_->flip_session_pool()->Remove(this); |
| 76 } | 67 } |
| 77 | 68 |
| 78 net::Error FlipSession::Connect(const std::string& group_name, | 69 net::Error FlipSession::Connect(const std::string& group_name, |
| 79 const HostResolver::RequestInfo& host, | 70 const HostResolver::RequestInfo& host, |
| 80 int priority) { | 71 int priority) { |
| 81 DCHECK(priority >= 0 && priority < 4); | 72 DCHECK(priority >= 0 && priority < 4); |
| 82 | 73 |
| 83 // If the connect process is started, let the caller continue. | 74 // If the connect process is started, let the caller continue. |
| 84 if (connection_started_) | 75 if (connection_started_) |
| 85 return net::OK; | 76 return net::OK; |
| (...skipping 176 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 262 | 253 |
| 263 // TODO(mbelshe): Write a method for tearing down a stream | 254 // TODO(mbelshe): Write a method for tearing down a stream |
| 264 // that cleans it out of the active list, the pending list, | 255 // that cleans it out of the active list, the pending list, |
| 265 // etc. | 256 // etc. |
| 266 FlipStream* stream = active_streams_[id]; | 257 FlipStream* stream = active_streams_[id]; |
| 267 DeactivateStream(id); | 258 DeactivateStream(id); |
| 268 delete stream; | 259 delete stream; |
| 269 return true; | 260 return true; |
| 270 } | 261 } |
| 271 | 262 |
| 272 bool FlipSession::IsStreamActive(int id) { | 263 bool FlipSession::IsStreamActive(int id) const { |
| 273 return active_streams_.find(id) != active_streams_.end(); | 264 return active_streams_.find(id) != active_streams_.end(); |
| 274 } | 265 } |
| 275 | 266 |
| 276 LoadState FlipSession::GetLoadState() const { | 267 LoadState FlipSession::GetLoadState() const { |
| 277 // TODO(mbelshe): needs more work | 268 // TODO(mbelshe): needs more work |
| 278 return LOAD_STATE_CONNECTING; | 269 return LOAD_STATE_CONNECTING; |
| 279 } | 270 } |
| 280 | 271 |
| 281 void FlipSession::OnTCPConnect(int result) { | 272 void FlipSession::OnTCPConnect(int result) { |
| 282 LOG(INFO) << "Flip socket connected (result=" << result << ")"; | 273 LOG(INFO) << "Flip socket connected (result=" << result << ")"; |
| (...skipping 445 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 728 DeactivateStream(stream_id); | 719 DeactivateStream(stream_id); |
| 729 delete stream; | 720 delete stream; |
| 730 } | 721 } |
| 731 } | 722 } |
| 732 | 723 |
| 733 void FlipSession::OnLameDuck() { | 724 void FlipSession::OnLameDuck() { |
| 734 NOTIMPLEMENTED(); | 725 NOTIMPLEMENTED(); |
| 735 } | 726 } |
| 736 | 727 |
| 737 } // namespace net | 728 } // namespace net |
| OLD | NEW |