blob: 4339fd350d77bb69cd11cd9a17d67a652524dcb1 [file] [log] [blame]
[email protected]7acf98292012-01-28 00:51:551// Copyright (c) 2012 The Chromium Authors. All rights reserved.
[email protected]102e27c2011-02-23 01:01:312// Use of this source code is governed by a BSD-style license that can be
3// found in the LICENSE file.
4
5#ifndef NET_HTTP_HTTP_STREAM_FACTORY_IMPL_H_
6#define NET_HTTP_HTTP_STREAM_FACTORY_IMPL_H_
7
8#include <map>
9#include <set>
[email protected]80059682012-03-03 00:42:3110#include <vector>
[email protected]102e27c2011-02-23 01:01:3111
[email protected]bf828982013-08-14 18:01:4712#include "base/gtest_prod_util.h"
[email protected]3b63f8f42011-03-28 01:54:1513#include "base/memory/ref_counted.h"
[email protected]2d6728692011-03-12 01:39:5514#include "net/base/host_port_pair.h"
[email protected]1b323172011-03-01 17:50:1715#include "net/base/net_log.h"
[email protected]5a60c8b2011-10-19 20:14:2916#include "net/http/http_pipelined_host_pool.h"
17#include "net/http/http_stream_factory.h"
[email protected]7f28a8df2011-02-25 22:26:0318#include "net/proxy/proxy_server.h"
[email protected]c30bcce2011-12-20 17:50:5119#include "net/socket/ssl_client_socket.h"
[email protected]e6d017652013-05-17 18:01:4020#include "net/spdy/spdy_session_key.h"
[email protected]102e27c2011-02-23 01:01:3121
22namespace net {
23
24class HttpNetworkSession;
[email protected]5a60c8b2011-10-19 20:14:2925class HttpPipelinedHost;
[email protected]7f28a8df2011-02-25 22:26:0326class SpdySession;
[email protected]102e27c2011-02-23 01:01:3127
[email protected]4b9f7292011-12-01 22:20:0628class NET_EXPORT_PRIVATE HttpStreamFactoryImpl :
29 public HttpStreamFactory,
[email protected]cb4bf8d2013-02-06 15:32:0730 public HttpPipelinedHostPool::Delegate {
[email protected]102e27c2011-02-23 01:01:3131 public:
[email protected]3732cea2013-06-21 06:50:5032 // RequestStream may only be called if |for_websockets| is false.
33 // RequestWebSocketStream may only be called if |for_websockets| is true.
34 HttpStreamFactoryImpl(HttpNetworkSession* session, bool for_websockets);
[email protected]102e27c2011-02-23 01:01:3135 virtual ~HttpStreamFactoryImpl();
36
[email protected]4b9f7292011-12-01 22:20:0637 // HttpStreamFactory interface
[email protected]102e27c2011-02-23 01:01:3138 virtual HttpStreamRequest* RequestStream(
39 const HttpRequestInfo& info,
[email protected]262eec82013-03-19 21:01:3640 RequestPriority priority,
[email protected]102957f2011-09-02 17:10:1441 const SSLConfig& server_ssl_config,
42 const SSLConfig& proxy_ssl_config,
[email protected]102e27c2011-02-23 01:01:3143 HttpStreamRequest::Delegate* delegate,
[email protected]f2cbbc82011-11-16 01:10:2944 const BoundNetLog& net_log) OVERRIDE;
[email protected]102e27c2011-02-23 01:01:3145
[email protected]3732cea2013-06-21 06:50:5046 virtual HttpStreamRequest* RequestWebSocketStream(
47 const HttpRequestInfo& info,
48 RequestPriority priority,
49 const SSLConfig& server_ssl_config,
50 const SSLConfig& proxy_ssl_config,
51 HttpStreamRequest::Delegate* delegate,
52 WebSocketStreamBase::Factory* factory,
53 const BoundNetLog& net_log) OVERRIDE;
54
[email protected]102e27c2011-02-23 01:01:3155 virtual void PreconnectStreams(int num_streams,
56 const HttpRequestInfo& info,
[email protected]262eec82013-03-19 21:01:3657 RequestPriority priority,
[email protected]102957f2011-09-02 17:10:1458 const SSLConfig& server_ssl_config,
[email protected]7acf98292012-01-28 00:51:5559 const SSLConfig& proxy_ssl_config) OVERRIDE;
[email protected]837c4f52011-12-20 22:17:0360 virtual base::Value* PipelineInfoToValue() const OVERRIDE;
[email protected]c2dad292012-09-07 21:27:3561 virtual const HostMappingRules* GetHostMappingRules() const OVERRIDE;
[email protected]102e27c2011-02-23 01:01:3162
[email protected]4b9f7292011-12-01 22:20:0663 // HttpPipelinedHostPool::Delegate interface
[email protected]5a60c8b2011-10-19 20:14:2964 virtual void OnHttpPipelinedHostHasAdditionalCapacity(
[email protected]5477d892012-03-01 21:31:3165 HttpPipelinedHost* host) OVERRIDE;
[email protected]5a60c8b2011-10-19 20:14:2966
[email protected]3732cea2013-06-21 06:50:5067 size_t num_orphaned_jobs() const { return orphaned_job_set_.size(); }
68
[email protected]102e27c2011-02-23 01:01:3169 private:
[email protected]bf828982013-08-14 18:01:4770 FRIEND_TEST_ALL_PREFIXES(HttpStreamFactoryImplRequestTest, SetPriority);
71
72 class NET_EXPORT_PRIVATE Request;
73 class NET_EXPORT_PRIVATE Job;
[email protected]102e27c2011-02-23 01:01:3174
[email protected]7f28a8df2011-02-25 22:26:0375 typedef std::set<Request*> RequestSet;
[email protected]80059682012-03-03 00:42:3176 typedef std::vector<Request*> RequestVector;
[email protected]e6d017652013-05-17 18:01:4077 typedef std::map<SpdySessionKey, RequestSet> SpdySessionRequestMap;
[email protected]80059682012-03-03 00:42:3178 typedef std::map<HttpPipelinedHost::Key,
79 RequestVector> HttpPipeliningRequestMap;
[email protected]7f28a8df2011-02-25 22:26:0380
[email protected]3732cea2013-06-21 06:50:5081 HttpStreamRequest* RequestStreamInternal(
82 const HttpRequestInfo& info,
83 RequestPriority priority,
84 const SSLConfig& server_ssl_config,
85 const SSLConfig& proxy_ssl_config,
86 HttpStreamRequest::Delegate* delegate,
87 WebSocketStreamBase::Factory* factory,
88 const BoundNetLog& net_log);
89
[email protected]61a527782013-02-21 03:58:0090 PortAlternateProtocolPair GetAlternateProtocolRequestFor(
91 const GURL& original_url,
92 GURL* alternate_url) const;
[email protected]2d6728692011-03-12 01:39:5593
[email protected]1b323172011-03-01 17:50:1794 // Detaches |job| from |request|.
95 void OrphanJob(Job* job, const Request* request);
[email protected]102e27c2011-02-23 01:01:3196
[email protected]7f28a8df2011-02-25 22:26:0397 // Called when a SpdySession is ready. It will find appropriate Requests and
98 // fulfill them. |direct| indicates whether or not |spdy_session| uses a
99 // proxy.
[email protected]795cbf82013-07-22 09:37:27100 void OnNewSpdySessionReady(const base::WeakPtr<SpdySession>& spdy_session,
[email protected]3732cea2013-06-21 06:50:50101 bool direct,
102 const SSLConfig& used_ssl_config,
103 const ProxyInfo& used_proxy_info,
104 bool was_npn_negotiated,
105 NextProto protocol_negotiated,
106 bool using_spdy,
107 const BoundNetLog& net_log);
[email protected]102e27c2011-02-23 01:01:31108
[email protected]7f28a8df2011-02-25 22:26:03109 // Called when the Job detects that the endpoint indicated by the
110 // Alternate-Protocol does not work. Lets the factory update
111 // HttpAlternateProtocols with the failure and resets the SPDY session key.
112 void OnBrokenAlternateProtocol(const Job*, const HostPortPair& origin);
113
[email protected]1b323172011-03-01 17:50:17114 // Invoked when an orphaned Job finishes.
115 void OnOrphanedJobComplete(const Job* job);
116
[email protected]7f28a8df2011-02-25 22:26:03117 // Invoked when the Job finishes preconnecting sockets.
[email protected]102e27c2011-02-23 01:01:31118 void OnPreconnectsComplete(const Job* job);
119
120 // Called when the Preconnect completes. Used for testing.
121 virtual void OnPreconnectsCompleteInternal() {}
122
[email protected]5477d892012-03-01 21:31:31123 void AbortPipelinedRequestsWithKey(const Job* job,
124 const HttpPipelinedHost::Key& key,
125 int status,
126 const SSLConfig& used_ssl_config);
127
[email protected]102e27c2011-02-23 01:01:31128 HttpNetworkSession* const session_;
129
[email protected]102e27c2011-02-23 01:01:31130 // All Requests are handed out to clients. By the time HttpStreamFactoryImpl
131 // is destroyed, all Requests should be deleted (which should remove them from
[email protected]7f28a8df2011-02-25 22:26:03132 // |request_map_|. The Requests will delete the corresponding job.
[email protected]102e27c2011-02-23 01:01:31133 std::map<const Job*, Request*> request_map_;
134
[email protected]7f28a8df2011-02-25 22:26:03135 SpdySessionRequestMap spdy_session_request_map_;
[email protected]5a60c8b2011-10-19 20:14:29136 HttpPipeliningRequestMap http_pipelining_request_map_;
137
138 HttpPipelinedHostPool http_pipelined_host_pool_;
[email protected]7f28a8df2011-02-25 22:26:03139
[email protected]1b323172011-03-01 17:50:17140 // These jobs correspond to jobs orphaned by Requests and now owned by
141 // HttpStreamFactoryImpl. Since they are no longer tied to Requests, they will
142 // not be canceled when Requests are canceled. Therefore, in
143 // ~HttpStreamFactoryImpl, it is possible for some jobs to still exist in this
144 // set. Leftover jobs will be deleted when the factory is destroyed.
145 std::set<const Job*> orphaned_job_set_;
146
[email protected]102e27c2011-02-23 01:01:31147 // These jobs correspond to preconnect requests and have no associated Request
148 // object. They're owned by HttpStreamFactoryImpl. Leftover jobs will be
149 // deleted when the factory is destroyed.
150 std::set<const Job*> preconnect_job_set_;
151
[email protected]3732cea2013-06-21 06:50:50152 const bool for_websockets_;
[email protected]102e27c2011-02-23 01:01:31153 DISALLOW_COPY_AND_ASSIGN(HttpStreamFactoryImpl);
154};
155
156} // namespace net
157
158#endif // NET_HTTP_HTTP_STREAM_FACTORY_IMPL_H_