| OLD | NEW |
| 1 // Copyright (c) 2006-2008 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2006-2008 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 | 5 |
| 6 #ifndef BASE_STATS_COUNTERS_H__ | 6 #ifndef BASE_STATS_COUNTERS_H__ |
| 7 #define BASE_STATS_COUNTERS_H__ | 7 #define BASE_STATS_COUNTERS_H__ |
| 8 | 8 |
| 9 #include <string> | 9 #include <string> |
| 10 #include "base/stats_table.h" | 10 #include "base/stats_table.h" |
| (...skipping 76 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 87 void Set(int value) { | 87 void Set(int value) { |
| 88 int* loc = GetPtr(); | 88 int* loc = GetPtr(); |
| 89 if (loc) *loc = value; | 89 if (loc) *loc = value; |
| 90 } | 90 } |
| 91 | 91 |
| 92 // Increments the counter. | 92 // Increments the counter. |
| 93 void Increment() { | 93 void Increment() { |
| 94 Add(1); | 94 Add(1); |
| 95 } | 95 } |
| 96 | 96 |
| 97 // TODO(jar) temporary hack include method till base and chrome use new name. | |
| 98 void Increment(int value) { | |
| 99 Add(value); | |
| 100 } | |
| 101 | |
| 102 virtual void Add(int value) { | 97 virtual void Add(int value) { |
| 103 int* loc = GetPtr(); | 98 int* loc = GetPtr(); |
| 104 if (loc) | 99 if (loc) |
| 105 (*loc) += value; | 100 (*loc) += value; |
| 106 } | 101 } |
| 107 | 102 |
| 108 // Decrements the counter. | 103 // Decrements the counter. |
| 109 void Decrement() { | 104 void Decrement() { |
| 110 Add(-1); | 105 Add(-1); |
| 111 } | 106 } |
| 112 | 107 |
| 113 void Subtract(int value) { | 108 void Subtract(int value) { |
| 114 Add(-value); | 109 Add(-value); |
| 115 } | 110 } |
| 116 | 111 |
| 117 // TODO(jar) temporary hack includes method till base and chrome use new name. | |
| 118 void Decrement(int value) { | |
| 119 Add(-value); | |
| 120 } | |
| 121 | |
| 122 // Is this counter enabled? | 112 // Is this counter enabled? |
| 123 // Returns false if table is full. | 113 // Returns false if table is full. |
| 124 bool Enabled() { | 114 bool Enabled() { |
| 125 return GetPtr() != NULL; | 115 return GetPtr() != NULL; |
| 126 } | 116 } |
| 127 | 117 |
| 128 int value() { | 118 int value() { |
| 129 int* loc = GetPtr(); | 119 int* loc = GetPtr(); |
| 130 if (loc) return *loc; | 120 if (loc) return *loc; |
| 131 return 0; | 121 return 0; |
| (...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 202 // Returns true if the timer is running. | 192 // Returns true if the timer is running. |
| 203 bool Running() { | 193 bool Running() { |
| 204 return Enabled() && !start_time_.is_null() && stop_time_.is_null(); | 194 return Enabled() && !start_time_.is_null() && stop_time_.is_null(); |
| 205 } | 195 } |
| 206 | 196 |
| 207 // Accept a TimeDelta to increment. | 197 // Accept a TimeDelta to increment. |
| 208 virtual void AddTime(base::TimeDelta time) { | 198 virtual void AddTime(base::TimeDelta time) { |
| 209 Add(static_cast<int>(time.InMilliseconds())); | 199 Add(static_cast<int>(time.InMilliseconds())); |
| 210 } | 200 } |
| 211 | 201 |
| 212 // TODO(jar) temporary hack include method till base and chrome use new name. | |
| 213 void IncrementTimer(base::TimeDelta time) { | |
| 214 AddTime(time); | |
| 215 } | |
| 216 | |
| 217 protected: | 202 protected: |
| 218 // Compute the delta between start and stop, in milliseconds. | 203 // Compute the delta between start and stop, in milliseconds. |
| 219 void Record() { | 204 void Record() { |
| 220 AddTime(stop_time_ - start_time_); | 205 AddTime(stop_time_ - start_time_); |
| 221 } | 206 } |
| 222 | 207 |
| 223 base::TimeTicks start_time_; | 208 base::TimeTicks start_time_; |
| 224 base::TimeTicks stop_time_; | 209 base::TimeTicks stop_time_; |
| 225 }; | 210 }; |
| 226 | 211 |
| (...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 263 | 248 |
| 264 void Stop() { | 249 void Stop() { |
| 265 timer_.Stop(); | 250 timer_.Stop(); |
| 266 } | 251 } |
| 267 | 252 |
| 268 private: | 253 private: |
| 269 T& timer_; | 254 T& timer_; |
| 270 }; | 255 }; |
| 271 | 256 |
| 272 #endif // BASE_STATS_COUNTERS_H__ | 257 #endif // BASE_STATS_COUNTERS_H__ |
| OLD | NEW |