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

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

Issue 2351513002: net: rename BoundNetLog to NetLogWithSource (Closed)
Patch Set: REBASE Created 4 years, 3 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 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 33 matching lines...) Expand 10 before | Expand all | Expand 10 after
44 44
45 // A mixin that forwards logging to (Bound)NetLog and ProxyResolverErrorObserver 45 // A mixin that forwards logging to (Bound)NetLog and ProxyResolverErrorObserver
46 // and DNS requests to a MojoHostResolverImpl, which is implemented in terms of 46 // and DNS requests to a MojoHostResolverImpl, which is implemented in terms of
47 // a HostResolver. 47 // a HostResolver.
48 template <typename ClientInterface> 48 template <typename ClientInterface>
49 class ClientMixin : public ClientInterface { 49 class ClientMixin : public ClientInterface {
50 public: 50 public:
51 ClientMixin(HostResolver* host_resolver, 51 ClientMixin(HostResolver* host_resolver,
52 ProxyResolverErrorObserver* error_observer, 52 ProxyResolverErrorObserver* error_observer,
53 NetLog* net_log, 53 NetLog* net_log,
54 const BoundNetLog& bound_net_log) 54 const NetLogWithSource& bound_net_log)
55 : host_resolver_(host_resolver, bound_net_log), 55 : host_resolver_(host_resolver, bound_net_log),
56 error_observer_(error_observer), 56 error_observer_(error_observer),
57 net_log_(net_log), 57 net_log_(net_log),
58 bound_net_log_(bound_net_log) {} 58 bound_net_log_(bound_net_log) {}
59 59
60 // Overridden from ClientInterface: 60 // Overridden from ClientInterface:
61 void Alert(const mojo::String& message) override { 61 void Alert(const mojo::String& message) override {
62 base::string16 message_str = message.To<base::string16>(); 62 base::string16 message_str = message.To<base::string16>();
63 auto callback = NetLog::StringCallback("message", &message_str); 63 auto callback = NetLog::StringCallback("message", &message_str);
64 bound_net_log_.AddEvent(NetLogEventType::PAC_JAVASCRIPT_ALERT, callback); 64 bound_net_log_.AddEvent(NetLogEventType::PAC_JAVASCRIPT_ALERT, callback);
(...skipping 18 matching lines...) Expand all
83 83
84 protected: 84 protected:
85 bool dns_request_in_progress() { 85 bool dns_request_in_progress() {
86 return host_resolver_.request_in_progress(); 86 return host_resolver_.request_in_progress();
87 } 87 }
88 88
89 private: 89 private:
90 MojoHostResolverImpl host_resolver_; 90 MojoHostResolverImpl host_resolver_;
91 ProxyResolverErrorObserver* const error_observer_; 91 ProxyResolverErrorObserver* const error_observer_;
92 NetLog* const net_log_; 92 NetLog* const net_log_;
93 const BoundNetLog bound_net_log_; 93 const NetLogWithSource bound_net_log_;
94 }; 94 };
95 95
96 // Implementation of ProxyResolver that connects to a Mojo service to evaluate 96 // Implementation of ProxyResolver that connects to a Mojo service to evaluate
97 // PAC scripts. This implementation only knows about Mojo services, and 97 // PAC scripts. This implementation only knows about Mojo services, and
98 // therefore that service may live in or out of process. 98 // therefore that service may live in or out of process.
99 // 99 //
100 // This implementation reports disconnections from the Mojo service (i.e. if the 100 // This implementation reports disconnections from the Mojo service (i.e. if the
101 // service is out-of-process and that process crashes) using the error code 101 // service is out-of-process and that process crashes) using the error code
102 // ERR_PAC_SCRIPT_TERMINATED. 102 // ERR_PAC_SCRIPT_TERMINATED.
103 class ProxyResolverMojo : public ProxyResolver { 103 class ProxyResolverMojo : public ProxyResolver {
104 public: 104 public:
105 // Constructs a ProxyResolverMojo that connects to a mojo proxy resolver 105 // Constructs a ProxyResolverMojo that connects to a mojo proxy resolver
106 // implementation using |resolver_ptr|. The implementation uses 106 // implementation using |resolver_ptr|. The implementation uses
107 // |host_resolver| as the DNS resolver, using |host_resolver_binding| to 107 // |host_resolver| as the DNS resolver, using |host_resolver_binding| to
108 // communicate with it. When deleted, the closure contained within 108 // communicate with it. When deleted, the closure contained within
109 // |on_delete_callback_runner| will be run. 109 // |on_delete_callback_runner| will be run.
110 ProxyResolverMojo( 110 ProxyResolverMojo(
111 interfaces::ProxyResolverPtr resolver_ptr, 111 interfaces::ProxyResolverPtr resolver_ptr,
112 HostResolver* host_resolver, 112 HostResolver* host_resolver,
113 std::unique_ptr<base::ScopedClosureRunner> on_delete_callback_runner, 113 std::unique_ptr<base::ScopedClosureRunner> on_delete_callback_runner,
114 std::unique_ptr<ProxyResolverErrorObserver> error_observer, 114 std::unique_ptr<ProxyResolverErrorObserver> error_observer,
115 NetLog* net_log); 115 NetLog* net_log);
116 ~ProxyResolverMojo() override; 116 ~ProxyResolverMojo() override;
117 117
118 // ProxyResolver implementation: 118 // ProxyResolver implementation:
119 int GetProxyForURL(const GURL& url, 119 int GetProxyForURL(const GURL& url,
120 ProxyInfo* results, 120 ProxyInfo* results,
121 const net::CompletionCallback& callback, 121 const net::CompletionCallback& callback,
122 RequestHandle* request, 122 RequestHandle* request,
123 const BoundNetLog& net_log) override; 123 const NetLogWithSource& net_log) override;
124 void CancelRequest(RequestHandle request) override; 124 void CancelRequest(RequestHandle request) override;
125 LoadState GetLoadState(RequestHandle request) const override; 125 LoadState GetLoadState(RequestHandle request) const override;
126 126
127 private: 127 private:
128 class Job; 128 class Job;
129 129
130 // Mojo error handler. 130 // Mojo error handler.
131 void OnConnectionError(); 131 void OnConnectionError();
132 132
133 void RemoveJob(Job* job); 133 void RemoveJob(Job* job);
(...skipping 16 matching lines...) Expand all
150 DISALLOW_COPY_AND_ASSIGN(ProxyResolverMojo); 150 DISALLOW_COPY_AND_ASSIGN(ProxyResolverMojo);
151 }; 151 };
152 152
153 class ProxyResolverMojo::Job 153 class ProxyResolverMojo::Job
154 : public ClientMixin<interfaces::ProxyResolverRequestClient> { 154 : public ClientMixin<interfaces::ProxyResolverRequestClient> {
155 public: 155 public:
156 Job(ProxyResolverMojo* resolver, 156 Job(ProxyResolverMojo* resolver,
157 const GURL& url, 157 const GURL& url,
158 ProxyInfo* results, 158 ProxyInfo* results,
159 const CompletionCallback& callback, 159 const CompletionCallback& callback,
160 const BoundNetLog& net_log); 160 const NetLogWithSource& net_log);
161 ~Job() override; 161 ~Job() override;
162 162
163 // Cancels the job and prevents the callback from being run. 163 // Cancels the job and prevents the callback from being run.
164 void Cancel(); 164 void Cancel();
165 165
166 // Returns the LoadState of this job. 166 // Returns the LoadState of this job.
167 LoadState GetLoadState(); 167 LoadState GetLoadState();
168 168
169 private: 169 private:
170 // Mojo error handler. 170 // Mojo error handler.
(...skipping 10 matching lines...) Expand all
181 CompletionCallback callback_; 181 CompletionCallback callback_;
182 182
183 base::ThreadChecker thread_checker_; 183 base::ThreadChecker thread_checker_;
184 mojo::Binding<interfaces::ProxyResolverRequestClient> binding_; 184 mojo::Binding<interfaces::ProxyResolverRequestClient> binding_;
185 }; 185 };
186 186
187 ProxyResolverMojo::Job::Job(ProxyResolverMojo* resolver, 187 ProxyResolverMojo::Job::Job(ProxyResolverMojo* resolver,
188 const GURL& url, 188 const GURL& url,
189 ProxyInfo* results, 189 ProxyInfo* results,
190 const CompletionCallback& callback, 190 const CompletionCallback& callback,
191 const BoundNetLog& net_log) 191 const NetLogWithSource& net_log)
192 : ClientMixin<interfaces::ProxyResolverRequestClient>( 192 : ClientMixin<interfaces::ProxyResolverRequestClient>(
193 resolver->host_resolver_, 193 resolver->host_resolver_,
194 resolver->error_observer_.get(), 194 resolver->error_observer_.get(),
195 resolver->net_log_, 195 resolver->net_log_,
196 net_log), 196 net_log),
197 resolver_(resolver), 197 resolver_(resolver),
198 url_(url), 198 url_(url),
199 results_(results), 199 results_(results),
200 callback_(callback), 200 callback_(callback),
201 binding_(this) { 201 binding_(this) {
(...skipping 76 matching lines...) Expand 10 before | Expand all | Expand 10 after
278 DCHECK(thread_checker_.CalledOnValidThread()); 278 DCHECK(thread_checker_.CalledOnValidThread());
279 size_t num_erased = pending_jobs_.erase(job); 279 size_t num_erased = pending_jobs_.erase(job);
280 DCHECK(num_erased); 280 DCHECK(num_erased);
281 delete job; 281 delete job;
282 } 282 }
283 283
284 int ProxyResolverMojo::GetProxyForURL(const GURL& url, 284 int ProxyResolverMojo::GetProxyForURL(const GURL& url,
285 ProxyInfo* results, 285 ProxyInfo* results,
286 const CompletionCallback& callback, 286 const CompletionCallback& callback,
287 RequestHandle* request, 287 RequestHandle* request,
288 const BoundNetLog& net_log) { 288 const NetLogWithSource& net_log) {
289 DCHECK(thread_checker_.CalledOnValidThread()); 289 DCHECK(thread_checker_.CalledOnValidThread());
290 290
291 if (!mojo_proxy_resolver_ptr_) 291 if (!mojo_proxy_resolver_ptr_)
292 return ERR_PAC_SCRIPT_TERMINATED; 292 return ERR_PAC_SCRIPT_TERMINATED;
293 293
294 Job* job = new Job(this, url, results, callback, net_log); 294 Job* job = new Job(this, url, results, callback, net_log);
295 bool inserted = pending_jobs_.insert(job).second; 295 bool inserted = pending_jobs_.insert(job).second;
296 DCHECK(inserted); 296 DCHECK(inserted);
297 *request = job; 297 *request = job;
298 298
(...skipping 13 matching lines...) Expand all
312 CHECK_EQ(1u, pending_jobs_.count(job)); 312 CHECK_EQ(1u, pending_jobs_.count(job));
313 return job->GetLoadState(); 313 return job->GetLoadState();
314 } 314 }
315 315
316 } // namespace 316 } // namespace
317 317
318 // A Job to create a ProxyResolver instance. 318 // A Job to create a ProxyResolver instance.
319 // 319 //
320 // Note: a Job instance is not tied to a particular resolve request, and hence 320 // Note: a Job instance is not tied to a particular resolve request, and hence
321 // there is no per-request logging to be done (any netlog events are only sent 321 // there is no per-request logging to be done (any netlog events are only sent
322 // globally) so this always uses an empty BoundNetLog. 322 // globally) so this always uses an empty NetLogWithSource.
323 class ProxyResolverFactoryMojo::Job 323 class ProxyResolverFactoryMojo::Job
324 : public ClientMixin<interfaces::ProxyResolverFactoryRequestClient>, 324 : public ClientMixin<interfaces::ProxyResolverFactoryRequestClient>,
325 public ProxyResolverFactory::Request { 325 public ProxyResolverFactory::Request {
326 public: 326 public:
327 Job(ProxyResolverFactoryMojo* factory, 327 Job(ProxyResolverFactoryMojo* factory,
328 const scoped_refptr<ProxyResolverScriptData>& pac_script, 328 const scoped_refptr<ProxyResolverScriptData>& pac_script,
329 std::unique_ptr<ProxyResolver>* resolver, 329 std::unique_ptr<ProxyResolver>* resolver,
330 const CompletionCallback& callback, 330 const CompletionCallback& callback,
331 std::unique_ptr<ProxyResolverErrorObserver> error_observer) 331 std::unique_ptr<ProxyResolverErrorObserver> error_observer)
332 : ClientMixin<interfaces::ProxyResolverFactoryRequestClient>( 332 : ClientMixin<interfaces::ProxyResolverFactoryRequestClient>(
333 factory->host_resolver_, 333 factory->host_resolver_,
334 error_observer.get(), 334 error_observer.get(),
335 factory->net_log_, 335 factory->net_log_,
336 BoundNetLog()), 336 NetLogWithSource()),
337 factory_(factory), 337 factory_(factory),
338 resolver_(resolver), 338 resolver_(resolver),
339 callback_(callback), 339 callback_(callback),
340 binding_(this), 340 binding_(this),
341 error_observer_(std::move(error_observer)) { 341 error_observer_(std::move(error_observer)) {
342 on_delete_callback_runner_ = factory_->mojo_proxy_factory_->CreateResolver( 342 on_delete_callback_runner_ = factory_->mojo_proxy_factory_->CreateResolver(
343 mojo::String::From(pac_script->utf16()), mojo::GetProxy(&resolver_ptr_), 343 mojo::String::From(pac_script->utf16()), mojo::GetProxy(&resolver_ptr_),
344 binding_.CreateInterfacePtrAndBind()); 344 binding_.CreateInterfacePtrAndBind());
345 resolver_ptr_.set_connection_error_handler( 345 resolver_ptr_.set_connection_error_handler(
346 base::Bind(&ProxyResolverFactoryMojo::Job::OnConnectionError, 346 base::Bind(&ProxyResolverFactoryMojo::Job::OnConnectionError,
(...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after
401 return ERR_PAC_SCRIPT_FAILED; 401 return ERR_PAC_SCRIPT_FAILED;
402 } 402 }
403 request->reset(new Job(this, pac_script, resolver, callback, 403 request->reset(new Job(this, pac_script, resolver, callback,
404 error_observer_factory_.is_null() 404 error_observer_factory_.is_null()
405 ? nullptr 405 ? nullptr
406 : error_observer_factory_.Run())); 406 : error_observer_factory_.Run()));
407 return ERR_IO_PENDING; 407 return ERR_IO_PENDING;
408 } 408 }
409 409
410 } // namespace net 410 } // namespace net
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698