1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/security/sandbox/chromium/base/profiler/tracked_time.h Wed Dec 31 06:09:35 2014 +0100 1.3 @@ -0,0 +1,71 @@ 1.4 +// Copyright (c) 2012 The Chromium Authors. All rights reserved. 1.5 +// Use of this source code is governed by a BSD-style license that can be 1.6 +// found in the LICENSE file. 1.7 + 1.8 +#ifndef BASE_PROFILER_TRACKED_TIME_H_ 1.9 +#define BASE_PROFILER_TRACKED_TIME_H_ 1.10 + 1.11 + 1.12 +#include "base/base_export.h" 1.13 +#include "base/basictypes.h" 1.14 +#include "base/time/time.h" 1.15 + 1.16 +namespace tracked_objects { 1.17 + 1.18 +//------------------------------------------------------------------------------ 1.19 + 1.20 +// TimeTicks maintains a wasteful 64 bits of data (we need less than 32), and on 1.21 +// windows, a 64 bit timer is expensive to even obtain. We use a simple 1.22 +// millisecond counter for most of our time values, as well as millisecond units 1.23 +// of duration between those values. This means we can only handle durations 1.24 +// up to 49 days (range), or 24 days (non-negative time durations). 1.25 +// We only define enough methods to service the needs of the tracking classes, 1.26 +// and our interfaces are modeled after what TimeTicks and TimeDelta use (so we 1.27 +// can swap them into place if we want to use the "real" classes). 1.28 + 1.29 +class BASE_EXPORT Duration { // Similar to base::TimeDelta. 1.30 + public: 1.31 + Duration(); 1.32 + 1.33 + Duration& operator+=(const Duration& other); 1.34 + Duration operator+(const Duration& other) const; 1.35 + 1.36 + bool operator==(const Duration& other) const; 1.37 + bool operator!=(const Duration& other) const; 1.38 + bool operator>(const Duration& other) const; 1.39 + 1.40 + static Duration FromMilliseconds(int ms); 1.41 + 1.42 + int32 InMilliseconds() const; 1.43 + 1.44 + private: 1.45 + friend class TrackedTime; 1.46 + explicit Duration(int32 duration); 1.47 + 1.48 + // Internal time is stored directly in milliseconds. 1.49 + int32 ms_; 1.50 +}; 1.51 + 1.52 +class BASE_EXPORT TrackedTime { // Similar to base::TimeTicks. 1.53 + public: 1.54 + TrackedTime(); 1.55 + explicit TrackedTime(const base::TimeTicks& time); 1.56 + 1.57 + static TrackedTime Now(); 1.58 + Duration operator-(const TrackedTime& other) const; 1.59 + TrackedTime operator+(const Duration& other) const; 1.60 + bool is_null() const; 1.61 + 1.62 + static TrackedTime FromMilliseconds(int32 ms) { return TrackedTime(ms); } 1.63 + 1.64 + private: 1.65 + friend class Duration; 1.66 + explicit TrackedTime(int32 ms); 1.67 + 1.68 + // Internal duration is stored directly in milliseconds. 1.69 + uint32 ms_; 1.70 +}; 1.71 + 1.72 +} // namespace tracked_objects 1.73 + 1.74 +#endif // BASE_PROFILER_TRACKED_TIME_H_