1 // Copyright 2013 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
5 #ifndef CHROME_BROWSER_NET_SPDYPROXY_DATA_REDUCTION_PROXY_SETTINGS_ANDROID_H_
6 #define CHROME_BROWSER_NET_SPDYPROXY_DATA_REDUCTION_PROXY_SETTINGS_ANDROID_H_
8 #include "base/android/jni_helper.h"
9 #include "base/android/jni_string.h"
10 #include "base/android/scoped_java_ref.h"
11 #include "base/basictypes.h"
12 #include "base/compiler_specific.h"
13 #include "base/gtest_prod_util.h"
14 #include "base/memory/scoped_ptr.h"
15 #include "base/prefs/pref_member.h"
16 #include "chrome/browser/net/spdyproxy/data_reduction_proxy_settings.h"
19 using base::android::ScopedJavaLocalRef;
22 // Central point for configuring the data reduction proxy on Android.
23 // This object lives on the UI thread and all of its methods are expected to
24 // be called from there.
25 class DataReductionProxySettingsAndroid : public DataReductionProxySettings {
27 DataReductionProxySettingsAndroid(JNIEnv* env, jobject obj);
28 // Parameter-free constructor for C++ unit tests.
29 DataReductionProxySettingsAndroid();
31 virtual ~DataReductionProxySettingsAndroid();
33 void InitDataReductionProxySettings(JNIEnv* env, jobject obj);
35 void BypassHostPattern(JNIEnv* env, jobject obj, jstring pattern);
36 // Add a URL pattern to bypass the proxy. Wildcards
37 // should be compatible with the JavaScript function shExpMatch, which can be
38 // used in proxy PAC resolution. These functions must only be called before
40 void BypassURLPattern(JNIEnv* env, jobject obj, jstring pattern);
42 virtual void AddURLPatternToBypass(const std::string& pattern) OVERRIDE;
44 // JNI wrapper interfaces to the indentically-named superclass methods.
45 jboolean IsDataReductionProxyAllowed(JNIEnv* env, jobject obj);
46 jboolean IsDataReductionProxyPromoAllowed(JNIEnv* env, jobject obj);
47 ScopedJavaLocalRef<jstring> GetDataReductionProxyOrigin(JNIEnv* env,
49 jboolean IsDataReductionProxyEnabled(JNIEnv* env, jobject obj);
50 jboolean IsDataReductionProxyManaged(JNIEnv* env, jobject obj);
51 void SetDataReductionProxyEnabled(JNIEnv* env, jobject obj, jboolean enabled);
53 jlong GetDataReductionLastUpdateTime(JNIEnv* env, jobject obj);
54 ScopedJavaLocalRef<jlongArray> GetDailyOriginalContentLengths(JNIEnv* env,
56 ScopedJavaLocalRef<jlongArray> GetDailyReceivedContentLengths(JNIEnv* env,
59 // Return a Java |ContentLengths| object wrapping the results of a call to
60 // DataReductionProxySettings::GetContentLengths.
61 base::android::ScopedJavaLocalRef<jobject> GetContentLengths(JNIEnv* env,
64 // Wrapper methods for handling auth challenges. In both of the following,
65 // a net::AuthChallengeInfo object is created from |host| and |realm| and
66 // passed in to the superclass method.
67 jboolean IsAcceptableAuthChallenge(JNIEnv* env,
72 ScopedJavaLocalRef<jstring> GetTokenForAuthChallenge(JNIEnv* env,
77 // Registers the native methods to be call from Java.
78 static bool Register(JNIEnv* env);
81 // DataReductionProxySettings overrides.
82 virtual void AddDefaultProxyBypassRules() OVERRIDE;
84 // Configures the proxy settings by generating a data URL containing a PAC
86 virtual void SetProxyConfigs(bool enabled, bool at_startup) OVERRIDE;
88 virtual void RecordDataReductionInit() OVERRIDE;
91 friend class DataReductionProxySettingsAndroidTest;
92 FRIEND_TEST_ALL_PREFIXES(DataReductionProxySettingsAndroidTest,
94 FRIEND_TEST_ALL_PREFIXES(DataReductionProxySettingsAndroidTest,
96 FRIEND_TEST_ALL_PREFIXES(DataReductionProxySettingsAndroidTest,
97 TestGetDailyContentLengths);
100 ScopedJavaLocalRef<jlongArray> GetDailyContentLengths(JNIEnv* env,
101 const char* pref_name);
102 std::string GetProxyPacScript();
104 std::vector<std::string> pac_bypass_rules_;
106 DISALLOW_COPY_AND_ASSIGN(DataReductionProxySettingsAndroid);
109 #endif // CHROME_BROWSER_NET_SPDYPROXY_DATA_REDUCTION_PROXY_SETTINGS_ANDROID_H_