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.
5 #include "chrome/browser/net/spdyproxy/data_reduction_proxy_settings_android.h"
7 #include "base/android/jni_android.h"
8 #include "base/android/jni_string.h"
9 #include "chrome/browser/net/spdyproxy/data_reduction_proxy_chrome_settings.h"
10 #include "chrome/browser/net/spdyproxy/data_reduction_proxy_chrome_settings_factory.h"
11 #include "chrome/browser/profiles/profile.h"
12 #include "chrome/browser/profiles/profile_manager.h"
13 #include "chrome/common/pref_names.h"
14 #include "components/data_reduction_proxy/core/browser/data_reduction_proxy_metrics.h"
15 #include "components/data_reduction_proxy/core/browser/data_reduction_proxy_settings.h"
16 #include "jni/DataReductionProxySettings_jni.h"
17 #include "net/proxy/proxy_server.h"
21 using base::android::ConvertUTF8ToJavaString
;
22 using base::android::ScopedJavaLocalRef
;
23 using data_reduction_proxy::DataReductionProxySettings
;
25 DataReductionProxySettingsAndroid::DataReductionProxySettingsAndroid() {
28 DataReductionProxySettingsAndroid::~DataReductionProxySettingsAndroid() {
31 jboolean
DataReductionProxySettingsAndroid::IsDataReductionProxyAllowed(
32 JNIEnv
* env
, jobject obj
) {
33 return Settings()->Allowed();
36 jboolean
DataReductionProxySettingsAndroid::IsDataReductionProxyPromoAllowed(
37 JNIEnv
* env
, jobject obj
) {
38 return Settings()->PromoAllowed();
41 jboolean
DataReductionProxySettingsAndroid::IsIncludedInAltFieldTrial(
42 JNIEnv
* env
, jobject obj
) {
46 jboolean
DataReductionProxySettingsAndroid::IsDataReductionProxyEnabled(
47 JNIEnv
* env
, jobject obj
) {
48 return Settings()->IsDataReductionProxyEnabled();
51 jboolean
DataReductionProxySettingsAndroid::CanUseDataReductionProxy(
52 JNIEnv
* env
, jobject obj
, jstring url
) {
53 return Settings()->CanUseDataReductionProxy(
54 GURL(base::android::ConvertJavaStringToUTF16(env
, url
)));
57 jboolean
DataReductionProxySettingsAndroid::WasLoFiModeActiveOnMainFrame(
58 JNIEnv
* env
, jobject obj
) {
59 return Settings()->WasLoFiModeActiveOnMainFrame();
62 jboolean
DataReductionProxySettingsAndroid::WasLoFiLoadImageRequestedBefore(
63 JNIEnv
* env
, jobject obj
) {
64 return Settings()->WasLoFiLoadImageRequestedBefore();
67 void DataReductionProxySettingsAndroid::SetLoFiLoadImageRequested(
68 JNIEnv
* env
, jobject obj
) {
69 Settings()->SetLoFiLoadImageRequested();
72 jboolean
DataReductionProxySettingsAndroid::IsDataReductionProxyManaged(
73 JNIEnv
* env
, jobject obj
) {
74 return Settings()->IsDataReductionProxyManaged();
77 void DataReductionProxySettingsAndroid::IncrementLoFiUserRequestsForImages(
78 JNIEnv
* env
, jobject obj
) {
79 Settings()->IncrementLoFiUserRequestsForImages();
82 void DataReductionProxySettingsAndroid::SetDataReductionProxyEnabled(
86 Settings()->SetDataReductionProxyEnabled(enabled
);
89 jlong
DataReductionProxySettingsAndroid::GetDataReductionLastUpdateTime(
90 JNIEnv
* env
, jobject obj
) {
91 return Settings()->GetDataReductionLastUpdateTime();
94 base::android::ScopedJavaLocalRef
<jobject
>
95 DataReductionProxySettingsAndroid::GetContentLengths(JNIEnv
* env
,
97 int64 original_content_length
;
98 int64 received_content_length
;
99 int64 last_update_internal
;
100 Settings()->GetContentLengths(
101 data_reduction_proxy::kNumDaysInHistorySummary
,
102 &original_content_length
,
103 &received_content_length
,
104 &last_update_internal
);
106 return Java_ContentLengths_create(env
,
107 original_content_length
,
108 received_content_length
);
111 ScopedJavaLocalRef
<jlongArray
>
112 DataReductionProxySettingsAndroid::GetDailyOriginalContentLengths(
113 JNIEnv
* env
, jobject obj
) {
114 return GetDailyContentLengths(
115 env
, data_reduction_proxy::prefs::kDailyHttpOriginalContentLength
);
118 ScopedJavaLocalRef
<jlongArray
>
119 DataReductionProxySettingsAndroid::GetDailyReceivedContentLengths(
120 JNIEnv
* env
, jobject obj
) {
121 return GetDailyContentLengths(
122 env
, data_reduction_proxy::prefs::kDailyHttpReceivedContentLength
);
125 jboolean
DataReductionProxySettingsAndroid::IsDataReductionProxyUnreachable(
126 JNIEnv
* env
, jobject obj
) {
127 return Settings()->IsDataReductionProxyUnreachable();
131 bool DataReductionProxySettingsAndroid::Register(JNIEnv
* env
) {
132 return RegisterNativesImpl(env
);
135 ScopedJavaLocalRef
<jlongArray
>
136 DataReductionProxySettingsAndroid::GetDailyContentLengths(
137 JNIEnv
* env
, const char* pref_name
) {
138 jlongArray result
= env
->NewLongArray(
139 data_reduction_proxy::kNumDaysInHistory
);
141 data_reduction_proxy::ContentLengthList lengths
=
142 Settings()->GetDailyContentLengths(pref_name
);
144 if (!lengths
.empty()) {
145 DCHECK_EQ(lengths
.size(), data_reduction_proxy::kNumDaysInHistory
);
146 env
->SetLongArrayRegion(result
, 0, lengths
.size(), &lengths
[0]);
147 return ScopedJavaLocalRef
<jlongArray
>(env
, result
);
150 return ScopedJavaLocalRef
<jlongArray
>(env
, result
);
153 DataReductionProxySettings
* DataReductionProxySettingsAndroid::Settings() {
154 DataReductionProxySettings
* settings
=
155 DataReductionProxyChromeSettingsFactory::GetForBrowserContext(
156 ProfileManager::GetActiveUserProfile());
162 // Used by generated jni code.
163 static jlong
Init(JNIEnv
* env
, jobject obj
) {
164 return reinterpret_cast<intptr_t>(new DataReductionProxySettingsAndroid());