// Copyright 2018 The Chromium Authors // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. #ifndef BASE_TASK_CURRENT_THREAD_H_ #define BASE_TASK_CURRENT_THREAD_H_ #include <ostream> #include <type_traits> #include "base/base_export.h" #include "base/callback_list.h" #include "base/check.h" #include "base/functional/callback_forward.h" #include "base/memory/raw_ptr.h" #include "base/memory/scoped_refptr.h" #include "base/message_loop/ios_cronet_buildflags.h" #include "base/message_loop/message_pump_for_io.h" #include "base/message_loop/message_pump_for_ui.h" #include "base/pending_task.h" #include "base/task/sequence_manager/task_time_observer.h" #include "base/task/single_thread_task_runner.h" #include "base/task/task_observer.h" #include "build/build_config.h" namespace autofill { class NextIdleBarrier; } namespace content { class BrowserMainLoop; } namespace web { class WebTaskEnvironment; } namespace base { namespace test { bool RunUntil(FunctionRef<bool(void)>); void TestPredicateOrRegisterOnNextIdleCallback(base::FunctionRef<bool(void)>, CallbackListSubscription*, OnceClosure); } // namespace test namespace sequence_manager { namespace internal { class SequenceManagerImpl; } } // namespace sequence_manager // CurrentThread is a proxy to a subset of Task related APIs bound to the // current thread // // Current(UI|IO)Thread is available statically through // Current(UI|IO)Thread::Get() on threads that have registered as CurrentThread // on this physical thread (e.g. by using SingleThreadTaskExecutor). APIs // intended for all consumers on the thread should be on Current(UI|IO)Thread, // while internal APIs might be on multiple internal classes (e.g. // SequenceManager). // // Why: Historically MessageLoop would take care of everything related to event // processing on a given thread. Nowadays that functionality is split among // different classes. At that time MessageLoop::current() gave access to the // full MessageLoop API, preventing both addition of powerful owner-only APIs as // well as making it harder to remove callers of deprecated APIs (that need to // stick around for a few owner-only use cases and re-accrue callers after // cleanup per remaining publicly available). // // As such, many methods below are flagged as deprecated and should be removed // once all static callers have been migrated. class BASE_EXPORT CurrentThread { … }; #if !BUILDFLAG(IS_NACL) // UI extension of CurrentThread. class BASE_EXPORT CurrentUIThread : public CurrentThread { … }; #endif // !BUILDFLAG(IS_NACL) // ForIO extension of CurrentThread. class BASE_EXPORT CurrentIOThread : public CurrentThread { … }; } // namespace base #endif // BASE_TASK_CURRENT_THREAD_H_