security/sandbox/chromium/base/profiler/tracked_time.h

Wed, 31 Dec 2014 07:16:47 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Wed, 31 Dec 2014 07:16:47 +0100
branch
TOR_BUG_9701
changeset 3
141e0f1194b1
permissions
-rw-r--r--

Revert simplistic fix pending revisit of Mozilla integration attempt.

michael@0 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved.
michael@0 2 // Use of this source code is governed by a BSD-style license that can be
michael@0 3 // found in the LICENSE file.
michael@0 4
michael@0 5 #ifndef BASE_PROFILER_TRACKED_TIME_H_
michael@0 6 #define BASE_PROFILER_TRACKED_TIME_H_
michael@0 7
michael@0 8
michael@0 9 #include "base/base_export.h"
michael@0 10 #include "base/basictypes.h"
michael@0 11 #include "base/time/time.h"
michael@0 12
michael@0 13 namespace tracked_objects {
michael@0 14
michael@0 15 //------------------------------------------------------------------------------
michael@0 16
michael@0 17 // TimeTicks maintains a wasteful 64 bits of data (we need less than 32), and on
michael@0 18 // windows, a 64 bit timer is expensive to even obtain. We use a simple
michael@0 19 // millisecond counter for most of our time values, as well as millisecond units
michael@0 20 // of duration between those values. This means we can only handle durations
michael@0 21 // up to 49 days (range), or 24 days (non-negative time durations).
michael@0 22 // We only define enough methods to service the needs of the tracking classes,
michael@0 23 // and our interfaces are modeled after what TimeTicks and TimeDelta use (so we
michael@0 24 // can swap them into place if we want to use the "real" classes).
michael@0 25
michael@0 26 class BASE_EXPORT Duration { // Similar to base::TimeDelta.
michael@0 27 public:
michael@0 28 Duration();
michael@0 29
michael@0 30 Duration& operator+=(const Duration& other);
michael@0 31 Duration operator+(const Duration& other) const;
michael@0 32
michael@0 33 bool operator==(const Duration& other) const;
michael@0 34 bool operator!=(const Duration& other) const;
michael@0 35 bool operator>(const Duration& other) const;
michael@0 36
michael@0 37 static Duration FromMilliseconds(int ms);
michael@0 38
michael@0 39 int32 InMilliseconds() const;
michael@0 40
michael@0 41 private:
michael@0 42 friend class TrackedTime;
michael@0 43 explicit Duration(int32 duration);
michael@0 44
michael@0 45 // Internal time is stored directly in milliseconds.
michael@0 46 int32 ms_;
michael@0 47 };
michael@0 48
michael@0 49 class BASE_EXPORT TrackedTime { // Similar to base::TimeTicks.
michael@0 50 public:
michael@0 51 TrackedTime();
michael@0 52 explicit TrackedTime(const base::TimeTicks& time);
michael@0 53
michael@0 54 static TrackedTime Now();
michael@0 55 Duration operator-(const TrackedTime& other) const;
michael@0 56 TrackedTime operator+(const Duration& other) const;
michael@0 57 bool is_null() const;
michael@0 58
michael@0 59 static TrackedTime FromMilliseconds(int32 ms) { return TrackedTime(ms); }
michael@0 60
michael@0 61 private:
michael@0 62 friend class Duration;
michael@0 63 explicit TrackedTime(int32 ms);
michael@0 64
michael@0 65 // Internal duration is stored directly in milliseconds.
michael@0 66 uint32 ms_;
michael@0 67 };
michael@0 68
michael@0 69 } // namespace tracked_objects
michael@0 70
michael@0 71 #endif // BASE_PROFILER_TRACKED_TIME_H_

mercurial