blob: 3cfda3c41fedace7c1358d7a24a5a722e881afc3 [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]3b63f8f42011-03-28 01:54:1512#include "base/memory/ref_counted.h"
[email protected]2d6728692011-03-12 01:39:5513#include "net/base/host_port_pair.h"
[email protected]1b323172011-03-01 17:50:1714#include "net/base/net_log.h"
[email protected]5a60c8b2011-10-19 20:14:2915#include "net/http/http_pipelined_host_pool.h"
16#include "net/http/http_stream_factory.h"
[email protected]7f28a8df2011-02-25 22:26:0317#include "net/proxy/proxy_server.h"
[email protected]c30bcce2011-12-20 17:50:5118#include "net/socket/ssl_client_socket.h"
[email protected]e6d017652013-05-17 18:01:4019#include "net/spdy/spdy_session_key.h"
[email protected]102e27c2011-02-23 01:01:3120
21namespace net {
22
23class HttpNetworkSession;
[email protected]5a60c8b2011-10-19 20:14:2924class HttpPipelinedHost;
[email protected]7f28a8df2011-02-25 22:26:0325class SpdySession;
[email protected]102e27c2011-02-23 01:01:3126
[email protected]4b9f7292011-12-01 22:20:0627class NET_EXPORT_PRIVATE HttpStreamFactoryImpl :
28 public HttpStreamFactory,
[email protected]cb4bf8d2013-02-06 15:32:0729 public HttpPipelinedHostPool::Delegate {
[email protected]102e27c2011-02-23 01:01:3130 public:
[email protected]3732cea2013-06-21 06:50:5031 // RequestStream may only be called if |for_websockets| is false.
32 // RequestWebSocketStream may only be called if |for_websockets| is true.
33 HttpStreamFactoryImpl(HttpNetworkSession* session, bool for_websockets);
[email protected]102e27c2011-02-23 01:01:3134 virtual ~HttpStreamFactoryImpl();
35
[email protected]4b9f7292011-12-01 22:20:0636 // HttpStreamFactory interface
[email protected]102e27c2011-02-23 01:01:3137 virtual HttpStreamRequest* RequestStream(
38 const HttpRequestInfo& info,
[email protected]262eec82013-03-19 21:01:3639 RequestPriority priority,
[email protected]102957f2011-09-02 17:10:1440 const SSLConfig& server_ssl_config,
41 const SSLConfig& proxy_ssl_config,
[email protected]102e27c2011-02-23 01:01:3142 HttpStreamRequest::Delegate* delegate,
[email protected]f2cbbc82011-11-16 01:10:2943 const BoundNetLog& net_log) OVERRIDE;
[email protected]102e27c2011-02-23 01:01:3144
[email protected]3732cea2013-06-21 06:50:5045 virtual HttpStreamRequest* RequestWebSocketStream(
46 const HttpRequestInfo& info,
47 RequestPriority priority,
48 const SSLConfig& server_ssl_config,
49 const SSLConfig& proxy_ssl_config,
50 HttpStreamRequest::Delegate* delegate,
51 WebSocketStreamBase::Factory* factory,
52 const BoundNetLog& net_log) OVERRIDE;
53
[email protected]102e27c2011-02-23 01:01:3154 virtual void PreconnectStreams(int num_streams,
55 const HttpRequestInfo& info,
[email protected]262eec82013-03-19 21:01:3656 RequestPriority priority,
[email protected]102957f2011-09-02 17:10:1457 const SSLConfig& server_ssl_config,
[email protected]7acf98292012-01-28 00:51:5558 const SSLConfig& proxy_ssl_config) OVERRIDE;
[email protected]837c4f52011-12-20 22:17:0359 virtual base::Value* PipelineInfoToValue() const OVERRIDE;
[email protected]c2dad292012-09-07 21:27:3560 virtual const HostMappingRules* GetHostMappingRules() const OVERRIDE;
[email protected]102e27c2011-02-23 01:01:3161
[email protected]4b9f7292011-12-01 22:20:0662 // HttpPipelinedHostPool::Delegate interface
[email protected]5a60c8b2011-10-19 20:14:2963 virtual void OnHttpPipelinedHostHasAdditionalCapacity(
[email protected]5477d892012-03-01 21:31:3164 HttpPipelinedHost* host) OVERRIDE;
[email protected]5a60c8b2011-10-19 20:14:2965
[email protected]3732cea2013-06-21 06:50:5066 size_t num_orphaned_jobs() const { return orphaned_job_set_.size(); }
67
[email protected]102e27c2011-02-23 01:01:3168 private:
69 class Request;
70 class Job;
71
[email protected]7f28a8df2011-02-25 22:26:0372 typedef std::set<Request*> RequestSet;
[email protected]80059682012-03-03 00:42:3173 typedef std::vector<Request*> RequestVector;
[email protected]e6d017652013-05-17 18:01:4074 typedef std::map<SpdySessionKey, RequestSet> SpdySessionRequestMap;
[email protected]80059682012-03-03 00:42:3175 typedef std::map<HttpPipelinedHost::Key,
76 RequestVector> HttpPipeliningRequestMap;
[email protected]7f28a8df2011-02-25 22:26:0377
[email protected]3732cea2013-06-21 06:50:5078 HttpStreamRequest* RequestStreamInternal(
79 const HttpRequestInfo& info,
80 RequestPriority priority,
81 const SSLConfig& server_ssl_config,
82 const SSLConfig& proxy_ssl_config,
83 HttpStreamRequest::Delegate* delegate,
84 WebSocketStreamBase::Factory* factory,
85 const BoundNetLog& net_log);
86
[email protected]61a527782013-02-21 03:58:0087 PortAlternateProtocolPair GetAlternateProtocolRequestFor(
88 const GURL& original_url,
89 GURL* alternate_url) const;
[email protected]2d6728692011-03-12 01:39:5590
[email protected]1b323172011-03-01 17:50:1791 // Detaches |job| from |request|.
92 void OrphanJob(Job* job, const Request* request);
[email protected]102e27c2011-02-23 01:01:3193
[email protected]7f28a8df2011-02-25 22:26:0394 // Called when a SpdySession is ready. It will find appropriate Requests and
95 // fulfill them. |direct| indicates whether or not |spdy_session| uses a
96 // proxy.
[email protected]3732cea2013-06-21 06:50:5097 void OnNewSpdySessionReady(scoped_refptr<SpdySession> spdy_session,
98 bool direct,
99 const SSLConfig& used_ssl_config,
100 const ProxyInfo& used_proxy_info,
101 bool was_npn_negotiated,
102 NextProto protocol_negotiated,
103 bool using_spdy,
104 const BoundNetLog& net_log);
[email protected]102e27c2011-02-23 01:01:31105
[email protected]7f28a8df2011-02-25 22:26:03106 // Called when the Job detects that the endpoint indicated by the
107 // Alternate-Protocol does not work. Lets the factory update
108 // HttpAlternateProtocols with the failure and resets the SPDY session key.
109 void OnBrokenAlternateProtocol(const Job*, const HostPortPair& origin);
110
[email protected]1b323172011-03-01 17:50:17111 // Invoked when an orphaned Job finishes.
112 void OnOrphanedJobComplete(const Job* job);
113
[email protected]7f28a8df2011-02-25 22:26:03114 // Invoked when the Job finishes preconnecting sockets.
[email protected]102e27c2011-02-23 01:01:31115 void OnPreconnectsComplete(const Job* job);
116
117 // Called when the Preconnect completes. Used for testing.
118 virtual void OnPreconnectsCompleteInternal() {}
119
[email protected]5477d892012-03-01 21:31:31120 void AbortPipelinedRequestsWithKey(const Job* job,
121 const HttpPipelinedHost::Key& key,
122 int status,
123 const SSLConfig& used_ssl_config);
124
[email protected]102e27c2011-02-23 01:01:31125 HttpNetworkSession* const session_;
126
[email protected]102e27c2011-02-23 01:01:31127 // All Requests are handed out to clients. By the time HttpStreamFactoryImpl
128 // is destroyed, all Requests should be deleted (which should remove them from
[email protected]7f28a8df2011-02-25 22:26:03129 // |request_map_|. The Requests will delete the corresponding job.
[email protected]102e27c2011-02-23 01:01:31130 std::map<const Job*, Request*> request_map_;
131
[email protected]7f28a8df2011-02-25 22:26:03132 SpdySessionRequestMap spdy_session_request_map_;
[email protected]5a60c8b2011-10-19 20:14:29133 HttpPipeliningRequestMap http_pipelining_request_map_;
134
135 HttpPipelinedHostPool http_pipelined_host_pool_;
[email protected]7f28a8df2011-02-25 22:26:03136
[email protected]1b323172011-03-01 17:50:17137 // These jobs correspond to jobs orphaned by Requests and now owned by
138 // HttpStreamFactoryImpl. Since they are no longer tied to Requests, they will
139 // not be canceled when Requests are canceled. Therefore, in
140 // ~HttpStreamFactoryImpl, it is possible for some jobs to still exist in this
141 // set. Leftover jobs will be deleted when the factory is destroyed.
142 std::set<const Job*> orphaned_job_set_;
143
[email protected]102e27c2011-02-23 01:01:31144 // These jobs correspond to preconnect requests and have no associated Request
145 // object. They're owned by HttpStreamFactoryImpl. Leftover jobs will be
146 // deleted when the factory is destroyed.
147 std::set<const Job*> preconnect_job_set_;
148
[email protected]3732cea2013-06-21 06:50:50149 const bool for_websockets_;
[email protected]102e27c2011-02-23 01:01:31150 DISALLOW_COPY_AND_ASSIGN(HttpStreamFactoryImpl);
151};
152
153} // namespace net
154
155#endif // NET_HTTP_HTTP_STREAM_FACTORY_IMPL_H_