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

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

Issue 1545233002: Convert Pass()→std::move() in //net (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 4 years, 12 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.cc ('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 <vector> 10 #include <vector>
10 11
11 #include "base/bind.h" 12 #include "base/bind.h"
12 #include "base/macros.h" 13 #include "base/macros.h"
13 #include "base/single_thread_task_runner.h" 14 #include "base/single_thread_task_runner.h"
14 #include "base/strings/stringprintf.h" 15 #include "base/strings/stringprintf.h"
15 #include "base/synchronization/cancellation_flag.h" 16 #include "base/synchronization/cancellation_flag.h"
16 #include "base/synchronization/waitable_event.h" 17 #include "base/synchronization/waitable_event.h"
17 #include "base/thread_task_runner_handle.h" 18 #include "base/thread_task_runner_handle.h"
18 #include "base/threading/thread.h" 19 #include "base/threading/thread.h"
(...skipping 306 matching lines...) Expand 10 before | Expand all | Expand 10 after
325 // The number of outstanding (non-cancelled) jobs. 326 // The number of outstanding (non-cancelled) jobs.
326 int num_outstanding_callbacks_; 327 int num_outstanding_callbacks_;
327 328
328 DISALLOW_COPY_AND_ASSIGN(ProxyResolverV8TracingImpl); 329 DISALLOW_COPY_AND_ASSIGN(ProxyResolverV8TracingImpl);
329 }; 330 };
330 331
331 Job::Job(const Job::Params* params, 332 Job::Job(const Job::Params* params,
332 scoped_ptr<ProxyResolverV8Tracing::Bindings> bindings) 333 scoped_ptr<ProxyResolverV8Tracing::Bindings> bindings)
333 : origin_runner_(base::ThreadTaskRunnerHandle::Get()), 334 : origin_runner_(base::ThreadTaskRunnerHandle::Get()),
334 params_(params), 335 params_(params),
335 bindings_(bindings.Pass()), 336 bindings_(std::move(bindings)),
336 event_(true, false), 337 event_(true, false),
337 last_num_dns_(0), 338 last_num_dns_(0),
338 pending_dns_(NULL) { 339 pending_dns_(NULL) {
339 CheckIsOnOriginThread(); 340 CheckIsOnOriginThread();
340 } 341 }
341 342
342 void Job::StartCreateV8Resolver( 343 void Job::StartCreateV8Resolver(
343 const scoped_refptr<ProxyResolverScriptData>& script_data, 344 const scoped_refptr<ProxyResolverScriptData>& script_data,
344 scoped_ptr<ProxyResolverV8>* resolver, 345 scoped_ptr<ProxyResolverV8>* resolver,
345 const CompletionCallback& callback) { 346 const CompletionCallback& callback) {
(...skipping 201 matching lines...) Expand 10 before | Expand all | Expand 10 after
547 } 548 }
548 549
549 int Job::ExecuteProxyResolver() { 550 int Job::ExecuteProxyResolver() {
550 int result = ERR_UNEXPECTED; // Initialized to silence warnings. 551 int result = ERR_UNEXPECTED; // Initialized to silence warnings.
551 552
552 switch (operation_) { 553 switch (operation_) {
553 case CREATE_V8_RESOLVER: { 554 case CREATE_V8_RESOLVER: {
554 scoped_ptr<ProxyResolverV8> resolver; 555 scoped_ptr<ProxyResolverV8> resolver;
555 result = ProxyResolverV8::Create(script_data_, this, &resolver); 556 result = ProxyResolverV8::Create(script_data_, this, &resolver);
556 if (result == OK) 557 if (result == OK)
557 *resolver_out_ = resolver.Pass(); 558 *resolver_out_ = std::move(resolver);
558 break; 559 break;
559 } 560 }
560 case GET_PROXY_FOR_URL: { 561 case GET_PROXY_FOR_URL: {
561 result = v8_resolver()->GetProxyForURL( 562 result = v8_resolver()->GetProxyForURL(
562 url_, 563 url_,
563 // Important: Do not write directly into |user_results_|, since if the 564 // Important: Do not write directly into |user_results_|, since if the
564 // request were to be cancelled from the origin thread, must guarantee 565 // request were to be cancelled from the origin thread, must guarantee
565 // that |user_results_| is not accessed anymore. 566 // that |user_results_| is not accessed anymore.
566 &results_, this); 567 &results_, this);
567 break; 568 break;
(...skipping 342 matching lines...) Expand 10 before | Expand all | Expand 10 after
910 VLOG(1) << "PAC-error: " << "line: " << line_number << ": " << message; 911 VLOG(1) << "PAC-error: " << "line: " << line_number << ": " << message;
911 912
912 bindings_->OnError(line_number, message); 913 bindings_->OnError(line_number, message);
913 } 914 }
914 } 915 }
915 916
916 ProxyResolverV8TracingImpl::ProxyResolverV8TracingImpl( 917 ProxyResolverV8TracingImpl::ProxyResolverV8TracingImpl(
917 scoped_ptr<base::Thread> thread, 918 scoped_ptr<base::Thread> thread,
918 scoped_ptr<ProxyResolverV8> resolver, 919 scoped_ptr<ProxyResolverV8> resolver,
919 scoped_ptr<Job::Params> job_params) 920 scoped_ptr<Job::Params> job_params)
920 : thread_(thread.Pass()), 921 : thread_(std::move(thread)),
921 v8_resolver_(resolver.Pass()), 922 v8_resolver_(std::move(resolver)),
922 job_params_(job_params.Pass()), 923 job_params_(std::move(job_params)),
923 num_outstanding_callbacks_(0) { 924 num_outstanding_callbacks_(0) {
924 job_params_->num_outstanding_callbacks = &num_outstanding_callbacks_; 925 job_params_->num_outstanding_callbacks = &num_outstanding_callbacks_;
925 } 926 }
926 927
927 ProxyResolverV8TracingImpl::~ProxyResolverV8TracingImpl() { 928 ProxyResolverV8TracingImpl::~ProxyResolverV8TracingImpl() {
928 // Note, all requests should have been cancelled. 929 // Note, all requests should have been cancelled.
929 CHECK_EQ(0, num_outstanding_callbacks_); 930 CHECK_EQ(0, num_outstanding_callbacks_);
930 931
931 // Join the worker thread. See http://crbug.com/69710. 932 // Join the worker thread. See http://crbug.com/69710.
932 base::ThreadRestrictions::ScopedAllowIO allow_io; 933 base::ThreadRestrictions::ScopedAllowIO allow_io;
933 thread_.reset(); 934 thread_.reset();
934 } 935 }
935 936
936 void ProxyResolverV8TracingImpl::GetProxyForURL( 937 void ProxyResolverV8TracingImpl::GetProxyForURL(
937 const GURL& url, 938 const GURL& url,
938 ProxyInfo* results, 939 ProxyInfo* results,
939 const CompletionCallback& callback, 940 const CompletionCallback& callback,
940 ProxyResolver::RequestHandle* request, 941 ProxyResolver::RequestHandle* request,
941 scoped_ptr<Bindings> bindings) { 942 scoped_ptr<Bindings> bindings) {
942 DCHECK(CalledOnValidThread()); 943 DCHECK(CalledOnValidThread());
943 DCHECK(!callback.is_null()); 944 DCHECK(!callback.is_null());
944 945
945 scoped_refptr<Job> job = new Job(job_params_.get(), bindings.Pass()); 946 scoped_refptr<Job> job = new Job(job_params_.get(), std::move(bindings));
946 947
947 if (request) 948 if (request)
948 *request = job.get(); 949 *request = job.get();
949 950
950 job->StartGetProxyForURL(url, results, callback); 951 job->StartGetProxyForURL(url, results, callback);
951 } 952 }
952 953
953 void ProxyResolverV8TracingImpl::CancelRequest( 954 void ProxyResolverV8TracingImpl::CancelRequest(
954 ProxyResolver::RequestHandle request) { 955 ProxyResolver::RequestHandle request) {
955 Job* job = reinterpret_cast<Job*>(request); 956 Job* job = reinterpret_cast<Job*>(request);
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after
996 thread_(new base::Thread("Proxy Resolver")), 997 thread_(new base::Thread("Proxy Resolver")),
997 resolver_out_(resolver_out), 998 resolver_out_(resolver_out),
998 callback_(callback), 999 callback_(callback),
999 num_outstanding_callbacks_(0) { 1000 num_outstanding_callbacks_(0) {
1000 // Start up the thread. 1001 // Start up the thread.
1001 base::Thread::Options options; 1002 base::Thread::Options options;
1002 options.timer_slack = base::TIMER_SLACK_MAXIMUM; 1003 options.timer_slack = base::TIMER_SLACK_MAXIMUM;
1003 CHECK(thread_->StartWithOptions(options)); 1004 CHECK(thread_->StartWithOptions(options));
1004 job_params_.reset( 1005 job_params_.reset(
1005 new Job::Params(thread_->task_runner(), &num_outstanding_callbacks_)); 1006 new Job::Params(thread_->task_runner(), &num_outstanding_callbacks_));
1006 create_resolver_job_ = new Job(job_params_.get(), bindings.Pass()); 1007 create_resolver_job_ = new Job(job_params_.get(), std::move(bindings));
1007 create_resolver_job_->StartCreateV8Resolver( 1008 create_resolver_job_->StartCreateV8Resolver(
1008 pac_script, &v8_resolver_, 1009 pac_script, &v8_resolver_,
1009 base::Bind( 1010 base::Bind(
1010 &ProxyResolverV8TracingFactoryImpl::CreateJob::OnV8ResolverCreated, 1011 &ProxyResolverV8TracingFactoryImpl::CreateJob::OnV8ResolverCreated,
1011 base::Unretained(this))); 1012 base::Unretained(this)));
1012 } 1013 }
1013 1014
1014 ~CreateJob() override { 1015 ~CreateJob() override {
1015 if (factory_) { 1016 if (factory_) {
1016 factory_->RemoveJob(this); 1017 factory_->RemoveJob(this);
(...skipping 10 matching lines...) Expand all
1027 create_resolver_job_ = nullptr; 1028 create_resolver_job_ = nullptr;
1028 StopWorkerThread(); 1029 StopWorkerThread();
1029 } 1030 }
1030 1031
1031 private: 1032 private:
1032 void OnV8ResolverCreated(int error) { 1033 void OnV8ResolverCreated(int error) {
1033 DCHECK(factory_); 1034 DCHECK(factory_);
1034 if (error == OK) { 1035 if (error == OK) {
1035 job_params_->v8_resolver = v8_resolver_.get(); 1036 job_params_->v8_resolver = v8_resolver_.get();
1036 resolver_out_->reset(new ProxyResolverV8TracingImpl( 1037 resolver_out_->reset(new ProxyResolverV8TracingImpl(
1037 thread_.Pass(), v8_resolver_.Pass(), job_params_.Pass())); 1038 std::move(thread_), std::move(v8_resolver_), std::move(job_params_)));
1038 } else { 1039 } else {
1039 StopWorkerThread(); 1040 StopWorkerThread();
1040 } 1041 }
1041 1042
1042 factory_->RemoveJob(this); 1043 factory_->RemoveJob(this);
1043 factory_ = nullptr; 1044 factory_ = nullptr;
1044 create_resolver_job_ = nullptr; 1045 create_resolver_job_ = nullptr;
1045 callback_.Run(error); 1046 callback_.Run(error);
1046 } 1047 }
1047 1048
(...skipping 24 matching lines...) Expand all
1072 } 1073 }
1073 } 1074 }
1074 1075
1075 void ProxyResolverV8TracingFactoryImpl::CreateProxyResolverV8Tracing( 1076 void ProxyResolverV8TracingFactoryImpl::CreateProxyResolverV8Tracing(
1076 const scoped_refptr<ProxyResolverScriptData>& pac_script, 1077 const scoped_refptr<ProxyResolverScriptData>& pac_script,
1077 scoped_ptr<ProxyResolverV8Tracing::Bindings> bindings, 1078 scoped_ptr<ProxyResolverV8Tracing::Bindings> bindings,
1078 scoped_ptr<ProxyResolverV8Tracing>* resolver, 1079 scoped_ptr<ProxyResolverV8Tracing>* resolver,
1079 const CompletionCallback& callback, 1080 const CompletionCallback& callback,
1080 scoped_ptr<ProxyResolverFactory::Request>* request) { 1081 scoped_ptr<ProxyResolverFactory::Request>* request) {
1081 scoped_ptr<CreateJob> job( 1082 scoped_ptr<CreateJob> job(
1082 new CreateJob(this, bindings.Pass(), pac_script, resolver, callback)); 1083 new CreateJob(this, std::move(bindings), pac_script, resolver, callback));
1083 jobs_.insert(job.get()); 1084 jobs_.insert(job.get());
1084 *request = job.Pass(); 1085 *request = std::move(job);
1085 } 1086 }
1086 1087
1087 void ProxyResolverV8TracingFactoryImpl::RemoveJob( 1088 void ProxyResolverV8TracingFactoryImpl::RemoveJob(
1088 ProxyResolverV8TracingFactoryImpl::CreateJob* job) { 1089 ProxyResolverV8TracingFactoryImpl::CreateJob* job) {
1089 size_t erased = jobs_.erase(job); 1090 size_t erased = jobs_.erase(job);
1090 DCHECK_EQ(1u, erased); 1091 DCHECK_EQ(1u, erased);
1091 } 1092 }
1092 1093
1093 } // namespace 1094 } // namespace
1094 1095
1095 // static 1096 // static
1096 scoped_ptr<ProxyResolverV8TracingFactory> 1097 scoped_ptr<ProxyResolverV8TracingFactory>
1097 ProxyResolverV8TracingFactory::Create() { 1098 ProxyResolverV8TracingFactory::Create() {
1098 return make_scoped_ptr(new ProxyResolverV8TracingFactoryImpl()); 1099 return make_scoped_ptr(new ProxyResolverV8TracingFactoryImpl());
1099 } 1100 }
1100 1101
1101 } // namespace net 1102 } // namespace net
OLDNEW
« no previous file with comments | « net/proxy/proxy_resolver_v8.cc ('k') | net/proxy/proxy_resolver_v8_tracing_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698