Add ICU message format support
[chromium-blink-merge.git] / base / profiler / tracked_time.h
blob23632749a00c8d3f044766ac20ed1b4d98d606a3
1 // Copyright (c) 2012 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 BASE_PROFILER_TRACKED_TIME_H_
6 #define BASE_PROFILER_TRACKED_TIME_H_
9 #include "base/base_export.h"
10 #include "base/basictypes.h"
11 #include "base/time/time.h"
13 namespace tracked_objects {
15 //------------------------------------------------------------------------------
17 // TimeTicks maintains a wasteful 64 bits of data (we need less than 32), and on
18 // windows, a 64 bit timer is expensive to even obtain. We use a simple
19 // millisecond counter for most of our time values, as well as millisecond units
20 // of duration between those values. This means we can only handle durations
21 // up to 49 days (range), or 24 days (non-negative time durations).
22 // We only define enough methods to service the needs of the tracking classes,
23 // and our interfaces are modeled after what TimeTicks and TimeDelta use (so we
24 // can swap them into place if we want to use the "real" classes).
26 class BASE_EXPORT Duration { // Similar to base::TimeDelta.
27 public:
28 Duration();
30 Duration& operator+=(const Duration& other);
31 Duration operator+(const Duration& other) const;
33 bool operator==(const Duration& other) const;
34 bool operator!=(const Duration& other) const;
35 bool operator>(const Duration& other) const;
37 static Duration FromMilliseconds(int ms);
39 int32 InMilliseconds() const;
41 private:
42 friend class TrackedTime;
43 explicit Duration(int32 duration);
45 // Internal time is stored directly in milliseconds.
46 int32 ms_;
49 class BASE_EXPORT TrackedTime { // Similar to base::TimeTicks.
50 public:
51 TrackedTime();
52 explicit TrackedTime(const base::TimeTicks& time);
54 static TrackedTime Now();
55 Duration operator-(const TrackedTime& other) const;
56 TrackedTime operator+(const Duration& other) const;
57 bool is_null() const;
59 static TrackedTime FromMilliseconds(int32 ms) { return TrackedTime(ms); }
61 private:
62 friend class Duration;
63 explicit TrackedTime(int32 ms);
65 // Internal duration is stored directly in milliseconds.
66 uint32 ms_;
69 } // namespace tracked_objects
71 #endif // BASE_PROFILER_TRACKED_TIME_H_