| OLD | NEW |
| 1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 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 #ifndef ASH_METRICS_TASK_SWITCH_TIME_TRACKER_H_ | 5 #ifndef ASH_METRICS_TASK_SWITCH_TIME_TRACKER_H_ |
| 6 #define ASH_METRICS_TASK_SWITCH_TIME_TRACKER_H_ | 6 #define ASH_METRICS_TASK_SWITCH_TIME_TRACKER_H_ |
| 7 | 7 |
| 8 #include <memory> |
| 8 #include <string> | 9 #include <string> |
| 9 | 10 |
| 10 #include "ash/ash_export.h" | 11 #include "ash/ash_export.h" |
| 11 #include "base/macros.h" | 12 #include "base/macros.h" |
| 12 #include "base/memory/scoped_ptr.h" | |
| 13 #include "base/time/time.h" | 13 #include "base/time/time.h" |
| 14 | 14 |
| 15 namespace base { | 15 namespace base { |
| 16 class HistogramBase; | 16 class HistogramBase; |
| 17 class TickClock; | 17 class TickClock; |
| 18 } | 18 } |
| 19 | 19 |
| 20 namespace ash { | 20 namespace ash { |
| 21 | 21 |
| 22 namespace test { | 22 namespace test { |
| (...skipping 12 matching lines...) Expand all Loading... |
| 35 // Notifies |this| that a task switch has occurred. A histogram data point | 35 // Notifies |this| that a task switch has occurred. A histogram data point |
| 36 // will be recorded for all calls but the first. | 36 // will be recorded for all calls but the first. |
| 37 void OnTaskSwitch(); | 37 void OnTaskSwitch(); |
| 38 | 38 |
| 39 private: | 39 private: |
| 40 friend class test::TaskSwitchTimeTrackerTestAPI; | 40 friend class test::TaskSwitchTimeTrackerTestAPI; |
| 41 | 41 |
| 42 // Private constructor that the test::TaskSwitchTimeTrackerTestAPI can use to | 42 // Private constructor that the test::TaskSwitchTimeTrackerTestAPI can use to |
| 43 // inject a custom |tick_clock|. | 43 // inject a custom |tick_clock|. |
| 44 TaskSwitchTimeTracker(const std::string& histogram_name, | 44 TaskSwitchTimeTracker(const std::string& histogram_name, |
| 45 scoped_ptr<base::TickClock> tick_clock); | 45 std::unique_ptr<base::TickClock> tick_clock); |
| 46 | 46 |
| 47 // Returns true if |last_action_time_| has a valid value. | 47 // Returns true if |last_action_time_| has a valid value. |
| 48 bool HasLastActionTime() const; | 48 bool HasLastActionTime() const; |
| 49 | 49 |
| 50 // Sets the |last_action_time_| to |tick_clock_|'s current value and returns | 50 // Sets the |last_action_time_| to |tick_clock_|'s current value and returns |
| 51 // the previous value for |last_action_time_|. | 51 // the previous value for |last_action_time_|. |
| 52 base::TimeTicks SetLastActionTime(); | 52 base::TimeTicks SetLastActionTime(); |
| 53 | 53 |
| 54 // Records a data point in the histogram. | 54 // Records a data point in the histogram. |
| 55 void RecordTimeDelta(); | 55 void RecordTimeDelta(); |
| 56 | 56 |
| 57 // Lazily obtains and sets the |histogram_|. | 57 // Lazily obtains and sets the |histogram_|. |
| 58 base::HistogramBase* GetHistogram(); | 58 base::HistogramBase* GetHistogram(); |
| 59 | 59 |
| 60 // The histogram name to record data to. | 60 // The histogram name to record data to. |
| 61 std::string histogram_name_; | 61 std::string histogram_name_; |
| 62 | 62 |
| 63 // The histogram to log data to. Set via GetHistogram() using lazy load. | 63 // The histogram to log data to. Set via GetHistogram() using lazy load. |
| 64 base::HistogramBase* histogram_ = nullptr; | 64 base::HistogramBase* histogram_ = nullptr; |
| 65 | 65 |
| 66 // Tracks the last time OnTaskSwitch() was called. A value of | 66 // Tracks the last time OnTaskSwitch() was called. A value of |
| 67 // base::TimeTicks() should be interpreted as not set. | 67 // base::TimeTicks() should be interpreted as not set. |
| 68 base::TimeTicks last_action_time_ = base::TimeTicks(); | 68 base::TimeTicks last_action_time_ = base::TimeTicks(); |
| 69 | 69 |
| 70 // The clock used to determine the |last_action_time_|. | 70 // The clock used to determine the |last_action_time_|. |
| 71 scoped_ptr<base::TickClock> tick_clock_; | 71 std::unique_ptr<base::TickClock> tick_clock_; |
| 72 | 72 |
| 73 DISALLOW_COPY_AND_ASSIGN(TaskSwitchTimeTracker); | 73 DISALLOW_COPY_AND_ASSIGN(TaskSwitchTimeTracker); |
| 74 }; | 74 }; |
| 75 | 75 |
| 76 } // namespace ash | 76 } // namespace ash |
| 77 | 77 |
| 78 #endif // ASH_METRICS_TASK_SWITCH_TIME_TRACKE_H_ | 78 #endif // ASH_METRICS_TASK_SWITCH_TIME_TRACKE_H_ |
| OLD | NEW |