| 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 #ifndef COMPONENTS_DOMAIN_RELIABILITY_UTIL_H_ | 5 #ifndef COMPONENTS_DOMAIN_RELIABILITY_UTIL_H_ |
| 6 #define COMPONENTS_DOMAIN_RELIABILITY_UTIL_H_ | 6 #define COMPONENTS_DOMAIN_RELIABILITY_UTIL_H_ |
| 7 | 7 |
| 8 #include <map> | 8 #include <map> |
| 9 | 9 |
| 10 #include "base/callback.h" | 10 #include "base/callback.h" |
| 11 #include "base/compiler_specific.h" | 11 #include "base/compiler_specific.h" |
| 12 #include "base/time/time.h" | 12 #include "base/time/time.h" |
| 13 #include "base/tracked_objects.h" | 13 #include "base/tracked_objects.h" |
| 14 #include "components/domain_reliability/domain_reliability_export.h" | 14 #include "components/domain_reliability/domain_reliability_export.h" |
| 15 | 15 |
| 16 namespace domain_reliability { | 16 namespace domain_reliability { |
| 17 | 17 |
| 18 class DOMAIN_RELIABILITY_EXPORT DomainReliabilityUtil { | 18 class DOMAIN_RELIABILITY_EXPORT DomainReliabilityUtil { |
| 19 public: | 19 public: |
| 20 // Attempts to convert a net error and an HTTP response code into the status | 20 // Attempts to convert a net error and an HTTP response code into the status |
| 21 // string that should be recorded in a beacon. Returns true if it could. | 21 // string that should be recorded in a beacon. Returns true if it could. |
| 22 static bool GetBeaconStatus( | 22 static bool GetBeaconStatus( |
| 23 int net_error, | 23 int net_error, |
| 24 int http_response_code, | 24 int http_response_code, |
| 25 std::string* beacon_status_out); | 25 std::string* beacon_status_out); |
| 26 }; | 26 }; |
| 27 | 27 |
| 28 // Mockable wrapper around TimeTicks::Now and Timer. Mock version is in | 28 // Mockable wrapper around TimeTicks::Now and Timer. Mock version is in |
| 29 // test_util.h. | 29 // test_util.h. |
| 30 // TODO(ttuttle): Rename to Time{Provider,Source,?}. |
| 30 class DOMAIN_RELIABILITY_EXPORT MockableTime { | 31 class DOMAIN_RELIABILITY_EXPORT MockableTime { |
| 31 public: | 32 public: |
| 32 // Mockable wrapper around (a subset of) base::Timer. | 33 // Mockable wrapper around (a subset of) base::Timer. |
| 33 class DOMAIN_RELIABILITY_EXPORT Timer { | 34 class DOMAIN_RELIABILITY_EXPORT Timer { |
| 34 public: | 35 public: |
| 35 virtual ~Timer(); | 36 virtual ~Timer(); |
| 36 | 37 |
| 37 virtual void Start(const tracked_objects::Location& posted_from, | 38 virtual void Start(const tracked_objects::Location& posted_from, |
| 38 base::TimeDelta delay, | 39 base::TimeDelta delay, |
| 39 const base::Closure& user_task) = 0; | 40 const base::Closure& user_task) = 0; |
| (...skipping 18 matching lines...) Expand all Loading... |
| 58 | 59 |
| 59 private: | 60 private: |
| 60 DISALLOW_COPY_AND_ASSIGN(MockableTime); | 61 DISALLOW_COPY_AND_ASSIGN(MockableTime); |
| 61 }; | 62 }; |
| 62 | 63 |
| 63 // Implementation of MockableTime that passes through to | 64 // Implementation of MockableTime that passes through to |
| 64 // base::Time{,Ticks}::Now() and base::Timer. | 65 // base::Time{,Ticks}::Now() and base::Timer. |
| 65 class DOMAIN_RELIABILITY_EXPORT ActualTime : public MockableTime { | 66 class DOMAIN_RELIABILITY_EXPORT ActualTime : public MockableTime { |
| 66 public: | 67 public: |
| 67 ActualTime(); | 68 ActualTime(); |
| 69 |
| 68 virtual ~ActualTime(); | 70 virtual ~ActualTime(); |
| 69 | 71 |
| 70 // MockableTime implementation: | 72 // MockableTime implementation: |
| 71 virtual base::Time Now() OVERRIDE; | 73 virtual base::Time Now() OVERRIDE; |
| 72 virtual base::TimeTicks NowTicks() OVERRIDE; | 74 virtual base::TimeTicks NowTicks() OVERRIDE; |
| 73 virtual scoped_ptr<MockableTime::Timer> CreateTimer() OVERRIDE; | 75 virtual scoped_ptr<MockableTime::Timer> CreateTimer() OVERRIDE; |
| 74 }; | 76 }; |
| 75 | 77 |
| 76 } // namespace domain_reliability | 78 } // namespace domain_reliability |
| 77 | 79 |
| 78 #endif // COMPONENTS_DOMAIN_RELIABILITY_UTIL_H_ | 80 #endif // COMPONENTS_DOMAIN_RELIABILITY_UTIL_H_ |
| OLD | NEW |