blob: b84f1585329d413a105bcb91f6df6f0f018902f3 [file] [log] [blame]
[email protected]7f28a8df2011-02-25 22:26:031// Copyright (c) 2011 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]102e27c2011-02-23 01:01:3110
[email protected]3b63f8f42011-03-28 01:54:1511#include "base/memory/ref_counted.h"
[email protected]2d6728692011-03-12 01:39:5512#include "net/base/host_port_pair.h"
[email protected]102e27c2011-02-23 01:01:3113#include "net/http/http_stream_factory.h"
[email protected]1b323172011-03-01 17:50:1714#include "net/base/net_log.h"
[email protected]7f28a8df2011-02-25 22:26:0315#include "net/proxy/proxy_server.h"
[email protected]102e27c2011-02-23 01:01:3116
17namespace net {
18
19class HttpNetworkSession;
[email protected]7f28a8df2011-02-25 22:26:0320class SpdySession;
[email protected]102e27c2011-02-23 01:01:3121
[email protected]172da1b2011-08-12 15:52:2622class NET_EXPORT_PRIVATE HttpStreamFactoryImpl : public HttpStreamFactory {
[email protected]102e27c2011-02-23 01:01:3123 public:
24 explicit HttpStreamFactoryImpl(HttpNetworkSession* session);
25 virtual ~HttpStreamFactoryImpl();
26
27 // HttpStreamFactory Interface
28 virtual HttpStreamRequest* RequestStream(
29 const HttpRequestInfo& info,
[email protected]102957f2011-09-02 17:10:1430 const SSLConfig& server_ssl_config,
31 const SSLConfig& proxy_ssl_config,
[email protected]102e27c2011-02-23 01:01:3132 HttpStreamRequest::Delegate* delegate,
33 const BoundNetLog& net_log);
34
35 virtual void PreconnectStreams(int num_streams,
36 const HttpRequestInfo& info,
[email protected]102957f2011-09-02 17:10:1437 const SSLConfig& server_ssl_config,
38 const SSLConfig& proxy_ssl_config,
[email protected]102e27c2011-02-23 01:01:3139 const BoundNetLog& net_log);
[email protected]2d6728692011-03-12 01:39:5540 virtual void AddTLSIntolerantServer(const HostPortPair& server);
41 virtual bool IsTLSIntolerantServer(const HostPortPair& server) const;
[email protected]102e27c2011-02-23 01:01:3142
43 private:
44 class Request;
45 class Job;
46
[email protected]7f28a8df2011-02-25 22:26:0347 typedef std::set<Request*> RequestSet;
48 typedef std::map<HostPortProxyPair, RequestSet> SpdySessionRequestMap;
49
[email protected]2d6728692011-03-12 01:39:5550 bool GetAlternateProtocolRequestFor(const GURL& original_url,
51 GURL* alternate_url) const;
52
[email protected]1b323172011-03-01 17:50:1753 // Detaches |job| from |request|.
54 void OrphanJob(Job* job, const Request* request);
[email protected]102e27c2011-02-23 01:01:3155
[email protected]7f28a8df2011-02-25 22:26:0356 // Called when a SpdySession is ready. It will find appropriate Requests and
57 // fulfill them. |direct| indicates whether or not |spdy_session| uses a
58 // proxy.
[email protected]1b323172011-03-01 17:50:1759 void OnSpdySessionReady(scoped_refptr<SpdySession> spdy_session,
60 bool direct,
61 const SSLConfig& used_ssl_config,
62 const ProxyInfo& used_proxy_info,
[email protected]1b323172011-03-01 17:50:1763 bool was_npn_negotiated,
64 bool using_spdy,
65 const NetLog::Source& source);
[email protected]102e27c2011-02-23 01:01:3166
[email protected]7f28a8df2011-02-25 22:26:0367 // Called when the Job detects that the endpoint indicated by the
68 // Alternate-Protocol does not work. Lets the factory update
69 // HttpAlternateProtocols with the failure and resets the SPDY session key.
70 void OnBrokenAlternateProtocol(const Job*, const HostPortPair& origin);
71
[email protected]1b323172011-03-01 17:50:1772 // Invoked when an orphaned Job finishes.
73 void OnOrphanedJobComplete(const Job* job);
74
[email protected]7f28a8df2011-02-25 22:26:0375 // Invoked when the Job finishes preconnecting sockets.
[email protected]102e27c2011-02-23 01:01:3176 void OnPreconnectsComplete(const Job* job);
77
78 // Called when the Preconnect completes. Used for testing.
79 virtual void OnPreconnectsCompleteInternal() {}
80
81 HttpNetworkSession* const session_;
82
[email protected]2d6728692011-03-12 01:39:5583 std::set<HostPortPair> tls_intolerant_servers_;
[email protected]102e27c2011-02-23 01:01:3184
85 // All Requests are handed out to clients. By the time HttpStreamFactoryImpl
86 // is destroyed, all Requests should be deleted (which should remove them from
[email protected]7f28a8df2011-02-25 22:26:0387 // |request_map_|. The Requests will delete the corresponding job.
[email protected]102e27c2011-02-23 01:01:3188 std::map<const Job*, Request*> request_map_;
89
[email protected]7f28a8df2011-02-25 22:26:0390 SpdySessionRequestMap spdy_session_request_map_;
91
[email protected]1b323172011-03-01 17:50:1792 // These jobs correspond to jobs orphaned by Requests and now owned by
93 // HttpStreamFactoryImpl. Since they are no longer tied to Requests, they will
94 // not be canceled when Requests are canceled. Therefore, in
95 // ~HttpStreamFactoryImpl, it is possible for some jobs to still exist in this
96 // set. Leftover jobs will be deleted when the factory is destroyed.
97 std::set<const Job*> orphaned_job_set_;
98
[email protected]102e27c2011-02-23 01:01:3199 // These jobs correspond to preconnect requests and have no associated Request
100 // object. They're owned by HttpStreamFactoryImpl. Leftover jobs will be
101 // deleted when the factory is destroyed.
102 std::set<const Job*> preconnect_job_set_;
103
104 DISALLOW_COPY_AND_ASSIGN(HttpStreamFactoryImpl);
105};
106
107} // namespace net
108
109#endif // NET_HTTP_HTTP_STREAM_FACTORY_IMPL_H_