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

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 additional comments 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"
mmenke 2013/09/11 16:08:59 need "base/compiler_specific.h" as well, for OVERR
mmenke 2013/09/11 16:08:59 Need the scoped_ptr header, too (base/memory/scope
bengr 2013/09/11 22:01:02 Done.
bengr 2013/09/11 22:01:02 Done.
12 #include "base/gtest_prod_util.h"
13 #include "base/prefs/pref_service.h"
mmenke 2013/09/11 16:08:59 Think this can be forward declared.
bengr 2013/09/11 22:01:02 Done.
14 #include "net/base/network_change_notifier.h"
15 #include "net/url_request/url_fetcher.h"
mmenke 2013/09/11 16:08:59 We can forward declare this.
bengr 2013/09/11 22:01:02 Done.
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 // Add a pattern for a Host or URL to bypass, respectively. Wildcards should
mmenke 2013/09/11 16:08:59 Think "Add a pattern for a Host or URL to bypass"
bengr 2013/09/11 22:01:02 Done.
46 // be compatible with the JavaScript function shExpMatch, which can be used
47 // in proxy PAC resolution. These function should be called before the proxy
mmenke 2013/09/11 16:08:59 nit: should -> must (Maybe I've been reading too
bengr 2013/09/11 22:01:02 changed to "must only." I've read too many RFCs in
48 // is used.
49 void BypassHostPattern(JNIEnv* env, jobject obj, jstring pattern);
50 void BypassURLPattern(JNIEnv* env, jobject obj, jstring pattern);
51
52 // Returns true if the data reduction proxy is available for use on this
53 // instance of Chrome. This could return false, for example, if this instance
54 // is not part of the field trial, or if the proxy name is not configured
55 // via gyp.
56 jboolean IsDataReductionProxyAvailable(JNIEnv* env, jobject obj);
mmenke 2013/09/10 19:54:06 How difficult is it to test these in C++ unit test
mmenke 2013/09/11 16:08:59 If it's difficult, could make them all lightweight
bengr 2013/09/11 22:01:02 I added a bunch of tests. Let me know if this is s
bengr 2013/09/11 22:01:02 It's not too bad (see my updated patch).
57
58 // Returns true if a screen promoting the data reduction proxy is available
59 // for use. Logic that decides when to show the promo should check its
60 // availability. This would return false if not part of a separate field
61 // trial that governs the use of the promotion.
62 jboolean IsDataReductionProxyPromoAvailable(JNIEnv* env, jobject obj);
63
64 // Returns the origin of the data reduction proxy.
65 ScopedJavaLocalRef<jstring> GetDataReductionProxyOrigin(JNIEnv* env,
66 jobject obj);
67
68 // Returns a configuration string for the proxy.
69 ScopedJavaLocalRef<jstring> GetDataReductionProxyAuth(JNIEnv* env,
70 jobject obj);
71
72 // Returns true if the proxy is enabled.
73 jboolean IsDataReductionProxyEnabled(JNIEnv* env, jobject obj);
74
75 // Returns true if the proxy is managed by an adminstrator's policy.
76 jboolean IsDataReductionProxyManaged(JNIEnv* env, jobject obj);
77
78 // Enables or disables the data reduction proxy.
79 void SetDataReductionProxyEnabled(JNIEnv* env, jobject obj, jboolean enabled);
80
81 // Returns the time in microseconds that the last update was made to the
82 // daily original and received content lengths.
83 jlong GetDataReductionLastUpdateTime(JNIEnv* env, jobject obj);
84
85 // Return a Java |ContentLengths| object containing the total number of bytes
86 // of all received content, before and after compression by the data
87 // reduction proxy.
88 base::android::ScopedJavaLocalRef<jobject> GetContentLengths(JNIEnv* env,
89 jobject obj);
90
91 // Returns an array containing the total size of all HTTP content that was
92 // received over the last |kNumDaysInHistory| before any compression by the
93 // data reduction proxy. Each element in the array contains one day of data.
94 ScopedJavaLocalRef<jlongArray> GetDailyOriginalContentLengths(JNIEnv* env,
95 jobject obj);
96
97 // Returning an array containing the aggregate received HTTP content in
98 // the last |kNumDaysInHistory| days
99 ScopedJavaLocalRef<jlongArray> GetDailyReceivedContentLengths(JNIEnv* env,
100 jobject obj);
101
102 // Registers the native methods to be call from Java.
103 static bool Register(JNIEnv* env);
104
105 private:
106 friend class DataReductionProxySettingsAndroidTest;
107 FRIEND_TEST_ALL_PREFIXES(DataReductionProxySettingsAndroidTest,
108 TestBypassRules);
109 FRIEND_TEST_ALL_PREFIXES(DataReductionProxySettingsAndroidTest,
110 TestFormatURL);
mmenke 2013/09/11 16:08:59 There's no such test. My general feeling is that
bengr 2013/09/11 22:01:02 I agree, but will leave as is because it's simpler
111 FRIEND_TEST_ALL_PREFIXES(DataReductionProxySettingsAndroidTest,
112 TestStatistics);
113
114 // net::URLFetcherDelegate:
115 virtual void OnURLFetchComplete(const net::URLFetcher* source) OVERRIDE;
116
117
118 // NetworkChangeNotifier::IPAddressObserver:
119 virtual void OnIPAddressChanged() OVERRIDE;
120
121 void AddDefaultProxyBypassRules();
122 void AddURLPatternToBypass(const std::string& pattern);
123 void AddHostPatternToBypass(const std::string& pattern);
124 void AddPatternToBypass(const std::string& url_or_host,
125 const std::string& pattern);
126 void AddHostToBypass(const std::string& host);
127
128 PrefService* OriginalProfilePrefs();
129 PrefService* GetLocalStatePrefs();
130 void set_profile_prefs_for_testing(PrefService* pref_service);
131 void set_local_state_prefs_for_testing(PrefService* local_state);
132
133 std::string GetDataReductionProxyOrigin();
134 std::string GetDataReductionProxyOriginHostPort();
135 void ResetDataReductionStatistics();
136
137 void SetProxyPac(bool enable_spdy_proxy, bool at_startup);
138
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);
mmenke 2013/09/10 19:54:06 I think the simplest thing to do is to just to add
mmenke 2013/09/10 19:54:06 nit: Think some more of these can probably be con
bengr 2013/09/11 22:01:02 Done.
bengr 2013/09/11 22:01:02 Sorry, which can be const?
145
146 void CheckDataReductionProxyIsAvailable(const std::string& url);
mmenke 2013/09/11 16:08:59 nit: I don't think this function name screams "Do
bengr 2013/09/11 22:01:02 Done.
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* profile_prefs_for_testing_;
165 PrefService* local_state_prefs_for_testing_;
166
167 DISALLOW_COPY_AND_ASSIGN(DataReductionProxySettingsAndroid);
168 };
169
170 #endif // CHROME_BROWSER_NET_SPDYPROXY_DATA_REDUCTION_PROXY_SETTINGS_ANDROID_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698