blob: 8ee03a6dc2aef74ded7e5a38070cf83f6c01a876 [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_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]7f28a8df2011-02-25 22:26:0324class SpdySession;
[email protected]102e27c2011-02-23 01:01:3125
[email protected]cf4cae32014-05-27 00:39:1026class NET_EXPORT_PRIVATE HttpStreamFactoryImpl : public HttpStreamFactory {
[email protected]102e27c2011-02-23 01:01:3127 public:
[email protected]3732cea2013-06-21 06:50:5028 // RequestStream may only be called if |for_websockets| is false.
[email protected]a9cf2b92013-10-30 12:08:4929 // RequestWebSocketHandshakeStream may only be called if |for_websockets|
30 // is true.
[email protected]3732cea2013-06-21 06:50:5031 HttpStreamFactoryImpl(HttpNetworkSession* session, bool for_websockets);
dchengb03027d2014-10-21 12:00:2032 ~HttpStreamFactoryImpl() override;
[email protected]102e27c2011-02-23 01:01:3133
[email protected]4b9f7292011-12-01 22:20:0634 // HttpStreamFactory interface
dchengb03027d2014-10-21 12:00:2035 HttpStreamRequest* RequestStream(const HttpRequestInfo& info,
36 RequestPriority priority,
37 const SSLConfig& server_ssl_config,
38 const SSLConfig& proxy_ssl_config,
39 HttpStreamRequest::Delegate* delegate,
40 const BoundNetLog& net_log) override;
[email protected]102e27c2011-02-23 01:01:3141
dchengb03027d2014-10-21 12:00:2042 HttpStreamRequest* RequestWebSocketHandshakeStream(
[email protected]3732cea2013-06-21 06:50:5043 const HttpRequestInfo& info,
44 RequestPriority priority,
45 const SSLConfig& server_ssl_config,
46 const SSLConfig& proxy_ssl_config,
47 HttpStreamRequest::Delegate* delegate,
[email protected]467086b2013-11-12 08:19:4648 WebSocketHandshakeStreamBase::CreateHelper* create_helper,
mostynbba063d6032014-10-09 11:01:1349 const BoundNetLog& net_log) override;
[email protected]3732cea2013-06-21 06:50:5050
dchengb03027d2014-10-21 12:00:2051 void PreconnectStreams(int num_streams,
52 const HttpRequestInfo& info,
53 RequestPriority priority,
54 const SSLConfig& server_ssl_config,
55 const SSLConfig& proxy_ssl_config) override;
56 const HostMappingRules* GetHostMappingRules() const override;
[email protected]102e27c2011-02-23 01:01:3157
[email protected]3732cea2013-06-21 06:50:5058 size_t num_orphaned_jobs() const { return orphaned_job_set_.size(); }
59
[email protected]102e27c2011-02-23 01:01:3160 private:
[email protected]bf828982013-08-14 18:01:4761 FRIEND_TEST_ALL_PREFIXES(HttpStreamFactoryImplRequestTest, SetPriority);
62
63 class NET_EXPORT_PRIVATE Request;
64 class NET_EXPORT_PRIVATE Job;
[email protected]102e27c2011-02-23 01:01:3165
[email protected]7f28a8df2011-02-25 22:26:0366 typedef std::set<Request*> RequestSet;
[email protected]e6d017652013-05-17 18:01:4067 typedef std::map<SpdySessionKey, RequestSet> SpdySessionRequestMap;
[email protected]7f28a8df2011-02-25 22:26:0368
[email protected]3732cea2013-06-21 06:50:5069 HttpStreamRequest* RequestStreamInternal(
70 const HttpRequestInfo& info,
71 RequestPriority priority,
72 const SSLConfig& server_ssl_config,
73 const SSLConfig& proxy_ssl_config,
74 HttpStreamRequest::Delegate* delegate,
[email protected]467086b2013-11-12 08:19:4675 WebSocketHandshakeStreamBase::CreateHelper* create_helper,
[email protected]3732cea2013-06-21 06:50:5076 const BoundNetLog& net_log);
77
[email protected]287d9412014-07-08 23:01:0078 AlternateProtocolInfo GetAlternateProtocolRequestFor(
[email protected]61a527782013-02-21 03:58:0079 const GURL& original_url,
[email protected]9801e3702014-03-07 09:33:5580 GURL* alternate_url);
[email protected]2d6728692011-03-12 01:39:5581
[email protected]1b323172011-03-01 17:50:1782 // Detaches |job| from |request|.
83 void OrphanJob(Job* job, const Request* request);
[email protected]102e27c2011-02-23 01:01:3184
[email protected]7f28a8df2011-02-25 22:26:0385 // Called when a SpdySession is ready. It will find appropriate Requests and
86 // fulfill them. |direct| indicates whether or not |spdy_session| uses a
87 // proxy.
[email protected]795cbf82013-07-22 09:37:2788 void OnNewSpdySessionReady(const base::WeakPtr<SpdySession>& spdy_session,
[email protected]3732cea2013-06-21 06:50:5089 bool direct,
90 const SSLConfig& used_ssl_config,
91 const ProxyInfo& used_proxy_info,
92 bool was_npn_negotiated,
93 NextProto protocol_negotiated,
94 bool using_spdy,
95 const BoundNetLog& net_log);
[email protected]102e27c2011-02-23 01:01:3196
[email protected]7f28a8df2011-02-25 22:26:0397 // Called when the Job detects that the endpoint indicated by the
98 // Alternate-Protocol does not work. Lets the factory update
99 // HttpAlternateProtocols with the failure and resets the SPDY session key.
100 void OnBrokenAlternateProtocol(const Job*, const HostPortPair& origin);
101
[email protected]1b323172011-03-01 17:50:17102 // Invoked when an orphaned Job finishes.
103 void OnOrphanedJobComplete(const Job* job);
104
[email protected]7f28a8df2011-02-25 22:26:03105 // Invoked when the Job finishes preconnecting sockets.
[email protected]102e27c2011-02-23 01:01:31106 void OnPreconnectsComplete(const Job* job);
107
108 // Called when the Preconnect completes. Used for testing.
109 virtual void OnPreconnectsCompleteInternal() {}
110
[email protected]102e27c2011-02-23 01:01:31111 HttpNetworkSession* const session_;
112
[email protected]102e27c2011-02-23 01:01:31113 // All Requests are handed out to clients. By the time HttpStreamFactoryImpl
114 // is destroyed, all Requests should be deleted (which should remove them from
[email protected]7f28a8df2011-02-25 22:26:03115 // |request_map_|. The Requests will delete the corresponding job.
[email protected]102e27c2011-02-23 01:01:31116 std::map<const Job*, Request*> request_map_;
117
[email protected]7f28a8df2011-02-25 22:26:03118 SpdySessionRequestMap spdy_session_request_map_;
[email protected]7f28a8df2011-02-25 22:26:03119
[email protected]1b323172011-03-01 17:50:17120 // These jobs correspond to jobs orphaned by Requests and now owned by
121 // HttpStreamFactoryImpl. Since they are no longer tied to Requests, they will
122 // not be canceled when Requests are canceled. Therefore, in
123 // ~HttpStreamFactoryImpl, it is possible for some jobs to still exist in this
124 // set. Leftover jobs will be deleted when the factory is destroyed.
125 std::set<const Job*> orphaned_job_set_;
126
[email protected]102e27c2011-02-23 01:01:31127 // These jobs correspond to preconnect requests and have no associated Request
128 // object. They're owned by HttpStreamFactoryImpl. Leftover jobs will be
129 // deleted when the factory is destroyed.
130 std::set<const Job*> preconnect_job_set_;
131
[email protected]3732cea2013-06-21 06:50:50132 const bool for_websockets_;
[email protected]102e27c2011-02-23 01:01:31133 DISALLOW_COPY_AND_ASSIGN(HttpStreamFactoryImpl);
134};
135
136} // namespace net
137
138#endif // NET_HTTP_HTTP_STREAM_FACTORY_IMPL_H_