Updating trunk VERSION from 2139.0 to 2140.0
[chromium-blink-merge.git] / components / domain_reliability / util.h
blobbbb0243b246fc452707c8129ea866621e35cfdb5
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_
8 #include <map>
10 #include "base/callback_forward.h"
11 #include "base/compiler_specific.h"
12 #include "base/memory/scoped_ptr.h"
13 #include "base/time/time.h"
14 #include "base/tracked_objects.h"
15 #include "components/domain_reliability/domain_reliability_export.h"
16 #include "net/http/http_response_info.h"
18 namespace domain_reliability {
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.
23 // N.B.: This functions as the whitelist of "safe" errors to report; network-
24 // local errors are purposefully not converted to avoid revealing
25 // information about the local network to the remote server.
26 bool GetDomainReliabilityBeaconStatus(
27 int net_error,
28 int http_response_code,
29 std::string* beacon_status_out);
31 std::string GetDomainReliabilityProtocol(
32 net::HttpResponseInfo::ConnectionInfo connection_info,
33 bool ssl_info_populated);
35 // Mockable wrapper around TimeTicks::Now and Timer. Mock version is in
36 // test_util.h.
37 // TODO(ttuttle): Rename to Time{Provider,Source,?}.
38 class DOMAIN_RELIABILITY_EXPORT MockableTime {
39 public:
40 // Mockable wrapper around (a subset of) base::Timer.
41 class DOMAIN_RELIABILITY_EXPORT Timer {
42 public:
43 virtual ~Timer();
45 virtual void Start(const tracked_objects::Location& posted_from,
46 base::TimeDelta delay,
47 const base::Closure& user_task) = 0;
48 virtual void Stop() = 0;
49 virtual bool IsRunning() = 0;
51 protected:
52 Timer();
55 virtual ~MockableTime();
57 // Returns base::Time::Now() or a mocked version thereof.
58 virtual base::Time Now() = 0;
59 // Returns base::TimeTicks::Now() or a mocked version thereof.
60 virtual base::TimeTicks NowTicks() = 0;
61 // Returns a new Timer, or a mocked version thereof.
62 virtual scoped_ptr<MockableTime::Timer> CreateTimer() = 0;
64 protected:
65 MockableTime();
67 private:
68 DISALLOW_COPY_AND_ASSIGN(MockableTime);
71 // Implementation of MockableTime that passes through to
72 // base::Time{,Ticks}::Now() and base::Timer.
73 class DOMAIN_RELIABILITY_EXPORT ActualTime : public MockableTime {
74 public:
75 ActualTime();
77 virtual ~ActualTime();
79 // MockableTime implementation:
80 virtual base::Time Now() OVERRIDE;
81 virtual base::TimeTicks NowTicks() OVERRIDE;
82 virtual scoped_ptr<MockableTime::Timer> CreateTimer() OVERRIDE;
85 } // namespace domain_reliability
87 #endif // COMPONENTS_DOMAIN_RELIABILITY_UTIL_H_