| 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/http/http_network_layer.h" | 5 #include "net/http/http_network_layer.h" |
| 6 | 6 |
| 7 #include "base/logging.h" | 7 #include "base/logging.h" |
| 8 #include "base/string_number_conversions.h" | 8 #include "base/string_number_conversions.h" |
| 9 #include "base/string_split.h" | 9 #include "base/string_split.h" |
| 10 #include "base/string_util.h" | 10 #include "base/string_util.h" |
| 11 #include "net/http/http_network_session.h" | 11 #include "net/http/http_network_session.h" |
| 12 #include "net/http/http_network_transaction.h" | 12 #include "net/http/http_network_transaction.h" |
| 13 #include "net/http/http_server_properties_impl.h" | 13 #include "net/http/http_server_properties_impl.h" |
| 14 #include "net/spdy/spdy_framer.h" | 14 #include "net/spdy/spdy_framer.h" |
| 15 #include "net/spdy/spdy_session.h" | 15 #include "net/spdy/spdy_session.h" |
| 16 #include "net/spdy/spdy_session_pool.h" | 16 #include "net/spdy/spdy_session_pool.h" |
| 17 | 17 |
| 18 namespace net { | 18 namespace net { |
| 19 | 19 |
| 20 //----------------------------------------------------------------------------- | 20 //----------------------------------------------------------------------------- |
| 21 HttpNetworkLayer::HttpNetworkLayer(HttpNetworkSession* session) | 21 HttpNetworkLayer::HttpNetworkLayer(HttpNetworkSession* session) |
| 22 : session_(session), | 22 : session_(session) { |
| 23 suspended_(false) { | |
| 24 DCHECK(session_.get()); | 23 DCHECK(session_.get()); |
| 25 } | 24 } |
| 26 | 25 |
| 27 HttpNetworkLayer::~HttpNetworkLayer() { | 26 HttpNetworkLayer::~HttpNetworkLayer() { |
| 28 } | 27 } |
| 29 | 28 |
| 30 //----------------------------------------------------------------------------- | 29 //----------------------------------------------------------------------------- |
| 31 | 30 |
| 32 // static | 31 // static |
| 33 HttpTransactionFactory* HttpNetworkLayer::CreateFactory( | 32 HttpTransactionFactory* HttpNetworkLayer::CreateFactory( |
| 34 HttpNetworkSession* session) { | 33 HttpNetworkSession* session) { |
| 35 DCHECK(session); | 34 DCHECK(session); |
| 36 | 35 |
| 37 return new HttpNetworkLayer(session); | 36 return new HttpNetworkLayer(session); |
| 38 } | 37 } |
| 39 | 38 |
| 40 // static | 39 // static |
| 41 void HttpNetworkLayer::ForceAlternateProtocol() { | 40 void HttpNetworkLayer::ForceAlternateProtocol() { |
| 42 PortAlternateProtocolPair pair; | 41 PortAlternateProtocolPair pair; |
| 43 pair.port = 443; | 42 pair.port = 443; |
| 44 pair.protocol = NPN_SPDY_2; | 43 pair.protocol = NPN_SPDY_2; |
| 45 HttpServerPropertiesImpl::ForceAlternateProtocol(pair); | 44 HttpServerPropertiesImpl::ForceAlternateProtocol(pair); |
| 46 } | 45 } |
| 47 | 46 |
| 48 //----------------------------------------------------------------------------- | 47 //----------------------------------------------------------------------------- |
| 49 | 48 |
| 50 int HttpNetworkLayer::CreateTransaction(scoped_ptr<HttpTransaction>* trans, | 49 int HttpNetworkLayer::CreateTransaction(scoped_ptr<HttpTransaction>* trans, |
| 51 HttpTransactionDelegate* delegate) { | 50 HttpTransactionDelegate* delegate) { |
| 52 if (suspended_) | |
| 53 return ERR_NETWORK_IO_SUSPENDED; | |
| 54 | |
| 55 trans->reset(new HttpNetworkTransaction(GetSession())); | 51 trans->reset(new HttpNetworkTransaction(GetSession())); |
| 56 return OK; | 52 return OK; |
| 57 } | 53 } |
| 58 | 54 |
| 59 HttpCache* HttpNetworkLayer::GetCache() { | 55 HttpCache* HttpNetworkLayer::GetCache() { |
| 60 return NULL; | 56 return NULL; |
| 61 } | 57 } |
| 62 | 58 |
| 63 HttpNetworkSession* HttpNetworkLayer::GetSession() { | 59 HttpNetworkSession* HttpNetworkLayer::GetSession() { |
| 64 return session_; | 60 return session_; |
| 65 } | 61 } |
| 66 | 62 |
| 67 void HttpNetworkLayer::OnSuspend() { | |
| 68 suspended_ = true; | |
| 69 | |
| 70 if (session_) | |
| 71 session_->CloseIdleConnections(); | |
| 72 } | |
| 73 | |
| 74 void HttpNetworkLayer::OnResume() { | |
| 75 suspended_ = false; | |
| 76 } | |
| 77 | |
| 78 } // namespace net | 63 } // namespace net |
| OLD | NEW |