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

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

Issue 2781323004: Create a new Data Saver settings page that adds the site breakdown (Closed)
Patch Set: rebase Created 3 years, 8 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
« no previous file with comments | « chrome/browser/net/spdyproxy/data_reduction_proxy_settings_android.h ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2013 The Chromium Authors. All rights reserved. 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 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "chrome/browser/net/spdyproxy/data_reduction_proxy_settings_android.h" 5 #include "chrome/browser/net/spdyproxy/data_reduction_proxy_settings_android.h"
6 6
7 #include <stdint.h> 7 #include <stdint.h>
8 8
9 #include <map>
10 #include <string>
11
9 #include "base/android/jni_android.h" 12 #include "base/android/jni_android.h"
10 #include "base/android/jni_string.h" 13 #include "base/android/jni_string.h"
14 #include "base/strings/string_piece.h"
11 #include "base/values.h" 15 #include "base/values.h"
12 #include "chrome/browser/net/spdyproxy/data_reduction_proxy_chrome_settings.h" 16 #include "chrome/browser/net/spdyproxy/data_reduction_proxy_chrome_settings.h"
13 #include "chrome/browser/net/spdyproxy/data_reduction_proxy_chrome_settings_fact ory.h" 17 #include "chrome/browser/net/spdyproxy/data_reduction_proxy_chrome_settings_fact ory.h"
14 #include "chrome/browser/profiles/profile.h" 18 #include "chrome/browser/profiles/profile.h"
15 #include "chrome/browser/profiles/profile_manager.h" 19 #include "chrome/browser/profiles/profile_manager.h"
16 #include "chrome/common/pref_names.h" 20 #include "chrome/common/pref_names.h"
21 #include "components/data_reduction_proxy/core/browser/data_reduction_proxy_comp ression_stats.h"
17 #include "components/data_reduction_proxy/core/browser/data_reduction_proxy_metr ics.h" 22 #include "components/data_reduction_proxy/core/browser/data_reduction_proxy_metr ics.h"
23 #include "components/data_reduction_proxy/core/browser/data_reduction_proxy_serv ice.h"
18 #include "components/data_reduction_proxy/core/browser/data_reduction_proxy_sett ings.h" 24 #include "components/data_reduction_proxy/core/browser/data_reduction_proxy_sett ings.h"
25 #include "components/data_reduction_proxy/core/browser/data_usage_store.h"
19 #include "components/data_reduction_proxy/core/common/data_reduction_proxy_event _store.h" 26 #include "components/data_reduction_proxy/core/common/data_reduction_proxy_event _store.h"
20 #include "components/data_reduction_proxy/core/common/data_reduction_proxy_param s.h" 27 #include "components/data_reduction_proxy/core/common/data_reduction_proxy_param s.h"
21 #include "components/data_reduction_proxy/core/common/data_reduction_proxy_pref_ names.h" 28 #include "components/data_reduction_proxy/core/common/data_reduction_proxy_pref_ names.h"
22 #include "jni/DataReductionProxySettings_jni.h" 29 #include "jni/DataReductionProxySettings_jni.h"
23 #include "net/proxy/proxy_server.h" 30 #include "net/proxy/proxy_server.h"
24 #include "url/gurl.h" 31 #include "url/gurl.h"
25 32
26 33
27 using base::android::ConvertUTF8ToJavaString; 34 using base::android::ConvertUTF8ToJavaString;
28 using base::android::JavaParamRef; 35 using base::android::JavaParamRef;
29 using base::android::ScopedJavaLocalRef; 36 using base::android::ScopedJavaLocalRef;
30 using data_reduction_proxy::DataReductionProxySettings; 37 using data_reduction_proxy::DataReductionProxySettings;
31 38
32 DataReductionProxySettingsAndroid::DataReductionProxySettingsAndroid() { 39 namespace {
40
41 constexpr size_t kBucketsPerDay =
42 24 * 60 / data_reduction_proxy::kDataUsageBucketLengthInMinutes;
43
44 struct DataUsageForHost {
45 DataUsageForHost() : data_used(0), original_size(0) {}
46
47 int64_t data_used;
48 int64_t original_size;
49 };
50
51 } // namespace
52
53 DataReductionProxySettingsAndroid::DataReductionProxySettingsAndroid()
54 : weak_factory_(this) {}
55
56 DataReductionProxySettingsAndroid::DataReductionProxySettingsAndroid(
57 JNIEnv* env,
58 const base::android::JavaParamRef<jobject>& obj)
59 : weak_factory_(this) {
60 j_settings_obj_ = JavaObjectWeakGlobalRef(env, obj);
33 } 61 }
34 62
35 DataReductionProxySettingsAndroid::~DataReductionProxySettingsAndroid() { 63 DataReductionProxySettingsAndroid::~DataReductionProxySettingsAndroid() {
36 } 64 }
37 65
38 jboolean DataReductionProxySettingsAndroid::IsDataReductionProxyPromoAllowed( 66 jboolean DataReductionProxySettingsAndroid::IsDataReductionProxyPromoAllowed(
39 JNIEnv* env, 67 JNIEnv* env,
40 const JavaParamRef<jobject>& obj) { 68 const JavaParamRef<jobject>& obj) {
41 return Settings()->PromoAllowed(); 69 return Settings()->PromoAllowed();
42 } 70 }
(...skipping 16 matching lines...) Expand all
59 jboolean enabled) { 87 jboolean enabled) {
60 Settings()->SetDataReductionProxyEnabled(enabled); 88 Settings()->SetDataReductionProxyEnabled(enabled);
61 } 89 }
62 90
63 jlong DataReductionProxySettingsAndroid::GetDataReductionLastUpdateTime( 91 jlong DataReductionProxySettingsAndroid::GetDataReductionLastUpdateTime(
64 JNIEnv* env, 92 JNIEnv* env,
65 const JavaParamRef<jobject>& obj) { 93 const JavaParamRef<jobject>& obj) {
66 return Settings()->GetDataReductionLastUpdateTime(); 94 return Settings()->GetDataReductionLastUpdateTime();
67 } 95 }
68 96
97 void DataReductionProxySettingsAndroid::ClearDataSavingStatistics(
98 JNIEnv* env,
99 const base::android::JavaParamRef<jobject>& obj) {
100 Settings()->ClearDataSavingStatistics();
101 }
102
69 base::android::ScopedJavaLocalRef<jobject> 103 base::android::ScopedJavaLocalRef<jobject>
70 DataReductionProxySettingsAndroid::GetContentLengths( 104 DataReductionProxySettingsAndroid::GetContentLengths(
71 JNIEnv* env, 105 JNIEnv* env,
72 const JavaParamRef<jobject>& obj) { 106 const JavaParamRef<jobject>& obj) {
73 int64_t original_content_length; 107 int64_t original_content_length;
74 int64_t received_content_length; 108 int64_t received_content_length;
75 int64_t last_update_internal; 109 int64_t last_update_internal;
76 Settings()->GetContentLengths( 110 Settings()->GetContentLengths(
77 data_reduction_proxy::kNumDaysInHistorySummary, 111 data_reduction_proxy::kNumDaysInHistorySummary,
78 &original_content_length, 112 &original_content_length,
(...skipping 88 matching lines...) Expand 10 before | Expand all | Expand 10 after
167 JNIEnv* env, 201 JNIEnv* env,
168 const JavaParamRef<jobject>& obj) { 202 const JavaParamRef<jobject>& obj) {
169 data_reduction_proxy::DataReductionProxyEventStore* event_store = 203 data_reduction_proxy::DataReductionProxyEventStore* event_store =
170 Settings()->GetEventStore(); 204 Settings()->GetEventStore();
171 if (!event_store) 205 if (!event_store)
172 return ConvertUTF8ToJavaString(env, std::string()); 206 return ConvertUTF8ToJavaString(env, std::string());
173 207
174 return ConvertUTF8ToJavaString(env, event_store->SanitizedLastBypassEvent()); 208 return ConvertUTF8ToJavaString(env, event_store->SanitizedLastBypassEvent());
175 } 209 }
176 210
211 void DataReductionProxySettingsAndroid::QueryDataUsage(
212 JNIEnv* env,
213 const JavaParamRef<jobject>& obj,
214 const JavaParamRef<jobject>& j_result_obj,
215 jint num_days) {
216 DCHECK(num_days <= data_reduction_proxy::kDataUsageHistoryNumDays);
217 j_query_result_obj_.Reset(env, j_result_obj);
218 num_day_for_query_ = num_days;
219 Settings()
220 ->data_reduction_proxy_service()
221 ->compression_stats()
222 ->GetHistoricalDataUsage(base::Bind(
223 &DataReductionProxySettingsAndroid::OnQueryDataUsageComplete,
224 weak_factory_.GetWeakPtr()));
225 }
226
227 void DataReductionProxySettingsAndroid::OnQueryDataUsageComplete(
228 std::unique_ptr<std::vector<data_reduction_proxy::DataUsageBucket>>
229 data_usage) {
230 if (j_query_result_obj_.is_null())
231 return;
232
233 JNIEnv* env = base::android::AttachCurrentThread();
234
235 std::map<base::StringPiece, DataUsageForHost> per_site_usage_map;
236
237 // Data usage is sorted chronologically with the last entry corresponding to
238 // |base::Time::Now()|.
239 const size_t num_buckets_to_display = num_day_for_query_ * kBucketsPerDay;
240 for (auto data_usage_it = data_usage->size() > num_buckets_to_display
241 ? data_usage->end() - num_buckets_to_display
242 : data_usage->begin();
243 data_usage_it != data_usage->end(); ++data_usage_it) {
244 for (const auto& connection_usage : data_usage_it->connection_usage()) {
245 for (const auto& site_usage : connection_usage.site_usage()) {
246 DataUsageForHost& usage = per_site_usage_map[site_usage.hostname()];
247 usage.data_used += site_usage.data_used();
248 usage.original_size += site_usage.original_size();
249 }
250 }
251 }
252
253 for (const auto& site_bucket : per_site_usage_map) {
254 Java_DataReductionProxySettings_createDataUseItemAndAddToList(
255 env, j_query_result_obj_.obj(),
256 ConvertUTF8ToJavaString(env, site_bucket.first),
257 site_bucket.second.data_used, site_bucket.second.original_size);
258 }
259
260 Java_DataReductionProxySettings_onQueryDataUsageComplete(
261 env, j_settings_obj_.get(env), j_query_result_obj_.obj());
262
263 j_query_result_obj_.Release();
264 }
265
177 // Used by generated jni code. 266 // Used by generated jni code.
178 static jlong Init(JNIEnv* env, const JavaParamRef<jobject>& obj) { 267 static jlong Init(JNIEnv* env, const JavaParamRef<jobject>& obj) {
179 return reinterpret_cast<intptr_t>(new DataReductionProxySettingsAndroid()); 268 return reinterpret_cast<intptr_t>(
269 new DataReductionProxySettingsAndroid(env, obj));
180 } 270 }
OLDNEW
« no previous file with comments | « chrome/browser/net/spdyproxy/data_reduction_proxy_settings_android.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698