1 // Copyright (c) 2011 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.
4
5 #include "net/http/http_network_session.h"
6
7 #include <utility>
8
9 #include "base/compiler_specific.h"
10 #include "base/logging.h"
11 #include "base/stl_util-inl.h"
12 #include "base/string_util.h"
13 #include "base/values.h"
14 #include "net/http/http_auth_handler_factory.h"
15 #include "net/http/http_response_body_drainer.h"
16 #include "net/http/http_stream_factory_impl.h"
17 #include "net/http/url_security_manager.h"
18 #include "net/proxy/proxy_service.h"
19 #include "net/socket/client_socket_factory.h"
20 #include "net/spdy/spdy_session_pool.h"
21
22 namespace net {
23
24 // TODO(mbelshe): Move the socket factories into HttpStreamFactory.
HttpNetworkSession(const Params & params)25 HttpNetworkSession::HttpNetworkSession(const Params& params)
26 : net_log_(params.net_log),
27 network_delegate_(params.network_delegate),
28 cert_verifier_(params.cert_verifier),
29 http_auth_handler_factory_(params.http_auth_handler_factory),
30 proxy_service_(params.proxy_service),
31 ssl_config_service_(params.ssl_config_service),
32 socket_pool_manager_(params.net_log,
33 params.client_socket_factory ?
34 params.client_socket_factory :
35 ClientSocketFactory::GetDefaultFactory(),
36 params.host_resolver,
37 params.cert_verifier,
38 params.dnsrr_resolver,
39 params.dns_cert_checker,
40 params.ssl_host_info_factory,
41 params.proxy_service,
42 params.ssl_config_service),
43 spdy_session_pool_(params.host_resolver, params.ssl_config_service),
44 ALLOW_THIS_IN_INITIALIZER_LIST(http_stream_factory_(
45 new HttpStreamFactoryImpl(this))) {
46 DCHECK(params.proxy_service);
47 DCHECK(params.ssl_config_service);
48 }
49
~HttpNetworkSession()50 HttpNetworkSession::~HttpNetworkSession() {
51 STLDeleteElements(&response_drainers_);
52 spdy_session_pool_.CloseAllSessions();
53 }
54
AddResponseDrainer(HttpResponseBodyDrainer * drainer)55 void HttpNetworkSession::AddResponseDrainer(HttpResponseBodyDrainer* drainer) {
56 DCHECK(!ContainsKey(response_drainers_, drainer));
57 response_drainers_.insert(drainer);
58 }
59
RemoveResponseDrainer(HttpResponseBodyDrainer * drainer)60 void HttpNetworkSession::RemoveResponseDrainer(
61 HttpResponseBodyDrainer* drainer) {
62 DCHECK(ContainsKey(response_drainers_, drainer));
63 response_drainers_.erase(drainer);
64 }
65
SpdySessionPoolInfoToValue() const66 Value* HttpNetworkSession::SpdySessionPoolInfoToValue() const {
67 return spdy_session_pool_.SpdySessionPoolInfoToValue();
68 }
69
70 } // namespace net
71