Commit 75fea56d authored by sgurun@chromium.org's avatar sgurun@chromium.org

Add the plumbing to enable DRP

BUG=b/12492817

Add the internal Aw API to enable/disable DRP.

NOTRY=true

notry due to irrelevant failures in windows rel tests.

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

git-svn-id: svn://svn.chromium.org/chrome/trunk/src@269498 0039d316-1c4b-4281-b951-d872f2087c98
parent 1358f270
...@@ -41,6 +41,9 @@ AwBrowserContext* g_browser_context = NULL; ...@@ -41,6 +41,9 @@ AwBrowserContext* g_browser_context = NULL;
} // namespace } // namespace
// Data reduction proxy is disabled by default.
bool AwBrowserContext::data_reduction_proxy_enabled_ = false;
AwBrowserContext::AwBrowserContext( AwBrowserContext::AwBrowserContext(
const FilePath path, const FilePath path,
JniDependencyFactory* native_factory) JniDependencyFactory* native_factory)
...@@ -73,6 +76,22 @@ AwBrowserContext* AwBrowserContext::FromWebContents( ...@@ -73,6 +76,22 @@ AwBrowserContext* AwBrowserContext::FromWebContents(
return static_cast<AwBrowserContext*>(web_contents->GetBrowserContext()); return static_cast<AwBrowserContext*>(web_contents->GetBrowserContext());
} }
// static
void AwBrowserContext::SetDataReductionProxyEnabled(bool enabled) {
// Cache the setting value. It is possible that data reduction proxy is
// not created yet.
data_reduction_proxy_enabled_ = enabled;
AwBrowserContext* context = AwBrowserContext::GetDefault();
// Can't enable Data reduction proxy if user pref service is not ready.
if (context == NULL || context->user_pref_service_.get() == NULL)
return;
DataReductionProxySettings* proxy_settings =
context->GetDataReductionProxySettings();
if (proxy_settings == NULL)
return;
proxy_settings->SetDataReductionProxyEnabled(data_reduction_proxy_enabled_);
}
void AwBrowserContext::PreMainMessageLoopRun() { void AwBrowserContext::PreMainMessageLoopRun() {
cookie_store_ = CreateCookieStore(this); cookie_store_ = CreateCookieStore(this);
DataReductionProxySettings::SetAllowed(true); DataReductionProxySettings::SetAllowed(true);
...@@ -169,9 +188,8 @@ void AwBrowserContext::CreateUserPrefServiceIfNecessary() { ...@@ -169,9 +188,8 @@ void AwBrowserContext::CreateUserPrefServiceIfNecessary() {
user_pref_service_.get(), user_pref_service_.get(),
GetRequestContext()); GetRequestContext());
//TODO(sgurun): Attach this to the API. It is currently hard coded in a data_reduction_proxy_settings_->SetDataReductionProxyEnabled(
// disabled state. data_reduction_proxy_enabled_);
data_reduction_proxy_settings_->SetDataReductionProxyEnabled(false);
} }
base::FilePath AwBrowserContext::GetPath() const { base::FilePath AwBrowserContext::GetPath() const {
......
...@@ -64,6 +64,8 @@ class AwBrowserContext : public content::BrowserContext, ...@@ -64,6 +64,8 @@ class AwBrowserContext : public content::BrowserContext,
static AwBrowserContext* FromWebContents( static AwBrowserContext* FromWebContents(
content::WebContents* web_contents); content::WebContents* web_contents);
static void SetDataReductionProxyEnabled(bool enabled);
// Maps to BrowserMainParts::PreMainMessageLoopRun. // Maps to BrowserMainParts::PreMainMessageLoopRun.
void PreMainMessageLoopRun(); void PreMainMessageLoopRun();
...@@ -132,6 +134,8 @@ class AwBrowserContext : public content::BrowserContext, ...@@ -132,6 +134,8 @@ class AwBrowserContext : public content::BrowserContext,
const scoped_refptr<URLEnumerator>& enumerator) OVERRIDE; const scoped_refptr<URLEnumerator>& enumerator) OVERRIDE;
private: private:
static bool data_reduction_proxy_enabled_;
// The file path where data for this context is persisted. // The file path where data for this context is persisted.
base::FilePath context_storage_path_; base::FilePath context_storage_path_;
......
...@@ -49,12 +49,22 @@ public class AwContentsStatics { ...@@ -49,12 +49,22 @@ public class AwContentsStatics {
* Set Data Reduction Proxy key for authentication. * Set Data Reduction Proxy key for authentication.
*/ */
public static void setDataReductionProxyKey(String key) { public static void setDataReductionProxyKey(String key) {
ThreadUtils.assertOnUiThread();
nativeSetDataReductionProxyKey(key); nativeSetDataReductionProxyKey(key);
} }
/*
* Enable or disable data reduction proxy.
*/
public static void setDataReductionProxyEnabled(boolean enabled) {
ThreadUtils.assertOnUiThread();
nativeSetDataReductionProxyEnabled(enabled);
}
//-------------------------------------------------------------------------------------------- //--------------------------------------------------------------------------------------------
// Native methods // Native methods
//-------------------------------------------------------------------------------------------- //--------------------------------------------------------------------------------------------
private static native void nativeClearClientCertPreferences(Runnable callback); private static native void nativeClearClientCertPreferences(Runnable callback);
private static native void nativeSetDataReductionProxyKey(String key); private static native void nativeSetDataReductionProxyKey(String key);
private static native void nativeSetDataReductionProxyEnabled(boolean enabled);
} }
...@@ -4,6 +4,7 @@ ...@@ -4,6 +4,7 @@
#include "android_webview/native/aw_contents_statics.h" #include "android_webview/native/aw_contents_statics.h"
#include "android_webview/browser/aw_browser_context.h"
#include "base/android/jni_string.h" #include "base/android/jni_string.h"
#include "base/android/scoped_java_ref.h" #include "base/android/scoped_java_ref.h"
#include "base/callback.h" #include "base/callback.h"
...@@ -49,7 +50,12 @@ void ClearClientCertPreferences(JNIEnv* env, jclass, jobject callback) { ...@@ -49,7 +50,12 @@ void ClearClientCertPreferences(JNIEnv* env, jclass, jobject callback) {
// static // static
void SetDataReductionProxyKey(JNIEnv* env, jclass, jstring key) { void SetDataReductionProxyKey(JNIEnv* env, jclass, jstring key) {
DataReductionProxySettings::SetKey(ConvertJavaStringToUTF8(env, key)); DataReductionProxySettings::SetKey(ConvertJavaStringToUTF8(env, key));
}
// static
void SetDataReductionProxyEnabled(JNIEnv* env, jclass, jboolean enabled) {
AwBrowserContext::SetDataReductionProxyEnabled(enabled);
} }
bool RegisterAwContentsStatics(JNIEnv* env) { bool RegisterAwContentsStatics(JNIEnv* env) {
......
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