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

Unified 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 comments from mmenke 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 side-by-side diff with in-line comments
Download patch
Index: chrome/browser/net/spdyproxy/data_reduction_proxy_settings_android.h
diff --git a/chrome/browser/net/spdyproxy/data_reduction_proxy_settings_android.h b/chrome/browser/net/spdyproxy/data_reduction_proxy_settings_android.h
new file mode 100644
index 0000000000000000000000000000000000000000..29dfbaeb765d54329005ce810c717ee413aca683
--- /dev/null
+++ b/chrome/browser/net/spdyproxy/data_reduction_proxy_settings_android.h
@@ -0,0 +1,170 @@
+// Copyright 2013 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#ifndef CHROME_BROWSER_NET_SPDYPROXY_DATA_REDUCTION_PROXY_SETTINGS_ANDROID_H_
+#define CHROME_BROWSER_NET_SPDYPROXY_DATA_REDUCTION_PROXY_SETTINGS_ANDROID_H_
+
+#include "base/android/jni_helper.h"
+#include "base/android/jni_string.h"
+#include "base/android/scoped_java_ref.h"
+#include "base/basictypes.h"
+#include "base/gtest_prod_util.h"
+#include "base/prefs/pref_service.h"
+#include "net/base/network_change_notifier.h"
+#include "net/url_request/url_fetcher.h"
+#include "net/url_request/url_fetcher_delegate.h"
+
+using base::android::ScopedJavaLocalRef;
+
+namespace spdyproxy {
+
+// The number of days of bandwidth usage statistics that are tracked.
+const unsigned int kNumDaysInHistory = 60;
+
+// The number of days of bandwidth usage statistics that are presented.
+const unsigned int kNumDaysInHistorySummary = 30;
+
+COMPILE_ASSERT(kNumDaysInHistorySummary <= kNumDaysInHistory,
+ DataReductionProxySettings_summary_too_long);
+
+} // namespace spdyproxy
+
+// Central point for configuring the data reduction proxy on Android.
+// This object lives on the UI thread and all of its methods are expected to
+// be called from there.
+class DataReductionProxySettingsAndroid
+ : public net::URLFetcherDelegate,
+ public net::NetworkChangeNotifier::IPAddressObserver {
+ public:
+ DataReductionProxySettingsAndroid(JNIEnv* env, jobject obj);
+ virtual ~DataReductionProxySettingsAndroid();
+
+ void InitDataReductionProxySettings(JNIEnv* env, jobject obj);
+
+ // Returns true if the data reduction proxy is available for use on this
+ // instance of Chrome. This could return false, for example, if this instance
+ // is not part of the field trial, or if the proxy name is not configured
+ // via gyp.
+ 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:
+
+ // Returns true if a screen promoting the data reduction proxy is available
+ // for use. Logic that decides when to show the promo should check its
+ // availability. This would return false if not part of a separate field
+ // trial that governs the use of the promotion.
+ jboolean IsDataReductionProxyPromoAvailable(JNIEnv* env, jobject obj);
+
+ // Returns the origin of the data reduction proxy.
+ ScopedJavaLocalRef<jstring> GetDataReductionProxyOrigin(JNIEnv* env,
+ jobject obj);
+
+ // Returns a configuration string for the proxy.
+ 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
+ jobject obj);
+
+ // Returns true if the proxy is enabled.
+ jboolean IsDataReductionProxyEnabled(JNIEnv* env, jobject obj);
+
+ // Returns true if the proxy is managed by an adminstrator's policy.
+ jboolean IsDataReductionProxyManaged(JNIEnv* env, jobject obj);
+
+ // Enables or disables the data reduction proxy.
+ void SetDataReductionProxyEnabled(JNIEnv* env, jobject obj, jboolean enabled);
+
+ // Returns the time in microseconds that the last update was made to the
+ // daily original and received content lengths.
+ jlong GetDataReductionLastUpdateTime(JNIEnv* env, jobject obj);
+
+ // Return a Java |ContentLengths| object containing the total number of bytes
+ // of all received content, before and after compression by the data
+ // reduction proxy.
+ base::android::ScopedJavaLocalRef<jobject> GetContentLengths(JNIEnv* env,
+ jobject obj);
+
+ // Returns an array containing the total size of all HTTP content that was
+ // received over the last |kNumDaysInHistory| before any compression by the
+ // data reduction proxy. Each element in the array contains one day of data.
+ ScopedJavaLocalRef<jlongArray> GetDailyOriginalContentLengths(JNIEnv* env,
+ jobject obj);
+
+ // Returning an array containing the aggregate received HTTP content in
+ // the last |kNumDaysInHistory| days
+ ScopedJavaLocalRef<jlongArray> GetDailyReceivedContentLengths(JNIEnv* env,
+ jobject obj);
+
+ // Registers the native methods to be call from Java.
+ static bool Register(JNIEnv* env);
+
+ private:
+ friend class DataReductionProxySettingsAndroidTest;
+ FRIEND_TEST_ALL_PREFIXES(DataReductionProxySettingsAndroidTest,
+ TestBypassRules);
+ FRIEND_TEST_ALL_PREFIXES(DataReductionProxySettingsAndroidTest,
+ TestFormatURL);
+ FRIEND_TEST_ALL_PREFIXES(DataReductionProxySettingsAndroidTest,
+ TestStatistics);
+
+ // net::URLFetcherDelegate:
+ virtual void OnURLFetchComplete(const net::URLFetcher* source) OVERRIDE;
+
+
+ // NetworkChangeNotifier::IPAddressObserver:
+ virtual void OnIPAddressChanged() OVERRIDE;
+
+ bool IsDataReductionProxyAvailable();
+ bool IsDataReductionProxyPromoAvailable();
+
+ void AddDefaultProxyBypassRules();
+ void AddURLPatternToBypass(const std::string& pattern);
+ void AddHostPatternToBypass(const std::string& pattern);
+ void AddPatternToBypass(const std::string& url_or_host,
+ const std::string& pattern);
+ void AddHostToBypass(const std::string& host);
+
+ PrefService* OriginalProfilePrefs();
+ PrefService* GetLocalStatePrefs();
+ 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.
+ void set_local_state_for_testing(PrefService* local_state);
+
+ std::string GetDataReductionProxyOrigin();
+ std::string GetDataReductionProxyOriginHostPort();
+ void RemoveSchemeAndTrailingSlash(std::string* url);
+ void ResetDataReductionStatistics();
+
+ void SetProxyPac(bool enable_spdy_proxy, bool at_startup);
+
+ std::string GetProxyCheckURL();
+
+ int64 GetInt64PrefValue(const ListValue& list_value, size_t index);
+ ScopedJavaLocalRef<jlongArray> GetDailyContentLengths(JNIEnv* env,
+ const char* pref_name);
+ void GetContentLengths(unsigned int days,
+ int64* original_content_length,
+ int64* received_content_length,
+ int64* last_update_time);
+
+ void CheckDataReductionProxyIsAvailable(const std::string& url);
+
+ std::string GetProxyPacScript();
+
+ std::vector<std::string> bypass_rules_;
+
+ // Indicate whether a user has turned on the data reduction proxy previously
+ // in this session.
+ bool has_turned_on_;
+
+ // Indicate whether a user has turned off the data reduction proxy previously
+ // in this session.
+ bool has_turned_off_;
+
+ bool disabled_by_carrier_;
+ bool enabled_by_user_;
+
+ scoped_ptr<net::URLFetcher> fetcher_;
+ PrefService* original_profile_prefs_for_testing_;
+ 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
+
+ DISALLOW_COPY_AND_ASSIGN(DataReductionProxySettingsAndroid);
+};
+
+#endif // CHROME_BROWSER_NET_SPDYPROXY_DATA_REDUCTION_PROXY_SETTINGS_ANDROID_H_

Powered by Google App Engine
This is Rietveld 408576698