sergeyu@chromium.org | 675d888 | 2012-05-10 05:16:14 +0900 | [diff] [blame] | 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. |
| 4 | |
| 5 | #ifndef BASE_THREAD_TASK_RUNNER_HANDLE_H_ |
| 6 | #define BASE_THREAD_TASK_RUNNER_HANDLE_H_ |
| 7 | |
| 8 | #include "base/base_export.h" |
| 9 | #include "base/memory/ref_counted.h" |
| 10 | |
| 11 | namespace base { |
| 12 | |
| 13 | class SingleThreadTaskRunner; |
| 14 | |
wez@chromium.org | 5667e26 | 2013-04-06 16:09:33 +0900 | [diff] [blame] | 15 | // ThreadTaskRunnerHandle stores a reference to a thread's TaskRunner |
| 16 | // in thread-local storage. Callers can then retrieve the TaskRunner |
| 17 | // for the current thread by calling ThreadTaskRunnerHandle::Get(). |
| 18 | // At most one TaskRunner may be bound to each thread at a time. |
sergeyu@chromium.org | 675d888 | 2012-05-10 05:16:14 +0900 | [diff] [blame] | 19 | class BASE_EXPORT ThreadTaskRunnerHandle { |
| 20 | public: |
| 21 | // Gets the SingleThreadTaskRunner for the current thread. |
| 22 | static scoped_refptr<SingleThreadTaskRunner> Get(); |
| 23 | |
alexeypa@chromium.org | b9baffc | 2013-04-25 05:44:38 +0900 | [diff] [blame] | 24 | // Returns true if the SingleThreadTaskRunner is already created for |
| 25 | // the current thread. |
| 26 | static bool IsSet(); |
| 27 | |
wez@chromium.org | 5667e26 | 2013-04-06 16:09:33 +0900 | [diff] [blame] | 28 | // Binds |task_runner| to the current thread. |task_runner| must belong |
| 29 | // to the current thread for this to succeed. |
hans@chromium.org | 07615b4 | 2013-01-15 19:52:11 +0900 | [diff] [blame] | 30 | explicit ThreadTaskRunnerHandle( |
sergeyu@chromium.org | 675d888 | 2012-05-10 05:16:14 +0900 | [diff] [blame] | 31 | const scoped_refptr<SingleThreadTaskRunner>& task_runner); |
| 32 | ~ThreadTaskRunnerHandle(); |
| 33 | |
| 34 | private: |
| 35 | scoped_refptr<SingleThreadTaskRunner> task_runner_; |
| 36 | }; |
| 37 | |
| 38 | } // namespace base |
| 39 | |
| 40 | #endif // BASE_THREAD_TASK_RUNNER_HANDLE_H_ |