OLD | NEW |
1 /* | 1 /* |
2 * Copyright (C) 2006, 2008 Apple Inc. All rights reserved. | 2 * Copyright (C) 2006, 2008 Apple Inc. All rights reserved. |
3 * Copyright (C) 2009 Google Inc. All rights reserved. | 3 * Copyright (C) 2009 Google Inc. All rights reserved. |
4 * | 4 * |
5 * Redistribution and use in source and binary forms, with or without | 5 * Redistribution and use in source and binary forms, with or without |
6 * modification, are permitted provided that the following conditions | 6 * modification, are permitted provided that the following conditions |
7 * are met: | 7 * are met: |
8 * 1. Redistributions of source code must retain the above copyright | 8 * 1. Redistributions of source code must retain the above copyright |
9 * notice, this list of conditions and the following disclaimer. | 9 * notice, this list of conditions and the following disclaimer. |
10 * 2. Redistributions in binary form must reproduce the above copyright | 10 * 2. Redistributions in binary form must reproduce the above copyright |
(...skipping 30 matching lines...) Expand all Loading... |
41 namespace blink { | 41 namespace blink { |
42 | 42 |
43 TimerBase::TimerBase(RefPtr<WebTaskRunner> web_task_runner) | 43 TimerBase::TimerBase(RefPtr<WebTaskRunner> web_task_runner) |
44 : next_fire_time_(0), | 44 : next_fire_time_(0), |
45 repeat_interval_(0), | 45 repeat_interval_(0), |
46 web_task_runner_(std::move(web_task_runner)), | 46 web_task_runner_(std::move(web_task_runner)), |
47 #if DCHECK_IS_ON() | 47 #if DCHECK_IS_ON() |
48 thread_(CurrentThread()), | 48 thread_(CurrentThread()), |
49 #endif | 49 #endif |
50 weak_ptr_factory_(this) { | 50 weak_ptr_factory_(this) { |
51 ASSERT(web_task_runner_); | 51 DCHECK(web_task_runner_); |
52 } | 52 } |
53 | 53 |
54 TimerBase::~TimerBase() { | 54 TimerBase::~TimerBase() { |
55 Stop(); | 55 Stop(); |
56 } | 56 } |
57 | 57 |
58 void TimerBase::Start(double next_fire_interval, | 58 void TimerBase::Start(double next_fire_interval, |
59 double repeat_interval, | 59 double repeat_interval, |
60 const WebTraceLocation& caller) { | 60 const WebTraceLocation& caller) { |
61 #if DCHECK_IS_ON() | 61 #if DCHECK_IS_ON() |
62 DCHECK_EQ(thread_, CurrentThread()); | 62 DCHECK_EQ(thread_, CurrentThread()); |
63 #endif | 63 #endif |
64 | 64 |
65 location_ = caller; | 65 location_ = caller; |
66 repeat_interval_ = repeat_interval; | 66 repeat_interval_ = repeat_interval; |
67 SetNextFireTime(TimerMonotonicallyIncreasingTime(), next_fire_interval); | 67 SetNextFireTime(TimerMonotonicallyIncreasingTime(), next_fire_interval); |
68 } | 68 } |
69 | 69 |
70 void TimerBase::Stop() { | 70 void TimerBase::Stop() { |
71 #if DCHECK_IS_ON() | 71 #if DCHECK_IS_ON() |
72 DCHECK_EQ(thread_, CurrentThread()); | 72 DCHECK_EQ(thread_, CurrentThread()); |
73 #endif | 73 #endif |
74 | 74 |
75 repeat_interval_ = 0; | 75 repeat_interval_ = 0; |
76 next_fire_time_ = 0; | 76 next_fire_time_ = 0; |
77 weak_ptr_factory_.RevokeAll(); | 77 weak_ptr_factory_.RevokeAll(); |
78 } | 78 } |
79 | 79 |
80 double TimerBase::NextFireInterval() const { | 80 double TimerBase::NextFireInterval() const { |
81 ASSERT(IsActive()); | 81 DCHECK(IsActive()); |
82 double current = TimerMonotonicallyIncreasingTime(); | 82 double current = TimerMonotonicallyIncreasingTime(); |
83 if (next_fire_time_ < current) | 83 if (next_fire_time_ < current) |
84 return 0; | 84 return 0; |
85 return next_fire_time_ - current; | 85 return next_fire_time_ - current; |
86 } | 86 } |
87 | 87 |
88 void TimerBase::MoveToNewTaskRunner(RefPtr<WebTaskRunner> task_runner) { | 88 void TimerBase::MoveToNewTaskRunner(RefPtr<WebTaskRunner> task_runner) { |
89 #if DCHECK_IS_ON() | 89 #if DCHECK_IS_ON() |
90 DCHECK_EQ(thread_, CurrentThread()); | 90 DCHECK_EQ(thread_, CurrentThread()); |
91 DCHECK(task_runner->RunsTasksOnCurrentThread()); | 91 DCHECK(task_runner->RunsTasksOnCurrentThread()); |
(...skipping 87 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
179 const TimerBase* b) const { | 179 const TimerBase* b) const { |
180 return a->next_fire_time_ < b->next_fire_time_; | 180 return a->next_fire_time_ < b->next_fire_time_; |
181 } | 181 } |
182 | 182 |
183 // static | 183 // static |
184 double TimerBase::TimerMonotonicallyIncreasingTime() const { | 184 double TimerBase::TimerMonotonicallyIncreasingTime() const { |
185 return TimerTaskRunner()->MonotonicallyIncreasingVirtualTimeSeconds(); | 185 return TimerTaskRunner()->MonotonicallyIncreasingVirtualTimeSeconds(); |
186 } | 186 } |
187 | 187 |
188 } // namespace blink | 188 } // namespace blink |
OLD | NEW |