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

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

Issue 1439053002: Change ProxyResolver::GetProxyForURL() to take a scoped_ptr<Request>* rather than a RequestHandle* (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Restore refptr due windows error Created 4 years, 10 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) 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 293 matching lines...) Expand 10 before | Expand all | Expand 10 after
304 ProxyResolverV8TracingImpl(scoped_ptr<base::Thread> thread, 304 ProxyResolverV8TracingImpl(scoped_ptr<base::Thread> thread,
305 scoped_ptr<ProxyResolverV8> resolver, 305 scoped_ptr<ProxyResolverV8> resolver,
306 scoped_ptr<Job::Params> job_params); 306 scoped_ptr<Job::Params> job_params);
307 307
308 ~ProxyResolverV8TracingImpl() override; 308 ~ProxyResolverV8TracingImpl() override;
309 309
310 // ProxyResolverV8Tracing overrides. 310 // ProxyResolverV8Tracing overrides.
311 void GetProxyForURL(const GURL& url, 311 void GetProxyForURL(const GURL& url,
312 ProxyInfo* results, 312 ProxyInfo* results,
313 const CompletionCallback& callback, 313 const CompletionCallback& callback,
314 ProxyResolver::RequestHandle* request, 314 scoped_ptr<ProxyResolver::Request>* request,
315 scoped_ptr<Bindings> bindings) override; 315 scoped_ptr<Bindings> bindings) override;
316 void CancelRequest(ProxyResolver::RequestHandle request) override; 316
317 LoadState GetLoadState(ProxyResolver::RequestHandle request) const override; 317 class RequestImpl : public ProxyResolverV8Tracing::Request {
318 public:
319 RequestImpl(scoped_refptr<Job> job);
eroman 2016/02/24 03:08:07 explicit
320 ~RequestImpl() override;
321 LoadState GetLoadState() override;
322
323 private:
324 scoped_refptr<Job> job_;
325 };
318 326
319 private: 327 private:
320 // The worker thread on which the ProxyResolverV8 will be run. 328 // The worker thread on which the ProxyResolverV8 will be run.
321 scoped_ptr<base::Thread> thread_; 329 scoped_ptr<base::Thread> thread_;
322 scoped_ptr<ProxyResolverV8> v8_resolver_; 330 scoped_ptr<ProxyResolverV8> v8_resolver_;
323 331
324 scoped_ptr<Job::Params> job_params_; 332 scoped_ptr<Job::Params> job_params_;
325 333
326 // The number of outstanding (non-cancelled) jobs. 334 // The number of outstanding (non-cancelled) jobs.
327 int num_outstanding_callbacks_; 335 int num_outstanding_callbacks_;
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after
374 // (a) The job has been posted to the worker thread, however script execution 382 // (a) The job has been posted to the worker thread, however script execution
375 // has not yet started. 383 // has not yet started.
376 // (b) The script is executing on the worker thread. 384 // (b) The script is executing on the worker thread.
377 // (c) The script is executing on the worker thread, however is blocked inside 385 // (c) The script is executing on the worker thread, however is blocked inside
378 // of dnsResolve() waiting for a response from the origin thread. 386 // of dnsResolve() waiting for a response from the origin thread.
379 // (d) Nothing is running on the worker thread, however the host resolver has 387 // (d) Nothing is running on the worker thread, however the host resolver has
380 // a pending DNS request which upon completion will restart the script 388 // a pending DNS request which upon completion will restart the script
381 // execution. 389 // execution.
382 // (e) The worker thread has a pending task to restart execution, which was 390 // (e) The worker thread has a pending task to restart execution, which was
383 // posted after the DNS dependency was resolved and saved to local cache. 391 // posted after the DNS dependency was resolved and saved to local cache.
384 // (f) The script execution completed entirely, and posted a task to the 392 // (f) The script execution completed entirely, and posted a task to the
eroman 2016/02/24 03:08:07 There is another possibility - that the job alread
385 // origin thread to notify the caller. 393 // origin thread to notify the caller.
386 // 394 //
387 // |cancelled_| is read on both the origin thread and worker thread. The 395 // |cancelled_| is read on both the origin thread and worker thread. The
388 // code that runs on the worker thread is littered with checks on 396 // code that runs on the worker thread is littered with checks on
389 // |cancelled_| to break out early. 397 // |cancelled_| to break out early.
390 cancelled_.Set(); 398 cancelled_.Set();
391 399
392 ReleaseCallback(); 400 ReleaseCallback();
393 401
394 if (pending_dns_) { 402 if (pending_dns_) {
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after
427 } 435 }
428 436
429 void Job::SetCallback(const CompletionCallback& callback) { 437 void Job::SetCallback(const CompletionCallback& callback) {
430 CheckIsOnOriginThread(); 438 CheckIsOnOriginThread();
431 DCHECK(callback_.is_null()); 439 DCHECK(callback_.is_null());
432 (*params_->num_outstanding_callbacks)++; 440 (*params_->num_outstanding_callbacks)++;
433 callback_ = callback; 441 callback_ = callback;
434 } 442 }
435 443
436 void Job::ReleaseCallback() { 444 void Job::ReleaseCallback() {
445 if (callback_.is_null())
eroman 2016/02/24 03:08:07 I don't think this change should go here. (I pres
446 return;
437 CheckIsOnOriginThread(); 447 CheckIsOnOriginThread();
438 DCHECK(!callback_.is_null()); 448 DCHECK(!callback_.is_null());
439 CHECK_GT(*params_->num_outstanding_callbacks, 0); 449 CHECK_GT(*params_->num_outstanding_callbacks, 0);
440 (*params_->num_outstanding_callbacks)--; 450 (*params_->num_outstanding_callbacks)--;
441 callback_.Reset(); 451 callback_.Reset();
442 452
443 // For good measure, clear this other user-owned pointer. 453 // For good measure, clear this other user-owned pointer.
444 user_results_ = NULL; 454 user_results_ = NULL;
445 } 455 }
446 456
(...skipping 480 matching lines...) Expand 10 before | Expand all | Expand 10 after
927 937
928 ProxyResolverV8TracingImpl::~ProxyResolverV8TracingImpl() { 938 ProxyResolverV8TracingImpl::~ProxyResolverV8TracingImpl() {
929 // Note, all requests should have been cancelled. 939 // Note, all requests should have been cancelled.
930 CHECK_EQ(0, num_outstanding_callbacks_); 940 CHECK_EQ(0, num_outstanding_callbacks_);
931 941
932 // Join the worker thread. See http://crbug.com/69710. 942 // Join the worker thread. See http://crbug.com/69710.
933 base::ThreadRestrictions::ScopedAllowIO allow_io; 943 base::ThreadRestrictions::ScopedAllowIO allow_io;
934 thread_.reset(); 944 thread_.reset();
935 } 945 }
936 946
947 ProxyResolverV8TracingImpl::RequestImpl::RequestImpl(scoped_refptr<Job> job)
948 : job_(job) {}
eroman 2016/02/24 03:08:07 std::move()
949
950 ProxyResolverV8TracingImpl::RequestImpl::~RequestImpl() {
951 job_->Cancel();
952 }
953
954 LoadState ProxyResolverV8TracingImpl::RequestImpl::GetLoadState() {
955 return job_->GetLoadState();
956 }
957
937 void ProxyResolverV8TracingImpl::GetProxyForURL( 958 void ProxyResolverV8TracingImpl::GetProxyForURL(
938 const GURL& url, 959 const GURL& url,
939 ProxyInfo* results, 960 ProxyInfo* results,
940 const CompletionCallback& callback, 961 const CompletionCallback& callback,
941 ProxyResolver::RequestHandle* request, 962 scoped_ptr<ProxyResolver::Request>* request,
942 scoped_ptr<Bindings> bindings) { 963 scoped_ptr<Bindings> bindings) {
943 DCHECK(CalledOnValidThread()); 964 DCHECK(CalledOnValidThread());
944 DCHECK(!callback.is_null()); 965 DCHECK(!callback.is_null());
945 966
946 scoped_refptr<Job> job = new Job(job_params_.get(), std::move(bindings)); 967 scoped_refptr<Job> job = new Job(job_params_.get(), std::move(bindings));
947 968
948 if (request) 969 request->reset(new RequestImpl(job));
eroman 2016/02/24 03:08:06 Was this intentionally removed? If nothing depends
eroman 2016/02/24 19:20:29 This comment was not addressed.
949 *request = job.get();
950 970
951 job->StartGetProxyForURL(url, results, callback); 971 job->StartGetProxyForURL(url, results, callback);
952 } 972 }
953 973
954 void ProxyResolverV8TracingImpl::CancelRequest(
955 ProxyResolver::RequestHandle request) {
956 Job* job = reinterpret_cast<Job*>(request);
957 job->Cancel();
958 }
959
960 LoadState ProxyResolverV8TracingImpl::GetLoadState(
961 ProxyResolver::RequestHandle request) const {
962 Job* job = reinterpret_cast<Job*>(request);
963 return job->GetLoadState();
964 }
965 974
966 class ProxyResolverV8TracingFactoryImpl : public ProxyResolverV8TracingFactory { 975 class ProxyResolverV8TracingFactoryImpl : public ProxyResolverV8TracingFactory {
967 public: 976 public:
968 ProxyResolverV8TracingFactoryImpl(); 977 ProxyResolverV8TracingFactoryImpl();
969 ~ProxyResolverV8TracingFactoryImpl() override; 978 ~ProxyResolverV8TracingFactoryImpl() override;
970 979
971 void CreateProxyResolverV8Tracing( 980 void CreateProxyResolverV8Tracing(
972 const scoped_refptr<ProxyResolverScriptData>& pac_script, 981 const scoped_refptr<ProxyResolverScriptData>& pac_script,
973 scoped_ptr<ProxyResolverV8Tracing::Bindings> bindings, 982 scoped_ptr<ProxyResolverV8Tracing::Bindings> bindings,
974 scoped_ptr<ProxyResolverV8Tracing>* resolver, 983 scoped_ptr<ProxyResolverV8Tracing>* resolver,
(...skipping 118 matching lines...) Expand 10 before | Expand all | Expand 10 after
1093 1102
1094 } // namespace 1103 } // namespace
1095 1104
1096 // static 1105 // static
1097 scoped_ptr<ProxyResolverV8TracingFactory> 1106 scoped_ptr<ProxyResolverV8TracingFactory>
1098 ProxyResolverV8TracingFactory::Create() { 1107 ProxyResolverV8TracingFactory::Create() {
1099 return make_scoped_ptr(new ProxyResolverV8TracingFactoryImpl()); 1108 return make_scoped_ptr(new ProxyResolverV8TracingFactoryImpl());
1100 } 1109 }
1101 1110
1102 } // namespace net 1111 } // namespace net
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698