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
3 // found in the LICENSE file.
5 #ifndef COMPONENTS_DOMAIN_RELIABILITY_UTIL_H_
6 #define COMPONENTS_DOMAIN_RELIABILITY_UTIL_H_
10 #include "base/callback.h"
11 #include "base/compiler_specific.h"
12 #include "base/time/time.h"
13 #include "base/tracked_objects.h"
14 #include "components/domain_reliability/domain_reliability_export.h"
16 namespace domain_reliability {
18 // Attempts to convert a net error and an HTTP response code into the status
19 // string that should be recorded in a beacon. Returns true if it could.
21 // N.B.: This functions as the whitelist of "safe" errors to report; network-
22 // local errors are purposefully not converted to avoid revealing
23 // information about the local network to the remote server.
24 bool GetDomainReliabilityBeaconStatus(
26 int http_response_code,
27 std::string* beacon_status_out);
29 // Mockable wrapper around TimeTicks::Now and Timer. Mock version is in
31 // TODO(ttuttle): Rename to Time{Provider,Source,?}.
32 class DOMAIN_RELIABILITY_EXPORT MockableTime {
34 // Mockable wrapper around (a subset of) base::Timer.
35 class DOMAIN_RELIABILITY_EXPORT Timer {
39 virtual void Start(const tracked_objects::Location& posted_from,
40 base::TimeDelta delay,
41 const base::Closure& user_task) = 0;
42 virtual void Stop() = 0;
43 virtual bool IsRunning() = 0;
49 virtual ~MockableTime();
51 // Returns base::Time::Now() or a mocked version thereof.
52 virtual base::Time Now() = 0;
53 // Returns base::TimeTicks::Now() or a mocked version thereof.
54 virtual base::TimeTicks NowTicks() = 0;
55 // Returns a new Timer, or a mocked version thereof.
56 virtual scoped_ptr<MockableTime::Timer> CreateTimer() = 0;
62 DISALLOW_COPY_AND_ASSIGN(MockableTime);
65 // Implementation of MockableTime that passes through to
66 // base::Time{,Ticks}::Now() and base::Timer.
67 class DOMAIN_RELIABILITY_EXPORT ActualTime : public MockableTime {
71 virtual ~ActualTime();
73 // MockableTime implementation:
74 virtual base::Time Now() OVERRIDE;
75 virtual base::TimeTicks NowTicks() OVERRIDE;
76 virtual scoped_ptr<MockableTime::Timer> CreateTimer() OVERRIDE;
79 } // namespace domain_reliability
81 #endif // COMPONENTS_DOMAIN_RELIABILITY_UTIL_H_