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
3 // found in the LICENSE file.
7 #include "base/test/test_pending_task.h"
11 TestPendingTask::TestPendingTask() : nestability(NESTABLE
) {}
13 TestPendingTask::TestPendingTask(
14 const tracked_objects::Location
& location
,
18 TestNestability nestability
)
23 nestability(nestability
) {}
25 TimeTicks
TestPendingTask::GetTimeToRun() const {
26 return post_time
+ delay
;
29 bool TestPendingTask::ShouldRunBefore(const TestPendingTask
& other
) const {
30 if (nestability
!= other
.nestability
)
31 return (nestability
== NESTABLE
);
32 return GetTimeToRun() < other
.GetTimeToRun();
35 TestPendingTask::~TestPendingTask() {}
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
) {
44 state
->SetString("nestability", "NESTABLE");
47 state
->SetString("nestability", "NON_NESTABLE");
50 state
->SetInteger("delay", delay
.ToInternalValue());
53 scoped_refptr
<base::debug::ConvertableToTraceFormat
> TestPendingTask::AsValue()
55 scoped_refptr
<base::debug::TracedValue
> state
=
56 new base::debug::TracedValue();
57 AsValueInto(state
.get());
61 std::string
TestPendingTask::ToString() const {
62 std::string
output("TestPendingTask(");
63 AsValue()->AppendAsTraceFormat(&output
);
68 std::ostream
& operator<<(std::ostream
& os
, const TestPendingTask
& task
) {
73 void PrintTo(const TestPendingTask
& task
, std::ostream
* os
) {
74 *os
<< task
.ToString();