Disable view source for Developer Tools.
[chromium-blink-merge.git] / chrome / browser / net / spdyproxy / data_reduction_proxy_settings_android.h
bloba90b7fa408a42a9ae1c6a34573dca54aa535d74c
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 {
26 public:
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
39 // the proxy is used.
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,
48 jobject obj);
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,
55 jobject obj);
56 ScopedJavaLocalRef<jlongArray> GetDailyReceivedContentLengths(JNIEnv* env,
57 jobject obj);
59 // Return a Java |ContentLengths| object wrapping the results of a call to
60 // DataReductionProxySettings::GetContentLengths.
61 base::android::ScopedJavaLocalRef<jobject> GetContentLengths(JNIEnv* env,
62 jobject obj);
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,
68 jobject obj,
69 jstring host,
70 jstring realm);
72 ScopedJavaLocalRef<jstring> GetTokenForAuthChallenge(JNIEnv* env,
73 jobject obj,
74 jstring host,
75 jstring realm);
77 // Registers the native methods to be call from Java.
78 static bool Register(JNIEnv* env);
80 protected:
81 // DataReductionProxySettings overrides.
82 virtual void AddDefaultProxyBypassRules() OVERRIDE;
84 // Configures the proxy settings by generating a data URL containing a PAC
85 // file.
86 virtual void SetProxyConfigs(
87 bool enabled, bool restricted, bool at_startup) OVERRIDE;
89 private:
90 friend class DataReductionProxySettingsAndroidTest;
91 FRIEND_TEST_ALL_PREFIXES(DataReductionProxySettingsAndroidTest,
92 TestBypassPACRules);
93 FRIEND_TEST_ALL_PREFIXES(DataReductionProxySettingsAndroidTest,
94 TestSetProxyPac);
95 FRIEND_TEST_ALL_PREFIXES(DataReductionProxySettingsAndroidTest,
96 TestGetDailyContentLengths);
99 ScopedJavaLocalRef<jlongArray> GetDailyContentLengths(JNIEnv* env,
100 const char* pref_name);
101 std::string GetProxyPacScript(bool restricted);
103 std::vector<std::string> pac_bypass_rules_;
105 DISALLOW_COPY_AND_ASSIGN(DataReductionProxySettingsAndroid);
108 #endif // CHROME_BROWSER_NET_SPDYPROXY_DATA_REDUCTION_PROXY_SETTINGS_ANDROID_H_