OLD | NEW |
---|---|
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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/domain_reliability/beacon.h" | 5 #include "components/domain_reliability/beacon.h" |
6 | 6 |
7 #include "base/values.h" | 7 #include "base/values.h" |
8 #include "net/base/net_errors.h" | 8 #include "net/base/net_errors.h" |
9 | 9 |
10 namespace domain_reliability { | 10 namespace domain_reliability { |
11 | 11 |
12 using base::Value; | 12 using base::Value; |
13 using base::DictionaryValue; | 13 using base::DictionaryValue; |
14 | 14 |
15 DomainReliabilityBeacon::DomainReliabilityBeacon() {} | 15 DomainReliabilityBeacon::DomainReliabilityBeacon() {} |
16 DomainReliabilityBeacon::~DomainReliabilityBeacon() {} | 16 DomainReliabilityBeacon::~DomainReliabilityBeacon() {} |
17 | 17 |
18 Value* DomainReliabilityBeacon::ToValue(base::TimeTicks upload_time) const { | 18 Value* DomainReliabilityBeacon::ToValue( |
19 base::TimeTicks upload_time, | |
20 base::TimeTicks last_network_change_time) const { | |
19 DictionaryValue* beacon_value = new DictionaryValue(); | 21 DictionaryValue* beacon_value = new DictionaryValue(); |
20 if (!url.empty()) | 22 if (!url.empty()) |
21 beacon_value->SetString("url", url); | 23 beacon_value->SetString("url", url); |
22 if (!domain.empty()) | 24 if (!domain.empty()) |
23 beacon_value->SetString("domain", domain); | 25 beacon_value->SetString("domain", domain); |
24 if (!resource.empty()) | 26 if (!resource.empty()) |
25 beacon_value->SetString("resource", resource); | 27 beacon_value->SetString("resource", resource); |
26 beacon_value->SetString("status", status); | 28 beacon_value->SetString("status", status); |
27 if (chrome_error != net::OK) { | 29 if (chrome_error != net::OK) { |
28 DictionaryValue* failure_value = new DictionaryValue(); | 30 DictionaryValue* failure_value = new DictionaryValue(); |
29 failure_value->SetString("custom_error", | 31 failure_value->SetString("custom_error", |
30 net::ErrorToString(chrome_error)); | 32 net::ErrorToString(chrome_error)); |
31 beacon_value->Set("failure_data", failure_value); | 33 beacon_value->Set("failure_data", failure_value); |
32 } | 34 } |
33 beacon_value->SetString("server_ip", server_ip); | 35 beacon_value->SetString("server_ip", server_ip); |
34 beacon_value->SetString("protocol", protocol); | 36 beacon_value->SetString("protocol", protocol); |
35 if (http_response_code >= 0) | 37 if (http_response_code >= 0) |
36 beacon_value->SetInteger("http_response_code", http_response_code); | 38 beacon_value->SetInteger("http_response_code", http_response_code); |
37 beacon_value->SetInteger("request_elapsed_ms", | 39 beacon_value->SetInteger("request_elapsed_ms", |
38 elapsed.InMilliseconds()); | 40 elapsed.InMilliseconds()); |
39 beacon_value->SetInteger("request_age_ms", | 41 beacon_value->SetInteger("request_age_ms", |
40 (upload_time - start_time).InMilliseconds()); | 42 (upload_time - start_time).InMilliseconds()); |
43 if (last_network_change_time > start_time + elapsed) | |
44 beacon_value->SetBoolean("network_changed", true); | |
davidben
2014/10/30 21:17:59
If the beacon came up because the network changed
Deprecated (see juliatuttle)
2014/10/31 22:01:02
Done.
| |
41 return beacon_value; | 45 return beacon_value; |
42 } | 46 } |
43 | 47 |
44 } // namespace domain_reliability | 48 } // namespace domain_reliability |
OLD | NEW |