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

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

Issue 2299963002: Reland "Change ProxyResolver::GetProxyForURL() to take a unique_ptr<Request>* " (Closed)
Patch Set: remove fields proposed by eroman 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 | « net/proxy/proxy_resolver_v8_tracing.h ('k') | net/proxy/proxy_resolver_v8_tracing_unittest.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2013 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2013 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_v8_tracing.h" 5 #include "net/proxy/proxy_resolver_v8_tracing.h"
6 6
7 #include <map> 7 #include <map>
8 #include <string> 8 #include <string>
9 #include <utility> 9 #include <utility>
10 #include <vector> 10 #include <vector>
(...skipping 296 matching lines...) Expand 10 before | Expand all | Expand 10 after
307 ProxyResolverV8TracingImpl(std::unique_ptr<base::Thread> thread, 307 ProxyResolverV8TracingImpl(std::unique_ptr<base::Thread> thread,
308 std::unique_ptr<ProxyResolverV8> resolver, 308 std::unique_ptr<ProxyResolverV8> resolver,
309 std::unique_ptr<Job::Params> job_params); 309 std::unique_ptr<Job::Params> job_params);
310 310
311 ~ProxyResolverV8TracingImpl() override; 311 ~ProxyResolverV8TracingImpl() override;
312 312
313 // ProxyResolverV8Tracing overrides. 313 // ProxyResolverV8Tracing overrides.
314 void GetProxyForURL(const GURL& url, 314 void GetProxyForURL(const GURL& url,
315 ProxyInfo* results, 315 ProxyInfo* results,
316 const CompletionCallback& callback, 316 const CompletionCallback& callback,
317 ProxyResolver::RequestHandle* request, 317 std::unique_ptr<ProxyResolver::Request>* request,
318 std::unique_ptr<Bindings> bindings) override; 318 std::unique_ptr<Bindings> bindings) override;
319 void CancelRequest(ProxyResolver::RequestHandle request) override; 319
320 LoadState GetLoadState(ProxyResolver::RequestHandle request) const override; 320 class RequestImpl : public ProxyResolver::Request {
321 public:
322 explicit RequestImpl(scoped_refptr<Job> job);
323 ~RequestImpl() override;
324 LoadState GetLoadState() override;
325
326 private:
327 scoped_refptr<Job> job_;
328 };
321 329
322 private: 330 private:
323 // The worker thread on which the ProxyResolverV8 will be run. 331 // The worker thread on which the ProxyResolverV8 will be run.
324 std::unique_ptr<base::Thread> thread_; 332 std::unique_ptr<base::Thread> thread_;
325 std::unique_ptr<ProxyResolverV8> v8_resolver_; 333 std::unique_ptr<ProxyResolverV8> v8_resolver_;
326 334
327 std::unique_ptr<Job::Params> job_params_; 335 std::unique_ptr<Job::Params> job_params_;
328 336
329 // The number of outstanding (non-cancelled) jobs. 337 // The number of outstanding (non-cancelled) jobs.
330 int num_outstanding_callbacks_; 338 int num_outstanding_callbacks_;
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after
379 // (b) The script is executing on the worker thread. 387 // (b) The script is executing on the worker thread.
380 // (c) The script is executing on the worker thread, however is blocked inside 388 // (c) The script is executing on the worker thread, however is blocked inside
381 // of dnsResolve() waiting for a response from the origin thread. 389 // of dnsResolve() waiting for a response from the origin thread.
382 // (d) Nothing is running on the worker thread, however the host resolver has 390 // (d) Nothing is running on the worker thread, however the host resolver has
383 // a pending DNS request which upon completion will restart the script 391 // a pending DNS request which upon completion will restart the script
384 // execution. 392 // execution.
385 // (e) The worker thread has a pending task to restart execution, which was 393 // (e) The worker thread has a pending task to restart execution, which was
386 // posted after the DNS dependency was resolved and saved to local cache. 394 // posted after the DNS dependency was resolved and saved to local cache.
387 // (f) The script execution completed entirely, and posted a task to the 395 // (f) The script execution completed entirely, and posted a task to the
388 // origin thread to notify the caller. 396 // origin thread to notify the caller.
397 // (g) The job is already completed.
389 // 398 //
390 // |cancelled_| is read on both the origin thread and worker thread. The 399 // |cancelled_| is read on both the origin thread and worker thread. The
391 // code that runs on the worker thread is littered with checks on 400 // code that runs on the worker thread is littered with checks on
392 // |cancelled_| to break out early. 401 // |cancelled_| to break out early.
402
403 // If the job already completed, there is nothing to be cancelled.
404 if (callback_.is_null())
405 return;
406
393 cancelled_.Set(); 407 cancelled_.Set();
394 408
395 ReleaseCallback(); 409 ReleaseCallback();
396 410
397 pending_dns_.reset(); 411 pending_dns_.reset();
398 412
399 // The worker thread might be blocked waiting for DNS. 413 // The worker thread might be blocked waiting for DNS.
400 event_.Signal(); 414 event_.Signal();
401 415
402 bindings_.reset(); 416 bindings_.reset();
(...skipping 525 matching lines...) Expand 10 before | Expand all | Expand 10 after
928 942
929 ProxyResolverV8TracingImpl::~ProxyResolverV8TracingImpl() { 943 ProxyResolverV8TracingImpl::~ProxyResolverV8TracingImpl() {
930 // Note, all requests should have been cancelled. 944 // Note, all requests should have been cancelled.
931 CHECK_EQ(0, num_outstanding_callbacks_); 945 CHECK_EQ(0, num_outstanding_callbacks_);
932 946
933 // Join the worker thread. See http://crbug.com/69710. 947 // Join the worker thread. See http://crbug.com/69710.
934 base::ThreadRestrictions::ScopedAllowIO allow_io; 948 base::ThreadRestrictions::ScopedAllowIO allow_io;
935 thread_.reset(); 949 thread_.reset();
936 } 950 }
937 951
952 ProxyResolverV8TracingImpl::RequestImpl::RequestImpl(scoped_refptr<Job> job)
953 : job_(std::move(job)) {}
954
955 ProxyResolverV8TracingImpl::RequestImpl::~RequestImpl() {
956 job_->Cancel();
957 }
958
959 LoadState ProxyResolverV8TracingImpl::RequestImpl::GetLoadState() {
960 return job_->GetLoadState();
961 }
962
938 void ProxyResolverV8TracingImpl::GetProxyForURL( 963 void ProxyResolverV8TracingImpl::GetProxyForURL(
939 const GURL& url, 964 const GURL& url,
940 ProxyInfo* results, 965 ProxyInfo* results,
941 const CompletionCallback& callback, 966 const CompletionCallback& callback,
942 ProxyResolver::RequestHandle* request, 967 std::unique_ptr<ProxyResolver::Request>* request,
943 std::unique_ptr<Bindings> bindings) { 968 std::unique_ptr<Bindings> bindings) {
944 DCHECK(CalledOnValidThread()); 969 DCHECK(CalledOnValidThread());
945 DCHECK(!callback.is_null()); 970 DCHECK(!callback.is_null());
946 971
947 scoped_refptr<Job> job = new Job(job_params_.get(), std::move(bindings)); 972 scoped_refptr<Job> job = new Job(job_params_.get(), std::move(bindings));
948 973
949 if (request) 974 request->reset(new RequestImpl(job));
950 *request = job.get();
951 975
952 job->StartGetProxyForURL(url, results, callback); 976 job->StartGetProxyForURL(url, results, callback);
953 } 977 }
954 978
955 void ProxyResolverV8TracingImpl::CancelRequest(
956 ProxyResolver::RequestHandle request) {
957 Job* job = reinterpret_cast<Job*>(request);
958 job->Cancel();
959 }
960
961 LoadState ProxyResolverV8TracingImpl::GetLoadState(
962 ProxyResolver::RequestHandle request) const {
963 Job* job = reinterpret_cast<Job*>(request);
964 return job->GetLoadState();
965 }
966 979
967 class ProxyResolverV8TracingFactoryImpl : public ProxyResolverV8TracingFactory { 980 class ProxyResolverV8TracingFactoryImpl : public ProxyResolverV8TracingFactory {
968 public: 981 public:
969 ProxyResolverV8TracingFactoryImpl(); 982 ProxyResolverV8TracingFactoryImpl();
970 ~ProxyResolverV8TracingFactoryImpl() override; 983 ~ProxyResolverV8TracingFactoryImpl() override;
971 984
972 void CreateProxyResolverV8Tracing( 985 void CreateProxyResolverV8Tracing(
973 const scoped_refptr<ProxyResolverScriptData>& pac_script, 986 const scoped_refptr<ProxyResolverScriptData>& pac_script,
974 std::unique_ptr<ProxyResolverV8Tracing::Bindings> bindings, 987 std::unique_ptr<ProxyResolverV8Tracing::Bindings> bindings,
975 std::unique_ptr<ProxyResolverV8Tracing>* resolver, 988 std::unique_ptr<ProxyResolverV8Tracing>* resolver,
(...skipping 118 matching lines...) Expand 10 before | Expand all | Expand 10 after
1094 1107
1095 } // namespace 1108 } // namespace
1096 1109
1097 // static 1110 // static
1098 std::unique_ptr<ProxyResolverV8TracingFactory> 1111 std::unique_ptr<ProxyResolverV8TracingFactory>
1099 ProxyResolverV8TracingFactory::Create() { 1112 ProxyResolverV8TracingFactory::Create() {
1100 return base::WrapUnique(new ProxyResolverV8TracingFactoryImpl()); 1113 return base::WrapUnique(new ProxyResolverV8TracingFactoryImpl());
1101 } 1114 }
1102 1115
1103 } // namespace net 1116 } // namespace net
OLDNEW
« no previous file with comments | « net/proxy/proxy_resolver_v8_tracing.h ('k') | net/proxy/proxy_resolver_v8_tracing_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698