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. 4 5 #ifndef CHROME_BROWSER_NET_SPDYPROXY_DATA_REDUCTION_PROXY_SETTINGS_ANDROID_H_ 6 #define CHROME_BROWSER_NET_SPDYPROXY_DATA_REDUCTION_PROXY_SETTINGS_ANDROID_H_ 7 8 #include "base/android/jni_string.h" 9 #include "base/android/jni_weak_ref.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 "components/data_reduction_proxy/browser/data_reduction_proxy_settings.h" 17 #include "components/keyed_service/core/keyed_service.h" 18 19 using base::android::ScopedJavaLocalRef; 20 21 class Profile; 22 23 namespace data_reduction_proxy { 24 class DataReductionProxyParams; 25 } 26 27 // Central point for configuring the data reduction proxy on Android. 28 // This object lives on the UI thread and all of its methods are expected to 29 // be called from there. 30 class DataReductionProxySettingsAndroid 31 : public data_reduction_proxy::DataReductionProxySettings, 32 public KeyedService { 33 public: 34 // Factory constructor. 35 DataReductionProxySettingsAndroid( 36 data_reduction_proxy::DataReductionProxyParams* params); 37 38 39 virtual ~DataReductionProxySettingsAndroid(); 40 41 void InitDataReductionProxySettings(Profile* profile); 42 43 void BypassHostPattern(JNIEnv* env, jobject obj, jstring pattern); 44 // Add a URL pattern to bypass the proxy. Wildcards 45 // should be compatible with the JavaScript function shExpMatch, which can be 46 // used in proxy PAC resolution. These functions must only be called before 47 // the proxy is used. 48 void BypassURLPattern(JNIEnv* env, jobject obj, jstring pattern); 49 50 // JNI wrapper interfaces to the indentically-named superclass methods. 51 jboolean IsDataReductionProxyAllowed(JNIEnv* env, jobject obj); 52 jboolean IsDataReductionProxyPromoAllowed(JNIEnv* env, jobject obj); 53 ScopedJavaLocalRef<jstring> GetDataReductionProxyOrigin(JNIEnv* env, 54 jobject obj); 55 jboolean IsDataReductionProxyEnabled(JNIEnv* env, jobject obj); 56 jboolean IsDataReductionProxyManaged(JNIEnv* env, jobject obj); 57 void SetDataReductionProxyEnabled(JNIEnv* env, jobject obj, jboolean enabled); 58 59 jlong GetDataReductionLastUpdateTime(JNIEnv* env, jobject obj); 60 ScopedJavaLocalRef<jlongArray> GetDailyOriginalContentLengths(JNIEnv* env, 61 jobject obj); 62 ScopedJavaLocalRef<jlongArray> GetDailyReceivedContentLengths(JNIEnv* env, 63 jobject obj); 64 65 // Return a Java |ContentLengths| object wrapping the results of a call to 66 // DataReductionProxySettings::GetContentLengths. 67 base::android::ScopedJavaLocalRef<jobject> GetContentLengths(JNIEnv* env, 68 jobject obj); 69 70 // Wrapper methods for handling auth challenges. In both of the following, 71 // a net::AuthChallengeInfo object is created from |host| and |realm| and 72 // passed in to the superclass method. 73 jboolean IsAcceptableAuthChallenge(JNIEnv* env, 74 jobject obj, 75 jstring host, 76 jstring realm); 77 78 ScopedJavaLocalRef<jstring> GetTokenForAuthChallenge(JNIEnv* env, 79 jobject obj, 80 jstring host, 81 jstring realm); 82 83 // Registers the native methods to be call from Java. 84 static bool Register(JNIEnv* env); 85 86 protected: 87 // DataReductionProxySettings overrides. 88 virtual void AddDefaultProxyBypassRules() OVERRIDE; 89 90 // Configures the proxy settings by generating a data URL containing a PAC 91 // file. 92 virtual void SetProxyConfigs(bool enabled, 93 bool alt_enabled, 94 bool restricted, 95 bool at_startup) OVERRIDE; 96 97 private: 98 friend class DataReductionProxySettingsAndroidTest; 99 FRIEND_TEST_ALL_PREFIXES(DataReductionProxySettingsAndroidTest, 100 TestGetDailyContentLengths); 101 102 103 ScopedJavaLocalRef<jlongArray> GetDailyContentLengths(JNIEnv* env, 104 const char* pref_name); 105 106 DISALLOW_COPY_AND_ASSIGN(DataReductionProxySettingsAndroid); 107 }; 108 109 #endif // CHROME_BROWSER_NET_SPDYPROXY_DATA_REDUCTION_PROXY_SETTINGS_ANDROID_H_ 110