| 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" |
| (...skipping 20 matching lines...) Expand all Loading... |
| 31 | 31 |
| 32 // static | 32 // static |
| 33 HttpTransactionFactory* HttpNetworkLayer::CreateFactory( | 33 HttpTransactionFactory* HttpNetworkLayer::CreateFactory( |
| 34 HttpNetworkSession* session) { | 34 HttpNetworkSession* session) { |
| 35 DCHECK(session); | 35 DCHECK(session); |
| 36 | 36 |
| 37 return new HttpNetworkLayer(session); | 37 return new HttpNetworkLayer(session); |
| 38 } | 38 } |
| 39 | 39 |
| 40 // static | 40 // static |
| 41 void HttpNetworkLayer::EnableSpdy(const std::string& mode) { | 41 void HttpNetworkLayer::ForceAlternateProtocol() { |
| 42 static const char kOff[] = "off"; | 42 PortAlternateProtocolPair pair; |
| 43 static const char kSSL[] = "ssl"; | 43 pair.port = 443; |
| 44 static const char kDisableSSL[] = "no-ssl"; | 44 pair.protocol = NPN_SPDY_2; |
| 45 static const char kDisablePing[] = "no-ping"; | 45 HttpServerPropertiesImpl::ForceAlternateProtocol(pair); |
| 46 static const char kExclude[] = "exclude"; // Hosts to exclude | |
| 47 static const char kDisableCompression[] = "no-compress"; | |
| 48 static const char kDisableAltProtocols[] = "no-alt-protocols"; | |
| 49 static const char kForceAltProtocols[] = "force-alt-protocols"; | |
| 50 static const char kSingleDomain[] = "single-domain"; | |
| 51 | |
| 52 static const char kInitialMaxConcurrentStreams[] = "init-max-streams"; | |
| 53 | |
| 54 std::vector<std::string> spdy_options; | |
| 55 base::SplitString(mode, ',', &spdy_options); | |
| 56 | |
| 57 for (std::vector<std::string>::iterator it = spdy_options.begin(); | |
| 58 it != spdy_options.end(); ++it) { | |
| 59 const std::string& element = *it; | |
| 60 std::vector<std::string> name_value; | |
| 61 base::SplitString(element, '=', &name_value); | |
| 62 const std::string& option = name_value[0]; | |
| 63 const std::string value = name_value.size() > 1 ? name_value[1] : ""; | |
| 64 | |
| 65 if (option == kOff) { | |
| 66 HttpStreamFactory::set_spdy_enabled(false); | |
| 67 } else if (option == kDisableSSL) { | |
| 68 SpdySession::set_default_protocol(kProtoSPDY2); | |
| 69 HttpStreamFactory::set_force_spdy_over_ssl(false); | |
| 70 HttpStreamFactory::set_force_spdy_always(true); | |
| 71 } else if (option == kSSL) { | |
| 72 SpdySession::set_default_protocol(kProtoSPDY2); | |
| 73 HttpStreamFactory::set_force_spdy_over_ssl(true); | |
| 74 HttpStreamFactory::set_force_spdy_always(true); | |
| 75 } else if (option == kDisablePing) { | |
| 76 SpdySession::set_enable_ping_based_connection_checking(false); | |
| 77 } else if (option == kExclude) { | |
| 78 HttpStreamFactory::add_forced_spdy_exclusion(value); | |
| 79 } else if (option == kDisableCompression) { | |
| 80 BufferedSpdyFramer::set_enable_compression_default(false); | |
| 81 } else if (option == kDisableAltProtocols) { | |
| 82 HttpStreamFactory::set_use_alternate_protocols(false); | |
| 83 } else if (option == kForceAltProtocols) { | |
| 84 PortAlternateProtocolPair pair; | |
| 85 pair.port = 443; | |
| 86 pair.protocol = NPN_SPDY_2; | |
| 87 HttpServerPropertiesImpl::ForceAlternateProtocol(pair); | |
| 88 } else if (option == kSingleDomain) { | |
| 89 SpdySessionPool::ForceSingleDomain(); | |
| 90 LOG(ERROR) << "FORCING SINGLE DOMAIN"; | |
| 91 } else if (option == kInitialMaxConcurrentStreams) { | |
| 92 int streams; | |
| 93 if (base::StringToInt(value, &streams) && streams > 0) | |
| 94 SpdySession::set_init_max_concurrent_streams(streams); | |
| 95 } else if (option.empty() && it == spdy_options.begin()) { | |
| 96 continue; | |
| 97 } else { | |
| 98 LOG(DFATAL) << "Unrecognized spdy option: " << option; | |
| 99 } | |
| 100 } | |
| 101 } | 46 } |
| 102 | 47 |
| 103 //----------------------------------------------------------------------------- | 48 //----------------------------------------------------------------------------- |
| 104 | 49 |
| 105 int HttpNetworkLayer::CreateTransaction(scoped_ptr<HttpTransaction>* trans, | 50 int HttpNetworkLayer::CreateTransaction(scoped_ptr<HttpTransaction>* trans, |
| 106 HttpTransactionDelegate* delegate) { | 51 HttpTransactionDelegate* delegate) { |
| 107 if (suspended_) | 52 if (suspended_) |
| 108 return ERR_NETWORK_IO_SUSPENDED; | 53 return ERR_NETWORK_IO_SUSPENDED; |
| 109 | 54 |
| 110 trans->reset(new HttpNetworkTransaction(GetSession())); | 55 trans->reset(new HttpNetworkTransaction(GetSession())); |
| (...skipping 13 matching lines...) Expand all Loading... |
| 124 | 69 |
| 125 if (session_) | 70 if (session_) |
| 126 session_->CloseIdleConnections(); | 71 session_->CloseIdleConnections(); |
| 127 } | 72 } |
| 128 | 73 |
| 129 void HttpNetworkLayer::OnResume() { | 74 void HttpNetworkLayer::OnResume() { |
| 130 suspended_ = false; | 75 suspended_ = false; |
| 131 } | 76 } |
| 132 | 77 |
| 133 } // namespace net | 78 } // namespace net |
| OLD | NEW |