Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(88)

Side by Side Diff: net/http/http_stream_factory_impl.h

Issue 1941083002: JobController 1: Adding a new class HttpStreamFactoryImpl::JobController (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: add JobFactory interface in JobController, remove JobControllerPeer Created 4 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 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 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #ifndef NET_HTTP_HTTP_STREAM_FACTORY_IMPL_H_ 5 #ifndef NET_HTTP_HTTP_STREAM_FACTORY_IMPL_H_
6 #define NET_HTTP_HTTP_STREAM_FACTORY_IMPL_H_ 6 #define NET_HTTP_HTTP_STREAM_FACTORY_IMPL_H_
7 7
8 #include <stddef.h> 8 #include <stddef.h>
9 9
10 #include <map> 10 #include <map>
11 #include <set> 11 #include <set>
12 #include <vector> 12 #include <vector>
13 13
14 #include "base/gtest_prod_util.h" 14 #include "base/gtest_prod_util.h"
15 #include "base/macros.h" 15 #include "base/macros.h"
16 #include "base/memory/ref_counted.h" 16 #include "base/memory/ref_counted.h"
17 #include "net/base/host_port_pair.h" 17 #include "net/base/host_port_pair.h"
18 #include "net/http/http_stream_factory.h" 18 #include "net/http/http_stream_factory.h"
19 #include "net/log/net_log.h" 19 #include "net/log/net_log.h"
20 #include "net/proxy/proxy_server.h" 20 #include "net/proxy/proxy_server.h"
21 #include "net/socket/ssl_client_socket.h" 21 #include "net/socket/ssl_client_socket.h"
22 #include "net/spdy/spdy_session_key.h" 22 #include "net/spdy/spdy_session_key.h"
23 23
24 namespace net { 24 namespace net {
25 25
26 class HttpNetworkSession; 26 class HttpNetworkSession;
27 class SpdySession; 27 class SpdySession;
28 class TestJobControllerPeer;
Ryan Hamilton 2016/06/06 17:57:31 I think this is unused?
28 29
29 class NET_EXPORT_PRIVATE HttpStreamFactoryImpl : public HttpStreamFactory { 30 class NET_EXPORT_PRIVATE HttpStreamFactoryImpl : public HttpStreamFactory {
30 public: 31 public:
31 // RequestStream may only be called if |for_websockets| is false. 32 // RequestStream may only be called if |for_websockets| is false.
32 // RequestWebSocketHandshakeStream may only be called if |for_websockets| 33 // RequestWebSocketHandshakeStream may only be called if |for_websockets|
33 // is true. 34 // is true.
34 HttpStreamFactoryImpl(HttpNetworkSession* session, bool for_websockets); 35 HttpStreamFactoryImpl(HttpNetworkSession* session, bool for_websockets);
35 ~HttpStreamFactoryImpl() override; 36 ~HttpStreamFactoryImpl() override;
36 37
37 // HttpStreamFactory interface 38 // HttpStreamFactory interface
(...skipping 17 matching lines...) Expand all
55 const HttpRequestInfo& info, 56 const HttpRequestInfo& info,
56 RequestPriority priority, 57 RequestPriority priority,
57 const SSLConfig& server_ssl_config, 58 const SSLConfig& server_ssl_config,
58 const SSLConfig& proxy_ssl_config, 59 const SSLConfig& proxy_ssl_config,
59 HttpStreamRequest::Delegate* delegate, 60 HttpStreamRequest::Delegate* delegate,
60 const BoundNetLog& net_log) override; 61 const BoundNetLog& net_log) override;
61 62
62 void PreconnectStreams(int num_streams, const HttpRequestInfo& info) override; 63 void PreconnectStreams(int num_streams, const HttpRequestInfo& info) override;
63 const HostMappingRules* GetHostMappingRules() const override; 64 const HostMappingRules* GetHostMappingRules() const override;
64 65
65 size_t num_orphaned_jobs() const { return orphaned_job_set_.size(); } 66 enum JobType {
67 MAIN,
68 ALTERNATIVE,
69 PRECONNECT,
70 };
66 71
67 private: 72 private:
68 FRIEND_TEST_ALL_PREFIXES(HttpStreamFactoryImplRequestTest, SetPriority); 73 FRIEND_TEST_ALL_PREFIXES(HttpStreamFactoryImplRequestTest, SetPriority);
69 FRIEND_TEST_ALL_PREFIXES(HttpStreamFactoryImplRequestTest, DelayMainJob); 74 FRIEND_TEST_ALL_PREFIXES(HttpStreamFactoryImplRequestTest, DelayMainJob);
70 75
76 friend class HttpStreamFactoryImplJobControllerTest;
77 friend class TestHttpStreamFactoryImplJob;
78 friend class TestJobFactory;
Ryan Hamilton 2016/06/06 17:57:31 Does these need to be friends?
Zhongyi Shi 2016/06/06 22:50:55 Unfortunately, yes. Those all access to HttpStream
Ryan Hamilton 2016/06/13 19:25:26 In that case, I wonder if we should make HttpStrea
79
71 class NET_EXPORT_PRIVATE Request; 80 class NET_EXPORT_PRIVATE Request;
72 class NET_EXPORT_PRIVATE Job; 81 class NET_EXPORT_PRIVATE Job;
82 class NET_EXPORT_PRIVATE JobController;
83 class NET_EXPORT_PRIVATE JobFactoryImpl;
Ryan Hamilton 2016/06/06 17:57:31 nit: I think we don't need NET_EXPORT_PRIVATE on a
Zhongyi Shi 2016/06/06 22:50:55 I can try after finish all the other part and sync
73 84
74 typedef std::set<Request*> RequestSet; 85 typedef std::set<Request*> RequestSet;
75 typedef std::map<SpdySessionKey, RequestSet> SpdySessionRequestMap; 86 typedef std::map<SpdySessionKey, RequestSet> SpdySessionRequestMap;
87 typedef std::set<std::unique_ptr<JobController>> JobControllerSet;
76 88
77 HttpStreamRequest* RequestStreamInternal( 89 HttpStreamRequest* RequestStreamInternal(
78 const HttpRequestInfo& info, 90 const HttpRequestInfo& info,
79 RequestPriority priority, 91 RequestPriority priority,
80 const SSLConfig& server_ssl_config, 92 const SSLConfig& server_ssl_config,
81 const SSLConfig& proxy_ssl_config, 93 const SSLConfig& proxy_ssl_config,
82 HttpStreamRequest::Delegate* delegate, 94 HttpStreamRequest::Delegate* delegate,
83 WebSocketHandshakeStreamBase::CreateHelper* create_helper, 95 WebSocketHandshakeStreamBase::CreateHelper* create_helper,
84 HttpStreamRequest::StreamType stream_type, 96 HttpStreamRequest::StreamType stream_type,
85 const BoundNetLog& net_log); 97 const BoundNetLog& net_log);
86 98
87 AlternativeService GetAlternativeServiceFor(
88 const HttpRequestInfo& request_info,
89 HttpStreamRequest::Delegate* delegate,
90 HttpStreamRequest::StreamType stream_type);
91
92 // Detaches |job| from |request|.
93 void OrphanJob(Job* job, const Request* request);
94
95 // Called when a SpdySession is ready. It will find appropriate Requests and 99 // Called when a SpdySession is ready. It will find appropriate Requests and
96 // fulfill them. |direct| indicates whether or not |spdy_session| uses a 100 // fulfill them. |direct| indicates whether or not |spdy_session| uses a
97 // proxy. 101 // proxy.
98 void OnNewSpdySessionReady(const base::WeakPtr<SpdySession>& spdy_session, 102 void OnNewSpdySessionReady(const base::WeakPtr<SpdySession>& spdy_session,
99 bool direct, 103 bool direct,
100 const SSLConfig& used_ssl_config, 104 const SSLConfig& used_ssl_config,
101 const ProxyInfo& used_proxy_info, 105 const ProxyInfo& used_proxy_info,
102 bool was_npn_negotiated, 106 bool was_npn_negotiated,
103 NextProto protocol_negotiated, 107 NextProto protocol_negotiated,
104 bool using_spdy, 108 bool using_spdy,
105 const BoundNetLog& net_log); 109 const BoundNetLog& net_log);
106 110
107 // Called when the Job detects that the endpoint indicated by the 111 // Called when the Job detects that the endpoint indicated by the
108 // Alternate-Protocol does not work. Lets the factory update 112 // Alternate-Protocol does not work. Lets the factory update
109 // HttpAlternateProtocols with the failure and resets the SPDY session key. 113 // HttpAlternateProtocols with the failure and resets the SPDY session key.
110 void OnBrokenAlternateProtocol(const Job*, const HostPortPair& origin); 114 void OnBrokenAlternateProtocol(const Job*, const HostPortPair& origin);
111 115
112 // Invoked when an orphaned Job finishes.
113 void OnOrphanedJobComplete(const Job* job);
114
115 // Invoked when the Job finishes preconnecting sockets.
116 void OnPreconnectsComplete(const Job* job);
117
118 // Called when the Preconnect completes. Used for testing. 116 // Called when the Preconnect completes. Used for testing.
119 virtual void OnPreconnectsCompleteInternal() {} 117 virtual void OnPreconnectsCompleteInternal() {}
120 118
121 // Returns true if QUIC is whitelisted for |host|. 119 // Called when the JobController finishes service. Delete the JobController
122 bool IsQuicWhitelistedForHost(const std::string& host); 120 // from |job_controller_set_|.
121 void OnJobControllerComplete(JobController* controller);
123 122
124 HttpNetworkSession* const session_; 123 HttpNetworkSession* const session_;
125 124
126 // All Requests are handed out to clients. By the time HttpStreamFactoryImpl 125 // All Requests are handed out to clients. By the time HttpStreamFactoryImpl
127 // is destroyed, all Requests should be deleted (which should remove them from 126 // is destroyed, all Requests should be deleted (which should remove them from
128 // |request_map_|. The Requests will delete the corresponding job. 127 // |request_map_|. The Requests will delete the corresponding job.
129 std::map<const Job*, Request*> request_map_; 128 std::map<const Job*, Request*> request_map_;
130 129
130 // All Requests/Preconnects are assigned with a JobController to manage
131 // serving Job(s). JobController might outlive Request when Request
132 // is served while there's some working Job left. JobController will be
133 // deleted from |job_controller_set_| when it determines the completion of
134 // its work.
135 JobControllerSet job_controller_set_;
136
137 std::unique_ptr<JobFactoryImpl> job_factory_;
Ryan Hamilton 2016/06/06 17:57:31 nit: comment
Zhongyi Shi 2016/06/06 22:50:55 Done.
138
131 SpdySessionRequestMap spdy_session_request_map_; 139 SpdySessionRequestMap spdy_session_request_map_;
132 140
133 // These jobs correspond to jobs orphaned by Requests and now owned by
134 // HttpStreamFactoryImpl. Since they are no longer tied to Requests, they will
135 // not be canceled when Requests are canceled. Therefore, in
136 // ~HttpStreamFactoryImpl, it is possible for some jobs to still exist in this
137 // set. Leftover jobs will be deleted when the factory is destroyed.
138 std::set<const Job*> orphaned_job_set_;
139
140 // These jobs correspond to preconnect requests and have no associated Request
141 // object. They're owned by HttpStreamFactoryImpl. Leftover jobs will be
142 // deleted when the factory is destroyed.
143 std::set<const Job*> preconnect_job_set_;
144
145 const bool for_websockets_; 141 const bool for_websockets_;
146 DISALLOW_COPY_AND_ASSIGN(HttpStreamFactoryImpl); 142 DISALLOW_COPY_AND_ASSIGN(HttpStreamFactoryImpl);
147 }; 143 };
148 144
149 } // namespace net 145 } // namespace net
150 146
151 #endif // NET_HTTP_HTTP_STREAM_FACTORY_IMPL_H_ 147 #endif // NET_HTTP_HTTP_STREAM_FACTORY_IMPL_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698