| OLD | NEW |
| 1 // Copyright (c) 2009 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2006-2008 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 #ifndef CHROME_COMMON_WORKER_THREAD_TICKER_H_ | 5 #ifndef CHROME_COMMON_WORKER_THREAD_TICKER_H__ |
| 6 #define CHROME_COMMON_WORKER_THREAD_TICKER_H_ | 6 #define CHROME_COMMON_WORKER_THREAD_TICKER_H__ |
| 7 | 7 |
| 8 #include <vector> | 8 #include <vector> |
| 9 | 9 |
| 10 #include "base/lock.h" | 10 #include "base/lock.h" |
| 11 #include "base/thread.h" | 11 #include "base/thread.h" |
| 12 | 12 |
| 13 // This class provides the following functionality: | 13 // This class provides the following functionality: |
| 14 // It invokes a set of registered handlers at periodic intervals in | 14 // It invokes a set of registered handlers at periodic intervals in |
| 15 // the context of an arbitrary worker thread. | 15 // the context of an arbitrary worker thread. |
| 16 // The timer runs on a separate thread, so it will run even if the current | 16 // The timer runs on a separate thread, so it will run even if the current |
| 17 // thread is hung. Similarly, the callbacks will be called on a separate | 17 // thread is hung. Similarly, the callbacks will be called on a separate |
| 18 // thread so they won't block the main thread. | 18 // thread so they won't block the main thread. |
| 19 class WorkerThreadTicker { | 19 class WorkerThreadTicker { |
| 20 public: | 20 public: |
| 21 // This callback interface to be implemented by clients of this | 21 // This callback interface to be implemented by clients of this |
| 22 // class | 22 // class |
| 23 class Callback { | 23 class Callback { |
| 24 public: | 24 public: |
| 25 // Gets invoked when the timer period is up | 25 // Gets invoked when the timer period is up |
| 26 virtual void OnTick() = 0; | 26 virtual void OnTick() = 0; |
| 27 | |
| 28 protected: | |
| 29 ~Callback() {} | |
| 30 }; | 27 }; |
| 31 | 28 |
| 32 // tick_interval is the periodic interval in which to invoke the | 29 // tick_interval is the periodic interval in which to invoke the |
| 33 // registered handlers (in milliseconds) | 30 // registered handlers (in milliseconds) |
| 34 explicit WorkerThreadTicker(int tick_interval); | 31 explicit WorkerThreadTicker(int tick_interval); |
| 35 | 32 |
| 36 ~WorkerThreadTicker(); | 33 ~WorkerThreadTicker(); |
| 37 | 34 |
| 38 // Registers a callback handler interface | 35 // Registers a callback handler interface |
| 39 // tick_handler is the handler interface to register. The ownership of this | 36 // tick_handler is the handler interface to register. The ownership of this |
| (...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 80 | 77 |
| 81 // The interval at which the callbacks are to be invoked | 78 // The interval at which the callbacks are to be invoked |
| 82 int tick_interval_; | 79 int tick_interval_; |
| 83 | 80 |
| 84 // A list that holds all registered callback interfaces | 81 // A list that holds all registered callback interfaces |
| 85 TickHandlerListType tick_handler_list_; | 82 TickHandlerListType tick_handler_list_; |
| 86 | 83 |
| 87 DISALLOW_COPY_AND_ASSIGN(WorkerThreadTicker); | 84 DISALLOW_COPY_AND_ASSIGN(WorkerThreadTicker); |
| 88 }; | 85 }; |
| 89 | 86 |
| 90 #endif // CHROME_COMMON_WORKER_THREAD_TICKER_H_ | 87 #endif // CHROME_COMMON_WORKER_THREAD_TICKER_H__ |
| OLD | NEW |