OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 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 | 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 #include <string> |
| 6 |
5 #include "base/test/test_pending_task.h" | 7 #include "base/test/test_pending_task.h" |
6 | 8 |
7 namespace base { | 9 namespace base { |
8 | 10 |
9 TestPendingTask::TestPendingTask() : nestability(NESTABLE) {} | 11 TestPendingTask::TestPendingTask() : nestability(NESTABLE) {} |
10 | 12 |
11 TestPendingTask::TestPendingTask( | 13 TestPendingTask::TestPendingTask( |
12 const tracked_objects::Location& location, | 14 const tracked_objects::Location& location, |
13 const Closure& task, | 15 const Closure& task, |
14 TimeTicks post_time, | 16 TimeTicks post_time, |
(...skipping 10 matching lines...) Expand all Loading... |
25 } | 27 } |
26 | 28 |
27 bool TestPendingTask::ShouldRunBefore(const TestPendingTask& other) const { | 29 bool TestPendingTask::ShouldRunBefore(const TestPendingTask& other) const { |
28 if (nestability != other.nestability) | 30 if (nestability != other.nestability) |
29 return (nestability == NESTABLE); | 31 return (nestability == NESTABLE); |
30 return GetTimeToRun() < other.GetTimeToRun(); | 32 return GetTimeToRun() < other.GetTimeToRun(); |
31 } | 33 } |
32 | 34 |
33 TestPendingTask::~TestPendingTask() {} | 35 TestPendingTask::~TestPendingTask() {} |
34 | 36 |
| 37 void TestPendingTask::AsValueInto(base::debug::TracedValue* state) const { |
| 38 state->SetInteger("run_at", GetTimeToRun().ToInternalValue()); |
| 39 state->SetString("posting_function", location.ToString()); |
| 40 state->SetInteger("post_time", post_time.ToInternalValue()); |
| 41 state->SetInteger("delay", delay.ToInternalValue()); |
| 42 switch (nestability) { |
| 43 case NESTABLE: |
| 44 state->SetString("nestability", "NESTABLE"); |
| 45 break; |
| 46 case NON_NESTABLE: |
| 47 state->SetString("nestability", "NON_NESTABLE"); |
| 48 break; |
| 49 } |
| 50 state->SetInteger("delay", delay.ToInternalValue()); |
| 51 } |
| 52 |
| 53 scoped_refptr<base::debug::ConvertableToTraceFormat> TestPendingTask::AsValue() |
| 54 const { |
| 55 scoped_refptr<base::debug::TracedValue> state = |
| 56 new base::debug::TracedValue(); |
| 57 AsValueInto(state); |
| 58 return state; |
| 59 } |
| 60 |
| 61 std::string TestPendingTask::ToString() const { |
| 62 std::string output("TestPendingTask("); |
| 63 AsValue()->AppendAsTraceFormat(&output); |
| 64 output += ")"; |
| 65 return output; |
| 66 } |
| 67 |
| 68 ::std::ostream& operator<<(::std::ostream& os, const TestPendingTask& task) { |
| 69 PrintTo(task, &os); |
| 70 return os; |
| 71 } |
| 72 |
| 73 void PrintTo(const TestPendingTask& task, ::std::ostream* os) { |
| 74 *os << task.ToString(); |
| 75 } |
| 76 |
35 } // namespace base | 77 } // namespace base |
OLD | NEW |