Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(348)

Side by Side Diff: chrome/browser/net/spdyproxy/data_reduction_proxy_settings_android.h

Issue 23458016: Added probe to determine if data reduction proxy can be used (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Addressed changes Created 7 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
(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/compiler_specific.h"
13 #include "base/gtest_prod_util.h"
14 #include "base/memory/scoped_ptr.h"
15 #include "base/prefs/pref_change_registrar.h"
16 #include "net/base/network_change_notifier.h"
17 #include "net/url_request/url_fetcher_delegate.h"
18
19 using base::android::ScopedJavaLocalRef;
20
21 class PrefService;
22
23 namespace net {
24 class URLFetcher;
25 }
26
27 namespace spdyproxy {
28
29 // The number of days of bandwidth usage statistics that are tracked.
30 const unsigned int kNumDaysInHistory = 60;
31
32 // The number of days of bandwidth usage statistics that are presented.
33 const unsigned int kNumDaysInHistorySummary = 30;
34
35 COMPILE_ASSERT(kNumDaysInHistorySummary <= kNumDaysInHistory,
36 DataReductionProxySettings_summary_too_long);
37
38 } // namespace spdyproxy
39
40 // Central point for configuring the data reduction proxy on Android.
41 // This object lives on the UI thread and all of its methods are expected to
42 // be called from there.
43 class DataReductionProxySettingsAndroid
44 : public net::URLFetcherDelegate,
45 public net::NetworkChangeNotifier::IPAddressObserver {
46 public:
47 DataReductionProxySettingsAndroid(JNIEnv* env, jobject obj);
48 virtual ~DataReductionProxySettingsAndroid();
49
50 void InitDataReductionProxySettings(JNIEnv* env, jobject obj);
51
52 // Add a host or URL pattern to bypass the proxy, respectively. Wildcards
53 // should be compatible with the JavaScript function shExpMatch, which can be
54 // used in proxy PAC resolution. These function must only be called before the
55 // proxy is used.
56 void BypassHostPattern(JNIEnv* env, jobject obj, jstring pattern);
57 void BypassURLPattern(JNIEnv* env, jobject obj, jstring pattern);
58
59 // Returns true if the data reduction proxy is allowed to be used on this
60 // instance of Chrome. This could return false, for example, if this instance
61 // is not part of the field trial, or if the proxy name is not configured
62 // via gyp.
63 jboolean IsDataReductionProxyAllowed(JNIEnv* env, jobject obj);
64
65 // Returns true if a screen promoting the data reduction proxy is allowed to
66 // be shown. Logic that decides when to show the promo should check its
67 // availability. This would return false if not part of a separate field
68 // trial that governs the use of the promotion.
69 jboolean IsDataReductionProxyPromoAllowed(JNIEnv* env, jobject obj);
70
71 // Returns the origin of the data reduction proxy.
72 ScopedJavaLocalRef<jstring> GetDataReductionProxyOrigin(JNIEnv* env,
73 jobject obj);
74
75 // Returns a configuration string for the proxy.
76 ScopedJavaLocalRef<jstring> GetDataReductionProxyAuth(JNIEnv* env,
77 jobject obj);
78
79 // Returns true if the proxy is enabled.
80 jboolean IsDataReductionProxyEnabled(JNIEnv* env, jobject obj);
81
82 // Returns true if the proxy is managed by an adminstrator's policy.
83 jboolean IsDataReductionProxyManaged(JNIEnv* env, jobject obj);
84
85 // Enables or disables the data reduction proxy. If a probe URL is available,
86 // and a probe request fails at some point, the proxy won't be used until a
87 // probe succeeds.
88 void SetDataReductionProxyEnabled(JNIEnv* env, jobject obj, jboolean enabled);
89
90 // Returns the time in microseconds that the last update was made to the
91 // daily original and received content lengths.
92 jlong GetDataReductionLastUpdateTime(JNIEnv* env, jobject obj);
93
94 // Return a Java |ContentLengths| object containing the total number of bytes
95 // of all received content, before and after compression by the data
96 // reduction proxy.
97 base::android::ScopedJavaLocalRef<jobject> GetContentLengths(JNIEnv* env,
98 jobject obj);
99
100 // Returns an array containing the total size of all HTTP content that was
101 // received over the last |kNumDaysInHistory| before any compression by the
102 // data reduction proxy. Each element in the array contains one day of data.
103 ScopedJavaLocalRef<jlongArray> GetDailyOriginalContentLengths(JNIEnv* env,
104 jobject obj);
105
106 // Returning an array containing the aggregate received HTTP content in
107 // the last |kNumDaysInHistory| days
108 ScopedJavaLocalRef<jlongArray> GetDailyReceivedContentLengths(JNIEnv* env,
109 jobject obj);
110
111 // Registers the native methods to be call from Java.
112 static bool Register(JNIEnv* env);
113
114 // net::URLFetcherDelegate:
115 virtual void OnURLFetchComplete(const net::URLFetcher* source) OVERRIDE;
116
117 protected:
118 virtual net::URLFetcher* GetURLFetcher();
119 virtual PrefService* GetOriginalProfilePrefs();
120 virtual PrefService* GetLocalStatePrefs();
121
122 private:
123 friend class DataReductionProxySettingsAndroidTest;
124 FRIEND_TEST_ALL_PREFIXES(DataReductionProxySettingsAndroidTest,
125 TestBypassRules);
126 FRIEND_TEST_ALL_PREFIXES(DataReductionProxySettingsAndroidTest,
127 TestGetDataReductionProxyOriginHostPort);
128 FRIEND_TEST_ALL_PREFIXES(DataReductionProxySettingsAndroidTest,
129 TestResetDataReductionStatistics);
130 FRIEND_TEST_ALL_PREFIXES(DataReductionProxySettingsAndroidTest,
131 TestIsProxyEnabledOrManaged);
132 FRIEND_TEST_ALL_PREFIXES(DataReductionProxySettingsAndroidTest,
133 TestSetProxyPac);
134 FRIEND_TEST_ALL_PREFIXES(DataReductionProxySettingsAndroidTest,
135 TestGetDailyContentLengths);
136 FRIEND_TEST_ALL_PREFIXES(DataReductionProxySettingsAndroidTest,
137 TestContentLengthsInternal);
138 FRIEND_TEST_ALL_PREFIXES(DataReductionProxySettingsAndroidTest,
139 TestMaybeActivateDataReductionProxy);
140
141
142
143
mmenke 2013/09/17 20:25:25 nit: Remove linebreaks.
bengr 2013/09/18 22:15:26 Done.
144 // NetworkChangeNotifier::IPAddressObserver:
145 virtual void OnIPAddressChanged() OVERRIDE;
146
147 void OnProxyEnabledPrefChange();
148
149 void AddDefaultProxyBypassRules();
150 void AddURLPatternToBypass(const std::string& pattern);
151 void AddHostPatternToBypass(const std::string& pattern);
152 void AddPatternToBypass(const std::string& url_or_host,
153 const std::string& pattern);
154 void AddHostToBypass(const std::string& host);
155
156 std::string GetDataReductionProxyOriginInternal();
157 std::string GetDataReductionProxyOriginHostPort();
158 void ResetDataReductionStatistics();
159
160 void MaybeActivateDataReductionProxy(bool at_startup);
161 void SetProxyPac(bool enable_spdy_proxy, bool at_startup);
162
163 ScopedJavaLocalRef<jlongArray> GetDailyContentLengths(JNIEnv* env,
164 const char* pref_name);
165 void GetContentLengthsInternal(unsigned int days,
166 int64* original_content_length,
167 int64* received_content_length,
168 int64* last_update_time);
169
170 // Requests the proxy probe URL, if one is set. If unable to do so, disables
171 // the proxy, if enabled. Otherwise enables the proxy if disabled by a probe
172 // failure.
173 void ProbeWhetherDataReductionProxyIsAvailable();
174
175 std::string GetProxyPacScript();
176
177 std::vector<std::string> bypass_rules_;
178
179 // Indicate whether a user has turned on the data reduction proxy previously
180 // in this session.
181 bool has_turned_on_;
182
183 // Indicate whether a user has turned off the data reduction proxy previously
184 // in this session.
185 bool has_turned_off_;
186
187 bool disabled_by_carrier_;
188 bool enabled_by_user_;
189
190 scoped_ptr<net::URLFetcher> fetcher_;
191 PrefChangeRegistrar pref_change_registrar_;
192
193 DISALLOW_COPY_AND_ASSIGN(DataReductionProxySettingsAndroid);
194 };
195
196 #endif // CHROME_BROWSER_NET_SPDYPROXY_DATA_REDUCTION_PROXY_SETTINGS_ANDROID_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698