OLD | NEW |
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 #include <utility> |
8 | 9 |
9 #include "base/macros.h" | 10 #include "base/macros.h" |
10 #include "base/stl_util.h" | 11 #include "base/stl_util.h" |
11 #include "net/base/net_errors.h" | 12 #include "net/base/net_errors.h" |
12 #include "net/proxy/mojo_proxy_resolver_impl.h" | 13 #include "net/proxy/mojo_proxy_resolver_impl.h" |
13 #include "net/proxy/mojo_proxy_resolver_v8_tracing_bindings.h" | 14 #include "net/proxy/mojo_proxy_resolver_v8_tracing_bindings.h" |
14 #include "net/proxy/proxy_resolver_factory.h" | 15 #include "net/proxy/proxy_resolver_factory.h" |
15 #include "net/proxy/proxy_resolver_v8_tracing.h" | 16 #include "net/proxy/proxy_resolver_v8_tracing.h" |
16 | 17 |
17 namespace net { | 18 namespace net { |
(...skipping 13 matching lines...) Expand all Loading... |
31 | 32 |
32 MojoProxyResolverImpl mojo_proxy_resolver_; | 33 MojoProxyResolverImpl mojo_proxy_resolver_; |
33 mojo::Binding<interfaces::ProxyResolver> binding_; | 34 mojo::Binding<interfaces::ProxyResolver> binding_; |
34 | 35 |
35 DISALLOW_COPY_AND_ASSIGN(MojoProxyResolverHolder); | 36 DISALLOW_COPY_AND_ASSIGN(MojoProxyResolverHolder); |
36 }; | 37 }; |
37 | 38 |
38 MojoProxyResolverHolder::MojoProxyResolverHolder( | 39 MojoProxyResolverHolder::MojoProxyResolverHolder( |
39 scoped_ptr<ProxyResolverV8Tracing> proxy_resolver_impl, | 40 scoped_ptr<ProxyResolverV8Tracing> proxy_resolver_impl, |
40 mojo::InterfaceRequest<interfaces::ProxyResolver> request) | 41 mojo::InterfaceRequest<interfaces::ProxyResolver> request) |
41 : mojo_proxy_resolver_(proxy_resolver_impl.Pass()), | 42 : mojo_proxy_resolver_(std::move(proxy_resolver_impl)), |
42 binding_(&mojo_proxy_resolver_, request.Pass()) { | 43 binding_(&mojo_proxy_resolver_, std::move(request)) { |
43 binding_.set_connection_error_handler(base::Bind( | 44 binding_.set_connection_error_handler(base::Bind( |
44 &MojoProxyResolverHolder::OnConnectionError, base::Unretained(this))); | 45 &MojoProxyResolverHolder::OnConnectionError, base::Unretained(this))); |
45 } | 46 } |
46 | 47 |
47 void MojoProxyResolverHolder::OnConnectionError() { | 48 void MojoProxyResolverHolder::OnConnectionError() { |
48 delete this; | 49 delete this; |
49 } | 50 } |
50 | 51 |
51 } // namespace | 52 } // namespace |
52 | 53 |
(...skipping 22 matching lines...) Expand all Loading... |
75 DISALLOW_COPY_AND_ASSIGN(Job); | 76 DISALLOW_COPY_AND_ASSIGN(Job); |
76 }; | 77 }; |
77 | 78 |
78 MojoProxyResolverFactoryImpl::Job::Job( | 79 MojoProxyResolverFactoryImpl::Job::Job( |
79 MojoProxyResolverFactoryImpl* factory, | 80 MojoProxyResolverFactoryImpl* factory, |
80 const scoped_refptr<ProxyResolverScriptData>& pac_script, | 81 const scoped_refptr<ProxyResolverScriptData>& pac_script, |
81 ProxyResolverV8TracingFactory* proxy_resolver_factory, | 82 ProxyResolverV8TracingFactory* proxy_resolver_factory, |
82 mojo::InterfaceRequest<interfaces::ProxyResolver> request, | 83 mojo::InterfaceRequest<interfaces::ProxyResolver> request, |
83 interfaces::ProxyResolverFactoryRequestClientPtr client) | 84 interfaces::ProxyResolverFactoryRequestClientPtr client) |
84 : parent_(factory), | 85 : parent_(factory), |
85 proxy_request_(request.Pass()), | 86 proxy_request_(std::move(request)), |
86 factory_(proxy_resolver_factory), | 87 factory_(proxy_resolver_factory), |
87 client_ptr_(client.Pass()) { | 88 client_ptr_(std::move(client)) { |
88 client_ptr_.set_connection_error_handler( | 89 client_ptr_.set_connection_error_handler( |
89 base::Bind(&MojoProxyResolverFactoryImpl::Job::OnConnectionError, | 90 base::Bind(&MojoProxyResolverFactoryImpl::Job::OnConnectionError, |
90 base::Unretained(this))); | 91 base::Unretained(this))); |
91 factory_->CreateProxyResolverV8Tracing( | 92 factory_->CreateProxyResolverV8Tracing( |
92 pac_script, | 93 pac_script, |
93 make_scoped_ptr(new MojoProxyResolverV8TracingBindings< | 94 make_scoped_ptr(new MojoProxyResolverV8TracingBindings< |
94 interfaces::ProxyResolverFactoryRequestClient>( | 95 interfaces::ProxyResolverFactoryRequestClient>( |
95 client_ptr_.get())), | 96 client_ptr_.get())), |
96 &proxy_resolver_impl_, | 97 &proxy_resolver_impl_, |
97 base::Bind(&MojoProxyResolverFactoryImpl::Job::OnProxyResolverCreated, | 98 base::Bind(&MojoProxyResolverFactoryImpl::Job::OnProxyResolverCreated, |
98 base::Unretained(this)), | 99 base::Unretained(this)), |
99 &request_); | 100 &request_); |
100 } | 101 } |
101 | 102 |
102 MojoProxyResolverFactoryImpl::Job::~Job() = default; | 103 MojoProxyResolverFactoryImpl::Job::~Job() = default; |
103 | 104 |
104 void MojoProxyResolverFactoryImpl::Job::OnConnectionError() { | 105 void MojoProxyResolverFactoryImpl::Job::OnConnectionError() { |
105 client_ptr_->ReportResult(ERR_PAC_SCRIPT_TERMINATED); | 106 client_ptr_->ReportResult(ERR_PAC_SCRIPT_TERMINATED); |
106 parent_->RemoveJob(this); | 107 parent_->RemoveJob(this); |
107 } | 108 } |
108 | 109 |
109 void MojoProxyResolverFactoryImpl::Job::OnProxyResolverCreated(int error) { | 110 void MojoProxyResolverFactoryImpl::Job::OnProxyResolverCreated(int error) { |
110 if (error == OK) { | 111 if (error == OK) { |
111 // The MojoProxyResolverHolder will delete itself if |proxy_request_| | 112 // The MojoProxyResolverHolder will delete itself if |proxy_request_| |
112 // encounters a connection error. | 113 // encounters a connection error. |
113 new MojoProxyResolverHolder(proxy_resolver_impl_.Pass(), | 114 new MojoProxyResolverHolder(std::move(proxy_resolver_impl_), |
114 proxy_request_.Pass()); | 115 std::move(proxy_request_)); |
115 } | 116 } |
116 client_ptr_->ReportResult(error); | 117 client_ptr_->ReportResult(error); |
117 parent_->RemoveJob(this); | 118 parent_->RemoveJob(this); |
118 } | 119 } |
119 | 120 |
120 MojoProxyResolverFactoryImpl::MojoProxyResolverFactoryImpl( | 121 MojoProxyResolverFactoryImpl::MojoProxyResolverFactoryImpl( |
121 scoped_ptr<ProxyResolverV8TracingFactory> proxy_resolver_factory, | 122 scoped_ptr<ProxyResolverV8TracingFactory> proxy_resolver_factory, |
122 mojo::InterfaceRequest<interfaces::ProxyResolverFactory> request) | 123 mojo::InterfaceRequest<interfaces::ProxyResolverFactory> request) |
123 : proxy_resolver_impl_factory_(proxy_resolver_factory.Pass()), | 124 : proxy_resolver_impl_factory_(std::move(proxy_resolver_factory)), |
124 binding_(this, request.Pass()) { | 125 binding_(this, std::move(request)) {} |
125 } | |
126 | 126 |
127 MojoProxyResolverFactoryImpl::MojoProxyResolverFactoryImpl( | 127 MojoProxyResolverFactoryImpl::MojoProxyResolverFactoryImpl( |
128 mojo::InterfaceRequest<interfaces::ProxyResolverFactory> request) | 128 mojo::InterfaceRequest<interfaces::ProxyResolverFactory> request) |
129 : MojoProxyResolverFactoryImpl(ProxyResolverV8TracingFactory::Create(), | 129 : MojoProxyResolverFactoryImpl(ProxyResolverV8TracingFactory::Create(), |
130 request.Pass()) { | 130 std::move(request)) {} |
131 } | |
132 | 131 |
133 MojoProxyResolverFactoryImpl::~MojoProxyResolverFactoryImpl() { | 132 MojoProxyResolverFactoryImpl::~MojoProxyResolverFactoryImpl() { |
134 STLDeleteElements(&jobs_); | 133 STLDeleteElements(&jobs_); |
135 } | 134 } |
136 | 135 |
137 void MojoProxyResolverFactoryImpl::CreateResolver( | 136 void MojoProxyResolverFactoryImpl::CreateResolver( |
138 const mojo::String& pac_script, | 137 const mojo::String& pac_script, |
139 mojo::InterfaceRequest<interfaces::ProxyResolver> request, | 138 mojo::InterfaceRequest<interfaces::ProxyResolver> request, |
140 interfaces::ProxyResolverFactoryRequestClientPtr client) { | 139 interfaces::ProxyResolverFactoryRequestClientPtr client) { |
141 // The Job will call RemoveJob on |this| when either the create request | 140 // The Job will call RemoveJob on |this| when either the create request |
142 // finishes or |request| or |client| encounters a connection error. | 141 // finishes or |request| or |client| encounters a connection error. |
143 jobs_.insert(new Job( | 142 jobs_.insert(new Job( |
144 this, ProxyResolverScriptData::FromUTF8(pac_script.To<std::string>()), | 143 this, ProxyResolverScriptData::FromUTF8(pac_script.To<std::string>()), |
145 proxy_resolver_impl_factory_.get(), request.Pass(), client.Pass())); | 144 proxy_resolver_impl_factory_.get(), std::move(request), |
| 145 std::move(client))); |
146 } | 146 } |
147 | 147 |
148 void MojoProxyResolverFactoryImpl::RemoveJob(Job* job) { | 148 void MojoProxyResolverFactoryImpl::RemoveJob(Job* job) { |
149 size_t erased = jobs_.erase(job); | 149 size_t erased = jobs_.erase(job); |
150 DCHECK_EQ(1u, erased); | 150 DCHECK_EQ(1u, erased); |
151 delete job; | 151 delete job; |
152 } | 152 } |
153 | 153 |
154 } // namespace net | 154 } // namespace net |
OLD | NEW |