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

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: Added more unit tests 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 "net/base/network_change_notifier.h"
16 #include "net/url_request/url_fetcher_delegate.h"
17
18 using base::android::ScopedJavaLocalRef;
19
20 class PrefService;
21
22 namespace net {
23 class URLFetcher;
24 }
25
26 namespace spdyproxy {
27
28 // The number of days of bandwidth usage statistics that are tracked.
29 const unsigned int kNumDaysInHistory = 60;
30
31 // The number of days of bandwidth usage statistics that are presented.
32 const unsigned int kNumDaysInHistorySummary = 30;
33
34 COMPILE_ASSERT(kNumDaysInHistorySummary <= kNumDaysInHistory,
35 DataReductionProxySettings_summary_too_long);
36
37 } // namespace spdyproxy
38
39 // Central point for configuring the data reduction proxy on Android.
40 // This object lives on the UI thread and all of its methods are expected to
41 // be called from there.
42 class DataReductionProxySettingsAndroid
43 : public net::URLFetcherDelegate,
44 public net::NetworkChangeNotifier::IPAddressObserver {
45 public:
46 DataReductionProxySettingsAndroid(JNIEnv* env, jobject obj);
47 virtual ~DataReductionProxySettingsAndroid();
48
49 void InitDataReductionProxySettings(JNIEnv* env, jobject obj);
50
51 // Add a host or URL pattern to bypass the proxy, respectively. Wildcards
52 // should be compatible with the JavaScript function shExpMatch, which can be
53 // used in proxy PAC resolution. These function must only be called before the
54 // proxy is used.
55 void BypassHostPattern(JNIEnv* env, jobject obj, jstring pattern);
56 void BypassURLPattern(JNIEnv* env, jobject obj, jstring pattern);
57
58 // Returns true if the data reduction proxy is available for use on this
59 // instance of Chrome. This could return false, for example, if this instance
60 // is not part of the field trial, or if the proxy name is not configured
61 // via gyp.
62 jboolean IsDataReductionProxyAvailable(JNIEnv* env, jobject obj);
mmenke 2013/09/12 16:30:41 "Allowed" may be clearer than "Available" ("Availa
bengr 2013/09/17 01:06:19 Done.
63
64 // Returns true if a screen promoting the data reduction proxy is available
65 // for use. Logic that decides when to show the promo should check its
66 // availability. This would return false if not part of a separate field
67 // trial that governs the use of the promotion.
68 jboolean IsDataReductionProxyPromoAvailable(JNIEnv* env, jobject obj);
69
70 // Returns the origin of the data reduction proxy.
71 ScopedJavaLocalRef<jstring> GetDataReductionProxyOrigin(JNIEnv* env,
72 jobject obj);
73
74 // Returns a configuration string for the proxy.
75 ScopedJavaLocalRef<jstring> GetDataReductionProxyAuth(JNIEnv* env,
76 jobject obj);
77
78 // Returns true if the proxy is enabled.
79 jboolean IsDataReductionProxyEnabled(JNIEnv* env, jobject obj);
80
81 // Returns true if the proxy is managed by an adminstrator's policy.
82 jboolean IsDataReductionProxyManaged(JNIEnv* env, jobject obj);
83
84 // Enables or disables the data reduction proxy.
mmenke 2013/09/12 16:30:41 Think it's worth adding something along the lines
bengr 2013/09/17 01:06:19 Done.
85 void SetDataReductionProxyEnabled(JNIEnv* env, jobject obj, jboolean enabled);
86
87 // Returns the time in microseconds that the last update was made to the
88 // daily original and received content lengths.
89 jlong GetDataReductionLastUpdateTime(JNIEnv* env, jobject obj);
90
91 // Return a Java |ContentLengths| object containing the total number of bytes
92 // of all received content, before and after compression by the data
93 // reduction proxy.
94 base::android::ScopedJavaLocalRef<jobject> GetContentLengths(JNIEnv* env,
95 jobject obj);
96
97 // Returns an array containing the total size of all HTTP content that was
98 // received over the last |kNumDaysInHistory| before any compression by the
99 // data reduction proxy. Each element in the array contains one day of data.
100 ScopedJavaLocalRef<jlongArray> GetDailyOriginalContentLengths(JNIEnv* env,
101 jobject obj);
102
103 // Returning an array containing the aggregate received HTTP content in
104 // the last |kNumDaysInHistory| days
105 ScopedJavaLocalRef<jlongArray> GetDailyReceivedContentLengths(JNIEnv* env,
106 jobject obj);
107
108 // Registers the native methods to be call from Java.
109 static bool Register(JNIEnv* env);
110
111 private:
112 friend class DataReductionProxySettingsAndroidTest;
113 FRIEND_TEST_ALL_PREFIXES(DataReductionProxySettingsAndroidTest,
114 TestBypassRules);
115 FRIEND_TEST_ALL_PREFIXES(DataReductionProxySettingsAndroidTest,
116 TestGetDataReductionProxyOriginHostPort);
117 FRIEND_TEST_ALL_PREFIXES(DataReductionProxySettingsAndroidTest,
118 TestResetDataReductionStatistics);
119 FRIEND_TEST_ALL_PREFIXES(DataReductionProxySettingsAndroidTest,
120 TestIsProxyEnabledOrManaged);
121 FRIEND_TEST_ALL_PREFIXES(DataReductionProxySettingsAndroidTest,
122 TestSetProxyPac);
123 FRIEND_TEST_ALL_PREFIXES(DataReductionProxySettingsAndroidTest,
124 TestGetDailyContentLengths);
125 FRIEND_TEST_ALL_PREFIXES(DataReductionProxySettingsAndroidTest,
126 TestContentLengthsInternal);
127
128 // net::URLFetcherDelegate:
129 virtual void OnURLFetchComplete(const net::URLFetcher* source) OVERRIDE;
130
131
132 // NetworkChangeNotifier::IPAddressObserver:
133 virtual void OnIPAddressChanged() OVERRIDE;
134
135 void AddDefaultProxyBypassRules();
136 void AddURLPatternToBypass(const std::string& pattern);
137 void AddHostPatternToBypass(const std::string& pattern);
138 void AddPatternToBypass(const std::string& url_or_host,
139 const std::string& pattern);
140 void AddHostToBypass(const std::string& host);
141
142 PrefService* OriginalProfilePrefs();
143 PrefService* GetLocalStatePrefs();
144 void set_profile_prefs_for_testing(PrefService* pref_service);
145 void set_local_state_prefs_for_testing(PrefService* local_state);
146
147 std::string GetDataReductionProxyOriginInternal();
148 std::string GetDataReductionProxyOriginHostPort();
149 void ResetDataReductionStatistics();
150
151 void SetProxyPac(bool enable_spdy_proxy, bool at_startup);
152
153 ScopedJavaLocalRef<jlongArray> GetDailyContentLengths(JNIEnv* env,
154 const char* pref_name);
155 void GetContentLengthsInternal(unsigned int days,
156 int64* original_content_length,
157 int64* received_content_length,
158 int64* last_update_time);
159
160 void ProbeWhetherDataReductionProxyIsAvailable(const std::string& url);
mmenke 2013/09/12 16:30:41 Think it's worth a description...Along the lines o
bengr 2013/09/17 01:06:19 Done.
161
162 std::string GetProxyPacScript();
163
164 std::vector<std::string> bypass_rules_;
165
166 // Indicate whether a user has turned on the data reduction proxy previously
167 // in this session.
168 bool has_turned_on_;
169
170 // Indicate whether a user has turned off the data reduction proxy previously
171 // in this session.
172 bool has_turned_off_;
173
174 bool disabled_by_carrier_;
175 bool enabled_by_user_;
176
177 scoped_ptr<net::URLFetcher> fetcher_;
178 PrefService* profile_prefs_for_testing_;
179 PrefService* local_state_prefs_for_testing_;
180
181 DISALLOW_COPY_AND_ASSIGN(DataReductionProxySettingsAndroid);
182 };
183
184 #endif // CHROME_BROWSER_NET_SPDYPROXY_DATA_REDUCTION_PROXY_SETTINGS_ANDROID_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698