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::trace_event::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::trace_event::ConvertableToTraceFormat
>
54 TestPendingTask::AsValue() const {
55 scoped_refptr
<base::trace_event::TracedValue
> state
=
56 new base::trace_event::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();