blob: 30ab4429504499f535da688366ff7c4bdc59a914 [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
Avi Drissman13fc8932015-12-20 04:40:468#include <stddef.h>
9
[email protected]102e27c2011-02-23 01:01:3110#include <map>
11#include <set>
[email protected]80059682012-03-03 00:42:3112#include <vector>
[email protected]102e27c2011-02-23 01:01:3113
[email protected]bf828982013-08-14 18:01:4714#include "base/gtest_prod_util.h"
Avi Drissman13fc8932015-12-20 04:40:4615#include "base/macros.h"
[email protected]3b63f8f42011-03-28 01:54:1516#include "base/memory/ref_counted.h"
[email protected]2d6728692011-03-12 01:39:5517#include "net/base/host_port_pair.h"
[email protected]5a60c8b2011-10-19 20:14:2918#include "net/http/http_stream_factory.h"
eroman87c53d62015-04-02 06:51:0719#include "net/log/net_log.h"
[email protected]7f28a8df2011-02-25 22:26:0320#include "net/proxy/proxy_server.h"
[email protected]c30bcce2011-12-20 17:50:5121#include "net/socket/ssl_client_socket.h"
[email protected]e6d017652013-05-17 18:01:4022#include "net/spdy/spdy_session_key.h"
[email protected]102e27c2011-02-23 01:01:3123
24namespace net {
25
26class HttpNetworkSession;
[email protected]7f28a8df2011-02-25 22:26:0327class SpdySession;
[email protected]102e27c2011-02-23 01:01:3128
[email protected]cf4cae32014-05-27 00:39:1029class NET_EXPORT_PRIVATE HttpStreamFactoryImpl : public HttpStreamFactory {
[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.
[email protected]a9cf2b92013-10-30 12:08:4932 // RequestWebSocketHandshakeStream may only be called if |for_websockets|
33 // is true.
[email protected]3732cea2013-06-21 06:50:5034 HttpStreamFactoryImpl(HttpNetworkSession* session, bool for_websockets);
dchengb03027d2014-10-21 12:00:2035 ~HttpStreamFactoryImpl() override;
[email protected]102e27c2011-02-23 01:01:3136
[email protected]4b9f7292011-12-01 22:20:0637 // HttpStreamFactory interface
dchengb03027d2014-10-21 12:00:2038 HttpStreamRequest* RequestStream(const HttpRequestInfo& info,
39 RequestPriority priority,
40 const SSLConfig& server_ssl_config,
41 const SSLConfig& proxy_ssl_config,
42 HttpStreamRequest::Delegate* delegate,
43 const BoundNetLog& net_log) override;
[email protected]102e27c2011-02-23 01:01:3144
dchengb03027d2014-10-21 12:00:2045 HttpStreamRequest* RequestWebSocketHandshakeStream(
[email protected]3732cea2013-06-21 06:50:5046 const HttpRequestInfo& info,
47 RequestPriority priority,
48 const SSLConfig& server_ssl_config,
49 const SSLConfig& proxy_ssl_config,
50 HttpStreamRequest::Delegate* delegate,
[email protected]467086b2013-11-12 08:19:4651 WebSocketHandshakeStreamBase::CreateHelper* create_helper,
mostynbba063d6032014-10-09 11:01:1352 const BoundNetLog& net_log) override;
[email protected]3732cea2013-06-21 06:50:5053
xunjieli11834f02015-12-22 04:27:0854 HttpStreamRequest* RequestBidirectionalStreamJob(
55 const HttpRequestInfo& info,
56 RequestPriority priority,
57 const SSLConfig& server_ssl_config,
58 const SSLConfig& proxy_ssl_config,
59 HttpStreamRequest::Delegate* delegate,
60 const BoundNetLog& net_log) override;
61
dchengb03027d2014-10-21 12:00:2062 void PreconnectStreams(int num_streams,
63 const HttpRequestInfo& info,
dchengb03027d2014-10-21 12:00:2064 const SSLConfig& server_ssl_config,
65 const SSLConfig& proxy_ssl_config) override;
66 const HostMappingRules* GetHostMappingRules() const override;
[email protected]102e27c2011-02-23 01:01:3167
[email protected]3732cea2013-06-21 06:50:5068 size_t num_orphaned_jobs() const { return orphaned_job_set_.size(); }
69
[email protected]102e27c2011-02-23 01:01:3170 private:
[email protected]bf828982013-08-14 18:01:4771 FRIEND_TEST_ALL_PREFIXES(HttpStreamFactoryImplRequestTest, SetPriority);
72
73 class NET_EXPORT_PRIVATE Request;
74 class NET_EXPORT_PRIVATE Job;
[email protected]102e27c2011-02-23 01:01:3175
[email protected]7f28a8df2011-02-25 22:26:0376 typedef std::set<Request*> RequestSet;
[email protected]e6d017652013-05-17 18:01:4077 typedef std::map<SpdySessionKey, RequestSet> SpdySessionRequestMap;
[email protected]7f28a8df2011-02-25 22:26:0378
[email protected]3732cea2013-06-21 06:50:5079 HttpStreamRequest* RequestStreamInternal(
80 const HttpRequestInfo& info,
81 RequestPriority priority,
82 const SSLConfig& server_ssl_config,
83 const SSLConfig& proxy_ssl_config,
84 HttpStreamRequest::Delegate* delegate,
[email protected]467086b2013-11-12 08:19:4685 WebSocketHandshakeStreamBase::CreateHelper* create_helper,
[email protected]3732cea2013-06-21 06:50:5086 const BoundNetLog& net_log);
87
zhongyi48704c182015-12-07 07:52:0288 AlternativeServiceVector GetAlternativeServicesFor(
89 const GURL& original_url,
90 HttpStreamRequest::Delegate* delegate);
[email protected]2d6728692011-03-12 01:39:5591
[email protected]1b323172011-03-01 17:50:1792 // Detaches |job| from |request|.
93 void OrphanJob(Job* job, const Request* request);
[email protected]102e27c2011-02-23 01:01:3194
[email protected]7f28a8df2011-02-25 22:26:0395 // Called when a SpdySession is ready. It will find appropriate Requests and
96 // fulfill them. |direct| indicates whether or not |spdy_session| uses a
97 // proxy.
[email protected]795cbf82013-07-22 09:37:2798 void OnNewSpdySessionReady(const base::WeakPtr<SpdySession>& spdy_session,
[email protected]3732cea2013-06-21 06:50:5099 bool direct,
100 const SSLConfig& used_ssl_config,
101 const ProxyInfo& used_proxy_info,
102 bool was_npn_negotiated,
103 NextProto protocol_negotiated,
104 bool using_spdy,
105 const BoundNetLog& net_log);
[email protected]102e27c2011-02-23 01:01:31106
[email protected]7f28a8df2011-02-25 22:26:03107 // Called when the Job detects that the endpoint indicated by the
108 // Alternate-Protocol does not work. Lets the factory update
109 // HttpAlternateProtocols with the failure and resets the SPDY session key.
110 void OnBrokenAlternateProtocol(const Job*, const HostPortPair& origin);
111
[email protected]1b323172011-03-01 17:50:17112 // Invoked when an orphaned Job finishes.
113 void OnOrphanedJobComplete(const Job* job);
114
[email protected]7f28a8df2011-02-25 22:26:03115 // Invoked when the Job finishes preconnecting sockets.
[email protected]102e27c2011-02-23 01:01:31116 void OnPreconnectsComplete(const Job* job);
117
118 // Called when the Preconnect completes. Used for testing.
119 virtual void OnPreconnectsCompleteInternal() {}
120
121 HttpNetworkSession* const session_;
122
[email protected]102e27c2011-02-23 01:01:31123 // All Requests are handed out to clients. By the time HttpStreamFactoryImpl
124 // is destroyed, all Requests should be deleted (which should remove them from
[email protected]7f28a8df2011-02-25 22:26:03125 // |request_map_|. The Requests will delete the corresponding job.
[email protected]102e27c2011-02-23 01:01:31126 std::map<const Job*, Request*> request_map_;
127
[email protected]7f28a8df2011-02-25 22:26:03128 SpdySessionRequestMap spdy_session_request_map_;
129
[email protected]1b323172011-03-01 17:50:17130 // These jobs correspond to jobs orphaned by Requests and now owned by
131 // HttpStreamFactoryImpl. Since they are no longer tied to Requests, they will
132 // not be canceled when Requests are canceled. Therefore, in
133 // ~HttpStreamFactoryImpl, it is possible for some jobs to still exist in this
134 // set. Leftover jobs will be deleted when the factory is destroyed.
135 std::set<const Job*> orphaned_job_set_;
136
[email protected]102e27c2011-02-23 01:01:31137 // These jobs correspond to preconnect requests and have no associated Request
138 // object. They're owned by HttpStreamFactoryImpl. Leftover jobs will be
139 // deleted when the factory is destroyed.
140 std::set<const Job*> preconnect_job_set_;
141
[email protected]3732cea2013-06-21 06:50:50142 const bool for_websockets_;
[email protected]102e27c2011-02-23 01:01:31143 DISALLOW_COPY_AND_ASSIGN(HttpStreamFactoryImpl);
144};
145
146} // namespace net
147
148#endif // NET_HTTP_HTTP_STREAM_FACTORY_IMPL_H_