Chromium Code Reviews| OLD | NEW |
|---|---|
| (Empty) | |
| 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_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/gtest_prod_util.h" | |
| 13 #include "base/prefs/pref_service.h" | |
| 14 #include "net/base/network_change_notifier.h" | |
| 15 #include "net/url_request/url_fetcher.h" | |
| 16 #include "net/url_request/url_fetcher_delegate.h" | |
| 17 | |
| 18 using base::android::ScopedJavaLocalRef; | |
| 19 | |
| 20 namespace spdyproxy { | |
| 21 | |
| 22 // The number of days of bandwidth usage statistics that are tracked. | |
| 23 const unsigned int kNumDaysInHistory = 60; | |
| 24 | |
| 25 // The number of days of bandwidth usage statistics that are presented. | |
| 26 const unsigned int kNumDaysInHistorySummary = 30; | |
| 27 | |
| 28 COMPILE_ASSERT(kNumDaysInHistorySummary <= kNumDaysInHistory, | |
| 29 DataReductionProxySettings_summary_too_long); | |
| 30 | |
| 31 } // namespace spdyproxy | |
| 32 | |
| 33 // Central point for configuring the data reduction proxy on Android. | |
| 34 // This object lives on the UI thread and all of its methods are expected to | |
| 35 // be called from there. | |
| 36 class DataReductionProxySettingsAndroid | |
| 37 : public net::URLFetcherDelegate, | |
| 38 public net::NetworkChangeNotifier::IPAddressObserver { | |
| 39 public: | |
| 40 DataReductionProxySettingsAndroid(JNIEnv* env, jobject obj); | |
| 41 virtual ~DataReductionProxySettingsAndroid(); | |
| 42 | |
| 43 void InitDataReductionProxySettings(JNIEnv* env, jobject obj); | |
| 44 | |
| 45 // Returns true if the data reduction proxy is available for use on this | |
| 46 // instance of Chrome. This could return false, for example, if this instance | |
| 47 // is not part of the field trial, or if the proxy name is not configured | |
| 48 // via gyp. | |
| 49 jboolean IsDataReductionProxyAvailable(JNIEnv* env, jobject obj); | |
|
mmenke
2013/09/10 16:17:29
Style guide comes out pretty strongly against over
bengr
2013/09/10 18:51:05
You mean the Google C++ guide? I didn't see anythi
mmenke
2013/09/10 19:54:06
Yes, the Google C++ style guide
On 2013/09/10 18:
| |
| 50 | |
| 51 // Returns true if a screen promoting the data reduction proxy is available | |
| 52 // for use. Logic that decides when to show the promo should check its | |
| 53 // availability. This would return false if not part of a separate field | |
| 54 // trial that governs the use of the promotion. | |
| 55 jboolean IsDataReductionProxyPromoAvailable(JNIEnv* env, jobject obj); | |
| 56 | |
| 57 // Returns the origin of the data reduction proxy. | |
| 58 ScopedJavaLocalRef<jstring> GetDataReductionProxyOrigin(JNIEnv* env, | |
| 59 jobject obj); | |
| 60 | |
| 61 // Returns a configuration string for the proxy. | |
| 62 ScopedJavaLocalRef<jstring> GetDataReductionProxyValue(JNIEnv* env, | |
|
mmenke
2013/09/10 16:17:29
Suggest renaming this "GetDataReductionProxyAuthSt
bengr
2013/09/10 18:51:05
Done. I'm leaving the switch as is b/c iOS relies
| |
| 63 jobject obj); | |
| 64 | |
| 65 // Returns true if the proxy is enabled. | |
| 66 jboolean IsDataReductionProxyEnabled(JNIEnv* env, jobject obj); | |
| 67 | |
| 68 // Returns true if the proxy is managed by an adminstrator's policy. | |
| 69 jboolean IsDataReductionProxyManaged(JNIEnv* env, jobject obj); | |
| 70 | |
| 71 // Enables or disables the data reduction proxy. | |
| 72 void SetDataReductionProxyEnabled(JNIEnv* env, jobject obj, jboolean enabled); | |
| 73 | |
| 74 // Returns the time in microseconds that the last update was made to the | |
| 75 // daily original and received content lengths. | |
| 76 jlong GetDataReductionLastUpdateTime(JNIEnv* env, jobject obj); | |
| 77 | |
| 78 // Return a Java |ContentLengths| object containing the total number of bytes | |
| 79 // of all received content, before and after compression by the data | |
| 80 // reduction proxy. | |
| 81 base::android::ScopedJavaLocalRef<jobject> GetContentLengths(JNIEnv* env, | |
| 82 jobject obj); | |
| 83 | |
| 84 // Returns an array containing the total size of all HTTP content that was | |
| 85 // received over the last |kNumDaysInHistory| before any compression by the | |
| 86 // data reduction proxy. Each element in the array contains one day of data. | |
| 87 ScopedJavaLocalRef<jlongArray> GetDailyOriginalContentLengths(JNIEnv* env, | |
| 88 jobject obj); | |
| 89 | |
| 90 // Returning an array containing the aggregate received HTTP content in | |
| 91 // the last |kNumDaysInHistory| days | |
| 92 ScopedJavaLocalRef<jlongArray> GetDailyReceivedContentLengths(JNIEnv* env, | |
| 93 jobject obj); | |
| 94 | |
| 95 // Registers the native methods to be call from Java. | |
| 96 static bool Register(JNIEnv* env); | |
| 97 | |
| 98 private: | |
| 99 friend class DataReductionProxySettingsAndroidTest; | |
| 100 FRIEND_TEST_ALL_PREFIXES(DataReductionProxySettingsAndroidTest, | |
| 101 TestBypassRules); | |
| 102 FRIEND_TEST_ALL_PREFIXES(DataReductionProxySettingsAndroidTest, | |
| 103 TestFormatURL); | |
| 104 FRIEND_TEST_ALL_PREFIXES(DataReductionProxySettingsAndroidTest, | |
| 105 TestStatistics); | |
| 106 | |
| 107 // net::URLFetcherDelegate: | |
| 108 virtual void OnURLFetchComplete(const net::URLFetcher* source) OVERRIDE; | |
| 109 | |
| 110 | |
| 111 // NetworkChangeNotifier::IPAddressObserver: | |
| 112 virtual void OnIPAddressChanged() OVERRIDE; | |
| 113 | |
| 114 bool IsDataReductionProxyAvailable(); | |
| 115 bool IsDataReductionProxyPromoAvailable(); | |
| 116 | |
| 117 void AddDefaultProxyBypassRules(); | |
| 118 void AddURLPatternToBypass(const std::string& pattern); | |
| 119 void AddHostPatternToBypass(const std::string& pattern); | |
| 120 void AddPatternToBypass(const std::string& url_or_host, | |
| 121 const std::string& pattern); | |
| 122 void AddHostToBypass(const std::string& host); | |
| 123 | |
| 124 PrefService* OriginalProfilePrefs(); | |
| 125 PrefService* GetLocalStatePrefs(); | |
| 126 void set_pref_service(PrefService* pref_service); | |
|
mmenke
2013/09/10 16:17:29
This should also be set_pref_service_for_testing.
bengr
2013/09/10 18:51:05
Done.
| |
| 127 void set_local_state_for_testing(PrefService* local_state); | |
| 128 | |
| 129 std::string GetDataReductionProxyOrigin(); | |
| 130 std::string GetDataReductionProxyOriginHostPort(); | |
| 131 void RemoveSchemeAndTrailingSlash(std::string* url); | |
| 132 void ResetDataReductionStatistics(); | |
| 133 | |
| 134 void SetProxyPac(bool enable_spdy_proxy, bool at_startup); | |
| 135 | |
| 136 std::string GetProxyCheckURL(); | |
| 137 | |
| 138 int64 GetInt64PrefValue(const ListValue& list_value, size_t index); | |
| 139 ScopedJavaLocalRef<jlongArray> GetDailyContentLengths(JNIEnv* env, | |
| 140 const char* pref_name); | |
| 141 void GetContentLengths(unsigned int days, | |
| 142 int64* original_content_length, | |
| 143 int64* received_content_length, | |
| 144 int64* last_update_time); | |
| 145 | |
| 146 void CheckDataReductionProxyIsAvailable(const std::string& url); | |
| 147 | |
| 148 std::string GetProxyPacScript(); | |
| 149 | |
| 150 std::vector<std::string> bypass_rules_; | |
| 151 | |
| 152 // Indicate whether a user has turned on the data reduction proxy previously | |
| 153 // in this session. | |
| 154 bool has_turned_on_; | |
| 155 | |
| 156 // Indicate whether a user has turned off the data reduction proxy previously | |
| 157 // in this session. | |
| 158 bool has_turned_off_; | |
| 159 | |
| 160 bool disabled_by_carrier_; | |
| 161 bool enabled_by_user_; | |
| 162 | |
| 163 scoped_ptr<net::URLFetcher> fetcher_; | |
| 164 PrefService* original_profile_prefs_for_testing_; | |
| 165 PrefService* local_state_prefs_for_testing_; | |
|
mmenke
2013/09/10 16:17:29
I'm still confused by these two. One is for the p
bengr
2013/09/10 18:51:05
One of these is for the profile. The other is for
| |
| 166 | |
| 167 DISALLOW_COPY_AND_ASSIGN(DataReductionProxySettingsAndroid); | |
| 168 }; | |
| 169 | |
| 170 #endif // CHROME_BROWSER_NET_SPDYPROXY_DATA_REDUCTION_PROXY_SETTINGS_ANDROID_H_ | |
| OLD | NEW |