Switch to use the ProxyResolverV8, fixes atom/atom#894.
authorCheng Zhao <zcbenz@gmail.com>
Sun, 29 Sep 2013 07:06:29 +0000 (15:06 +0800)
committerCheng Zhao <zcbenz@gmail.com>
Sun, 29 Sep 2013 07:06:29 +0000 (15:06 +0800)
browser/atom_browser_main_parts.cc
browser/atom_browser_main_parts.h
browser/net/atom_url_request_context_getter.cc
vendor/brightray

index aaec24b..1427d7e 100644 (file)
@@ -10,6 +10,7 @@
 #include "browser/atom_browser_context.h"
 #include "browser/browser.h"
 #include "common/node_bindings.h"
+#include "net/proxy/proxy_resolver_v8.h"
 #include "vendor/node/src/node.h"
 #include "vendor/node/src/node_internals.h"
 
@@ -87,4 +88,13 @@ void AtomBrowserMainParts::PreMainMessageLoopRun() {
 #endif
 }
 
+int AtomBrowserMainParts::PreCreateThreads() {
+#if defined(OS_WIN)
+  net::ProxyResolverV8::CreateIsolate();
+#else
+  net::ProxyResolverV8::RememberDefaultIsolate();
+#endif
+  return 0;
+}
+
 }  // namespace atom
index 3b7ac10..a7fd180 100644 (file)
@@ -30,6 +30,7 @@ class AtomBrowserMainParts : public brightray::BrowserMainParts {
   // Implementations of content::BrowserMainParts.
   virtual void PostEarlyInitialization() OVERRIDE;
   virtual void PreMainMessageLoopRun() OVERRIDE;
+  virtual int PreCreateThreads() OVERRIDE;
 #if defined(OS_MACOSX)
   virtual void PreMainMessageLoopStart() OVERRIDE;
   virtual void PostDestroyThreads() OVERRIDE;
index 0472905..92a3d9e 100644 (file)
 #include "net/http/http_auth_handler_factory.h"
 #include "net/http/http_cache.h"
 #include "net/http/http_server_properties_impl.h"
+#include "net/proxy/dhcp_proxy_script_fetcher_factory.h"
+#include "net/proxy/proxy_config_service.h"
+#include "net/proxy/proxy_script_fetcher_impl.h"
 #include "net/proxy/proxy_service.h"
+#include "net/proxy/proxy_service_v8.h"
 #include "net/ssl/default_server_bound_cert_store.h"
 #include "net/ssl/server_bound_cert_service.h"
 #include "net/ssl/ssl_config_service_defaults.h"
@@ -43,7 +47,12 @@ AtomURLRequestContextGetter::AtomURLRequestContextGetter(
       network_delegate_(network_delegate.Pass()) {
   // Must first be created on the UI thread.
   DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
+
   std::swap(protocol_handlers_, *protocol_handlers);
+
+  // We must create the proxy config service on the UI loop on Linux because it
+  // must synchronously run on the glib message loop. This will be passed to
+  // the URLRequestContextStorage on the IO thread in GetURLRequestContext().
   proxy_config_service_.reset(
       net::ProxyService::CreateSystemProxyConfigService(
           io_loop_->message_loop_proxy(),
@@ -77,12 +86,6 @@ net::URLRequestContext* AtomURLRequestContextGetter::GetURLRequestContext() {
         net::HostResolver::CreateDefaultResolver(NULL));
 
     storage_->set_cert_verifier(net::CertVerifier::CreateDefault());
-    // TODO(jam): use v8 if possible, look at chrome code.
-    storage_->set_proxy_service(
-        net::ProxyService::CreateUsingSystemProxyResolver(
-        proxy_config_service_.release(),
-        0,
-        NULL));
     storage_->set_ssl_config_service(new net::SSLConfigServiceDefaults);
     storage_->set_http_auth_handler_factory(
         net::HttpAuthHandlerFactory::CreateDefault(host_resolver.get()));
@@ -119,6 +122,16 @@ net::URLRequestContext* AtomURLRequestContextGetter::GetURLRequestContext() {
     network_session_params.host_resolver =
         url_request_context_->host_resolver();
 
+    net::DhcpProxyScriptFetcherFactory dhcp_factory;
+    storage_->set_proxy_service(
+        net::CreateProxyServiceUsingV8ProxyResolver(
+            proxy_config_service_.release(),
+            new net::ProxyScriptFetcherImpl(url_request_context_.get()),
+            dhcp_factory.Create(url_request_context_.get()),
+            url_request_context_->host_resolver(),
+            NULL,
+            url_request_context_->network_delegate()));
+
     net::HttpCache* main_cache = new net::HttpCache(
         network_session_params, main_backend);
     storage_->set_http_transaction_factory(main_cache);
index 3cb2782..b207f0e 160000 (submodule)
@@ -1 +1 @@
-Subproject commit 3cb2782cff77081df2788c68948163dea53530d5
+Subproject commit b207f0e5bed9c06142879abdd6749ac954eff8b8