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

Side by Side Diff: net/proxy/proxy_resolver_factory_mojo.cc

Issue 2430953004: Merge ProxyResolverMojo::Job and ProxyResolverMojo::RequestImpl (Closed)
Patch Set: nits Created 4 years, 2 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
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2015 The Chromium Authors. All rights reserved. 1 // Copyright 2015 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 #include "net/proxy/proxy_resolver_factory_mojo.h" 5 #include "net/proxy/proxy_resolver_factory_mojo.h"
6 6
7 #include <set> 7 #include <set>
8 #include <utility> 8 #include <utility>
9 9
10 #include "base/bind.h" 10 #include "base/bind.h"
(...skipping 111 matching lines...) Expand 10 before | Expand all | Expand 10 after
122 122
123 // ProxyResolver implementation: 123 // ProxyResolver implementation:
124 int GetProxyForURL(const GURL& url, 124 int GetProxyForURL(const GURL& url,
125 ProxyInfo* results, 125 ProxyInfo* results,
126 const net::CompletionCallback& callback, 126 const net::CompletionCallback& callback,
127 std::unique_ptr<Request>* request, 127 std::unique_ptr<Request>* request,
128 const NetLogWithSource& net_log) override; 128 const NetLogWithSource& net_log) override;
129 129
130 private: 130 private:
131 class Job; 131 class Job;
132 class RequestImpl;
133 132
134 base::ThreadChecker thread_checker_; 133 base::ThreadChecker thread_checker_;
135 134
136 // Mojo error handler. 135 // Mojo error handler.
137 void OnConnectionError(); 136 void OnConnectionError();
138 137
139 // Connection to the Mojo proxy resolver. 138 // Connection to the Mojo proxy resolver.
140 interfaces::ProxyResolverPtr mojo_proxy_resolver_ptr_; 139 interfaces::ProxyResolverPtr mojo_proxy_resolver_ptr_;
141 140
142 HostResolver* host_resolver_; 141 HostResolver* host_resolver_;
143 142
144 std::unique_ptr<ProxyResolverErrorObserver> error_observer_; 143 std::unique_ptr<ProxyResolverErrorObserver> error_observer_;
145 144
146 NetLog* net_log_; 145 NetLog* net_log_;
147 146
148 std::unique_ptr<base::ScopedClosureRunner> on_delete_callback_runner_; 147 std::unique_ptr<base::ScopedClosureRunner> on_delete_callback_runner_;
149 148
150 DISALLOW_COPY_AND_ASSIGN(ProxyResolverMojo); 149 DISALLOW_COPY_AND_ASSIGN(ProxyResolverMojo);
151 }; 150 };
152 151
153 class ProxyResolverMojo::RequestImpl : public ProxyResolver::Request {
154 public:
155 explicit RequestImpl(std::unique_ptr<Job> job);
156
157 ~RequestImpl() override {}
158
159 LoadState GetLoadState() override;
160
161 private:
162 std::unique_ptr<Job> job_;
163
164 DISALLOW_COPY_AND_ASSIGN(RequestImpl);
165 };
166
167 class ProxyResolverMojo::Job 152 class ProxyResolverMojo::Job
168 : public ClientMixin<interfaces::ProxyResolverRequestClient> { 153 : public ProxyResolver::Request,
154 public ClientMixin<interfaces::ProxyResolverRequestClient> {
169 public: 155 public:
170 Job(ProxyResolverMojo* resolver, 156 Job(ProxyResolverMojo* resolver,
171 const GURL& url, 157 const GURL& url,
172 ProxyInfo* results, 158 ProxyInfo* results,
173 const CompletionCallback& callback, 159 const CompletionCallback& callback,
174 const NetLogWithSource& net_log); 160 const NetLogWithSource& net_log);
175 ~Job() override; 161 ~Job() override;
176 162
177 // Returns the LoadState of this job. 163 // Returns the LoadState of this job.
178 LoadState GetLoadState(); 164 LoadState GetLoadState() override;
179 165
180 private: 166 private:
181 // Mojo error handler. 167 // Mojo error handler.
182 void OnConnectionError(); 168 void OnConnectionError();
183 169
184 // Overridden from interfaces::ProxyResolverRequestClient: 170 // Overridden from interfaces::ProxyResolverRequestClient:
185 void ReportResult(int32_t error, const net::ProxyInfo& proxy_info) override; 171 void ReportResult(int32_t error, const net::ProxyInfo& proxy_info) override;
186 172
187 // Completes a request with a result code. 173 // Completes a request with a result code.
188 void CompleteRequest(int result); 174 void CompleteRequest(int result);
189 175
190 const GURL url_; 176 const GURL url_;
191 ProxyInfo* results_; 177 ProxyInfo* results_;
192 CompletionCallback callback_; 178 CompletionCallback callback_;
193 179
194 base::ThreadChecker thread_checker_; 180 base::ThreadChecker thread_checker_;
195 mojo::Binding<interfaces::ProxyResolverRequestClient> binding_; 181 mojo::Binding<interfaces::ProxyResolverRequestClient> binding_;
196 182
197 DISALLOW_COPY_AND_ASSIGN(Job); 183 DISALLOW_COPY_AND_ASSIGN(Job);
198 }; 184 };
199 185
200 ProxyResolverMojo::RequestImpl::RequestImpl(std::unique_ptr<Job> job)
201 : job_(std::move(job)) {}
202
203 LoadState ProxyResolverMojo::RequestImpl::GetLoadState() {
204 return job_->GetLoadState();
205 }
206
207 ProxyResolverMojo::Job::Job(ProxyResolverMojo* resolver, 186 ProxyResolverMojo::Job::Job(ProxyResolverMojo* resolver,
208 const GURL& url, 187 const GURL& url,
209 ProxyInfo* results, 188 ProxyInfo* results,
210 const CompletionCallback& callback, 189 const CompletionCallback& callback,
211 const NetLogWithSource& net_log) 190 const NetLogWithSource& net_log)
212 : ClientMixin<interfaces::ProxyResolverRequestClient>( 191 : ClientMixin<interfaces::ProxyResolverRequestClient>(
213 resolver->host_resolver_, 192 resolver->host_resolver_,
214 resolver->error_observer_.get(), 193 resolver->error_observer_.get(),
215 resolver->net_log_, 194 resolver->net_log_,
216 net_log), 195 net_log),
(...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after
287 int ProxyResolverMojo::GetProxyForURL(const GURL& url, 266 int ProxyResolverMojo::GetProxyForURL(const GURL& url,
288 ProxyInfo* results, 267 ProxyInfo* results,
289 const CompletionCallback& callback, 268 const CompletionCallback& callback,
290 std::unique_ptr<Request>* request, 269 std::unique_ptr<Request>* request,
291 const NetLogWithSource& net_log) { 270 const NetLogWithSource& net_log) {
292 DCHECK(thread_checker_.CalledOnValidThread()); 271 DCHECK(thread_checker_.CalledOnValidThread());
293 272
294 if (!mojo_proxy_resolver_ptr_) 273 if (!mojo_proxy_resolver_ptr_)
295 return ERR_PAC_SCRIPT_TERMINATED; 274 return ERR_PAC_SCRIPT_TERMINATED;
296 275
297 std::unique_ptr<Job> job(new Job(this, url, results, callback, net_log)); 276 *request = base::MakeUnique<Job>(this, url, results, callback, net_log);
298 request->reset(new RequestImpl(std::move(job)));
299 277
300 return ERR_IO_PENDING; 278 return ERR_IO_PENDING;
301 } 279 }
302 280
303 } // namespace 281 } // namespace
304 282
305 // A Job to create a ProxyResolver instance. 283 // A Job to create a ProxyResolver instance.
306 // 284 //
307 // Note: a Job instance is not tied to a particular resolve request, and hence 285 // Note: a Job instance is not tied to a particular resolve request, and hence
308 // there is no per-request logging to be done (any netlog events are only sent 286 // there is no per-request logging to be done (any netlog events are only sent
(...skipping 79 matching lines...) Expand 10 before | Expand all | Expand 10 after
388 return ERR_PAC_SCRIPT_FAILED; 366 return ERR_PAC_SCRIPT_FAILED;
389 } 367 }
390 request->reset(new Job(this, pac_script, resolver, callback, 368 request->reset(new Job(this, pac_script, resolver, callback,
391 error_observer_factory_.is_null() 369 error_observer_factory_.is_null()
392 ? nullptr 370 ? nullptr
393 : error_observer_factory_.Run())); 371 : error_observer_factory_.Run()));
394 return ERR_IO_PENDING; 372 return ERR_IO_PENDING;
395 } 373 }
396 374
397 } // namespace net 375 } // namespace net
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698