| OLD | NEW |
| 1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 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 "extensions/common/one_shot_event.h" | 5 #include "extensions/common/one_shot_event.h" |
| 6 | 6 |
| 7 #include <stddef.h> | 7 #include <stddef.h> |
| 8 | 8 |
| 9 #include "base/callback.h" | 9 #include "base/callback.h" |
| 10 #include "base/lazy_instance.h" | 10 #include "base/lazy_instance.h" |
| (...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 58 | 58 |
| 59 void OneShotEvent::PostDelayed(const tracked_objects::Location& from_here, | 59 void OneShotEvent::PostDelayed(const tracked_objects::Location& from_here, |
| 60 const base::Closure& task, | 60 const base::Closure& task, |
| 61 const base::TimeDelta& delay) const { | 61 const base::TimeDelta& delay) const { |
| 62 PostImpl(from_here, task, base::ThreadTaskRunnerHandle::Get(), delay); | 62 PostImpl(from_here, task, base::ThreadTaskRunnerHandle::Get(), delay); |
| 63 } | 63 } |
| 64 | 64 |
| 65 void OneShotEvent::Signal() { | 65 void OneShotEvent::Signal() { |
| 66 DCHECK(thread_checker_.CalledOnValidThread()); | 66 DCHECK(thread_checker_.CalledOnValidThread()); |
| 67 | 67 |
| 68 CHECK(!signaled_) << "Only call Signal once."; | 68 // Only call Signal once. |
| 69 CHECK(!signaled_); |
| 69 | 70 |
| 70 signaled_ = true; | 71 signaled_ = true; |
| 71 // After this point, a call to Post() from one of the queued tasks | 72 // After this point, a call to Post() from one of the queued tasks |
| 72 // could proceed immediately, but the fact that this object is | 73 // could proceed immediately, but the fact that this object is |
| 73 // single-threaded prevents that from being relevant. | 74 // single-threaded prevents that from being relevant. |
| 74 | 75 |
| 75 // We could randomize tasks_ in debug mode in order to check that | 76 // We could randomize tasks_ in debug mode in order to check that |
| 76 // the order doesn't matter... | 77 // the order doesn't matter... |
| 77 for (size_t i = 0; i < tasks_.size(); ++i) { | 78 for (size_t i = 0; i < tasks_.size(); ++i) { |
| 78 const TaskInfo& task = tasks_[i]; | 79 const TaskInfo& task = tasks_[i]; |
| (...skipping 14 matching lines...) Expand all Loading... |
| 93 if (delay.is_zero()) | 94 if (delay.is_zero()) |
| 94 runner->PostTask(from_here, task); | 95 runner->PostTask(from_here, task); |
| 95 else | 96 else |
| 96 runner->PostDelayedTask(from_here, task, delay); | 97 runner->PostDelayedTask(from_here, task, delay); |
| 97 } else { | 98 } else { |
| 98 tasks_.push_back(TaskInfo(from_here, runner, task, delay)); | 99 tasks_.push_back(TaskInfo(from_here, runner, task, delay)); |
| 99 } | 100 } |
| 100 } | 101 } |
| 101 | 102 |
| 102 } // namespace extensions | 103 } // namespace extensions |
| OLD | NEW |