blob: c8022b7547648c19ef3b1a8a9426751bdabaa8f3 [file] [log] [blame]
license.botbf09a502008-08-24 00:55:551// Copyright (c) 2006-2008 The Chromium Authors. All rights reserved.
2// Use of this source code is governed by a BSD-style license that can be
3// found in the LICENSE file.
initial.commit586acc5fe2008-07-26 22:42:524
5#include "net/http/http_network_layer.h"
6
[email protected]0dfc81b2008-08-25 03:44:407#include "base/logging.h"
[email protected]85c0ed82009-12-15 23:14:148#include "base/string_util.h"
[email protected]650e2cae2009-10-21 23:52:079#include "net/flip/flip_framer.h"
[email protected]7adaccb2009-10-13 04:43:2110#include "net/flip/flip_network_transaction.h"
[email protected]650e2cae2009-10-21 23:52:0711#include "net/flip/flip_session.h"
[email protected]d1eda932009-11-04 01:03:1012#include "net/flip/flip_session_pool.h"
initial.commit586acc5fe2008-07-26 22:42:5213#include "net/http/http_network_session.h"
14#include "net/http/http_network_transaction.h"
[email protected]f7984fc62009-06-22 23:26:4415#include "net/socket/client_socket_factory.h"
initial.commit586acc5fe2008-07-26 22:42:5216
17namespace net {
18
19//-----------------------------------------------------------------------------
20
initial.commit586acc5fe2008-07-26 22:42:5221// static
22HttpTransactionFactory* HttpNetworkLayer::CreateFactory(
[email protected]d13c3272010-02-04 00:24:5123 NetworkChangeNotifier* network_change_notifier,
[email protected]8a00f00a2009-06-12 00:49:3824 HostResolver* host_resolver,
[email protected]db36938c2009-08-19 21:48:4225 ProxyService* proxy_service,
26 SSLConfigService* ssl_config_service) {
[email protected]63de95b2008-12-10 04:11:2727 DCHECK(proxy_service);
initial.commit586acc5fe2008-07-26 22:42:5228
[email protected]c6894572009-06-16 17:10:1029 return new HttpNetworkLayer(ClientSocketFactory::GetDefaultFactory(),
[email protected]d13c3272010-02-04 00:24:5130 network_change_notifier,
[email protected]db36938c2009-08-19 21:48:4231 host_resolver, proxy_service, ssl_config_service);
initial.commit586acc5fe2008-07-26 22:42:5232}
33
[email protected]e7f29642009-03-02 22:53:1834// static
35HttpTransactionFactory* HttpNetworkLayer::CreateFactory(
36 HttpNetworkSession* session) {
37 DCHECK(session);
38
39 return new HttpNetworkLayer(session);
40}
41
initial.commit586acc5fe2008-07-26 22:42:5242//-----------------------------------------------------------------------------
[email protected]85c0ed82009-12-15 23:14:1443bool HttpNetworkLayer::force_flip_ = false;
initial.commit586acc5fe2008-07-26 22:42:5244
[email protected]d13c3272010-02-04 00:24:5145HttpNetworkLayer::HttpNetworkLayer(
46 ClientSocketFactory* socket_factory,
47 NetworkChangeNotifier* network_change_notifier,
48 HostResolver* host_resolver,
49 ProxyService* proxy_service,
50 SSLConfigService* ssl_config_service)
[email protected]c6894572009-06-16 17:10:1051 : socket_factory_(socket_factory),
[email protected]d13c3272010-02-04 00:24:5152 network_change_notifier_(network_change_notifier),
[email protected]c6894572009-06-16 17:10:1053 host_resolver_(host_resolver),
[email protected]8a00f00a2009-06-12 00:49:3854 proxy_service_(proxy_service),
[email protected]db36938c2009-08-19 21:48:4255 ssl_config_service_(ssl_config_service),
[email protected]8a00f00a2009-06-12 00:49:3856 session_(NULL),
[email protected]d1eda932009-11-04 01:03:1057 flip_session_pool_(NULL),
[email protected]8a00f00a2009-06-12 00:49:3858 suspended_(false) {
[email protected]63de95b2008-12-10 04:11:2759 DCHECK(proxy_service_);
[email protected]db36938c2009-08-19 21:48:4260 DCHECK(ssl_config_service_.get());
initial.commit586acc5fe2008-07-26 22:42:5261}
62
[email protected]e7f29642009-03-02 22:53:1863HttpNetworkLayer::HttpNetworkLayer(HttpNetworkSession* session)
[email protected]c6894572009-06-16 17:10:1064 : socket_factory_(ClientSocketFactory::GetDefaultFactory()),
[email protected]d13c3272010-02-04 00:24:5165 network_change_notifier_(NULL),
[email protected]db36938c2009-08-19 21:48:4266 ssl_config_service_(NULL),
[email protected]c6894572009-06-16 17:10:1067 session_(session),
[email protected]d1eda932009-11-04 01:03:1068 flip_session_pool_(session->flip_session_pool()),
[email protected]c6894572009-06-16 17:10:1069 suspended_(false) {
[email protected]e7f29642009-03-02 22:53:1870 DCHECK(session_.get());
71}
72
initial.commit586acc5fe2008-07-26 22:42:5273HttpNetworkLayer::~HttpNetworkLayer() {
74}
75
[email protected]1638d602009-09-24 03:49:1776int HttpNetworkLayer::CreateTransaction(scoped_ptr<HttpTransaction>* trans) {
initial.commit586acc5fe2008-07-26 22:42:5277 if (suspended_)
[email protected]1638d602009-09-24 03:49:1778 return ERR_NETWORK_IO_SUSPENDED;
initial.commit586acc5fe2008-07-26 22:42:5279
[email protected]85c0ed82009-12-15 23:14:1480 if (force_flip_)
[email protected]7adaccb2009-10-13 04:43:2181 trans->reset(new FlipNetworkTransaction(GetSession()));
82 else
83 trans->reset(new HttpNetworkTransaction(GetSession()));
[email protected]1638d602009-09-24 03:49:1784 return OK;
initial.commit586acc5fe2008-07-26 22:42:5285}
86
87HttpCache* HttpNetworkLayer::GetCache() {
88 return NULL;
89}
90
initial.commit586acc5fe2008-07-26 22:42:5291void HttpNetworkLayer::Suspend(bool suspend) {
92 suspended_ = suspend;
93
[email protected]a3b006eea2008-10-22 21:23:0894 if (suspend && session_)
[email protected]a937a06d2009-08-19 21:19:2495 session_->tcp_socket_pool()->CloseIdleSockets();
initial.commit586acc5fe2008-07-26 22:42:5296}
97
[email protected]e7f29642009-03-02 22:53:1898HttpNetworkSession* HttpNetworkLayer::GetSession() {
99 if (!session_) {
100 DCHECK(proxy_service_);
[email protected]85c0ed82009-12-15 23:14:14101 FlipSessionPool* flip_pool = new FlipSessionPool;
[email protected]d1eda932009-11-04 01:03:10102 session_ = new HttpNetworkSession(
[email protected]d13c3272010-02-04 00:24:51103 network_change_notifier_, host_resolver_, proxy_service_,
104 socket_factory_, ssl_config_service_, flip_pool);
[email protected]80d6524d2009-08-18 03:58:09105 // These were just temps for lazy-initializing HttpNetworkSession.
[email protected]d13c3272010-02-04 00:24:51106 network_change_notifier_ = NULL;
[email protected]80d6524d2009-08-18 03:58:09107 host_resolver_ = NULL;
108 proxy_service_ = NULL;
[email protected]5695b8c2009-09-30 21:36:43109 socket_factory_ = NULL;
[email protected]e7f29642009-03-02 22:53:18110 }
111 return session_;
112}
113
[email protected]7adaccb2009-10-13 04:43:21114// static
[email protected]650e2cae2009-10-21 23:52:07115void HttpNetworkLayer::EnableFlip(const std::string& mode) {
[email protected]85c0ed82009-12-15 23:14:14116 static const char kDisableSSL[] = "no-ssl";
117 static const char kDisableCompression[] = "no-compress";
[email protected]1f14a912009-12-21 20:32:44118 static const char kEnableNPN[] = "npn";
[email protected]650e2cae2009-10-21 23:52:07119
[email protected]85c0ed82009-12-15 23:14:14120 std::vector<std::string> flip_options;
121 SplitString(mode, ',', &flip_options);
[email protected]650e2cae2009-10-21 23:52:07122
[email protected]85c0ed82009-12-15 23:14:14123 // Force flip mode (use FlipNetworkTransaction for all http requests).
124 force_flip_ = true;
[email protected]650e2cae2009-10-21 23:52:07125
[email protected]85c0ed82009-12-15 23:14:14126 for (std::vector<std::string>::iterator it = flip_options.begin();
127 it != flip_options.end(); ++it) {
128 const std::string& option = *it;
129
130 // Disable SSL
131 if (option == kDisableSSL) {
132 FlipSession::SetSSLMode(false);
133 } else if (option == kDisableCompression) {
134 flip::FlipFramer::set_enable_compression_default(false);
[email protected]1f14a912009-12-21 20:32:44135 } else if (option == kEnableNPN) {
136 HttpNetworkTransaction::SetNextProtos("\007http1.1\004spdy");
137 force_flip_ = false;
[email protected]85c0ed82009-12-15 23:14:14138 } else if (option.empty() && it == flip_options.begin()) {
139 continue;
140 } else {
141 LOG(DFATAL) << "Unrecognized flip option: " << option;
142 }
143 }
[email protected]7adaccb2009-10-13 04:43:21144}
145
initial.commit586acc5fe2008-07-26 22:42:52146} // namespace net