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

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

Issue 862813002: WIP: Prototype OOP V8 PAC. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Slight cleanup and report JS memory usage. Created 5 years, 10 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_host.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
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
3 // found in the LICENSE file.
4
5 #include "net/proxy/proxy_resolver_mojo.h"
6
7 #include "base/logging.h"
8 #include "base/memory/ref_counted.h"
9 #include "base/strings/string16.h"
10 #include "base/strings/utf_string_conversions.h"
11 #include "mojo/public/cpp/bindings/interface_ptr.h"
12 #include "net/base/address_list.h"
13 #include "net/base/completion_callback.h"
14 #include "net/base/load_states.h"
15 #include "net/base/net_errors.h"
16 #include "net/base/net_export.h"
17 #include "net/base/net_log.h"
18 #include "net/dns/single_request_host_resolver.h"
19 #include "net/proxy/proxy_info.h"
20 #include "net/proxy/proxy_resolver_script_data.h"
21 #include "url/gurl.h"
22
23 namespace net {
24
25 namespace {
26
27 class Job : public mojo::InterfaceImpl<proxy::ResolveRequestClient> {
28 public:
29 Job(ProxyInfo* results,
30 const CompletionCallback& callback,
31 const BoundNetLog& net_log,
32 HostResolver* host_resolver);
33 ~Job() override;
34
35 LoadState GetLoadState() const;
36
37 private:
38 void ReportResult(const mojo::String& pac_string) override;
39 void ReportError(int32_t error) override;
40 void UpdateLoadState(int32_t load_state) override;
41
42 void OnConnectionError() override;
43
44 void ResolveHostDone(int32_t result);
45 ProxyInfo* results_;
46 CompletionCallback callback_;
47 BoundNetLog net_log_;
48
49 SingleRequestHostResolver host_resolver_;
50
51 bool host_resolve_in_progress_;
52 AddressList host_resolve_result_;
53 LoadState load_state_ = LOAD_STATE_RESOLVING_PROXY_FOR_URL;
54 mojo::Callback<void(int32_t, mojo::Array<mojo::String>)>
55 host_resolve_callback_;
56
57 DISALLOW_COPY_AND_ASSIGN(Job);
58 };
59
60 Job::Job(ProxyInfo* results,
61 const CompletionCallback& callback,
62 const BoundNetLog& net_log,
63 HostResolver* host_resolver)
64 : results_(results),
65 callback_(callback),
66 net_log_(net_log),
67 host_resolver_(host_resolver) {
68 }
69
70 Job::~Job() = default;
71
72 LoadState Job::GetLoadState() const {
73 return load_state_;
74 }
75
76 void Job::ReportResult(const mojo::String& pac_string) {
77 VLOG(1) << pac_string.To<std::string>();
78 results_->UsePacString(pac_string);
79 ReportError(0);
80 }
81
82 void Job::ReportError(int32_t error) {
83 callback_.Run(error);
84 delete this;
85 }
86
87 void Job::UpdateLoadState(int32_t load_state) {
88 load_state_ = static_cast<LoadState>(load_state);
89 }
90
91 void Job::OnConnectionError() {
92 callback_.Run(ERR_FAILED);
93 delete this;
94 }
95
96 void Job::ResolveHostDone(int32_t result) {
97 host_resolve_in_progress_ = false;
98 if (result != 0) {
99 host_resolve_callback_.Run(result, mojo::Array<mojo::String>());
100 return;
101 }
102 }
103
104 } // namespace
105
106 class ProxyResolverMojo::SetPacScriptJob
107 : public mojo::InterfaceImpl<proxy::SetPacScriptClient> {
108 public:
109 explicit SetPacScriptJob(const CompletionCallback& callback);
110 ~SetPacScriptJob() override;
111
112 base::WeakPtr<SetPacScriptJob> GetWeakPtr();
113
114 private:
115 void ReportResult(int32_t error) override;
116
117 void OnConnectionError() override;
118
119 CompletionCallback callback_;
120
121 base::WeakPtrFactory<SetPacScriptJob> weak_factory_;
122
123 DISALLOW_COPY_AND_ASSIGN(SetPacScriptJob);
124 };
125
126 ProxyResolverMojo::ProxyResolverMojo(
127 mojo::InterfacePtr<proxy::Resolver> resolver,
128 HostResolver* host_resolver)
129 : ProxyResolver(true),
130 resolver_(resolver.Pass()),
131 host_resolver_(host_resolver) {
132 // XXX: Call SetResolver().
133 }
134
135 ProxyResolverMojo::~ProxyResolverMojo() = default;
136
137 int ProxyResolverMojo::GetProxyForURL(const GURL& url,
138 ProxyInfo* results,
139 const CompletionCallback& callback,
140 RequestHandle* request,
141 const BoundNetLog& net_log) {
142 VLOG(1) << "GetProxyForURL " << url;
143 mojo::InterfacePtr<proxy::ResolveRequestClient> handle;
144 *request = mojo::WeakBindToProxy(
145 new Job(results, callback, net_log, host_resolver_), &handle);
146 resolver_->GetProxyForUrl(url.spec(), handle.Pass());
147 return ERR_IO_PENDING;
148 }
149
150 void ProxyResolverMojo::CancelRequest(RequestHandle request) {
151 delete static_cast<Job*>(request);
152 }
153
154 LoadState ProxyResolverMojo::GetLoadState(RequestHandle request) const {
155 return static_cast<Job*>(request)->GetLoadState();
156 }
157
158 void ProxyResolverMojo::CancelSetPacScript() {
159 if (set_pac_script_job_)
160 delete set_pac_script_job_.get();
161 }
162
163 int ProxyResolverMojo::SetPacScript(
164 const scoped_refptr<ProxyResolverScriptData>& pac_script,
165 const CompletionCallback& callback) {
166 proxy::SetPacScriptClientPtr handle;
167 set_pac_script_job_ = mojo::WeakBindToProxy(new SetPacScriptJob(callback),
168 &handle)->GetWeakPtr();
169 VLOG(1) << "SetPacScript";
170 // XXX: Try to avoid converting between utf16 and utf8 and back to utf16.
171 resolver_->SetPacScript(base::UTF16ToUTF8(pac_script->utf16()),
172 handle.Pass());
173 return ERR_IO_PENDING;
174 }
175
176 ProxyResolverMojo::SetPacScriptJob::SetPacScriptJob(
177 const CompletionCallback& callback)
178 : callback_(callback), weak_factory_(this) {
179 }
180
181 ProxyResolverMojo::SetPacScriptJob::~SetPacScriptJob() = default;
182
183 base::WeakPtr<ProxyResolverMojo::SetPacScriptJob>
184 ProxyResolverMojo::SetPacScriptJob::GetWeakPtr() {
185 return weak_factory_.GetWeakPtr();
186 }
187
188 void ProxyResolverMojo::SetPacScriptJob::ReportResult(int32_t error) {
189 callback_.Run(error);
190 delete this;
191 }
192
193 void ProxyResolverMojo::SetPacScriptJob::OnConnectionError() {
194 callback_.Run(ERR_FAILED);
195 delete this;
196 }
197
198 } // namespace net
OLDNEW
« no previous file with comments | « net/proxy/proxy_resolver_mojo.h ('k') | net/proxy/proxy_resolver_mojo_host.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698