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

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

Issue 1100763002: Inject CanAddURLToHistory into TopSitesImpl (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@prefs
Patch Set: Fix error introduced during rebase Created 5 years, 7 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_mojo.h ('k') | net/proxy/proxy_resolver_mojo_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 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| */),
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after
156 } 157 }
157 158
158 void ProxyResolverMojo::OnSetPacScriptDone( 159 void ProxyResolverMojo::OnSetPacScriptDone(
159 const scoped_refptr<ProxyResolverScriptData>& pac_script, 160 const scoped_refptr<ProxyResolverScriptData>& pac_script,
160 const CompletionCallback& callback, 161 const CompletionCallback& callback,
161 int32_t result) { 162 int32_t result) {
162 DCHECK(thread_checker_.CalledOnValidThread()); 163 DCHECK(thread_checker_.CalledOnValidThread());
163 DCHECK(!set_pac_script_callback_.IsCancelled()); 164 DCHECK(!set_pac_script_callback_.IsCancelled());
164 DVLOG(1) << "ProxyResolverMojo::OnSetPacScriptDone: " << result; 165 DVLOG(1) << "ProxyResolverMojo::OnSetPacScriptDone: " << result;
165 166
166 callback.Run(result); 167 // |callback| is owned by |set_pac_script_callback_|, so make a copy before
168 // cancelling.
169 auto callback_copy = callback;
167 set_pac_script_callback_.Cancel(); 170 set_pac_script_callback_.Cancel();
171 callback_copy.Run(result);
168 } 172 }
169 173
170 void ProxyResolverMojo::SetUpServices() { 174 void ProxyResolverMojo::SetUpServices() {
171 DCHECK(thread_checker_.CalledOnValidThread()); 175 DCHECK(thread_checker_.CalledOnValidThread());
172 // A Mojo service implementation must outlive its binding. 176 // A Mojo service implementation must outlive its binding.
173 mojo_host_resolver_binding_.reset(); 177 mojo_host_resolver_binding_.reset();
174 178
175 interfaces::HostResolverPtr mojo_host_resolver_ptr; 179 interfaces::HostResolverPtr mojo_host_resolver_ptr;
176 mojo_host_resolver_.reset(new MojoHostResolverImpl(host_resolver_)); 180 mojo_host_resolver_.reset(new MojoHostResolverImpl(host_resolver_));
177 mojo_host_resolver_binding_.reset(new mojo::Binding<interfaces::HostResolver>( 181 mojo_host_resolver_binding_.reset(new mojo::Binding<interfaces::HostResolver>(
178 mojo_host_resolver_.get(), mojo::GetProxy(&mojo_host_resolver_ptr))); 182 mojo_host_resolver_.get(), mojo::GetProxy(&mojo_host_resolver_ptr)));
179 mojo_proxy_resolver_ptr_.reset(); 183 mojo_proxy_resolver_ptr_.reset();
180 mojo_proxy_resolver_factory_->Create( 184 mojo_proxy_resolver_factory_->Create(
181 mojo::GetProxy(&mojo_proxy_resolver_ptr_), mojo_host_resolver_ptr.Pass()); 185 mojo::GetProxy(&mojo_proxy_resolver_ptr_), mojo_host_resolver_ptr.Pass());
182 mojo_proxy_resolver_ptr_.set_error_handler(this); 186 mojo_proxy_resolver_ptr_.set_error_handler(this);
183 } 187 }
184 188
185 void ProxyResolverMojo::AbortPendingRequests() {
186 DCHECK(thread_checker_.CalledOnValidThread());
187 if (!set_pac_script_callback_.IsCancelled()) {
188 set_pac_script_callback_.callback().Run(ERR_PAC_SCRIPT_TERMINATED);
189 set_pac_script_callback_.Cancel();
190 }
191
192 // 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.
194 while (!pending_jobs_.empty()) {
195 auto it = pending_jobs_.begin();
196 Job* job = *it;
197 pending_jobs_.erase(it);
198
199 // Deleting the job will cause its completion callback to be run with an
200 // ERR_PAC_SCRIPT_TERMINATED error.
201 delete job;
202 }
203 }
204
205 void ProxyResolverMojo::OnConnectionError() { 189 void ProxyResolverMojo::OnConnectionError() {
206 DCHECK(thread_checker_.CalledOnValidThread()); 190 DCHECK(thread_checker_.CalledOnValidThread());
207 DVLOG(1) << "ProxyResolverMojo::OnConnectionError"; 191 DVLOG(1) << "ProxyResolverMojo::OnConnectionError";
208 192
209 // Disconnect from the Mojo proxy resolver service. An attempt to reconnect 193 // Disconnect from the Mojo proxy resolver service. An attempt to reconnect
210 // will happen on the next |SetPacScript()| request. 194 // will happen on the next |SetPacScript()| request.
211 mojo_proxy_resolver_ptr_.reset(); 195 mojo_proxy_resolver_ptr_.reset();
212 196
213 // Aborting requests will invoke their callbacks, which may call 197 // This callback may call |SetPacScript()| and re-create the connection. So
214 // |SetPacScript()| and re-create the connection. So disconnect from the Mojo 198 // disconnect from the Mojo service (above) before aborting the pending
215 // service (above) before aborting the pending requests. 199 // request.
216 AbortPendingRequests(); 200 if (!set_pac_script_callback_.IsCancelled())
201 set_pac_script_callback_.callback().Run(ERR_PAC_SCRIPT_TERMINATED);
217 } 202 }
218 203
219 void ProxyResolverMojo::RemoveJob(Job* job) { 204 void ProxyResolverMojo::RemoveJob(Job* job) {
220 DCHECK(thread_checker_.CalledOnValidThread()); 205 DCHECK(thread_checker_.CalledOnValidThread());
221 size_t num_erased = pending_jobs_.erase(job); 206 size_t num_erased = pending_jobs_.erase(job);
222 DCHECK(num_erased); 207 DCHECK(num_erased);
223 delete job; 208 delete job;
224 } 209 }
225 210
226 int ProxyResolverMojo::GetProxyForURL(const GURL& url, 211 int ProxyResolverMojo::GetProxyForURL(const GURL& url,
(...skipping 28 matching lines...) Expand all
255 RemoveJob(job); 240 RemoveJob(job);
256 } 241 }
257 242
258 LoadState ProxyResolverMojo::GetLoadState(RequestHandle request) const { 243 LoadState ProxyResolverMojo::GetLoadState(RequestHandle request) const {
259 Job* job = static_cast<Job*>(request); 244 Job* job = static_cast<Job*>(request);
260 CHECK_EQ(1u, pending_jobs_.count(job)); 245 CHECK_EQ(1u, pending_jobs_.count(job));
261 return job->load_state(); 246 return job->load_state();
262 } 247 }
263 248
264 } // namespace net 249 } // namespace net
OLDNEW
« no previous file with comments | « net/proxy/proxy_resolver_mojo.h ('k') | net/proxy/proxy_resolver_mojo_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698