1 // Copyright 2020 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 COMPONENTS_SAFE_BROWSING_CORE_COMMON_THREAD_UTILS_H_ 6 #define COMPONENTS_SAFE_BROWSING_CORE_COMMON_THREAD_UTILS_H_ 7 8 #include "base/task/task_traits.h" 9 10 namespace safe_browsing { 11 12 // Safe Browsing thread-related utility functions, which need separate 13 // implementations for content/ clients and for ios/ since content/ and ios/ 14 // use distinct classes for representing threads (content::BrowserThread and 15 // web::WebThread). 16 17 // An enumeration of well-known threads. 18 enum class ThreadID { 19 // The main thread in the browser. 20 UI, 21 22 // The thread that processes non-blocking IO (IPC and network). 23 IO, 24 }; 25 26 // Callable on any thread. Returns true if the current thread matches the given 27 // identifier. 28 bool CurrentlyOnThread(ThreadID thread_id) WARN_UNUSED_RESULT; 29 30 // Callable on any thread. Returns TaskTraits for running a task on the given 31 // thread. 32 base::TaskTraits CreateTaskTraits(ThreadID thread_id); 33 34 } // namespace safe_browsing 35 36 #endif // COMPONENTS_SAFE_BROWSING_CORE_COMMON_THREAD_UTILS_H_ 37