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

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

Issue 1017453005: Add support for ProxyResolverErrorObserver to ProxyResolverMojo. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: 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
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/mojo_proxy_resolver_factory_impl.h" 5 #include "net/proxy/mojo_proxy_resolver_factory_impl.h"
6 6
7 #include <string> 7 #include <string>
8 8
9 #include "base/stl_util.h" 9 #include "base/stl_util.h"
10 #include "net/base/net_errors.h" 10 #include "net/base/net_errors.h"
11 #include "net/dns/host_resolver_mojo.h" 11 #include "net/dns/host_resolver_mojo.h"
12 #include "net/proxy/mojo_proxy_resolver_impl.h" 12 #include "net/proxy/mojo_proxy_resolver_impl.h"
13 #include "net/proxy/proxy_resolver_error_observer.h" 13 #include "net/proxy/proxy_resolver_error_observer_mojo.h"
14 #include "net/proxy/proxy_resolver_factory.h" 14 #include "net/proxy/proxy_resolver_factory.h"
15 #include "net/proxy/proxy_resolver_v8.h" 15 #include "net/proxy/proxy_resolver_v8.h"
16 #include "net/proxy/proxy_resolver_v8_tracing.h" 16 #include "net/proxy/proxy_resolver_v8_tracing.h"
17 #include "third_party/mojo/src/mojo/public/cpp/bindings/error_handler.h" 17 #include "third_party/mojo/src/mojo/public/cpp/bindings/error_handler.h"
18 18
19 namespace net { 19 namespace net {
20 namespace { 20 namespace {
21 21
22 scoped_ptr<ProxyResolverErrorObserver> ReturnNullErrorObserver() { 22 scoped_ptr<ProxyResolverErrorObserver> ReturnErrorObserver(
23 return nullptr; 23 scoped_ptr<ProxyResolverErrorObserver> error_observer) {
24 return error_observer;
24 } 25 }
25 26
26 scoped_ptr<ProxyResolverFactory> CreateDefaultProxyResolver( 27 scoped_ptr<ProxyResolverFactory> CreateDefaultProxyResolver(
27 HostResolver* host_resolver, 28 HostResolver* host_resolver,
29 scoped_ptr<ProxyResolverErrorObserver> error_observer,
28 const ProxyResolver::LoadStateChangedCallback& callback) { 30 const ProxyResolver::LoadStateChangedCallback& callback) {
29 return make_scoped_ptr(new ProxyResolverFactoryV8Tracing( 31 return make_scoped_ptr(new ProxyResolverFactoryV8Tracing(
30 host_resolver, nullptr, callback, base::Bind(&ReturnNullErrorObserver))); 32 host_resolver, nullptr, callback,
33 base::Bind(&ReturnErrorObserver, base::Passed(&error_observer))));
31 } 34 }
32 35
33 class LoadStateChangeForwarder 36 class LoadStateChangeForwarder
34 : public base::RefCounted<LoadStateChangeForwarder> { 37 : public base::RefCounted<LoadStateChangeForwarder> {
35 public: 38 public:
36 LoadStateChangeForwarder() = default; 39 LoadStateChangeForwarder() = default;
37 40
38 void OnLoadStateChanged(ProxyResolver::RequestHandle request_handle, 41 void OnLoadStateChanged(ProxyResolver::RequestHandle request_handle,
39 LoadState load_state) const { 42 LoadState load_state) const {
40 if (!callback_.is_null()) 43 if (!callback_.is_null())
(...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after
100 103
101 } // namespace 104 } // namespace
102 105
103 class MojoProxyResolverFactoryImpl::Job : public mojo::ErrorHandler { 106 class MojoProxyResolverFactoryImpl::Job : public mojo::ErrorHandler {
104 public: 107 public:
105 Job(MojoProxyResolverFactoryImpl* parent, 108 Job(MojoProxyResolverFactoryImpl* parent,
106 const scoped_refptr<ProxyResolverScriptData>& pac_script, 109 const scoped_refptr<ProxyResolverScriptData>& pac_script,
107 const MojoProxyResolverFactoryImpl::Factory& proxy_resolver_factory, 110 const MojoProxyResolverFactoryImpl::Factory& proxy_resolver_factory,
108 mojo::InterfaceRequest<interfaces::ProxyResolver> request, 111 mojo::InterfaceRequest<interfaces::ProxyResolver> request,
109 interfaces::HostResolverPtr host_resolver, 112 interfaces::HostResolverPtr host_resolver,
113 interfaces::ProxyResolverErrorObserverPtr error_observer,
110 interfaces::ProxyResolverFactoryRequestClientPtr client); 114 interfaces::ProxyResolverFactoryRequestClientPtr client);
111 ~Job() override; 115 ~Job() override;
112 116
113 private: 117 private:
114 // mojo::ErrorHandler override. 118 // mojo::ErrorHandler override.
115 void OnConnectionError() override; 119 void OnConnectionError() override;
116 120
117 void OnProxyResolverCreated(int error); 121 void OnProxyResolverCreated(int error);
118 122
119 MojoProxyResolverFactoryImpl* const parent_; 123 MojoProxyResolverFactoryImpl* const parent_;
120 scoped_ptr<HostResolverMojo> host_resolver_; 124 scoped_ptr<HostResolverMojo> host_resolver_;
121 scoped_refptr<LoadStateChangeForwarder> load_state_change_forwarder_; 125 scoped_refptr<LoadStateChangeForwarder> load_state_change_forwarder_;
122 scoped_ptr<ProxyResolver> proxy_resolver_impl_; 126 scoped_ptr<ProxyResolver> proxy_resolver_impl_;
123 mojo::InterfaceRequest<interfaces::ProxyResolver> proxy_request_; 127 mojo::InterfaceRequest<interfaces::ProxyResolver> proxy_request_;
124 scoped_ptr<net::ProxyResolverFactory> factory_; 128 scoped_ptr<net::ProxyResolverFactory> factory_;
125 scoped_ptr<net::ProxyResolverFactory::Request> request_; 129 scoped_ptr<net::ProxyResolverFactory::Request> request_;
126 interfaces::ProxyResolverFactoryRequestClientPtr client_ptr_; 130 interfaces::ProxyResolverFactoryRequestClientPtr client_ptr_;
127 131
128 DISALLOW_COPY_AND_ASSIGN(Job); 132 DISALLOW_COPY_AND_ASSIGN(Job);
129 }; 133 };
130 134
131 MojoProxyResolverFactoryImpl::Job::Job( 135 MojoProxyResolverFactoryImpl::Job::Job(
132 MojoProxyResolverFactoryImpl* factory, 136 MojoProxyResolverFactoryImpl* factory,
133 const scoped_refptr<ProxyResolverScriptData>& pac_script, 137 const scoped_refptr<ProxyResolverScriptData>& pac_script,
134 const MojoProxyResolverFactoryImpl::Factory& proxy_resolver_factory, 138 const MojoProxyResolverFactoryImpl::Factory& proxy_resolver_factory,
135 mojo::InterfaceRequest<interfaces::ProxyResolver> request, 139 mojo::InterfaceRequest<interfaces::ProxyResolver> request,
136 interfaces::HostResolverPtr host_resolver, 140 interfaces::HostResolverPtr host_resolver,
141 interfaces::ProxyResolverErrorObserverPtr error_observer,
137 interfaces::ProxyResolverFactoryRequestClientPtr client) 142 interfaces::ProxyResolverFactoryRequestClientPtr client)
138 : parent_(factory), 143 : parent_(factory),
139 host_resolver_(new HostResolverMojo( 144 host_resolver_(new HostResolverMojo(
140 host_resolver.Pass(), 145 host_resolver.Pass(),
141 base::Bind(&MojoProxyResolverFactoryImpl::Job::OnConnectionError, 146 base::Bind(&MojoProxyResolverFactoryImpl::Job::OnConnectionError,
142 base::Unretained(this)))), 147 base::Unretained(this)))),
143 load_state_change_forwarder_(new LoadStateChangeForwarder), 148 load_state_change_forwarder_(new LoadStateChangeForwarder),
144 proxy_request_(request.Pass()), 149 proxy_request_(request.Pass()),
145 factory_(proxy_resolver_factory.Run( 150 factory_(proxy_resolver_factory.Run(
146 host_resolver_.get(), 151 host_resolver_.get(),
152 ProxyResolverErrorObserverMojo::Create(error_observer.Pass()),
147 base::Bind(&LoadStateChangeForwarder::OnLoadStateChanged, 153 base::Bind(&LoadStateChangeForwarder::OnLoadStateChanged,
148 load_state_change_forwarder_))), 154 load_state_change_forwarder_))),
149 client_ptr_(client.Pass()) { 155 client_ptr_(client.Pass()) {
150 client_ptr_.set_error_handler(this); 156 client_ptr_.set_error_handler(this);
151 factory_->CreateProxyResolver( 157 factory_->CreateProxyResolver(
152 pac_script, &proxy_resolver_impl_, 158 pac_script, &proxy_resolver_impl_,
153 base::Bind(&MojoProxyResolverFactoryImpl::Job::OnProxyResolverCreated, 159 base::Bind(&MojoProxyResolverFactoryImpl::Job::OnProxyResolverCreated,
154 base::Unretained(this)), 160 base::Unretained(this)),
155 &request_); 161 &request_);
156 } 162 }
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after
188 } 194 }
189 195
190 MojoProxyResolverFactoryImpl::~MojoProxyResolverFactoryImpl() { 196 MojoProxyResolverFactoryImpl::~MojoProxyResolverFactoryImpl() {
191 STLDeleteElements(&jobs_); 197 STLDeleteElements(&jobs_);
192 } 198 }
193 199
194 void MojoProxyResolverFactoryImpl::CreateResolver( 200 void MojoProxyResolverFactoryImpl::CreateResolver(
195 const mojo::String& pac_script, 201 const mojo::String& pac_script,
196 mojo::InterfaceRequest<interfaces::ProxyResolver> request, 202 mojo::InterfaceRequest<interfaces::ProxyResolver> request,
197 interfaces::HostResolverPtr host_resolver, 203 interfaces::HostResolverPtr host_resolver,
204 interfaces::ProxyResolverErrorObserverPtr error_observer,
198 interfaces::ProxyResolverFactoryRequestClientPtr client) { 205 interfaces::ProxyResolverFactoryRequestClientPtr client) {
199 // The Job will call RemoveJob on |this| when either the create request 206 // The Job will call RemoveJob on |this| when either the create request
200 // finishes or |request| or |client| encounters a connection error. 207 // finishes or |request| or |client| encounters a connection error.
201 jobs_.insert(new Job( 208 jobs_.insert(new Job(
202 this, ProxyResolverScriptData::FromUTF8(pac_script.To<std::string>()), 209 this, ProxyResolverScriptData::FromUTF8(pac_script.To<std::string>()),
203 proxy_resolver_impl_factory_, request.Pass(), host_resolver.Pass(), 210 proxy_resolver_impl_factory_, request.Pass(), host_resolver.Pass(),
204 client.Pass())); 211 error_observer.Pass(), client.Pass()));
205 } 212 }
206 213
207 void MojoProxyResolverFactoryImpl::RemoveJob(Job* job) { 214 void MojoProxyResolverFactoryImpl::RemoveJob(Job* job) {
208 size_t erased = jobs_.erase(job); 215 size_t erased = jobs_.erase(job);
209 DCHECK_EQ(1u, erased); 216 DCHECK_EQ(1u, erased);
210 delete job; 217 delete job;
211 } 218 }
212 219
213 } // namespace net 220 } // namespace net
OLDNEW
« no previous file with comments | « net/proxy/mojo_proxy_resolver_factory_impl.h ('k') | net/proxy/mojo_proxy_resolver_factory_impl_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698