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 18 matching lines...) Expand all Loading... |
29 return entry_value; | 29 return entry_value; |
30 } | 30 } |
31 | 31 |
32 int64 GetExpirationTicks(int bypass_seconds) { | 32 int64 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. Ownership of the base::Value is passed to the | 39 // the Data Reduction Proxy. |
40 // caller. | 40 scoped_ptr<base::Value> EnableDataReductionProxyCallback( |
41 base::Value* EnableDataReductionProxyCallback( | |
42 bool secure_transport_restricted, | 41 bool secure_transport_restricted, |
43 const std::vector<net::ProxyServer>& proxies_for_http, | 42 const std::vector<net::ProxyServer>& proxies_for_http, |
44 const std::vector<net::ProxyServer>& proxies_for_https, | 43 const std::vector<net::ProxyServer>& proxies_for_https, |
45 net::NetLogCaptureMode /* capture_mode */) { | 44 net::NetLogCaptureMode /* capture_mode */) { |
46 base::DictionaryValue* dict = new base::DictionaryValue(); | 45 scoped_ptr<base::DictionaryValue> dict(new base::DictionaryValue()); |
47 dict->SetBoolean("enabled", true); | 46 dict->SetBoolean("enabled", true); |
48 dict->SetBoolean("secure_transport_restricted", secure_transport_restricted); | 47 dict->SetBoolean("secure_transport_restricted", secure_transport_restricted); |
49 scoped_ptr<base::ListValue> http_proxy_list(new base::ListValue()); | 48 scoped_ptr<base::ListValue> http_proxy_list(new base::ListValue()); |
50 for (const auto& proxy : proxies_for_http) | 49 for (const auto& proxy : proxies_for_http) |
51 http_proxy_list->AppendString(proxy.ToURI()); | 50 http_proxy_list->AppendString(proxy.ToURI()); |
52 | 51 |
53 scoped_ptr<base::ListValue> https_proxy_list(new base::ListValue()); | 52 scoped_ptr<base::ListValue> https_proxy_list(new base::ListValue()); |
54 for (const auto& proxy : proxies_for_https) | 53 for (const auto& proxy : proxies_for_https) |
55 https_proxy_list->AppendString(proxy.ToURI()); | 54 https_proxy_list->AppendString(proxy.ToURI()); |
56 | 55 |
57 dict->Set("http_proxy_list", http_proxy_list.Pass()); | 56 dict->Set("http_proxy_list", http_proxy_list.Pass()); |
58 dict->Set("https_proxy_list", https_proxy_list.Pass()); | 57 dict->Set("https_proxy_list", https_proxy_list.Pass()); |
59 | 58 |
60 return dict; | 59 return dict.Pass(); |
61 } | 60 } |
62 | 61 |
63 // A callback which creates a base::Value containing information about disabling | 62 // A callback which creates a base::Value containing information about disabling |
64 // the Data Reduction Proxy. Ownership of the base::Value is passed to the | 63 // the Data Reduction Proxy. |
65 // caller. | 64 scoped_ptr<base::Value> DisableDataReductionProxyCallback( |
66 base::Value* DisableDataReductionProxyCallback( | |
67 net::NetLogCaptureMode /* capture_mode */) { | 65 net::NetLogCaptureMode /* capture_mode */) { |
68 base::DictionaryValue* dict = new base::DictionaryValue(); | 66 scoped_ptr<base::DictionaryValue> dict(new base::DictionaryValue()); |
69 dict->SetBoolean("enabled", false); | 67 dict->SetBoolean("enabled", false); |
70 return dict; | 68 return dict.Pass(); |
71 } | 69 } |
72 | 70 |
73 // A callback which creates a base::Value containing information about bypassing | 71 // A callback which creates a base::Value containing information about bypassing |
74 // the Data Reduction Proxy. Ownership of the base::Value is passed to the | 72 // the Data Reduction Proxy. |
75 // caller. | 73 scoped_ptr<base::Value> UrlBypassActionCallback( |
76 base::Value* UrlBypassActionCallback( | |
77 DataReductionProxyBypassAction action, | 74 DataReductionProxyBypassAction action, |
78 const std::string& request_method, | 75 const std::string& request_method, |
79 const GURL& url, | 76 const GURL& url, |
80 bool should_retry, | 77 bool should_retry, |
81 int bypass_seconds, | 78 int bypass_seconds, |
82 int64 expiration_ticks, | 79 int64 expiration_ticks, |
83 net::NetLogCaptureMode /* capture_mode */) { | 80 net::NetLogCaptureMode /* capture_mode */) { |
84 base::DictionaryValue* dict = new base::DictionaryValue(); | 81 scoped_ptr<base::DictionaryValue> dict(new base::DictionaryValue()); |
85 dict->SetInteger("bypass_action_type", action); | 82 dict->SetInteger("bypass_action_type", action); |
86 dict->SetString("method", request_method); | 83 dict->SetString("method", request_method); |
87 dict->SetString("url", url.spec()); | 84 dict->SetString("url", url.spec()); |
88 dict->SetBoolean("should_retry", should_retry); | 85 dict->SetBoolean("should_retry", should_retry); |
89 dict->SetString("bypass_duration_seconds", | 86 dict->SetString("bypass_duration_seconds", |
90 base::Int64ToString(bypass_seconds)); | 87 base::Int64ToString(bypass_seconds)); |
91 dict->SetString("expiration", base::Int64ToString(expiration_ticks)); | 88 dict->SetString("expiration", base::Int64ToString(expiration_ticks)); |
92 return dict; | 89 return dict.Pass(); |
93 } | 90 } |
94 | 91 |
95 // A callback which creates a base::Value containing information about bypassing | 92 // A callback which creates a base::Value containing information about bypassing |
96 // the Data Reduction Proxy. Ownership of the base::Value is passed to the | 93 // the Data Reduction Proxy. |
97 // caller. | 94 scoped_ptr<base::Value> UrlBypassTypeCallback( |
98 base::Value* UrlBypassTypeCallback(DataReductionProxyBypassType bypass_type, | 95 DataReductionProxyBypassType bypass_type, |
99 const std::string& request_method, | 96 const std::string& request_method, |
100 const GURL& url, | 97 const GURL& url, |
101 bool should_retry, | 98 bool should_retry, |
102 int bypass_seconds, | 99 int bypass_seconds, |
103 int64 expiration_ticks, | 100 int64 expiration_ticks, |
104 net::NetLogCaptureMode /* capture_mode */) { | 101 net::NetLogCaptureMode /* capture_mode */) { |
105 base::DictionaryValue* dict = new base::DictionaryValue(); | 102 scoped_ptr<base::DictionaryValue> dict(new base::DictionaryValue()); |
106 dict->SetInteger("bypass_type", bypass_type); | 103 dict->SetInteger("bypass_type", bypass_type); |
107 dict->SetString("method", request_method); | 104 dict->SetString("method", request_method); |
108 dict->SetString("url", url.spec()); | 105 dict->SetString("url", url.spec()); |
109 dict->SetBoolean("should_retry", should_retry); | 106 dict->SetBoolean("should_retry", should_retry); |
110 dict->SetString("bypass_duration_seconds", | 107 dict->SetString("bypass_duration_seconds", |
111 base::Int64ToString(bypass_seconds)); | 108 base::Int64ToString(bypass_seconds)); |
112 dict->SetString("expiration", base::Int64ToString(expiration_ticks)); | 109 dict->SetString("expiration", base::Int64ToString(expiration_ticks)); |
113 return dict; | 110 return dict.Pass(); |
114 } | 111 } |
115 | 112 |
116 // A callback which creates a base::Value containing information about | 113 // A callback which creates a base::Value containing information about |
117 // completing the Data Reduction Proxy secure proxy check. Ownership of the | 114 // completing the Data Reduction Proxy secure proxy check. |
118 // base::Value is passed to the caller. | 115 scoped_ptr<base::Value> EndCanaryRequestCallback( |
119 base::Value* EndCanaryRequestCallback( | |
120 int net_error, | 116 int net_error, |
121 int http_response_code, | 117 int http_response_code, |
122 bool succeeded, | 118 bool succeeded, |
123 net::NetLogCaptureMode /* capture_mode */) { | 119 net::NetLogCaptureMode /* capture_mode */) { |
124 base::DictionaryValue* dict = new base::DictionaryValue(); | 120 scoped_ptr<base::DictionaryValue> dict(new base::DictionaryValue()); |
125 dict->SetInteger("net_error", net_error); | 121 dict->SetInteger("net_error", net_error); |
126 dict->SetInteger("http_response_code", http_response_code); | 122 dict->SetInteger("http_response_code", http_response_code); |
127 dict->SetBoolean("check_succeeded", succeeded); | 123 dict->SetBoolean("check_succeeded", succeeded); |
128 return dict; | 124 return dict.Pass(); |
129 } | 125 } |
130 | 126 |
131 // A callback that creates a base::Value containing information about | 127 // A callback that creates a base::Value containing information about |
132 // completing the Data Reduction Proxy configuration request. Ownership of the | 128 // completing the Data Reduction Proxy configuration request. |
133 // base::Value is passed to the caller. | 129 scoped_ptr<base::Value> EndConfigRequestCallback( |
134 base::Value* EndConfigRequestCallback( | |
135 int net_error, | 130 int net_error, |
136 int http_response_code, | 131 int http_response_code, |
137 int failure_count, | 132 int failure_count, |
138 int64 expiration_ticks, | 133 int64 expiration_ticks, |
139 net::NetLogCaptureMode /* capture_mode */) { | 134 net::NetLogCaptureMode /* capture_mode */) { |
140 base::DictionaryValue* dict = new base::DictionaryValue(); | 135 scoped_ptr<base::DictionaryValue> dict(new base::DictionaryValue()); |
141 dict->SetInteger("net_error", net_error); | 136 dict->SetInteger("net_error", net_error); |
142 dict->SetInteger("http_response_code", http_response_code); | 137 dict->SetInteger("http_response_code", http_response_code); |
143 dict->SetInteger("failure_count", failure_count); | 138 dict->SetInteger("failure_count", failure_count); |
144 dict->SetString("expiration", base::Int64ToString(expiration_ticks)); | 139 dict->SetString("expiration", base::Int64ToString(expiration_ticks)); |
145 return dict; | 140 return dict.Pass(); |
146 } | 141 } |
147 | 142 |
148 } // namespace | 143 } // namespace |
149 | 144 |
150 DataReductionProxyEventCreator::DataReductionProxyEventCreator( | 145 DataReductionProxyEventCreator::DataReductionProxyEventCreator( |
151 DataReductionProxyEventStorageDelegate* storage_delegate) | 146 DataReductionProxyEventStorageDelegate* storage_delegate) |
152 : storage_delegate_(storage_delegate) { | 147 : storage_delegate_(storage_delegate) { |
153 DCHECK(storage_delegate); | 148 DCHECK(storage_delegate); |
154 // Constructed on the UI thread, but should be checked on the IO thread. | 149 // Constructed on the UI thread, but should be checked on the IO thread. |
155 thread_checker_.DetachFromThread(); | 150 thread_checker_.DetachFromThread(); |
(...skipping 161 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
317 const net::NetLog::ParametersCallback& callback) { | 312 const net::NetLog::ParametersCallback& callback) { |
318 scoped_ptr<base::Value> event( | 313 scoped_ptr<base::Value> event( |
319 BuildDataReductionProxyEvent(type, net_log.source(), phase, callback)); | 314 BuildDataReductionProxyEvent(type, net_log.source(), phase, callback)); |
320 if (event) { | 315 if (event) { |
321 storage_delegate_->AddEvent(event.Pass()); | 316 storage_delegate_->AddEvent(event.Pass()); |
322 net_log.AddEntry(type, phase, callback); | 317 net_log.AddEntry(type, phase, callback); |
323 } | 318 } |
324 } | 319 } |
325 | 320 |
326 } // namespace data_reduction_proxy | 321 } // namespace data_reduction_proxy |
OLD | NEW |