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

Side by Side Diff: chrome/browser/net/chrome_network_delegate.cc

Issue 473723002: Update data reduction proxy statistics prefs less often on desktop (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@tooManyWritesPatch
Patch Set: Addressed bengr comments Created 6 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
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 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/chrome_network_delegate.h" 5 #include "chrome/browser/net/chrome_network_delegate.h"
6 6
7 #include <stdlib.h> 7 #include <stdlib.h>
8 8
9 #include <vector> 9 #include <vector>
10 10
(...skipping 16 matching lines...) Expand all
27 #include "chrome/browser/net/safe_search_util.h" 27 #include "chrome/browser/net/safe_search_util.h"
28 #include "chrome/browser/performance_monitor/performance_monitor.h" 28 #include "chrome/browser/performance_monitor/performance_monitor.h"
29 #include "chrome/browser/prerender/prerender_tracker.h" 29 #include "chrome/browser/prerender/prerender_tracker.h"
30 #include "chrome/browser/profiles/profile_manager.h" 30 #include "chrome/browser/profiles/profile_manager.h"
31 #include "chrome/browser/task_manager/task_manager.h" 31 #include "chrome/browser/task_manager/task_manager.h"
32 #include "chrome/common/pref_names.h" 32 #include "chrome/common/pref_names.h"
33 #include "components/data_reduction_proxy/browser/data_reduction_proxy_auth_requ est_handler.h" 33 #include "components/data_reduction_proxy/browser/data_reduction_proxy_auth_requ est_handler.h"
34 #include "components/data_reduction_proxy/browser/data_reduction_proxy_metrics.h " 34 #include "components/data_reduction_proxy/browser/data_reduction_proxy_metrics.h "
35 #include "components/data_reduction_proxy/browser/data_reduction_proxy_params.h" 35 #include "components/data_reduction_proxy/browser/data_reduction_proxy_params.h"
36 #include "components/data_reduction_proxy/browser/data_reduction_proxy_protocol. h" 36 #include "components/data_reduction_proxy/browser/data_reduction_proxy_protocol. h"
37 #include "components/data_reduction_proxy/browser/data_reduction_proxy_statistic s_prefs.h"
37 #include "components/data_reduction_proxy/browser/data_reduction_proxy_usage_sta ts.h" 38 #include "components/data_reduction_proxy/browser/data_reduction_proxy_usage_sta ts.h"
38 #include "components/domain_reliability/monitor.h" 39 #include "components/domain_reliability/monitor.h"
39 #include "content/public/browser/browser_thread.h" 40 #include "content/public/browser/browser_thread.h"
40 #include "content/public/browser/render_frame_host.h" 41 #include "content/public/browser/render_frame_host.h"
41 #include "content/public/browser/render_view_host.h" 42 #include "content/public/browser/render_view_host.h"
42 #include "content/public/browser/resource_request_info.h" 43 #include "content/public/browser/resource_request_info.h"
43 #include "net/base/host_port_pair.h" 44 #include "net/base/host_port_pair.h"
44 #include "net/base/net_errors.h" 45 #include "net/base/net_errors.h"
45 #include "net/base/net_log.h" 46 #include "net/base/net_log.h"
46 #include "net/cookies/canonical_cookie.h" 47 #include "net/cookies/canonical_cookie.h"
(...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after
109 int rv) { 110 int rv) {
110 if (rv == net::OK && new_url->is_empty()) 111 if (rv == net::OK && new_url->is_empty())
111 safe_search_util::ForceGoogleSafeSearch(request, new_url); 112 safe_search_util::ForceGoogleSafeSearch(request, new_url);
112 callback.Run(rv); 113 callback.Run(rv);
113 } 114 }
114 115
115 void UpdateContentLengthPrefs( 116 void UpdateContentLengthPrefs(
116 int received_content_length, 117 int received_content_length,
117 int original_content_length, 118 int original_content_length,
118 data_reduction_proxy::DataReductionProxyRequestType request_type, 119 data_reduction_proxy::DataReductionProxyRequestType request_type,
119 Profile* profile) { 120 Profile* profile,
121 data_reduction_proxy::DataReductionProxyStatisticsPrefs* statistics_prefs) {
120 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 122 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
121 DCHECK_GE(received_content_length, 0); 123 DCHECK_GE(received_content_length, 0);
122 DCHECK_GE(original_content_length, 0); 124 DCHECK_GE(original_content_length, 0);
123 125
124 // Can be NULL in a unit test. 126 // Can be NULL in a unit test.
125 if (!g_browser_process) 127 if (!g_browser_process)
126 return; 128 return;
127 129
128 PrefService* prefs = g_browser_process->local_state();
129 if (!prefs)
130 return;
131
132 // Ignore off-the-record data. 130 // Ignore off-the-record data.
133 if (!g_browser_process->profile_manager()->IsValidProfile(profile) || 131 if (!g_browser_process->profile_manager()->IsValidProfile(profile) ||
134 profile->IsOffTheRecord()) { 132 profile->IsOffTheRecord()) {
135 return; 133 return;
136 } 134 }
137 #if defined(OS_ANDROID) && defined(SPDY_PROXY_AUTH_ORIGIN) 135 #if defined(OS_ANDROID) && defined(SPDY_PROXY_AUTH_ORIGIN)
138 // If Android ever goes multi profile, the profile should be passed so that 136 // If Android ever goes multi profile, the profile should be passed so that
139 // the browser preference will be taken. 137 // the browser preference will be taken.
140 bool with_data_reduction_proxy_enabled = 138 bool with_data_reduction_proxy_enabled =
141 ProfileManager::GetActiveUserProfile()->GetPrefs()->GetBoolean( 139 ProfileManager::GetActiveUserProfile()->GetPrefs()->GetBoolean(
142 data_reduction_proxy::prefs::kDataReductionProxyEnabled); 140 data_reduction_proxy::prefs::kDataReductionProxyEnabled);
143 #else 141 #else
144 bool with_data_reduction_proxy_enabled = false; 142 bool with_data_reduction_proxy_enabled = false;
145 #endif 143 #endif
146 144
147 data_reduction_proxy::UpdateContentLengthPrefs(received_content_length, 145 data_reduction_proxy::UpdateContentLengthPrefs(
148 original_content_length, 146 received_content_length,
149 with_data_reduction_proxy_enabled, 147 original_content_length,
150 request_type, prefs); 148 with_data_reduction_proxy_enabled,
149 request_type,
150 statistics_prefs);
151 } 151 }
152 152
153 void StoreAccumulatedContentLength( 153 void StoreAccumulatedContentLength(
154 int received_content_length, 154 int received_content_length,
155 int original_content_length, 155 int original_content_length,
156 data_reduction_proxy::DataReductionProxyRequestType request_type, 156 data_reduction_proxy::DataReductionProxyRequestType request_type,
157 Profile* profile) { 157 Profile* profile,
158 data_reduction_proxy::DataReductionProxyStatisticsPrefs* statistics_prefs) {
158 BrowserThread::PostTask(BrowserThread::UI, FROM_HERE, 159 BrowserThread::PostTask(BrowserThread::UI, FROM_HERE,
159 base::Bind(&UpdateContentLengthPrefs, 160 base::Bind(&UpdateContentLengthPrefs,
160 received_content_length, original_content_length, 161 received_content_length, original_content_length,
161 request_type, profile)); 162 request_type, profile, statistics_prefs));
162 } 163 }
163 164
164 void RecordContentLengthHistograms( 165 void RecordContentLengthHistograms(
165 int64 received_content_length, 166 int64 received_content_length,
166 int64 original_content_length, 167 int64 original_content_length,
167 const base::TimeDelta& freshness_lifetime) { 168 const base::TimeDelta& freshness_lifetime) {
168 // Add the current resource to these histograms only when a valid 169 // Add the current resource to these histograms only when a valid
169 // X-Original-Content-Length header is present. 170 // X-Original-Content-Length header is present.
170 if (original_content_length >= 0) { 171 if (original_content_length >= 0) {
171 UMA_HISTOGRAM_COUNTS("Net.HttpContentLengthWithValidOCL", 172 UMA_HISTOGRAM_COUNTS("Net.HttpContentLengthWithValidOCL",
(...skipping 75 matching lines...) Expand 10 before | Expand all | Expand 10 after
247 #if defined(ENABLE_CONFIGURATION_POLICY) 248 #if defined(ENABLE_CONFIGURATION_POLICY)
248 url_blacklist_manager_(NULL), 249 url_blacklist_manager_(NULL),
249 #endif 250 #endif
250 domain_reliability_monitor_(NULL), 251 domain_reliability_monitor_(NULL),
251 received_content_length_(0), 252 received_content_length_(0),
252 original_content_length_(0), 253 original_content_length_(0),
253 first_request_(true), 254 first_request_(true),
254 prerender_tracker_(NULL), 255 prerender_tracker_(NULL),
255 data_reduction_proxy_params_(NULL), 256 data_reduction_proxy_params_(NULL),
256 data_reduction_proxy_usage_stats_(NULL), 257 data_reduction_proxy_usage_stats_(NULL),
257 data_reduction_proxy_auth_request_handler_(NULL) { 258 data_reduction_proxy_auth_request_handler_(NULL),
259 statistics_prefs_(NULL) {
258 DCHECK(enable_referrers); 260 DCHECK(enable_referrers);
259 extensions_delegate_.reset( 261 extensions_delegate_.reset(
260 ChromeExtensionsNetworkDelegate::Create(event_router)); 262 ChromeExtensionsNetworkDelegate::Create(event_router));
261 } 263 }
262 264
263 ChromeNetworkDelegate::~ChromeNetworkDelegate() {} 265 ChromeNetworkDelegate::~ChromeNetworkDelegate() {}
264 266
265 void ChromeNetworkDelegate::set_extension_info_map( 267 void ChromeNetworkDelegate::set_extension_info_map(
266 extensions::InfoMap* extension_info_map) { 268 extensions::InfoMap* extension_info_map) {
267 extensions_delegate_->set_extension_info_map(extension_info_map); 269 extensions_delegate_->set_extension_info_map(extension_info_map);
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after
316 BrowserThread::GetMessageLoopProxyForThread(BrowserThread::IO)); 318 BrowserThread::GetMessageLoopProxyForThread(BrowserThread::IO));
317 } 319 }
318 } 320 }
319 321
320 // static 322 // static
321 void ChromeNetworkDelegate::AllowAccessToAllFiles() { 323 void ChromeNetworkDelegate::AllowAccessToAllFiles() {
322 g_allow_file_access_ = true; 324 g_allow_file_access_ = true;
323 } 325 }
324 326
325 // static 327 // static
328 // TODO(megjablon): Use data_reduction_proxy_delayed_pref_service to read prefs.
329 // Until updated the pref values may be up to an hour behind on desktop.
326 base::Value* ChromeNetworkDelegate::HistoricNetworkStatsInfoToValue() { 330 base::Value* ChromeNetworkDelegate::HistoricNetworkStatsInfoToValue() {
327 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 331 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
328 PrefService* prefs = g_browser_process->local_state(); 332 PrefService* prefs = g_browser_process->local_state();
329 int64 total_received = prefs->GetInt64( 333 int64 total_received = prefs->GetInt64(
330 data_reduction_proxy::prefs::kHttpReceivedContentLength); 334 data_reduction_proxy::prefs::kHttpReceivedContentLength);
331 int64 total_original = prefs->GetInt64( 335 int64 total_original = prefs->GetInt64(
332 data_reduction_proxy::prefs::kHttpOriginalContentLength); 336 data_reduction_proxy::prefs::kHttpOriginalContentLength);
333 337
334 base::DictionaryValue* dict = new base::DictionaryValue(); 338 base::DictionaryValue* dict = new base::DictionaryValue();
335 // Use strings to avoid overflow. base::Value only supports 32-bit integers. 339 // Use strings to avoid overflow. base::Value only supports 32-bit integers.
(...skipping 474 matching lines...) Expand 10 before | Expand all | Expand 10 after
810 #endif 814 #endif
811 return net::OK; 815 return net::OK;
812 } 816 }
813 817
814 void ChromeNetworkDelegate::AccumulateContentLength( 818 void ChromeNetworkDelegate::AccumulateContentLength(
815 int64 received_content_length, 819 int64 received_content_length,
816 int64 original_content_length, 820 int64 original_content_length,
817 data_reduction_proxy::DataReductionProxyRequestType request_type) { 821 data_reduction_proxy::DataReductionProxyRequestType request_type) {
818 DCHECK_GE(received_content_length, 0); 822 DCHECK_GE(received_content_length, 0);
819 DCHECK_GE(original_content_length, 0); 823 DCHECK_GE(original_content_length, 0);
820 StoreAccumulatedContentLength(received_content_length, 824 if (statistics_prefs_) {
821 original_content_length, 825 StoreAccumulatedContentLength(received_content_length,
822 request_type, 826 original_content_length,
823 reinterpret_cast<Profile*>(profile_)); 827 request_type,
828 reinterpret_cast<Profile*>(profile_),
829 statistics_prefs_);
830 }
824 received_content_length_ += received_content_length; 831 received_content_length_ += received_content_length;
825 original_content_length_ += original_content_length; 832 original_content_length_ += original_content_length;
826 } 833 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698