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

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

Issue 1069483003: Handle ERR_PAC_SCRIPT_TERMINATED in ProxyService. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 5 years, 8 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_mojo.h" 5 #include "net/proxy/proxy_resolver_mojo.h"
6 6
7 #include "base/bind.h" 7 #include "base/bind.h"
8 #include "base/logging.h" 8 #include "base/logging.h"
9 #include "base/stl_util.h" 9 #include "base/stl_util.h"
10 #include "mojo/common/common_type_converters.h" 10 #include "mojo/common/common_type_converters.h"
(...skipping 82 matching lines...) Expand 10 before | Expand all | Expand 10 after
93 int32_t error, 93 int32_t error,
94 mojo::Array<interfaces::ProxyServerPtr> proxy_servers) { 94 mojo::Array<interfaces::ProxyServerPtr> proxy_servers) {
95 DCHECK(thread_checker_.CalledOnValidThread()); 95 DCHECK(thread_checker_.CalledOnValidThread());
96 DVLOG(1) << "ProxyResolverMojo::Job::ReportResult: " << error; 96 DVLOG(1) << "ProxyResolverMojo::Job::ReportResult: " << error;
97 97
98 if (error == OK) { 98 if (error == OK) {
99 *results_ = proxy_servers.To<ProxyInfo>(); 99 *results_ = proxy_servers.To<ProxyInfo>();
100 DVLOG(1) << "Servers: " << results_->ToPacString(); 100 DVLOG(1) << "Servers: " << results_->ToPacString();
101 } 101 }
102 102
103 callback_.Run(error); 103 CompletionCallback callback = callback_;
104 callback_.Reset(); 104 callback_.Reset();
105 resolver_->RemoveJob(this); 105 resolver_->RemoveJob(this);
106 callback.Run(error);
106 } 107 }
107 108
108 void ProxyResolverMojo::Job::LoadStateChanged(int32_t load_state) { 109 void ProxyResolverMojo::Job::LoadStateChanged(int32_t load_state) {
109 load_state_ = static_cast<LoadState>(load_state); 110 load_state_ = static_cast<LoadState>(load_state);
110 } 111 }
111 112
112 ProxyResolverMojo::ProxyResolverMojo( 113 ProxyResolverMojo::ProxyResolverMojo(
113 MojoProxyResolverFactory* mojo_proxy_resolver_factory, 114 MojoProxyResolverFactory* mojo_proxy_resolver_factory,
114 HostResolver* host_resolver) 115 HostResolver* host_resolver)
115 : ProxyResolver(true /* |expects_pac_bytes| */), 116 : ProxyResolver(true /* |expects_pac_bytes| */),
116 mojo_proxy_resolver_factory_(mojo_proxy_resolver_factory), 117 mojo_proxy_resolver_factory_(mojo_proxy_resolver_factory),
117 host_resolver_(host_resolver) { 118 host_resolver_(host_resolver),
119 weak_factory_(this) {
118 } 120 }
119 121
120 ProxyResolverMojo::~ProxyResolverMojo() { 122 ProxyResolverMojo::~ProxyResolverMojo() {
121 DCHECK(thread_checker_.CalledOnValidThread()); 123 DCHECK(thread_checker_.CalledOnValidThread());
122 // All pending requests should have been cancelled. 124 // All pending requests should have been cancelled.
123 DCHECK(pending_jobs_.empty()); 125 DCHECK(pending_jobs_.empty());
124 DCHECK(set_pac_script_callback_.IsCancelled()); 126 DCHECK(set_pac_script_callback_.IsCancelled());
125 } 127 }
126 128
127 void ProxyResolverMojo::CancelSetPacScript() { 129 void ProxyResolverMojo::CancelSetPacScript() {
(...skipping 28 matching lines...) Expand all
156 } 158 }
157 159
158 void ProxyResolverMojo::OnSetPacScriptDone( 160 void ProxyResolverMojo::OnSetPacScriptDone(
159 const scoped_refptr<ProxyResolverScriptData>& pac_script, 161 const scoped_refptr<ProxyResolverScriptData>& pac_script,
160 const net::CompletionCallback& callback, 162 const net::CompletionCallback& callback,
161 int32_t result) { 163 int32_t result) {
162 DCHECK(thread_checker_.CalledOnValidThread()); 164 DCHECK(thread_checker_.CalledOnValidThread());
163 DCHECK(!set_pac_script_callback_.IsCancelled()); 165 DCHECK(!set_pac_script_callback_.IsCancelled());
164 DVLOG(1) << "ProxyResolverMojo::OnSetPacScriptDone: " << result; 166 DVLOG(1) << "ProxyResolverMojo::OnSetPacScriptDone: " << result;
165 167
166 callback.Run(result); 168 // |callback| is owned by |set_pac_script_callback_|, so make a copy before
169 // cancelling.
170 auto callback_copy = callback;
167 set_pac_script_callback_.Cancel(); 171 set_pac_script_callback_.Cancel();
172 callback_copy.Run(result);
168 } 173 }
169 174
170 void ProxyResolverMojo::SetUpServices() { 175 void ProxyResolverMojo::SetUpServices() {
171 DCHECK(thread_checker_.CalledOnValidThread()); 176 DCHECK(thread_checker_.CalledOnValidThread());
172 // A Mojo service implementation must outlive its binding. 177 // A Mojo service implementation must outlive its binding.
173 mojo_host_resolver_binding_.reset(); 178 mojo_host_resolver_binding_.reset();
174 179
175 interfaces::HostResolverPtr mojo_host_resolver_ptr; 180 interfaces::HostResolverPtr mojo_host_resolver_ptr;
176 mojo_host_resolver_.reset(new MojoHostResolverImpl(host_resolver_)); 181 mojo_host_resolver_.reset(new MojoHostResolverImpl(host_resolver_));
177 mojo_host_resolver_binding_.reset(new mojo::Binding<interfaces::HostResolver>( 182 mojo_host_resolver_binding_.reset(new mojo::Binding<interfaces::HostResolver>(
178 mojo_host_resolver_.get(), mojo::GetProxy(&mojo_host_resolver_ptr))); 183 mojo_host_resolver_.get(), mojo::GetProxy(&mojo_host_resolver_ptr)));
179 mojo_proxy_resolver_ptr_.reset(); 184 mojo_proxy_resolver_ptr_.reset();
180 mojo_proxy_resolver_factory_->Create( 185 mojo_proxy_resolver_factory_->Create(
181 mojo::GetProxy(&mojo_proxy_resolver_ptr_), mojo_host_resolver_ptr.Pass()); 186 mojo::GetProxy(&mojo_proxy_resolver_ptr_), mojo_host_resolver_ptr.Pass());
182 mojo_proxy_resolver_ptr_.set_error_handler(this); 187 mojo_proxy_resolver_ptr_.set_error_handler(this);
183 } 188 }
184 189
185 void ProxyResolverMojo::AbortPendingRequests() { 190 void ProxyResolverMojo::AbortPendingRequests() {
186 DCHECK(thread_checker_.CalledOnValidThread()); 191 DCHECK(thread_checker_.CalledOnValidThread());
187 if (!set_pac_script_callback_.IsCancelled()) { 192 // |this| could be deleted as a result of one of these callbacks so use
193 // |weak_this| to check.
194 base::WeakPtr<ProxyResolverMojo> weak_this = weak_factory_.GetWeakPtr();
195 if (!set_pac_script_callback_.IsCancelled())
188 set_pac_script_callback_.callback().Run(ERR_PAC_SCRIPT_TERMINATED); 196 set_pac_script_callback_.callback().Run(ERR_PAC_SCRIPT_TERMINATED);
189 set_pac_script_callback_.Cancel();
190 }
191 197
192 // Need to use this loop because deleting a Job will cause its callback to be 198 // Need to use this loop because deleting a Job will cause its callback to be
193 // run with a failure error code, which may cause other Jobs to be deleted. 199 // run with a failure error code, which may cause other Jobs to be deleted.
194 while (!pending_jobs_.empty()) { 200 while (weak_this && !pending_jobs_.empty()) {
eroman 2015/04/15 00:56:52 What is this needed for? This doesn't seem right,
Sam McNally 2015/04/15 04:35:56 Done. GetProxyForUrl requests will no longer immed
195 auto it = pending_jobs_.begin(); 201 auto it = pending_jobs_.begin();
196 Job* job = *it; 202 Job* job = *it;
197 pending_jobs_.erase(it); 203 pending_jobs_.erase(it);
198 204
199 // Deleting the job will cause its completion callback to be run with an 205 // Deleting the job will cause its completion callback to be run with an
200 // ERR_PAC_SCRIPT_TERMINATED error. 206 // ERR_PAC_SCRIPT_TERMINATED error.
201 delete job; 207 delete job;
202 } 208 }
203 } 209 }
204 210
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after
255 RemoveJob(job); 261 RemoveJob(job);
256 } 262 }
257 263
258 LoadState ProxyResolverMojo::GetLoadState(RequestHandle request) const { 264 LoadState ProxyResolverMojo::GetLoadState(RequestHandle request) const {
259 Job* job = static_cast<Job*>(request); 265 Job* job = static_cast<Job*>(request);
260 CHECK_EQ(1u, pending_jobs_.count(job)); 266 CHECK_EQ(1u, pending_jobs_.count(job));
261 return job->load_state(); 267 return job->load_state();
262 } 268 }
263 269
264 } // namespace net 270 } // namespace net
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698