Update V8 to version 4.7.53.
[chromium-blink-merge.git] / net / http / http_stream_factory_impl.h
blob1ac451dd99ec14c616be8c752486376d50e8260f
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
5 #ifndef NET_HTTP_HTTP_STREAM_FACTORY_IMPL_H_
6 #define NET_HTTP_HTTP_STREAM_FACTORY_IMPL_H_
8 #include <map>
9 #include <set>
10 #include <vector>
12 #include "base/gtest_prod_util.h"
13 #include "base/memory/ref_counted.h"
14 #include "net/base/host_port_pair.h"
15 #include "net/http/http_stream_factory.h"
16 #include "net/log/net_log.h"
17 #include "net/proxy/proxy_server.h"
18 #include "net/socket/ssl_client_socket.h"
19 #include "net/spdy/spdy_session_key.h"
21 namespace net {
23 class HttpNetworkSession;
24 class SpdySession;
26 class NET_EXPORT_PRIVATE HttpStreamFactoryImpl : public HttpStreamFactory {
27 public:
28 // RequestStream may only be called if |for_websockets| is false.
29 // RequestWebSocketHandshakeStream may only be called if |for_websockets|
30 // is true.
31 HttpStreamFactoryImpl(HttpNetworkSession* session, bool for_websockets);
32 ~HttpStreamFactoryImpl() override;
34 // HttpStreamFactory interface
35 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;
42 HttpStreamRequest* RequestWebSocketHandshakeStream(
43 const HttpRequestInfo& info,
44 RequestPriority priority,
45 const SSLConfig& server_ssl_config,
46 const SSLConfig& proxy_ssl_config,
47 HttpStreamRequest::Delegate* delegate,
48 WebSocketHandshakeStreamBase::CreateHelper* create_helper,
49 const BoundNetLog& net_log) override;
51 void PreconnectStreams(int num_streams,
52 const HttpRequestInfo& info,
53 const SSLConfig& server_ssl_config,
54 const SSLConfig& proxy_ssl_config) override;
55 const HostMappingRules* GetHostMappingRules() const override;
57 size_t num_orphaned_jobs() const { return orphaned_job_set_.size(); }
59 private:
60 FRIEND_TEST_ALL_PREFIXES(HttpStreamFactoryImplRequestTest, SetPriority);
62 class NET_EXPORT_PRIVATE Request;
63 class NET_EXPORT_PRIVATE Job;
65 typedef std::set<Request*> RequestSet;
66 typedef std::map<SpdySessionKey, RequestSet> SpdySessionRequestMap;
68 HttpStreamRequest* RequestStreamInternal(
69 const HttpRequestInfo& info,
70 RequestPriority priority,
71 const SSLConfig& server_ssl_config,
72 const SSLConfig& proxy_ssl_config,
73 HttpStreamRequest::Delegate* delegate,
74 WebSocketHandshakeStreamBase::CreateHelper* create_helper,
75 const BoundNetLog& net_log);
77 AlternativeServiceVector GetAlternativeServicesFor(const GURL& original_url);
79 // Detaches |job| from |request|.
80 void OrphanJob(Job* job, const Request* request);
82 // Called when a SpdySession is ready. It will find appropriate Requests and
83 // fulfill them. |direct| indicates whether or not |spdy_session| uses a
84 // proxy.
85 void OnNewSpdySessionReady(const base::WeakPtr<SpdySession>& spdy_session,
86 bool direct,
87 const SSLConfig& used_ssl_config,
88 const ProxyInfo& used_proxy_info,
89 bool was_npn_negotiated,
90 NextProto protocol_negotiated,
91 bool using_spdy,
92 const BoundNetLog& net_log);
94 // Called when the Job detects that the endpoint indicated by the
95 // Alternate-Protocol does not work. Lets the factory update
96 // HttpAlternateProtocols with the failure and resets the SPDY session key.
97 void OnBrokenAlternateProtocol(const Job*, const HostPortPair& origin);
99 // Invoked when an orphaned Job finishes.
100 void OnOrphanedJobComplete(const Job* job);
102 // Invoked when the Job finishes preconnecting sockets.
103 void OnPreconnectsComplete(const Job* job);
105 // Called when the Preconnect completes. Used for testing.
106 virtual void OnPreconnectsCompleteInternal() {}
108 HttpNetworkSession* const session_;
110 // All Requests are handed out to clients. By the time HttpStreamFactoryImpl
111 // is destroyed, all Requests should be deleted (which should remove them from
112 // |request_map_|. The Requests will delete the corresponding job.
113 std::map<const Job*, Request*> request_map_;
115 SpdySessionRequestMap spdy_session_request_map_;
117 // These jobs correspond to jobs orphaned by Requests and now owned by
118 // HttpStreamFactoryImpl. Since they are no longer tied to Requests, they will
119 // not be canceled when Requests are canceled. Therefore, in
120 // ~HttpStreamFactoryImpl, it is possible for some jobs to still exist in this
121 // set. Leftover jobs will be deleted when the factory is destroyed.
122 std::set<const Job*> orphaned_job_set_;
124 // These jobs correspond to preconnect requests and have no associated Request
125 // object. They're owned by HttpStreamFactoryImpl. Leftover jobs will be
126 // deleted when the factory is destroyed.
127 std::set<const Job*> preconnect_job_set_;
129 const bool for_websockets_;
130 DISALLOW_COPY_AND_ASSIGN(HttpStreamFactoryImpl);
133 } // namespace net
135 #endif // NET_HTTP_HTTP_STREAM_FACTORY_IMPL_H_