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