blob: b43bf135444baa3438ba7e4cf47d78c5c7376258 [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]7f28a8df2011-02-25 22:26:0311#include "base/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
22class HttpStreamFactoryImpl : public HttpStreamFactory {
23 public:
24 explicit HttpStreamFactoryImpl(HttpNetworkSession* session);
25 virtual ~HttpStreamFactoryImpl();
26
27 // HttpStreamFactory Interface
28 virtual HttpStreamRequest* RequestStream(
29 const HttpRequestInfo& info,
30 const SSLConfig& ssl_config,
31 HttpStreamRequest::Delegate* delegate,
32 const BoundNetLog& net_log);
33
34 virtual void PreconnectStreams(int num_streams,
35 const HttpRequestInfo& info,
36 const SSLConfig& ssl_config,
37 const BoundNetLog& net_log);
[email protected]2d6728692011-03-12 01:39:5538 virtual void AddTLSIntolerantServer(const HostPortPair& server);
39 virtual bool IsTLSIntolerantServer(const HostPortPair& server) const;
[email protected]102e27c2011-02-23 01:01:3140
41 private:
42 class Request;
43 class Job;
44
[email protected]7f28a8df2011-02-25 22:26:0345 typedef std::set<Request*> RequestSet;
46 typedef std::map<HostPortProxyPair, RequestSet> SpdySessionRequestMap;
47
[email protected]2d6728692011-03-12 01:39:5548 bool GetAlternateProtocolRequestFor(const GURL& original_url,
49 GURL* alternate_url) const;
50
[email protected]1b323172011-03-01 17:50:1751 // Detaches |job| from |request|.
52 void OrphanJob(Job* job, const Request* request);
[email protected]102e27c2011-02-23 01:01:3153
[email protected]7f28a8df2011-02-25 22:26:0354 // Called when a SpdySession is ready. It will find appropriate Requests and
55 // fulfill them. |direct| indicates whether or not |spdy_session| uses a
56 // proxy.
[email protected]1b323172011-03-01 17:50:1757 void OnSpdySessionReady(scoped_refptr<SpdySession> spdy_session,
58 bool direct,
59 const SSLConfig& used_ssl_config,
60 const ProxyInfo& used_proxy_info,
[email protected]1b323172011-03-01 17:50:1761 bool was_npn_negotiated,
62 bool using_spdy,
63 const NetLog::Source& source);
[email protected]102e27c2011-02-23 01:01:3164
[email protected]7f28a8df2011-02-25 22:26:0365 // Called when the Job detects that the endpoint indicated by the
66 // Alternate-Protocol does not work. Lets the factory update
67 // HttpAlternateProtocols with the failure and resets the SPDY session key.
68 void OnBrokenAlternateProtocol(const Job*, const HostPortPair& origin);
69
[email protected]1b323172011-03-01 17:50:1770 // Invoked when an orphaned Job finishes.
71 void OnOrphanedJobComplete(const Job* job);
72
[email protected]7f28a8df2011-02-25 22:26:0373 // Invoked when the Job finishes preconnecting sockets.
[email protected]102e27c2011-02-23 01:01:3174 void OnPreconnectsComplete(const Job* job);
75
76 // Called when the Preconnect completes. Used for testing.
77 virtual void OnPreconnectsCompleteInternal() {}
78
79 HttpNetworkSession* const session_;
80
[email protected]2d6728692011-03-12 01:39:5581 std::set<HostPortPair> tls_intolerant_servers_;
[email protected]102e27c2011-02-23 01:01:3182
83 // All Requests are handed out to clients. By the time HttpStreamFactoryImpl
84 // is destroyed, all Requests should be deleted (which should remove them from
[email protected]7f28a8df2011-02-25 22:26:0385 // |request_map_|. The Requests will delete the corresponding job.
[email protected]102e27c2011-02-23 01:01:3186 std::map<const Job*, Request*> request_map_;
87
[email protected]7f28a8df2011-02-25 22:26:0388 SpdySessionRequestMap spdy_session_request_map_;
89
[email protected]1b323172011-03-01 17:50:1790 // These jobs correspond to jobs orphaned by Requests and now owned by
91 // HttpStreamFactoryImpl. Since they are no longer tied to Requests, they will
92 // not be canceled when Requests are canceled. Therefore, in
93 // ~HttpStreamFactoryImpl, it is possible for some jobs to still exist in this
94 // set. Leftover jobs will be deleted when the factory is destroyed.
95 std::set<const Job*> orphaned_job_set_;
96
[email protected]102e27c2011-02-23 01:01:3197 // These jobs correspond to preconnect requests and have no associated Request
98 // object. They're owned by HttpStreamFactoryImpl. Leftover jobs will be
99 // deleted when the factory is destroyed.
100 std::set<const Job*> preconnect_job_set_;
101
102 DISALLOW_COPY_AND_ASSIGN(HttpStreamFactoryImpl);
103};
104
105} // namespace net
106
107#endif // NET_HTTP_HTTP_STREAM_FACTORY_IMPL_H_