summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authortfarina@chromium.org <tfarina@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2012-08-31 14:50:48 +0000
committertfarina@chromium.org <tfarina@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2012-08-31 14:50:48 +0000
commitffd3eff06f253f6a96e79af6a5aad40d3f363059 (patch)
treea987ecc75069bf5c7e050ce466e08d5f5d240104
parent55cc34ef3dfeb7f61efd0f1e8d433802d6d2b236 (diff)
downloadchromium_src-ffd3eff06f253f6a96e79af6a5aad40d3f363059.zip
chromium_src-ffd3eff06f253f6a96e79af6a5aad40d3f363059.tar.gz
chromium_src-ffd3eff06f253f6a96e79af6a5aad40d3f363059.tar.bz2
net: Add a new target 'net_with_v8'.
This target depends on v8 as the name implies, and thus we can remove the v8 dependency from net library itself. This will benefit views package, because views does not need anything from v8, but since it depends on ui_base it needs things from net too. BUG=137800 R=eroman@chromium.org TBR=ben@chromium.org Review URL: https://chromiumcodereview.appspot.com/10874077 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@154434 0039d316-1c4b-4281-b951-d872f2087c98
-rw-r--r--chrome/browser/net/connection_tester.cc17
-rw-r--r--chrome/browser/net/proxy_service_factory.cc3
-rw-r--r--chrome/chrome_browser.gypi2
-rw-r--r--net/net.gyp42
-rw-r--r--net/proxy/proxy_resolver_v8.cc4
-rw-r--r--net/proxy/proxy_service.cc89
-rw-r--r--net/proxy/proxy_service.h49
-rw-r--r--net/proxy/proxy_service_v8.cc107
-rw-r--r--net/proxy/proxy_service_v8.h66
9 files changed, 225 insertions, 154 deletions
diff --git a/chrome/browser/net/connection_tester.cc b/chrome/browser/net/connection_tester.cc
index 2303aca..2bebe6e 100644
--- a/chrome/browser/net/connection_tester.cc
+++ b/chrome/browser/net/connection_tester.cc
@@ -31,6 +31,7 @@
#include "net/proxy/proxy_config_service_fixed.h"
#include "net/proxy/proxy_script_fetcher_impl.h"
#include "net/proxy/proxy_service.h"
+#include "net/proxy/proxy_service_v8.h"
#include "net/url_request/url_request.h"
#include "net/url_request/url_request_context.h"
#include "net/url_request/url_request_context_storage.h"
@@ -192,14 +193,14 @@ class ExperimentURLRequestContext : public net::URLRequestContext {
}
experiment_proxy_service->reset(
- net::ProxyService::CreateUsingV8ProxyResolver(
- proxy_config_service->release(),
- 0u,
- new net::ProxyScriptFetcherImpl(proxy_request_context_),
- dhcp_factory.Create(proxy_request_context_),
- host_resolver(),
- NULL,
- NULL));
+ net::CreateProxyServiceUsingV8ProxyResolver(
+ proxy_config_service->release(),
+ 0u,
+ new net::ProxyScriptFetcherImpl(proxy_request_context_),
+ dhcp_factory.Create(proxy_request_context_),
+ host_resolver(),
+ NULL,
+ NULL));
return net::OK;
}
diff --git a/chrome/browser/net/proxy_service_factory.cc b/chrome/browser/net/proxy_service_factory.cc
index a738f08..24f46eb 100644
--- a/chrome/browser/net/proxy_service_factory.cc
+++ b/chrome/browser/net/proxy_service_factory.cc
@@ -17,6 +17,7 @@
#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/url_request/url_request_context.h"
#if defined(OS_CHROMEOS)
@@ -108,7 +109,7 @@ net::ProxyService* ProxyServiceFactory::CreateProxyService(
dhcp_factory.set_enabled(false);
}
- proxy_service = net::ProxyService::CreateUsingV8ProxyResolver(
+ proxy_service = net::CreateProxyServiceUsingV8ProxyResolver(
proxy_config_service,
num_pac_threads,
new net::ProxyScriptFetcherImpl(context),
diff --git a/chrome/chrome_browser.gypi b/chrome/chrome_browser.gypi
index 13650e0..c74fbbf 100644
--- a/chrome/chrome_browser.gypi
+++ b/chrome/chrome_browser.gypi
@@ -35,7 +35,7 @@
'../content/content.gyp:content_common',
'../crypto/crypto.gyp:crypto',
'../media/media.gyp:media',
- '../net/net.gyp:net',
+ '../net/net.gyp:net_with_v8',
'../ppapi/ppapi_internal.gyp:ppapi_ipc', # For PpapiMsg_LoadPlugin
'../printing/printing.gyp:printing',
'../skia/skia.gyp:skia',
diff --git a/net/net.gyp b/net/net.gyp
index 5363b49..48757ee 100644
--- a/net/net.gyp
+++ b/net/net.gyp
@@ -596,8 +596,6 @@
'proxy/proxy_resolver_script.h',
'proxy/proxy_resolver_script_data.cc',
'proxy/proxy_resolver_script_data.h',
- 'proxy/proxy_resolver_v8.cc',
- 'proxy/proxy_resolver_v8.h',
'proxy/proxy_resolver_winhttp.cc',
'proxy/proxy_resolver_winhttp.h',
'proxy/proxy_retry_info.h',
@@ -825,12 +823,6 @@
'../base/base.gyp:base',
],
'conditions': [
- ['OS != "ios"', {
- 'dependencies': [
- # The v8 gyp file is not available in the iOS tree.
- '../v8/tools/gyp/v8.gyp:v8',
- ],
- }],
['chromeos==1', {
'sources!': [
'base/network_change_notifier_linux.cc',
@@ -1150,6 +1142,35 @@
],
},
{
+ 'target_name': 'net_with_v8',
+ 'type': '<(component)',
+ 'variables': { 'enable_wexit_time_destructors': 1, },
+ 'dependencies': [
+ '../base/base.gyp:base',
+ '../build/temp_gyp/googleurl.gyp:googleurl',
+ 'net'
+ ],
+ 'defines': [
+ 'NET_IMPLEMENTATION',
+ ],
+ 'sources': [
+ 'proxy/proxy_resolver_v8.cc',
+ 'proxy/proxy_resolver_v8.h',
+ 'proxy/proxy_service_v8.cc',
+ 'proxy/proxy_service_v8.h',
+ ],
+ 'conditions': [
+ ['OS != "ios"',
+ {
+ 'dependencies': [
+ # The v8 gyp file is not available in the iOS tree.
+ '../v8/tools/gyp/v8.gyp:v8',
+ ],
+ }
+ ],
+ ],
+ },
+ {
'target_name': 'net_unittests',
'type': '<(gtest_target_type)',
'dependencies': [
@@ -1162,6 +1183,7 @@
'../third_party/zlib/zlib.gyp:zlib',
'net',
'net_test_support',
+ 'net_with_v8',
],
'sources': [
'base/address_list_unittest.cc',
@@ -1568,6 +1590,7 @@
'../testing/gtest.gyp:gtest',
'net',
'net_test_support',
+ 'net_with_v8',
],
'sources': [
'cookies/cookie_monster_perftest.cc',
@@ -1603,6 +1626,7 @@
'../base/base.gyp:test_support_base',
'../testing/gtest.gyp:gtest',
'net',
+ 'net_with_v8',
],
'export_dependent_settings': [
'../base/base.gyp:base',
@@ -1802,6 +1826,7 @@
'../build/temp_gyp/googleurl.gyp:googleurl',
'../testing/gtest.gyp:gtest',
'net',
+ 'net_with_v8',
],
'sources': [
'tools/fetch/fetch_client.cc',
@@ -1848,6 +1873,7 @@
'dependencies': [
'../base/base.gyp:base',
'net',
+ 'net_with_v8',
],
'sources': [
'tools/net_watcher/net_watcher.cc',
diff --git a/net/proxy/proxy_resolver_v8.cc b/net/proxy/proxy_resolver_v8.cc
index b3b19d6..5150317 100644
--- a/net/proxy/proxy_resolver_v8.cc
+++ b/net/proxy/proxy_resolver_v8.cc
@@ -2,11 +2,11 @@
// 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_v8.h"
+
#include <algorithm>
#include <cstdio>
-#include "net/proxy/proxy_resolver_v8.h"
-
#include "base/basictypes.h"
#include "base/compiler_specific.h"
#include "base/logging.h"
diff --git a/net/proxy/proxy_service.cc b/net/proxy/proxy_service.cc
index 7decae8..248c64c 100644
--- a/net/proxy/proxy_service.cc
+++ b/net/proxy/proxy_service.cc
@@ -26,8 +26,6 @@
#include "net/proxy/network_delegate_error_observer.h"
#include "net/proxy/proxy_config_service_fixed.h"
#include "net/proxy/proxy_resolver.h"
-#include "net/proxy/proxy_resolver_js_bindings.h"
-#include "net/proxy/proxy_resolver_v8.h"
#include "net/proxy/proxy_script_decider.h"
#include "net/proxy/proxy_script_fetcher.h"
#include "net/proxy/sync_host_resolver_bridge.h"
@@ -53,7 +51,6 @@ namespace net {
namespace {
const size_t kMaxNumNetLogEntries = 100;
-const size_t kDefaultNumPacThreads = 4;
// When the IP address changes we don't immediately re-run proxy auto-config.
// Instead, we wait for |kDelayAfterNetworkChangesMs| before
@@ -258,54 +255,6 @@ class ProxyResolverFromPacString : public ProxyResolver {
const std::string pac_string_;
};
-// This factory creates V8ProxyResolvers with appropriate javascript bindings.
-class ProxyResolverFactoryForV8 : public ProxyResolverFactory {
- public:
- // |async_host_resolver|, |io_loop| and |net_log| must remain
- // valid for the duration of our lifetime.
- // |async_host_resolver| will only be operated on |io_loop|.
- // TODO(willchan): remove io_loop and replace it with origin_loop.
- ProxyResolverFactoryForV8(HostResolver* async_host_resolver,
- MessageLoop* io_loop,
- base::MessageLoopProxy* origin_loop,
- NetLog* net_log,
- NetworkDelegate* network_delegate)
- : ProxyResolverFactory(true /*expects_pac_bytes*/),
- async_host_resolver_(async_host_resolver),
- io_loop_(io_loop),
- origin_loop_(origin_loop),
- net_log_(net_log),
- network_delegate_(network_delegate) {
- }
-
- virtual ProxyResolver* CreateProxyResolver() OVERRIDE {
- // Create a synchronous host resolver wrapper that operates
- // |async_host_resolver_| on |io_loop_|.
- SyncHostResolverBridge* sync_host_resolver =
- new SyncHostResolverBridge(async_host_resolver_, io_loop_);
-
- NetworkDelegateErrorObserver* error_observer =
- new NetworkDelegateErrorObserver(
- network_delegate_, origin_loop_.get());
-
- // ProxyResolverJSBindings takes ownership of |error_observer| and
- // |sync_host_resolver|.
- ProxyResolverJSBindings* js_bindings =
- ProxyResolverJSBindings::CreateDefault(
- sync_host_resolver, net_log_, error_observer);
-
- // ProxyResolverV8 takes ownership of |js_bindings|.
- return new ProxyResolverV8(js_bindings);
- }
-
- private:
- HostResolver* const async_host_resolver_;
- MessageLoop* io_loop_;
- scoped_refptr<base::MessageLoopProxy> origin_loop_;
- NetLog* net_log_;
- NetworkDelegate* network_delegate_;
-};
-
// Creates ProxyResolvers using a platform-specific implementation.
class ProxyResolverFactoryForSystem : public ProxyResolverFactory {
public:
@@ -919,44 +868,6 @@ ProxyService::ProxyService(ProxyConfigService* config_service,
}
// static
-ProxyService* ProxyService::CreateUsingV8ProxyResolver(
- ProxyConfigService* proxy_config_service,
- size_t num_pac_threads,
- ProxyScriptFetcher* proxy_script_fetcher,
- DhcpProxyScriptFetcher* dhcp_proxy_script_fetcher,
- HostResolver* host_resolver,
- NetLog* net_log,
- NetworkDelegate* network_delegate) {
- DCHECK(proxy_config_service);
- DCHECK(proxy_script_fetcher);
- DCHECK(dhcp_proxy_script_fetcher);
- DCHECK(host_resolver);
-
- if (num_pac_threads == 0)
- num_pac_threads = kDefaultNumPacThreads;
-
- ProxyResolverFactory* sync_resolver_factory =
- new ProxyResolverFactoryForV8(
- host_resolver,
- MessageLoop::current(),
- base::MessageLoopProxy::current(),
- net_log,
- network_delegate);
-
- ProxyResolver* proxy_resolver =
- new MultiThreadedProxyResolver(sync_resolver_factory, num_pac_threads);
-
- ProxyService* proxy_service =
- new ProxyService(proxy_config_service, proxy_resolver, net_log);
-
- // Configure fetchers to use for PAC script downloads and auto-detect.
- proxy_service->SetProxyScriptFetchers(proxy_script_fetcher,
- dhcp_proxy_script_fetcher);
-
- return proxy_service;
-}
-
-// static
ProxyService* ProxyService::CreateUsingSystemProxyResolver(
ProxyConfigService* proxy_config_service,
size_t num_pac_threads,
diff --git a/net/proxy/proxy_service.h b/net/proxy/proxy_service.h
index 7ba1c13..25b2548 100644
--- a/net/proxy/proxy_service.h
+++ b/net/proxy/proxy_service.h
@@ -46,6 +46,8 @@ class NET_EXPORT ProxyService : public NetworkChangeNotifier::IPAddressObserver,
public ProxyConfigService::Observer,
NON_EXPORTED_BASE(public base::NonThreadSafe) {
public:
+ static const size_t kDefaultNumPacThreads = 4;
+
// This interface defines the set of policies for when to poll the PAC
// script for changes.
//
@@ -198,51 +200,8 @@ class NET_EXPORT ProxyService : public NetworkChangeNotifier::IPAddressObserver,
// to downloading and testing the PAC files.
void ForceReloadProxyConfig();
- // Creates a proxy service that polls |proxy_config_service| to notice when
- // the proxy settings change. We take ownership of |proxy_config_service|.
- //
- // |num_pac_threads| specifies the maximum number of threads to use for
- // executing PAC scripts. Threads are created lazily on demand.
- // If |0| is specified, then a default number of threads will be selected.
- //
- // Having more threads avoids stalling proxy resolve requests when the
- // PAC script takes a while to run. This is particularly a problem when PAC
- // scripts do synchronous DNS resolutions, since that can take on the order
- // of seconds.
- //
- // However, the disadvantages of using more than 1 thread are:
- // (a) can cause compatibility issues for scripts that rely on side effects
- // between runs (such scripts should not be common though).
- // (b) increases the memory used by proxy resolving, as each thread will
- // duplicate its own script context.
-
- // |proxy_script_fetcher| specifies the dependency to use for downloading
- // any PAC scripts. The resulting ProxyService will take ownership of it.
- //
- // |dhcp_proxy_script_fetcher| specifies the dependency to use for attempting
- // to retrieve the most appropriate PAC script configured in DHCP. The
- // resulting ProxyService will take ownership of it.
- //
- // |host_resolver| points to the host resolving dependency the PAC script
- // should use for any DNS queries. It must remain valid throughout the
- // lifetime of the ProxyService.
- //
- // ##########################################################################
- // # See the warnings in net/proxy/proxy_resolver_v8.h describing the
- // # multi-threading model. In order for this to be safe to use, *ALL* the
- // # other V8's running in the process must use v8::Locker.
- // ##########################################################################
- static ProxyService* CreateUsingV8ProxyResolver(
- ProxyConfigService* proxy_config_service,
- size_t num_pac_threads,
- ProxyScriptFetcher* proxy_script_fetcher,
- DhcpProxyScriptFetcher* dhcp_proxy_script_fetcher,
- HostResolver* host_resolver,
- NetLog* net_log,
- NetworkDelegate* network_delegate);
-
- // Same as CreateUsingV8ProxyResolver, except it uses system libraries
- // for evaluating the PAC script if available, otherwise skips
+ // Same as CreateProxyServiceUsingV8ProxyResolver, except it uses system
+ // libraries for evaluating the PAC script if available, otherwise skips
// proxy autoconfig.
static ProxyService* CreateUsingSystemProxyResolver(
ProxyConfigService* proxy_config_service,
diff --git a/net/proxy/proxy_service_v8.cc b/net/proxy/proxy_service_v8.cc
new file mode 100644
index 0000000..44ae82c
--- /dev/null
+++ b/net/proxy/proxy_service_v8.cc
@@ -0,0 +1,107 @@
+// Copyright (c) 2012 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_service_v8.h"
+
+#include "base/logging.h"
+#include "net/proxy/multi_threaded_proxy_resolver.h"
+#include "net/proxy/network_delegate_error_observer.h"
+#include "net/proxy/proxy_resolver.h"
+#include "net/proxy/proxy_resolver_js_bindings.h"
+#include "net/proxy/proxy_resolver_v8.h"
+#include "net/proxy/proxy_service.h"
+#include "net/proxy/sync_host_resolver_bridge.h"
+
+namespace net {
+namespace {
+
+// This factory creates V8ProxyResolvers with appropriate javascript bindings.
+class ProxyResolverFactoryForV8 : public ProxyResolverFactory {
+ public:
+ // |async_host_resolver|, |io_loop| and |net_log| must remain
+ // valid for the duration of our lifetime.
+ // |async_host_resolver| will only be operated on |io_loop|.
+ // TODO(willchan): remove io_loop and replace it with origin_loop.
+ ProxyResolverFactoryForV8(HostResolver* async_host_resolver,
+ MessageLoop* io_loop,
+ base::MessageLoopProxy* origin_loop,
+ NetLog* net_log,
+ NetworkDelegate* network_delegate)
+ : ProxyResolverFactory(true /*expects_pac_bytes*/),
+ async_host_resolver_(async_host_resolver),
+ io_loop_(io_loop),
+ origin_loop_(origin_loop),
+ net_log_(net_log),
+ network_delegate_(network_delegate) {
+ }
+
+ virtual ProxyResolver* CreateProxyResolver() OVERRIDE {
+ // Create a synchronous host resolver wrapper that operates
+ // |async_host_resolver_| on |io_loop_|.
+ SyncHostResolverBridge* sync_host_resolver =
+ new SyncHostResolverBridge(async_host_resolver_, io_loop_);
+
+ NetworkDelegateErrorObserver* error_observer =
+ new NetworkDelegateErrorObserver(
+ network_delegate_, origin_loop_.get());
+
+ // ProxyResolverJSBindings takes ownership of |error_observer| and
+ // |sync_host_resolver|.
+ ProxyResolverJSBindings* js_bindings =
+ ProxyResolverJSBindings::CreateDefault(
+ sync_host_resolver, net_log_, error_observer);
+
+ // ProxyResolverV8 takes ownership of |js_bindings|.
+ return new ProxyResolverV8(js_bindings);
+ }
+
+ private:
+ HostResolver* const async_host_resolver_;
+ MessageLoop* io_loop_;
+ scoped_refptr<base::MessageLoopProxy> origin_loop_;
+ NetLog* net_log_;
+ NetworkDelegate* network_delegate_;
+};
+
+} // namespace
+
+// static
+ProxyService* CreateProxyServiceUsingV8ProxyResolver(
+ ProxyConfigService* proxy_config_service,
+ size_t num_pac_threads,
+ ProxyScriptFetcher* proxy_script_fetcher,
+ DhcpProxyScriptFetcher* dhcp_proxy_script_fetcher,
+ HostResolver* host_resolver,
+ NetLog* net_log,
+ NetworkDelegate* network_delegate) {
+ DCHECK(proxy_config_service);
+ DCHECK(proxy_script_fetcher);
+ DCHECK(dhcp_proxy_script_fetcher);
+ DCHECK(host_resolver);
+
+ if (num_pac_threads == 0)
+ num_pac_threads = ProxyService::kDefaultNumPacThreads;
+
+ ProxyResolverFactory* sync_resolver_factory =
+ new ProxyResolverFactoryForV8(
+ host_resolver,
+ MessageLoop::current(),
+ base::MessageLoopProxy::current(),
+ net_log,
+ network_delegate);
+
+ ProxyResolver* proxy_resolver =
+ new MultiThreadedProxyResolver(sync_resolver_factory, num_pac_threads);
+
+ ProxyService* proxy_service =
+ new ProxyService(proxy_config_service, proxy_resolver, net_log);
+
+ // Configure fetchers to use for PAC script downloads and auto-detect.
+ proxy_service->SetProxyScriptFetchers(proxy_script_fetcher,
+ dhcp_proxy_script_fetcher);
+
+ return proxy_service;
+}
+
+} // namespace net
diff --git a/net/proxy/proxy_service_v8.h b/net/proxy/proxy_service_v8.h
new file mode 100644
index 0000000..0ff574d
--- /dev/null
+++ b/net/proxy/proxy_service_v8.h
@@ -0,0 +1,66 @@
+// Copyright (c) 2012 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.
+
+#ifndef NET_PROXY_PROXY_SERVICE_V8_H_
+#define NET_PROXY_PROXY_SERVICE_V8_H_
+
+#include "base/basictypes.h"
+#include "net/base/net_export.h"
+
+namespace net {
+
+class DhcpProxyScriptFetcher;
+class HostResolver;
+class NetLog;
+class NetworkDelegate;
+class ProxyConfigService;
+class ProxyScriptFetcher;
+class ProxyService;
+
+// Creates a proxy service that polls |proxy_config_service| to notice when
+// the proxy settings change. We take ownership of |proxy_config_service|.
+//
+// |num_pac_threads| specifies the maximum number of threads to use for
+// executing PAC scripts. Threads are created lazily on demand.
+// If |0| is specified, then a default number of threads will be selected.
+//
+// Having more threads avoids stalling proxy resolve requests when the
+// PAC script takes a while to run. This is particularly a problem when PAC
+// scripts do synchronous DNS resolutions, since that can take on the order
+// of seconds.
+//
+// However, the disadvantages of using more than 1 thread are:
+// (a) can cause compatibility issues for scripts that rely on side effects
+// between runs (such scripts should not be common though).
+// (b) increases the memory used by proxy resolving, as each thread will
+// duplicate its own script context.
+
+// |proxy_script_fetcher| specifies the dependency to use for downloading
+// any PAC scripts. The resulting ProxyService will take ownership of it.
+//
+// |dhcp_proxy_script_fetcher| specifies the dependency to use for attempting
+// to retrieve the most appropriate PAC script configured in DHCP. The
+// resulting ProxyService will take ownership of it.
+//
+// |host_resolver| points to the host resolving dependency the PAC script
+// should use for any DNS queries. It must remain valid throughout the
+// lifetime of the ProxyService.
+//
+// ##########################################################################
+// # See the warnings in net/proxy/proxy_resolver_v8.h describing the
+// # multi-threading model. In order for this to be safe to use, *ALL* the
+// # other V8's running in the process must use v8::Locker.
+// ##########################################################################
+NET_EXPORT ProxyService* CreateProxyServiceUsingV8ProxyResolver(
+ ProxyConfigService* proxy_config_service,
+ size_t num_pac_threads,
+ ProxyScriptFetcher* proxy_script_fetcher,
+ DhcpProxyScriptFetcher* dhcp_proxy_script_fetcher,
+ HostResolver* host_resolver,
+ NetLog* net_log,
+ NetworkDelegate* network_delegate);
+
+} // namespace net
+
+#endif // NET_PROXY_PROXY_SERVICE_V8_H_