Thu, 22 Jan 2015 13:21:57 +0100
Incorporate requested changes from Mozilla in review:
https://bugzilla.mozilla.org/show_bug.cgi?id=1123480#c6
michael@0 | 1 | // Copyright (c) 2012 The Chromium Authors. All rights reserved. |
michael@0 | 2 | // Use of this source code is governed by a BSD-style license that can be |
michael@0 | 3 | // found in the LICENSE file. |
michael@0 | 4 | |
michael@0 | 5 | #ifndef BASE_THREAD_TASK_RUNNER_HANDLE_H_ |
michael@0 | 6 | #define BASE_THREAD_TASK_RUNNER_HANDLE_H_ |
michael@0 | 7 | |
michael@0 | 8 | #include "base/base_export.h" |
michael@0 | 9 | #include "base/memory/ref_counted.h" |
michael@0 | 10 | |
michael@0 | 11 | namespace base { |
michael@0 | 12 | |
michael@0 | 13 | class SingleThreadTaskRunner; |
michael@0 | 14 | |
michael@0 | 15 | // ThreadTaskRunnerHandle stores a reference to a thread's TaskRunner |
michael@0 | 16 | // in thread-local storage. Callers can then retrieve the TaskRunner |
michael@0 | 17 | // for the current thread by calling ThreadTaskRunnerHandle::Get(). |
michael@0 | 18 | // At most one TaskRunner may be bound to each thread at a time. |
michael@0 | 19 | class BASE_EXPORT ThreadTaskRunnerHandle { |
michael@0 | 20 | public: |
michael@0 | 21 | // Gets the SingleThreadTaskRunner for the current thread. |
michael@0 | 22 | static scoped_refptr<SingleThreadTaskRunner> Get(); |
michael@0 | 23 | |
michael@0 | 24 | // Returns true if the SingleThreadTaskRunner is already created for |
michael@0 | 25 | // the current thread. |
michael@0 | 26 | static bool IsSet(); |
michael@0 | 27 | |
michael@0 | 28 | // Binds |task_runner| to the current thread. |task_runner| must belong |
michael@0 | 29 | // to the current thread for this to succeed. |
michael@0 | 30 | explicit ThreadTaskRunnerHandle( |
michael@0 | 31 | const scoped_refptr<SingleThreadTaskRunner>& task_runner); |
michael@0 | 32 | ~ThreadTaskRunnerHandle(); |
michael@0 | 33 | |
michael@0 | 34 | private: |
michael@0 | 35 | scoped_refptr<SingleThreadTaskRunner> task_runner_; |
michael@0 | 36 | }; |
michael@0 | 37 | |
michael@0 | 38 | } // namespace base |
michael@0 | 39 | |
michael@0 | 40 | #endif // BASE_THREAD_TASK_RUNNER_HANDLE_H_ |