Commit 319828dc authored by bengr's avatar bengr Committed by Commit bot

Put Data Reduction Proxy support in Cronet behind a gyp flag

Compile the Data Reduction Proxy into Cronet only if the gyp
variable enable_data_reduction_proxy_support is set to 1.
By default, it is set to 0.

BUG=461910

Review URL: https://codereview.chromium.org/1112513003

Cr-Commit-Position: refs/heads/master@{#330021}
parent a20d1d5f
...@@ -108,20 +108,36 @@ ...@@ -108,20 +108,36 @@
'DISABLE_FTP_SUPPORT=1', 'DISABLE_FTP_SUPPORT=1',
], ],
'dependencies': [ 'dependencies': [
'../components/components.gyp:data_reduction_proxy_core_browser_small',
'../net/net.gyp:net_small', '../net/net.gyp:net_small',
], ],
'includes': [ 'cronet/cronet_static.gypi' ], 'includes': [ 'cronet/cronet_static.gypi' ],
'conditions': [
['enable_data_reduction_proxy_support==1',
{
'dependencies': [
'../components/components.gyp:data_reduction_proxy_core_browser_small',
],
},
],
],
}, },
{ {
# cronet_static target depends on ICU and includes file and ftp support. # cronet_static target depends on ICU and includes file and ftp support.
'target_name': 'cronet_static', 'target_name': 'cronet_static',
'dependencies': [ 'dependencies': [
'../base/base.gyp:base_i18n', '../base/base.gyp:base_i18n',
'../components/components.gyp:data_reduction_proxy_core_browser',
'../net/net.gyp:net', '../net/net.gyp:net',
], ],
'includes': [ 'cronet/cronet_static.gypi' ], 'includes': [ 'cronet/cronet_static.gypi' ],
'conditions': [
['enable_data_reduction_proxy_support==1',
{
'dependencies': [
'../components/components.gyp:data_reduction_proxy_core_browser',
],
},
],
],
}, },
{ {
'target_name': 'libcronet', 'target_name': 'libcronet',
...@@ -303,6 +319,15 @@ ...@@ -303,6 +319,15 @@
'../third_party/icu/icu.gyp:icui18n', '../third_party/icu/icu.gyp:icui18n',
'../third_party/icu/icu.gyp:icuuc', '../third_party/icu/icu.gyp:icuuc',
], ],
'conditions' : [
['enable_data_reduction_proxy_support==1',
{
'defines' : [
'DATA_REDUCTION_PROXY_SUPPORT'
],
},
],
],
}, },
{ {
'target_name': 'cronet_test_apk', 'target_name': 'cronet_test_apk',
...@@ -473,6 +498,9 @@ ...@@ -473,6 +498,9 @@
], ],
}, },
], ],
'variables': {
'enable_data_reduction_proxy_support%': 0,
},
}], # OS=="android" }], # OS=="android"
], ],
} }
...@@ -13,7 +13,6 @@ ...@@ -13,7 +13,6 @@
#include "base/memory/scoped_vector.h" #include "base/memory/scoped_vector.h"
#include "base/single_thread_task_runner.h" #include "base/single_thread_task_runner.h"
#include "base/values.h" #include "base/values.h"
#include "components/cronet/android/cronet_data_reduction_proxy.h"
#include "components/cronet/url_request_context_config.h" #include "components/cronet/url_request_context_config.h"
#include "jni/CronetUrlRequestContext_jni.h" #include "jni/CronetUrlRequestContext_jni.h"
#include "net/base/load_flags.h" #include "net/base/load_flags.h"
...@@ -27,6 +26,10 @@ ...@@ -27,6 +26,10 @@
#include "net/url_request/url_request_context_builder.h" #include "net/url_request/url_request_context_builder.h"
#include "net/url_request/url_request_interceptor.h" #include "net/url_request/url_request_interceptor.h"
#if defined(DATA_REDUCTION_PROXY_SUPPORT)
#include "components/cronet/android/cronet_data_reduction_proxy.h"
#endif
namespace { namespace {
class BasicNetworkDelegate : public net::NetworkDelegateImpl { class BasicNetworkDelegate : public net::NetworkDelegateImpl {
...@@ -157,6 +160,7 @@ void CronetURLRequestContextAdapter::InitializeOnNetworkThread( ...@@ -157,6 +160,7 @@ void CronetURLRequestContextAdapter::InitializeOnNetworkThread(
scoped_ptr<net::NetLog> net_log(new net::NetLog); scoped_ptr<net::NetLog> net_log(new net::NetLog);
scoped_ptr<net::NetworkDelegate> network_delegate(new BasicNetworkDelegate()); scoped_ptr<net::NetworkDelegate> network_delegate(new BasicNetworkDelegate());
#if defined(DATA_REDUCTION_PROXY_SUPPORT)
DCHECK(!data_reduction_proxy_); DCHECK(!data_reduction_proxy_);
// For now, the choice to enable the data reduction proxy happens once, // For now, the choice to enable the data reduction proxy happens once,
// at initialization. It cannot be disabled thereafter. // at initialization. It cannot be disabled thereafter.
...@@ -176,6 +180,7 @@ void CronetURLRequestContextAdapter::InitializeOnNetworkThread( ...@@ -176,6 +180,7 @@ void CronetURLRequestContextAdapter::InitializeOnNetworkThread(
interceptors.push_back(data_reduction_proxy_->CreateInterceptor()); interceptors.push_back(data_reduction_proxy_->CreateInterceptor());
context_builder.SetInterceptors(interceptors.Pass()); context_builder.SetInterceptors(interceptors.Pass());
} }
#endif // defined(DATA_REDUCTION_PROXY_SUPPORT)
context_builder.set_network_delegate(network_delegate.release()); context_builder.set_network_delegate(network_delegate.release());
context_builder.set_net_log(net_log.release()); context_builder.set_net_log(net_log.release());
context_builder.set_proxy_config_service(proxy_config_service_.release()); context_builder.set_proxy_config_service(proxy_config_service_.release());
...@@ -241,8 +246,10 @@ void CronetURLRequestContextAdapter::InitializeOnNetworkThread( ...@@ -241,8 +246,10 @@ void CronetURLRequestContextAdapter::InitializeOnNetworkThread(
Java_CronetUrlRequestContext_initNetworkThread( Java_CronetUrlRequestContext_initNetworkThread(
env, jcronet_url_request_context.obj()); env, jcronet_url_request_context.obj());
#if defined(DATA_REDUCTION_PROXY_SUPPORT)
if (data_reduction_proxy_) if (data_reduction_proxy_)
data_reduction_proxy_->Init(true, GetURLRequestContext()); data_reduction_proxy_->Init(true, GetURLRequestContext());
#endif
is_context_initialized_ = true; is_context_initialized_ = true;
while (!tasks_waiting_for_context_.empty()) { while (!tasks_waiting_for_context_.empty()) {
tasks_waiting_for_context_.front().Run(); tasks_waiting_for_context_.front().Run();
......
...@@ -30,7 +30,10 @@ class SdchOwner; ...@@ -30,7 +30,10 @@ class SdchOwner;
namespace cronet { namespace cronet {
#if defined(DATA_REDUCTION_PROXY_SUPPORT)
class CronetDataReductionProxy; class CronetDataReductionProxy;
#endif
struct URLRequestContextConfig; struct URLRequestContextConfig;
bool CronetUrlRequestContextAdapterRegisterJni(JNIEnv* env); bool CronetUrlRequestContextAdapterRegisterJni(JNIEnv* env);
...@@ -104,7 +107,10 @@ class CronetURLRequestContextAdapter { ...@@ -104,7 +107,10 @@ class CronetURLRequestContextAdapter {
std::queue<base::Closure> tasks_waiting_for_context_; std::queue<base::Closure> tasks_waiting_for_context_;
bool is_context_initialized_; bool is_context_initialized_;
int default_load_flags_; int default_load_flags_;
#if defined(DATA_REDUCTION_PROXY_SUPPORT)
scoped_ptr<CronetDataReductionProxy> data_reduction_proxy_; scoped_ptr<CronetDataReductionProxy> data_reduction_proxy_;
#endif
DISALLOW_COPY_AND_ASSIGN(CronetURLRequestContextAdapter); DISALLOW_COPY_AND_ASSIGN(CronetURLRequestContextAdapter);
}; };
......
...@@ -116,7 +116,9 @@ public class CronetUrlRequestContextTest extends CronetTestBase { ...@@ -116,7 +116,9 @@ public class CronetUrlRequestContextTest extends CronetTestBase {
assertTrue(NativeTestServer.startNativeTestServer( assertTrue(NativeTestServer.startNativeTestServer(
getInstrumentation().getTargetContext())); getInstrumentation().getTargetContext()));
if (!NativeTestServer.isDataReductionProxySupported()) {
return;
}
String serverHostPort = NativeTestServer.getHostPort(); String serverHostPort = NativeTestServer.getHostPort();
// Enable the Data Reduction Proxy and configure it to use the test // Enable the Data Reduction Proxy and configure it to use the test
......
...@@ -306,6 +306,14 @@ jstring GetHostPort(JNIEnv* env, jclass jcaller) { ...@@ -306,6 +306,14 @@ jstring GetHostPort(JNIEnv* env, jclass jcaller) {
return base::android::ConvertUTF8ToJavaString(env, host_port).Release(); return base::android::ConvertUTF8ToJavaString(env, host_port).Release();
} }
jboolean IsDataReductionProxySupported(JNIEnv* env, jclass jcaller) {
#if defined(DATA_REDUCTION_PROXY_SUPPORT)
return JNI_TRUE;
#else
return JNI_FALSE;
#endif
}
bool RegisterNativeTestServer(JNIEnv* env) { bool RegisterNativeTestServer(JNIEnv* env) {
return RegisterNativesImpl(env); return RegisterNativesImpl(env);
} }
......
...@@ -95,6 +95,10 @@ public final class NativeTestServer { ...@@ -95,6 +95,10 @@ public final class NativeTestServer {
return nativeGetHostPort(); return nativeGetHostPort();
} }
public static boolean isDataReductionProxySupported() {
return nativeIsDataReductionProxySupported();
}
@CalledByNative @CalledByNative
private static void onHostResolverProcRegistered() { private static void onHostResolverProcRegistered() {
sHostResolverBlock.open(); sHostResolverBlock.open();
...@@ -112,4 +116,5 @@ public final class NativeTestServer { ...@@ -112,4 +116,5 @@ public final class NativeTestServer {
private static native String nativeGetFileURL(String filePath); private static native String nativeGetFileURL(String filePath);
private static native String nativeGetSdchURL(); private static native String nativeGetSdchURL();
private static native String nativeGetHostPort(); private static native String nativeGetHostPort();
private static native boolean nativeIsDataReductionProxySupported();
} }
...@@ -21,8 +21,6 @@ ...@@ -21,8 +21,6 @@
'android/chromium_url_request_context.h', 'android/chromium_url_request_context.h',
'android/chromium_url_request_error_list.h', 'android/chromium_url_request_error_list.h',
'android/chromium_url_request_priority_list.h', 'android/chromium_url_request_priority_list.h',
'android/cronet_data_reduction_proxy.cc',
'android/cronet_data_reduction_proxy.h',
'android/cronet_histogram_manager.cc', 'android/cronet_histogram_manager.cc',
'android/cronet_histogram_manager.h', 'android/cronet_histogram_manager.h',
'android/cronet_in_memory_pref_store.cc', 'android/cronet_in_memory_pref_store.cc',
...@@ -65,4 +63,20 @@ ...@@ -65,4 +63,20 @@
'-Wl,--gc-sections', '-Wl,--gc-sections',
'-Wl,--exclude-libs,ALL' '-Wl,--exclude-libs,ALL'
], ],
'conditions': [
# If Data Reduction Proxy support is enabled, add the following
# defines and sources. Dependencies are target-specific and are
# not included here.
['enable_data_reduction_proxy_support==1',
{
'defines' : [
'DATA_REDUCTION_PROXY_SUPPORT'
],
'sources': [
'android/cronet_data_reduction_proxy.cc',
'android/cronet_data_reduction_proxy.h',
],
}
],
],
} }
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment