| OLD | NEW |
| 1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 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 "components/data_reduction_proxy/core/common/data_reduction_proxy_event
_creator.h" | 5 #include "components/data_reduction_proxy/core/common/data_reduction_proxy_event
_creator.h" |
| 6 | 6 |
| 7 #include "base/bind.h" | 7 #include "base/bind.h" |
| 8 #include "base/strings/string_number_conversions.h" | 8 #include "base/strings/string_number_conversions.h" |
| 9 #include "base/time/time.h" | 9 #include "base/time/time.h" |
| 10 #include "base/values.h" | 10 #include "base/values.h" |
| (...skipping 11 matching lines...) Expand all Loading... |
| 22 base::TimeTicks ticks_now = base::TimeTicks::Now(); | 22 base::TimeTicks ticks_now = base::TimeTicks::Now(); |
| 23 net::NetLog::EntryData entry_data(type, source, phase, ticks_now, | 23 net::NetLog::EntryData entry_data(type, source, phase, ticks_now, |
| 24 ¶meters_callback); | 24 ¶meters_callback); |
| 25 net::NetLog::Entry entry(&entry_data, | 25 net::NetLog::Entry entry(&entry_data, |
| 26 net::NetLogCaptureMode::IncludeSocketBytes()); | 26 net::NetLogCaptureMode::IncludeSocketBytes()); |
| 27 scoped_ptr<base::Value> entry_value(entry.ToValue()); | 27 scoped_ptr<base::Value> entry_value(entry.ToValue()); |
| 28 | 28 |
| 29 return entry_value; | 29 return entry_value; |
| 30 } | 30 } |
| 31 | 31 |
| 32 int64 GetExpirationTicks(int bypass_seconds) { | 32 int64_t GetExpirationTicks(int bypass_seconds) { |
| 33 base::TimeTicks expiration_ticks = | 33 base::TimeTicks expiration_ticks = |
| 34 base::TimeTicks::Now() + base::TimeDelta::FromSeconds(bypass_seconds); | 34 base::TimeTicks::Now() + base::TimeDelta::FromSeconds(bypass_seconds); |
| 35 return (expiration_ticks - base::TimeTicks()).InMilliseconds(); | 35 return (expiration_ticks - base::TimeTicks()).InMilliseconds(); |
| 36 } | 36 } |
| 37 | 37 |
| 38 // A callback which creates a base::Value containing information about enabling | 38 // A callback which creates a base::Value containing information about enabling |
| 39 // the Data Reduction Proxy. | 39 // the Data Reduction Proxy. |
| 40 scoped_ptr<base::Value> EnableDataReductionProxyCallback( | 40 scoped_ptr<base::Value> EnableDataReductionProxyCallback( |
| 41 bool secure_transport_restricted, | 41 bool secure_transport_restricted, |
| 42 const std::vector<net::ProxyServer>& proxies_for_http, | 42 const std::vector<net::ProxyServer>& proxies_for_http, |
| (...skipping 26 matching lines...) Expand all Loading... |
| 69 } | 69 } |
| 70 | 70 |
| 71 // A callback which creates a base::Value containing information about bypassing | 71 // A callback which creates a base::Value containing information about bypassing |
| 72 // the Data Reduction Proxy. | 72 // the Data Reduction Proxy. |
| 73 scoped_ptr<base::Value> UrlBypassActionCallback( | 73 scoped_ptr<base::Value> UrlBypassActionCallback( |
| 74 DataReductionProxyBypassAction action, | 74 DataReductionProxyBypassAction action, |
| 75 const std::string& request_method, | 75 const std::string& request_method, |
| 76 const GURL& url, | 76 const GURL& url, |
| 77 bool should_retry, | 77 bool should_retry, |
| 78 int bypass_seconds, | 78 int bypass_seconds, |
| 79 int64 expiration_ticks, | 79 int64_t expiration_ticks, |
| 80 net::NetLogCaptureMode /* capture_mode */) { | 80 net::NetLogCaptureMode /* capture_mode */) { |
| 81 scoped_ptr<base::DictionaryValue> dict(new base::DictionaryValue()); | 81 scoped_ptr<base::DictionaryValue> dict(new base::DictionaryValue()); |
| 82 dict->SetInteger("bypass_action_type", action); | 82 dict->SetInteger("bypass_action_type", action); |
| 83 dict->SetString("method", request_method); | 83 dict->SetString("method", request_method); |
| 84 dict->SetString("url", url.spec()); | 84 dict->SetString("url", url.spec()); |
| 85 dict->SetBoolean("should_retry", should_retry); | 85 dict->SetBoolean("should_retry", should_retry); |
| 86 dict->SetString("bypass_duration_seconds", | 86 dict->SetString("bypass_duration_seconds", |
| 87 base::Int64ToString(bypass_seconds)); | 87 base::Int64ToString(bypass_seconds)); |
| 88 dict->SetString("expiration", base::Int64ToString(expiration_ticks)); | 88 dict->SetString("expiration", base::Int64ToString(expiration_ticks)); |
| 89 return dict.Pass(); | 89 return dict.Pass(); |
| 90 } | 90 } |
| 91 | 91 |
| 92 // A callback which creates a base::Value containing information about bypassing | 92 // A callback which creates a base::Value containing information about bypassing |
| 93 // the Data Reduction Proxy. | 93 // the Data Reduction Proxy. |
| 94 scoped_ptr<base::Value> UrlBypassTypeCallback( | 94 scoped_ptr<base::Value> UrlBypassTypeCallback( |
| 95 DataReductionProxyBypassType bypass_type, | 95 DataReductionProxyBypassType bypass_type, |
| 96 const std::string& request_method, | 96 const std::string& request_method, |
| 97 const GURL& url, | 97 const GURL& url, |
| 98 bool should_retry, | 98 bool should_retry, |
| 99 int bypass_seconds, | 99 int bypass_seconds, |
| 100 int64 expiration_ticks, | 100 int64_t expiration_ticks, |
| 101 net::NetLogCaptureMode /* capture_mode */) { | 101 net::NetLogCaptureMode /* capture_mode */) { |
| 102 scoped_ptr<base::DictionaryValue> dict(new base::DictionaryValue()); | 102 scoped_ptr<base::DictionaryValue> dict(new base::DictionaryValue()); |
| 103 dict->SetInteger("bypass_type", bypass_type); | 103 dict->SetInteger("bypass_type", bypass_type); |
| 104 dict->SetString("method", request_method); | 104 dict->SetString("method", request_method); |
| 105 dict->SetString("url", url.spec()); | 105 dict->SetString("url", url.spec()); |
| 106 dict->SetBoolean("should_retry", should_retry); | 106 dict->SetBoolean("should_retry", should_retry); |
| 107 dict->SetString("bypass_duration_seconds", | 107 dict->SetString("bypass_duration_seconds", |
| 108 base::Int64ToString(bypass_seconds)); | 108 base::Int64ToString(bypass_seconds)); |
| 109 dict->SetString("expiration", base::Int64ToString(expiration_ticks)); | 109 dict->SetString("expiration", base::Int64ToString(expiration_ticks)); |
| 110 return dict.Pass(); | 110 return dict.Pass(); |
| (...skipping 25 matching lines...) Expand all Loading... |
| 136 return dict.Pass(); | 136 return dict.Pass(); |
| 137 } | 137 } |
| 138 | 138 |
| 139 // A callback that creates a base::Value containing information about | 139 // A callback that creates a base::Value containing information about |
| 140 // completing the Data Reduction Proxy configuration request. | 140 // completing the Data Reduction Proxy configuration request. |
| 141 scoped_ptr<base::Value> EndConfigRequestCallback( | 141 scoped_ptr<base::Value> EndConfigRequestCallback( |
| 142 int net_error, | 142 int net_error, |
| 143 int http_response_code, | 143 int http_response_code, |
| 144 int failure_count, | 144 int failure_count, |
| 145 const std::vector<net::ProxyServer>& proxies_for_http, | 145 const std::vector<net::ProxyServer>& proxies_for_http, |
| 146 int64 refresh_duration_minutes, | 146 int64_t refresh_duration_minutes, |
| 147 int64 expiration_ticks, | 147 int64_t expiration_ticks, |
| 148 net::NetLogCaptureMode /* capture_mode */) { | 148 net::NetLogCaptureMode /* capture_mode */) { |
| 149 scoped_ptr<base::ListValue> http_proxy_list(new base::ListValue()); | 149 scoped_ptr<base::ListValue> http_proxy_list(new base::ListValue()); |
| 150 for (const auto& proxy : proxies_for_http) | 150 for (const auto& proxy : proxies_for_http) |
| 151 http_proxy_list->AppendString(proxy.ToURI()); | 151 http_proxy_list->AppendString(proxy.ToURI()); |
| 152 scoped_ptr<base::DictionaryValue> dict(new base::DictionaryValue()); | 152 scoped_ptr<base::DictionaryValue> dict(new base::DictionaryValue()); |
| 153 dict->SetInteger("net_error", net_error); | 153 dict->SetInteger("net_error", net_error); |
| 154 dict->SetInteger("http_response_code", http_response_code); | 154 dict->SetInteger("http_response_code", http_response_code); |
| 155 dict->SetInteger("failure_count", failure_count); | 155 dict->SetInteger("failure_count", failure_count); |
| 156 dict->Set("http_proxy_list_in_config", http_proxy_list.Pass()); | 156 dict->Set("http_proxy_list_in_config", http_proxy_list.Pass()); |
| 157 dict->SetString("refresh_duration", | 157 dict->SetString("refresh_duration", |
| (...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 196 } | 196 } |
| 197 | 197 |
| 198 void DataReductionProxyEventCreator::AddBypassActionEvent( | 198 void DataReductionProxyEventCreator::AddBypassActionEvent( |
| 199 const net::BoundNetLog& net_log, | 199 const net::BoundNetLog& net_log, |
| 200 DataReductionProxyBypassAction bypass_action, | 200 DataReductionProxyBypassAction bypass_action, |
| 201 const std::string& request_method, | 201 const std::string& request_method, |
| 202 const GURL& url, | 202 const GURL& url, |
| 203 bool should_retry, | 203 bool should_retry, |
| 204 const base::TimeDelta& bypass_duration) { | 204 const base::TimeDelta& bypass_duration) { |
| 205 DCHECK(thread_checker_.CalledOnValidThread()); | 205 DCHECK(thread_checker_.CalledOnValidThread()); |
| 206 int64 expiration_ticks = GetExpirationTicks(bypass_duration.InSeconds()); | 206 int64_t expiration_ticks = GetExpirationTicks(bypass_duration.InSeconds()); |
| 207 const net::NetLog::ParametersCallback& parameters_callback = | 207 const net::NetLog::ParametersCallback& parameters_callback = |
| 208 base::Bind(&UrlBypassActionCallback, bypass_action, request_method, url, | 208 base::Bind(&UrlBypassActionCallback, bypass_action, request_method, url, |
| 209 should_retry, bypass_duration.InSeconds(), expiration_ticks); | 209 should_retry, bypass_duration.InSeconds(), expiration_ticks); |
| 210 PostBoundNetLogBypassEvent( | 210 PostBoundNetLogBypassEvent( |
| 211 net_log, net::NetLog::TYPE_DATA_REDUCTION_PROXY_BYPASS_REQUESTED, | 211 net_log, net::NetLog::TYPE_DATA_REDUCTION_PROXY_BYPASS_REQUESTED, |
| 212 net::NetLog::PHASE_NONE, expiration_ticks, parameters_callback); | 212 net::NetLog::PHASE_NONE, expiration_ticks, parameters_callback); |
| 213 } | 213 } |
| 214 | 214 |
| 215 void DataReductionProxyEventCreator::AddBypassTypeEvent( | 215 void DataReductionProxyEventCreator::AddBypassTypeEvent( |
| 216 const net::BoundNetLog& net_log, | 216 const net::BoundNetLog& net_log, |
| 217 DataReductionProxyBypassType bypass_type, | 217 DataReductionProxyBypassType bypass_type, |
| 218 const std::string& request_method, | 218 const std::string& request_method, |
| 219 const GURL& url, | 219 const GURL& url, |
| 220 bool should_retry, | 220 bool should_retry, |
| 221 const base::TimeDelta& bypass_duration) { | 221 const base::TimeDelta& bypass_duration) { |
| 222 DCHECK(thread_checker_.CalledOnValidThread()); | 222 DCHECK(thread_checker_.CalledOnValidThread()); |
| 223 int64 expiration_ticks = GetExpirationTicks(bypass_duration.InSeconds()); | 223 int64_t expiration_ticks = GetExpirationTicks(bypass_duration.InSeconds()); |
| 224 const net::NetLog::ParametersCallback& parameters_callback = | 224 const net::NetLog::ParametersCallback& parameters_callback = |
| 225 base::Bind(&UrlBypassTypeCallback, bypass_type, request_method, url, | 225 base::Bind(&UrlBypassTypeCallback, bypass_type, request_method, url, |
| 226 should_retry, bypass_duration.InSeconds(), expiration_ticks); | 226 should_retry, bypass_duration.InSeconds(), expiration_ticks); |
| 227 PostBoundNetLogBypassEvent( | 227 PostBoundNetLogBypassEvent( |
| 228 net_log, net::NetLog::TYPE_DATA_REDUCTION_PROXY_BYPASS_REQUESTED, | 228 net_log, net::NetLog::TYPE_DATA_REDUCTION_PROXY_BYPASS_REQUESTED, |
| 229 net::NetLog::PHASE_NONE, expiration_ticks, parameters_callback); | 229 net::NetLog::PHASE_NONE, expiration_ticks, parameters_callback); |
| 230 } | 230 } |
| 231 | 231 |
| 232 void DataReductionProxyEventCreator::AddProxyFallbackEvent( | 232 void DataReductionProxyEventCreator::AddProxyFallbackEvent( |
| 233 net::NetLog* net_log, | 233 net::NetLog* net_log, |
| (...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 282 } | 282 } |
| 283 | 283 |
| 284 void DataReductionProxyEventCreator::EndConfigRequest( | 284 void DataReductionProxyEventCreator::EndConfigRequest( |
| 285 const net::BoundNetLog& net_log, | 285 const net::BoundNetLog& net_log, |
| 286 int net_error, | 286 int net_error, |
| 287 int http_response_code, | 287 int http_response_code, |
| 288 int failure_count, | 288 int failure_count, |
| 289 const std::vector<net::ProxyServer>& proxies_for_http, | 289 const std::vector<net::ProxyServer>& proxies_for_http, |
| 290 const base::TimeDelta& refresh_duration, | 290 const base::TimeDelta& refresh_duration, |
| 291 const base::TimeDelta& retry_delay) { | 291 const base::TimeDelta& retry_delay) { |
| 292 int64 refresh_duration_minutes = refresh_duration.InMinutes(); | 292 int64_t refresh_duration_minutes = refresh_duration.InMinutes(); |
| 293 int64 expiration_ticks = GetExpirationTicks(retry_delay.InSeconds()); | 293 int64_t expiration_ticks = GetExpirationTicks(retry_delay.InSeconds()); |
| 294 const net::NetLog::ParametersCallback& parameters_callback = base::Bind( | 294 const net::NetLog::ParametersCallback& parameters_callback = base::Bind( |
| 295 &EndConfigRequestCallback, net_error, http_response_code, failure_count, | 295 &EndConfigRequestCallback, net_error, http_response_code, failure_count, |
| 296 proxies_for_http, refresh_duration_minutes, expiration_ticks); | 296 proxies_for_http, refresh_duration_minutes, expiration_ticks); |
| 297 PostBoundNetLogConfigRequestEvent( | 297 PostBoundNetLogConfigRequestEvent( |
| 298 net_log, net::NetLog::TYPE_DATA_REDUCTION_PROXY_CONFIG_REQUEST, | 298 net_log, net::NetLog::TYPE_DATA_REDUCTION_PROXY_CONFIG_REQUEST, |
| 299 net::NetLog::PHASE_END, parameters_callback); | 299 net::NetLog::PHASE_END, parameters_callback); |
| 300 } | 300 } |
| 301 | 301 |
| 302 void DataReductionProxyEventCreator::PostEvent( | 302 void DataReductionProxyEventCreator::PostEvent( |
| 303 net::NetLog* net_log, | 303 net::NetLog* net_log, |
| (...skipping 19 matching lines...) Expand all Loading... |
| 323 storage_delegate_->AddEnabledEvent(event.Pass(), enabled); | 323 storage_delegate_->AddEnabledEvent(event.Pass(), enabled); |
| 324 | 324 |
| 325 if (net_log) | 325 if (net_log) |
| 326 net_log->AddGlobalEntry(type, callback); | 326 net_log->AddGlobalEntry(type, callback); |
| 327 } | 327 } |
| 328 | 328 |
| 329 void DataReductionProxyEventCreator::PostBoundNetLogBypassEvent( | 329 void DataReductionProxyEventCreator::PostBoundNetLogBypassEvent( |
| 330 const net::BoundNetLog& net_log, | 330 const net::BoundNetLog& net_log, |
| 331 net::NetLog::EventType type, | 331 net::NetLog::EventType type, |
| 332 net::NetLog::EventPhase phase, | 332 net::NetLog::EventPhase phase, |
| 333 int64 expiration_ticks, | 333 int64_t expiration_ticks, |
| 334 const net::NetLog::ParametersCallback& callback) { | 334 const net::NetLog::ParametersCallback& callback) { |
| 335 scoped_ptr<base::Value> event = | 335 scoped_ptr<base::Value> event = |
| 336 BuildDataReductionProxyEvent(type, net_log.source(), phase, callback); | 336 BuildDataReductionProxyEvent(type, net_log.source(), phase, callback); |
| 337 if (event) | 337 if (event) |
| 338 storage_delegate_->AddAndSetLastBypassEvent(event.Pass(), expiration_ticks); | 338 storage_delegate_->AddAndSetLastBypassEvent(event.Pass(), expiration_ticks); |
| 339 net_log.AddEntry(type, phase, callback); | 339 net_log.AddEntry(type, phase, callback); |
| 340 } | 340 } |
| 341 | 341 |
| 342 void DataReductionProxyEventCreator::PostBoundNetLogSecureProxyCheckEvent( | 342 void DataReductionProxyEventCreator::PostBoundNetLogSecureProxyCheckEvent( |
| 343 const net::BoundNetLog& net_log, | 343 const net::BoundNetLog& net_log, |
| (...skipping 15 matching lines...) Expand all Loading... |
| 359 const net::NetLog::ParametersCallback& callback) { | 359 const net::NetLog::ParametersCallback& callback) { |
| 360 scoped_ptr<base::Value> event( | 360 scoped_ptr<base::Value> event( |
| 361 BuildDataReductionProxyEvent(type, net_log.source(), phase, callback)); | 361 BuildDataReductionProxyEvent(type, net_log.source(), phase, callback)); |
| 362 if (event) { | 362 if (event) { |
| 363 storage_delegate_->AddEvent(event.Pass()); | 363 storage_delegate_->AddEvent(event.Pass()); |
| 364 net_log.AddEntry(type, phase, callback); | 364 net_log.AddEntry(type, phase, callback); |
| 365 } | 365 } |
| 366 } | 366 } |
| 367 | 367 |
| 368 } // namespace data_reduction_proxy | 368 } // namespace data_reduction_proxy |
| OLD | NEW |