blob: 103e2c6d09e69cfaeaa94e639c1f760bf9e2b325 [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]102e27c2011-02-23 01:01:3119
20namespace net {
21
22class HttpNetworkSession;
[email protected]5a60c8b2011-10-19 20:14:2923class HttpPipelinedHost;
[email protected]7f28a8df2011-02-25 22:26:0324class SpdySession;
[email protected]102e27c2011-02-23 01:01:3125
[email protected]4b9f7292011-12-01 22:20:0626class NET_EXPORT_PRIVATE HttpStreamFactoryImpl :
27 public HttpStreamFactory,
28 public HttpPipelinedHostPool::Delegate {
[email protected]102e27c2011-02-23 01:01:3129 public:
30 explicit HttpStreamFactoryImpl(HttpNetworkSession* session);
31 virtual ~HttpStreamFactoryImpl();
32
[email protected]4b9f7292011-12-01 22:20:0633 // HttpStreamFactory interface
[email protected]102e27c2011-02-23 01:01:3134 virtual HttpStreamRequest* RequestStream(
35 const HttpRequestInfo& info,
[email protected]102957f2011-09-02 17:10:1436 const SSLConfig& server_ssl_config,
37 const SSLConfig& proxy_ssl_config,
[email protected]102e27c2011-02-23 01:01:3138 HttpStreamRequest::Delegate* delegate,
[email protected]f2cbbc82011-11-16 01:10:2939 const BoundNetLog& net_log) OVERRIDE;
[email protected]102e27c2011-02-23 01:01:3140
41 virtual void PreconnectStreams(int num_streams,
42 const HttpRequestInfo& info,
[email protected]102957f2011-09-02 17:10:1443 const SSLConfig& server_ssl_config,
[email protected]7acf98292012-01-28 00:51:5544 const SSLConfig& proxy_ssl_config) OVERRIDE;
[email protected]f2cbbc82011-11-16 01:10:2945 virtual void AddTLSIntolerantServer(const HostPortPair& server) OVERRIDE;
46 virtual bool IsTLSIntolerantServer(const HostPortPair& server) const OVERRIDE;
[email protected]837c4f52011-12-20 22:17:0347 virtual base::Value* PipelineInfoToValue() const OVERRIDE;
[email protected]102e27c2011-02-23 01:01:3148
[email protected]4b9f7292011-12-01 22:20:0649 // HttpPipelinedHostPool::Delegate interface
[email protected]5a60c8b2011-10-19 20:14:2950 virtual void OnHttpPipelinedHostHasAdditionalCapacity(
[email protected]5477d892012-03-01 21:31:3151 HttpPipelinedHost* host) OVERRIDE;
[email protected]5a60c8b2011-10-19 20:14:2952
[email protected]102e27c2011-02-23 01:01:3153 private:
54 class Request;
55 class Job;
56
[email protected]7f28a8df2011-02-25 22:26:0357 typedef std::set<Request*> RequestSet;
[email protected]80059682012-03-03 00:42:3158 typedef std::vector<Request*> RequestVector;
[email protected]7f28a8df2011-02-25 22:26:0359 typedef std::map<HostPortProxyPair, RequestSet> SpdySessionRequestMap;
[email protected]80059682012-03-03 00:42:3160 typedef std::map<HttpPipelinedHost::Key,
61 RequestVector> HttpPipeliningRequestMap;
[email protected]7f28a8df2011-02-25 22:26:0362
[email protected]2d6728692011-03-12 01:39:5563 bool GetAlternateProtocolRequestFor(const GURL& original_url,
64 GURL* alternate_url) const;
65
[email protected]1b323172011-03-01 17:50:1766 // Detaches |job| from |request|.
67 void OrphanJob(Job* job, const Request* request);
[email protected]102e27c2011-02-23 01:01:3168
[email protected]7f28a8df2011-02-25 22:26:0369 // Called when a SpdySession is ready. It will find appropriate Requests and
70 // fulfill them. |direct| indicates whether or not |spdy_session| uses a
71 // proxy.
[email protected]1b323172011-03-01 17:50:1772 void OnSpdySessionReady(scoped_refptr<SpdySession> spdy_session,
73 bool direct,
74 const SSLConfig& used_ssl_config,
75 const ProxyInfo& used_proxy_info,
[email protected]1b323172011-03-01 17:50:1776 bool was_npn_negotiated,
[email protected]c30bcce2011-12-20 17:50:5177 SSLClientSocket::NextProto protocol_negotiated,
[email protected]1b323172011-03-01 17:50:1778 bool using_spdy,
[email protected]68697a42011-12-19 21:47:5579 const BoundNetLog& net_log);
[email protected]102e27c2011-02-23 01:01:3180
[email protected]7f28a8df2011-02-25 22:26:0381 // Called when the Job detects that the endpoint indicated by the
82 // Alternate-Protocol does not work. Lets the factory update
83 // HttpAlternateProtocols with the failure and resets the SPDY session key.
84 void OnBrokenAlternateProtocol(const Job*, const HostPortPair& origin);
85
[email protected]1b323172011-03-01 17:50:1786 // Invoked when an orphaned Job finishes.
87 void OnOrphanedJobComplete(const Job* job);
88
[email protected]7f28a8df2011-02-25 22:26:0389 // Invoked when the Job finishes preconnecting sockets.
[email protected]102e27c2011-02-23 01:01:3190 void OnPreconnectsComplete(const Job* job);
91
92 // Called when the Preconnect completes. Used for testing.
93 virtual void OnPreconnectsCompleteInternal() {}
94
[email protected]5477d892012-03-01 21:31:3195 void AbortPipelinedRequestsWithKey(const Job* job,
96 const HttpPipelinedHost::Key& key,
97 int status,
98 const SSLConfig& used_ssl_config);
99
[email protected]102e27c2011-02-23 01:01:31100 HttpNetworkSession* const session_;
101
[email protected]2d6728692011-03-12 01:39:55102 std::set<HostPortPair> tls_intolerant_servers_;
[email protected]102e27c2011-02-23 01:01:31103
104 // All Requests are handed out to clients. By the time HttpStreamFactoryImpl
105 // is destroyed, all Requests should be deleted (which should remove them from
[email protected]7f28a8df2011-02-25 22:26:03106 // |request_map_|. The Requests will delete the corresponding job.
[email protected]102e27c2011-02-23 01:01:31107 std::map<const Job*, Request*> request_map_;
108
[email protected]7f28a8df2011-02-25 22:26:03109 SpdySessionRequestMap spdy_session_request_map_;
[email protected]5a60c8b2011-10-19 20:14:29110 HttpPipeliningRequestMap http_pipelining_request_map_;
111
112 HttpPipelinedHostPool http_pipelined_host_pool_;
[email protected]7f28a8df2011-02-25 22:26:03113
[email protected]1b323172011-03-01 17:50:17114 // These jobs correspond to jobs orphaned by Requests and now owned by
115 // HttpStreamFactoryImpl. Since they are no longer tied to Requests, they will
116 // not be canceled when Requests are canceled. Therefore, in
117 // ~HttpStreamFactoryImpl, it is possible for some jobs to still exist in this
118 // set. Leftover jobs will be deleted when the factory is destroyed.
119 std::set<const Job*> orphaned_job_set_;
120
[email protected]102e27c2011-02-23 01:01:31121 // These jobs correspond to preconnect requests and have no associated Request
122 // object. They're owned by HttpStreamFactoryImpl. Leftover jobs will be
123 // deleted when the factory is destroyed.
124 std::set<const Job*> preconnect_job_set_;
125
126 DISALLOW_COPY_AND_ASSIGN(HttpStreamFactoryImpl);
127};
128
129} // namespace net
130
131#endif // NET_HTTP_HTTP_STREAM_FACTORY_IMPL_H_