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

Unified Diff: net/proxy/proxy_resolver_mojo_host.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, 11 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
« no previous file with comments | « net/proxy/proxy_resolver_mojo_host.h ('k') | net/proxy/proxy_resolver_v8.h » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: net/proxy/proxy_resolver_mojo_host.cc
diff --git a/net/proxy/proxy_resolver_mojo_host.cc b/net/proxy/proxy_resolver_mojo_host.cc
new file mode 100644
index 0000000000000000000000000000000000000000..b9bcd33fe4f1a198a203c8b3e88a0be4d1e21833
--- /dev/null
+++ b/net/proxy/proxy_resolver_mojo_host.cc
@@ -0,0 +1,163 @@
+// 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/proxy_resolver_mojo_host.h"
+
+#include "mojo/common/common_type_converters.h"
+#include "net/base/net_errors.h"
+#include "net/base/net_log.h"
+#include "net/dns/host_resolver_mojo.h"
+#include "net/proxy/proxy_info.h"
+#include "net/proxy/proxy_resolver.h"
+#include "net/proxy/proxy_resolver_error_observer_mojo.h"
+#include "net/proxy/proxy_resolver_mojo_host.h"
+#include "net/proxy/proxy_resolver_script_data.h"
+#include "net/proxy/proxy_resolver_v8.h"
+#include "net/proxy/proxy_resolver_v8_tracing.h"
+
+namespace net {
+namespace {
+
+class Job : public mojo::ErrorHandler {
+ public:
+ Job(const GURL& url,
+ proxy::ResolveRequestClientPtr client,
+ base::WeakPtr<ProxyResolverMojoHost> parent);
+
+ private:
+ ~Job() override;
+
+ // mojo::ErrorHandler override.
+ void OnConnectionError() override;
+
+ void GetProxyDone(int32_t error);
+
+ proxy::ResolveRequestClientPtr client_;
+ base::WeakPtr<ProxyResolverMojoHost> parent_;
+ ProxyInfo result_;
+ BoundNetLog net_log_;
+ ProxyResolver::RequestHandle request_handle_ = nullptr;
+
+ DISALLOW_COPY_AND_ASSIGN(Job);
+};
+
+class SetPacScriptJob : public mojo::ErrorHandler {
+ public:
+ SetPacScriptJob(const std::string& pac_script,
+ proxy::SetPacScriptClientPtr client,
+ base::WeakPtr<ProxyResolverMojoHost> parent);
+
+ private:
+ ~SetPacScriptJob() override;
+ void OnConnectionError() override;
+ void SetPacScriptDone(int32_t error);
+
+ proxy::SetPacScriptClientPtr client_;
+ base::WeakPtr<ProxyResolverMojoHost> parent_;
+
+ DISALLOW_COPY_AND_ASSIGN(SetPacScriptJob);
+};
+
+Job::Job(const GURL& url,
+ proxy::ResolveRequestClientPtr client,
+ base::WeakPtr<ProxyResolverMojoHost> parent)
+ : client_(client.Pass()), parent_(parent) {
+ client_.set_error_handler(this);
+ parent_->resolver()->GetProxyForURL(
+ url, &result_, base::Bind(&Job::GetProxyDone, base::Unretained(this)),
+ &request_handle_, net_log_);
+}
+
+void Job::GetProxyDone(int32_t error) {
+ request_handle_ = nullptr;
+ if (error)
+ client_->ReportError(error);
+ else
+ client_->ReportResult(result_.ToPacString());
+ delete this;
+}
+
+Job::~Job() = default;
+
+void Job::OnConnectionError() {
+ if (parent_ && request_handle_)
+ parent_->resolver()->CancelRequest(request_handle_);
+ delete this;
+}
+
+SetPacScriptJob::SetPacScriptJob(const std::string& pac_script,
+ proxy::SetPacScriptClientPtr client,
+ base::WeakPtr<ProxyResolverMojoHost> parent)
+ : client_(client.Pass()), parent_(parent) {
+ client_.set_error_handler(this);
+ auto result = parent_->resolver()->SetPacScript(
+ ProxyResolverScriptData::FromUTF8(pac_script),
+ base::Bind(&SetPacScriptJob::SetPacScriptDone, base::Unretained(this)));
+ if (result != ERR_IO_PENDING)
+ SetPacScriptDone(result);
+}
+
+void SetPacScriptJob::SetPacScriptDone(int32_t error) {
+ client_->ReportResult(error);
+ delete this;
+}
+
+SetPacScriptJob::~SetPacScriptJob() = default;
+
+void SetPacScriptJob::OnConnectionError() {
+ if (parent_)
+ parent_->resolver()->CancelSetPacScript();
+ delete this;
+}
+
+} // namespace
+
+ProxyResolverMojoHost::ProxyResolverMojoHost(
+ scoped_ptr<ProxyResolver> resolver,
+ scoped_ptr<HostResolverMojo> host_resolver)
+ : resolver_(resolver.Pass()),
+ host_resolver_(host_resolver.Pass()),
+ weak_factory_(this) {
+}
+
+ProxyResolverMojoHost::~ProxyResolverMojoHost() = default;
+
+void ProxyResolverMojoHost::SetPacScript(const mojo::String& data,
+ proxy::SetPacScriptClientPtr client) {
+ VLOG(1) << "SetPacScript: " << data;
+ new SetPacScriptJob(data, client.Pass(), weak_factory_.GetWeakPtr());
+}
+
+void ProxyResolverMojoHost::GetProxyForUrl(
+ const mojo::String& url,
+ proxy::ResolveRequestClientPtr client) {
+ VLOG(1) << "GetProxyForUrl: " << url;
+ new Job(url.To<GURL>(), client.Pass(), weak_factory_.GetWeakPtr());
+}
+
+ProxyResolverMojoFactory::ProxyResolverMojoFactory(NetLog* net_log)
+ : net_log_(net_log) {
+}
+
+ProxyResolverMojoFactory::~ProxyResolverMojoFactory() = default;
+
+void ProxyResolverMojoFactory::CreateResolver(
+ mojo::InterfaceRequest<proxy::Resolver> resolver,
+ dns::ResolverPtr host_resolver_handle,
+ proxy::ErrorObserverPtr error_observer_handle) {
+ net::ProxyResolverV8::EnsureIsolateCreated();
+
+ HostResolverMojo* host_resolver =
+ new HostResolverMojo(host_resolver_handle.Pass());
+ ProxyResolverErrorObserverMojo* error_observer =
+ new ProxyResolverErrorObserverMojo(error_observer_handle.Pass());
+
+ mojo::BindToRequest(
+ new ProxyResolverMojoHost(make_scoped_ptr(new ProxyResolverV8Tracing(
+ host_resolver, error_observer, net_log_)),
+ make_scoped_ptr(host_resolver)),
+ &resolver);
+}
+
+} // namespace net
« no previous file with comments | « net/proxy/proxy_resolver_mojo_host.h ('k') | net/proxy/proxy_resolver_v8.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698