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

Unified Diff: net/proxy/mojo_proxy_resolver_impl.cc

Issue 896203003: Implement utility-side proxy resolver Mojo service. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@proxy-diffbase
Patch Set: 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 side-by-side diff with in-line comments
Download patch
Index: net/proxy/mojo_proxy_resolver_impl.cc
diff --git a/net/proxy/mojo_proxy_resolver_impl.cc b/net/proxy/mojo_proxy_resolver_impl.cc
new file mode 100644
index 0000000000000000000000000000000000000000..2f565474a5e9055f80b237360ddaef93a67ac671
--- /dev/null
+++ b/net/proxy/mojo_proxy_resolver_impl.cc
@@ -0,0 +1,124 @@
+// Copyright 2015 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#include "net/proxy/mojo_proxy_resolver_impl.h"
+
+#include "base/stl_util.h"
+#include "mojo/common/common_type_converters.h"
+#include "net/base/net_errors.h"
+#include "net/base/net_log.h"
+#include "net/proxy/proxy_info.h"
+#include "net/proxy/proxy_resolver.h"
+#include "net/proxy/proxy_resolver_script_data.h"
+#include "net/proxy/type_converters.h"
+
+namespace net {
+
+class MojoProxyResolverImpl::Job : public mojo::ErrorHandler {
+ public:
+ Job(interfaces::ProxyResolverRequestClientPtr client,
+ MojoProxyResolverImpl* resolver);
+ ~Job() override;
+
+ void Start(const GURL& url);
+
+ private:
+ // mojo::ErrorHandler override.
+ void OnConnectionError() override;
+
+ void GetProxyDone(int32_t error);
+
+ MojoProxyResolverImpl* resolver_;
+
+ interfaces::ProxyResolverRequestClientPtr client_;
+ ProxyInfo result_;
+ net::ProxyResolver::RequestHandle request_handle_;
+
+ DISALLOW_COPY_AND_ASSIGN(Job);
+};
+
+MojoProxyResolverImpl::MojoProxyResolverImpl(
+ scoped_ptr<net::ProxyResolver> resolver)
+ : resolver_(resolver.Pass()) {
+ DCHECK(resolver_->expects_pac_bytes());
+}
+
+MojoProxyResolverImpl::~MojoProxyResolverImpl() {
+ resolver_->CancelSetPacScript();
+ if (!set_pac_script_callback_.is_null())
+ set_pac_script_callback_.Run(ERR_ABORTED);
+ STLDeleteElements(&resolve_jobs_);
+}
+
+void MojoProxyResolverImpl::SetPacScript(
+ const mojo::String& data,
+ const mojo::Callback<void(int32_t)>& callback) {
+ set_pac_script_callback_ = callback;
Anand Mistry (off Chromium) 2015/02/10 03:54:08 DCHECK(set_pac_script_callback_.is_null());
Sam McNally 2015/02/10 06:27:42 Done.
+ int result = resolver_->SetPacScript(
+ ProxyResolverScriptData::FromUTF8(data),
+ base::Bind(&MojoProxyResolverImpl::SetPacScriptDone,
+ base::Unretained(this)));
+ if (result != ERR_IO_PENDING)
+ SetPacScriptDone(result);
+}
+
+void MojoProxyResolverImpl::GetProxyForUrl(
Anand Mistry (off Chromium) 2015/02/10 03:54:08 I think it would be nice to have a few DVLOGs scat
Sam McNally 2015/02/10 06:27:42 Done.
+ const mojo::String& url,
+ interfaces::ProxyResolverRequestClientPtr client) {
+ Job* job = new Job(client.Pass(), this);
+ bool inserted = resolve_jobs_.insert(job).second;
+ DCHECK(inserted);
+ job->Start(url.To<GURL>());
Anand Mistry (off Chromium) 2015/02/10 03:54:08 URL is a property of the job. Shouldn't it be in t
Sam McNally 2015/02/10 06:27:41 Done.
+}
+
+void MojoProxyResolverImpl::DeleteJob(Job* job) {
+ size_t num_erased = resolve_jobs_.erase(job);
+ DCHECK(num_erased);
+ delete job;
+}
+
+void MojoProxyResolverImpl::SetPacScriptDone(int result) {
+ DCHECK(!set_pac_script_callback_.is_null());
+ set_pac_script_callback_.Run(result);
+ set_pac_script_callback_ = mojo::Callback<void(int32_t)>();
Anand Mistry (off Chromium) 2015/02/10 03:54:08 I've been using .reset() instead. Not sure which o
Sam McNally 2015/02/10 06:27:41 Changed to reset(). I got used to mojo::Callbacks
+}
+
+MojoProxyResolverImpl::Job::Job(
+ interfaces::ProxyResolverRequestClientPtr client,
+ MojoProxyResolverImpl* resolver)
+ : resolver_(resolver), client_(client.Pass()), request_handle_(nullptr) {
+}
+
+MojoProxyResolverImpl::Job::~Job() {
+ if (request_handle_)
+ resolver_->resolver_->CancelRequest(request_handle_);
+}
+
+void MojoProxyResolverImpl::Job::Start(const GURL& url) {
+ int result = resolver_->resolver_->GetProxyForURL(
+ url, &result_, base::Bind(&Job::GetProxyDone, base::Unretained(this)),
+ &request_handle_, BoundNetLog());
+ if (result != ERR_IO_PENDING) {
+ GetProxyDone(result);
+ return;
+ }
+ client_.set_error_handler(this);
+}
+
+void MojoProxyResolverImpl::Job::GetProxyDone(int32_t error) {
+ request_handle_ = nullptr;
+ if (error) {
+ client_->ReportResult(error, mojo::Array<interfaces::ProxyServerPtr>());
+ } else {
+ client_->ReportResult(OK, mojo::Array<interfaces::ProxyServerPtr>::From(
+ result_.proxy_list().GetAll()));
+ }
+ resolver_->DeleteJob(this);
+}
+
+void MojoProxyResolverImpl::Job::OnConnectionError() {
+ resolver_->DeleteJob(this);
+}
+
+} // namespace net

Powered by Google App Engine
This is Rietveld 408576698