| 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/util.h" | 5 #include "components/domain_reliability/util.h" |
| 6 | 6 |
| 7 #include "base/callback.h" | 7 #include "base/callback.h" |
| 8 #include "base/logging.h" | 8 #include "base/logging.h" |
| 9 #include "base/memory/weak_ptr.h" | 9 #include "base/memory/weak_ptr.h" |
| 10 #include "base/strings/stringprintf.h" | 10 #include "base/strings/stringprintf.h" |
| 11 #include "base/time/time.h" | 11 #include "base/time/time.h" |
| 12 #include "base/timer/timer.h" | 12 #include "base/timer/timer.h" |
| 13 #include "net/base/net_errors.h" | 13 #include "net/base/net_errors.h" |
| 14 | 14 |
| 15 namespace domain_reliability { | 15 namespace domain_reliability { |
| 16 | 16 |
| 17 namespace { | 17 namespace { |
| 18 | 18 |
| 19 class ActualTimer : public MockableTime::Timer { | 19 class ActualTimer : public MockableTime::Timer { |
| 20 public: | 20 public: |
| 21 // Initialize base timer with retain_user_info and is_repeating false. | 21 // Initialize base timer with retain_user_info and is_repeating false. |
| 22 ActualTimer() : base_timer_(false, false) {} | 22 ActualTimer() : base_timer_(false, false) {} |
| 23 |
| 23 virtual ~ActualTimer() {} | 24 virtual ~ActualTimer() {} |
| 24 | 25 |
| 25 // MockableTime::Timer implementation: | 26 // MockableTime::Timer implementation: |
| 26 virtual void Start(const tracked_objects::Location& posted_from, | 27 virtual void Start(const tracked_objects::Location& posted_from, |
| 27 base::TimeDelta delay, | 28 base::TimeDelta delay, |
| 28 const base::Closure& user_task) OVERRIDE { | 29 const base::Closure& user_task) OVERRIDE { |
| 29 base_timer_.Start(posted_from, delay, user_task); | 30 base_timer_.Start(posted_from, delay, user_task); |
| 30 } | 31 } |
| 31 | 32 |
| 32 virtual void Stop() OVERRIDE { | 33 virtual void Stop() OVERRIDE { |
| (...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 70 { net::ERR_SPDY_PROTOCOL_ERROR, "spdy.protocol" }, | 71 { net::ERR_SPDY_PROTOCOL_ERROR, "spdy.protocol" }, |
| 71 { net::ERR_QUIC_PROTOCOL_ERROR, "quic.protocol" }, | 72 { net::ERR_QUIC_PROTOCOL_ERROR, "quic.protocol" }, |
| 72 { net::ERR_DNS_MALFORMED_RESPONSE, "dns.protocol" }, | 73 { net::ERR_DNS_MALFORMED_RESPONSE, "dns.protocol" }, |
| 73 { net::ERR_DNS_SERVER_FAILED, "dns.server" }, | 74 { net::ERR_DNS_SERVER_FAILED, "dns.server" }, |
| 74 { net::ERR_DNS_TIMED_OUT, "dns.timed_out" }, | 75 { net::ERR_DNS_TIMED_OUT, "dns.timed_out" }, |
| 75 }; | 76 }; |
| 76 | 77 |
| 77 } // namespace | 78 } // namespace |
| 78 | 79 |
| 79 // static | 80 // static |
| 80 bool DomainReliabilityUtil::GetBeaconStatus( | 81 bool GetDomainReliabilityBeaconStatus( |
| 81 int net_error, | 82 int net_error, |
| 82 int http_response_code, | 83 int http_response_code, |
| 83 std::string* beacon_status_out) { | 84 std::string* beacon_status_out) { |
| 84 if (net_error == net::OK) { | 85 if (net_error == net::OK) { |
| 85 if (http_response_code >= 400 && http_response_code < 600) | 86 if (http_response_code >= 400 && http_response_code < 600) |
| 86 *beacon_status_out = base::StringPrintf("http.%d", http_response_code); | 87 *beacon_status_out = base::StringPrintf("http.%d", http_response_code); |
| 87 else | 88 else |
| 88 *beacon_status_out = "ok"; | 89 *beacon_status_out = "ok"; |
| 89 return true; | 90 return true; |
| 90 } else { | 91 } |
| 91 for (size_t i = 0; i < arraysize(net_error_map); i++) { | 92 |
| 92 if (net_error_map[i].net_error == net_error) { | 93 // TODO(ttuttle): Consider sorting and using binary search? |
| 93 *beacon_status_out = net_error_map[i].beacon_status; | 94 for (size_t i = 0; i < arraysize(net_error_map); i++) { |
| 94 return true; | 95 if (net_error_map[i].net_error == net_error) { |
| 95 } | 96 *beacon_status_out = net_error_map[i].beacon_status; |
| 97 return true; |
| 96 } | 98 } |
| 97 return false; | |
| 98 } | 99 } |
| 100 return false; |
| 99 } | 101 } |
| 100 | 102 |
| 101 MockableTime::Timer::~Timer() {} | 103 MockableTime::Timer::~Timer() {} |
| 102 MockableTime::Timer::Timer() {} | 104 MockableTime::Timer::Timer() {} |
| 103 | 105 |
| 104 MockableTime::~MockableTime() {} | 106 MockableTime::~MockableTime() {} |
| 105 MockableTime::MockableTime() {} | 107 MockableTime::MockableTime() {} |
| 106 | 108 |
| 107 ActualTime::ActualTime() {} | 109 ActualTime::ActualTime() {} |
| 108 ActualTime::~ActualTime() {} | 110 ActualTime::~ActualTime() {} |
| 109 | 111 |
| 110 base::Time ActualTime::Now() { return base::Time::Now(); } | 112 base::Time ActualTime::Now() { return base::Time::Now(); } |
| 111 base::TimeTicks ActualTime::NowTicks() { return base::TimeTicks::Now(); } | 113 base::TimeTicks ActualTime::NowTicks() { return base::TimeTicks::Now(); } |
| 112 | 114 |
| 113 scoped_ptr<MockableTime::Timer> ActualTime::CreateTimer() { | 115 scoped_ptr<MockableTime::Timer> ActualTime::CreateTimer() { |
| 114 return scoped_ptr<MockableTime::Timer>(new ActualTimer()); | 116 return scoped_ptr<MockableTime::Timer>(new ActualTimer()); |
| 115 } | 117 } |
| 116 | 118 |
| 117 } // namespace domain_reliability | 119 } // namespace domain_reliability |
| OLD | NEW |