OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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 "chrome/common/worker_thread_ticker.h" | 5 #include "chrome/common/worker_thread_ticker.h" |
6 | 6 |
7 #include <algorithm> | 7 #include <algorithm> |
8 | 8 |
9 #include "base/bind.h" | 9 #include "base/bind.h" |
10 #include "base/bind_helpers.h" | 10 #include "base/bind_helpers.h" |
11 #include "base/logging.h" | 11 #include "base/logging.h" |
12 #include "base/message_loop.h" | 12 #include "base/message_loop.h" |
13 #include "base/threading/thread.h" | 13 #include "base/threading/thread.h" |
14 | 14 |
15 WorkerThreadTicker::WorkerThreadTicker(int tick_interval) | 15 WorkerThreadTicker::WorkerThreadTicker(int tick_interval) |
16 : timer_thread_("worker_thread_ticker"), | 16 : timer_thread_("worker_thread_ticker"), |
17 is_running_(false), | 17 is_running_(false), |
18 tick_interval_(base::TimeDelta::FromMilliseconds(tick_interval)) { | 18 tick_interval_(tick_interval) { |
19 } | 19 } |
20 | 20 |
21 WorkerThreadTicker::~WorkerThreadTicker() { | 21 WorkerThreadTicker::~WorkerThreadTicker() { |
22 Stop(); | 22 Stop(); |
23 } | 23 } |
24 | 24 |
25 bool WorkerThreadTicker::RegisterTickHandler(Callback *tick_handler) { | 25 bool WorkerThreadTicker::RegisterTickHandler(Callback *tick_handler) { |
26 DCHECK(tick_handler); | 26 DCHECK(tick_handler); |
27 base::AutoLock lock(lock_); | 27 base::AutoLock lock(lock_); |
28 // You cannot change the list of handlers when the timer is running. | 28 // You cannot change the list of handlers when the timer is running. |
(...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
87 // So we can do the enumeration safely without a lock | 87 // So we can do the enumeration safely without a lock |
88 const TickHandlerListType& handlers = tick_handler_list_; | 88 const TickHandlerListType& handlers = tick_handler_list_; |
89 for (TickHandlerListType::const_iterator i = handlers.begin(); | 89 for (TickHandlerListType::const_iterator i = handlers.begin(); |
90 i != handlers.end(); ++i) { | 90 i != handlers.end(); ++i) { |
91 (*i)->OnTick(); | 91 (*i)->OnTick(); |
92 } | 92 } |
93 | 93 |
94 ScheduleTimerTask(); | 94 ScheduleTimerTask(); |
95 } | 95 } |
96 | 96 |
OLD | NEW |