michael@0: // Copyright (c) 2012 The Chromium Authors. All rights reserved. michael@0: // Use of this source code is governed by a BSD-style license that can be michael@0: // found in the LICENSE file. michael@0: michael@0: #ifndef BASE_THREAD_TASK_RUNNER_HANDLE_H_ michael@0: #define BASE_THREAD_TASK_RUNNER_HANDLE_H_ michael@0: michael@0: #include "base/base_export.h" michael@0: #include "base/memory/ref_counted.h" michael@0: michael@0: namespace base { michael@0: michael@0: class SingleThreadTaskRunner; michael@0: michael@0: // ThreadTaskRunnerHandle stores a reference to a thread's TaskRunner michael@0: // in thread-local storage. Callers can then retrieve the TaskRunner michael@0: // for the current thread by calling ThreadTaskRunnerHandle::Get(). michael@0: // At most one TaskRunner may be bound to each thread at a time. michael@0: class BASE_EXPORT ThreadTaskRunnerHandle { michael@0: public: michael@0: // Gets the SingleThreadTaskRunner for the current thread. michael@0: static scoped_refptr Get(); michael@0: michael@0: // Returns true if the SingleThreadTaskRunner is already created for michael@0: // the current thread. michael@0: static bool IsSet(); michael@0: michael@0: // Binds |task_runner| to the current thread. |task_runner| must belong michael@0: // to the current thread for this to succeed. michael@0: explicit ThreadTaskRunnerHandle( michael@0: const scoped_refptr& task_runner); michael@0: ~ThreadTaskRunnerHandle(); michael@0: michael@0: private: michael@0: scoped_refptr task_runner_; michael@0: }; michael@0: michael@0: } // namespace base michael@0: michael@0: #endif // BASE_THREAD_TASK_RUNNER_HANDLE_H_