123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725 |
- #ifndef BASE_THREADING_THREAD_RESTRICTIONS_H_
- #define BASE_THREADING_THREAD_RESTRICTIONS_H_
- #include "base/base_export.h"
- #include "base/check_op.h"
- #include "base/gtest_prod_util.h"
- #include "base/location.h"
- #include "base/macros.h"
- #include "base/threading/hang_watcher.h"
- class BrowserProcessImpl;
- class ChromeNSSCryptoModuleDelegate;
- class HistogramSynchronizer;
- class KeyStorageLinux;
- class NativeBackendKWallet;
- class NativeDesktopMediaList;
- namespace android_webview {
- class AwFormDatabaseService;
- class CookieManager;
- class ScopedAllowInitGLBindings;
- class VizCompositorThreadRunnerWebView;
- }
- namespace audio {
- class OutputDevice;
- }
- namespace blink {
- class DiskDataAllocator;
- class RTCVideoDecoderAdapter;
- class RTCVideoEncoder;
- class SourceStream;
- class VideoFrameResourceProvider;
- class WorkerThread;
- namespace scheduler {
- class WorkerThread;
- }
- }
- namespace cc {
- class CompletionEvent;
- class TileTaskManagerImpl;
- }
- namespace chromeos {
- class BlockingMethodCaller;
- class MojoUtils;
- namespace system {
- class StatisticsProviderImpl;
- }
- }
- namespace chrome_browser_net {
- class Predictor;
- }
- namespace chrome_cleaner {
- class SystemReportComponent;
- }
- namespace content {
- class BrowserGpuChannelHostFactory;
- class BrowserMainLoop;
- class BrowserProcessSubThread;
- class BrowserShutdownProfileDumper;
- class BrowserTestBase;
- class CategorizedWorkerPool;
- class DesktopCaptureDevice;
- class InProcessUtilityThread;
- class NestedMessagePumpAndroid;
- class NetworkServiceInstancePrivate;
- class PepperPrintSettingsManagerImpl;
- class RenderProcessHostImpl;
- class RenderWidgetHostViewMac;
- class RTCVideoDecoder;
- class SandboxHostLinux;
- class ScopedAllowWaitForDebugURL;
- class ServiceWorkerContextClient;
- class SoftwareOutputDeviceMus;
- class SynchronousCompositor;
- class SynchronousCompositorHost;
- class SynchronousCompositorSyncCallBridge;
- class TextInputClientMac;
- class WaitForProcessesToDumpProfilingInfo;
- class WebContentsViewMac;
- }
- namespace cronet {
- class CronetPrefsManager;
- class CronetURLRequestContext;
- }
- namespace dbus {
- class Bus;
- }
- namespace disk_cache {
- class BackendImpl;
- class InFlightIO;
- }
- namespace functions {
- class ExecScriptScopedAllowBaseSyncPrimitives;
- }
- namespace history_report {
- class HistoryReportJniBridge;
- }
- namespace gpu {
- class GpuChannelHost;
- }
- namespace leveldb_env {
- class DBTracker;
- }
- namespace location {
- namespace nearby {
- namespace chrome {
- class ScheduledExecutor;
- class SubmittableExecutor;
- }
- }
- }
- namespace media {
- class AudioInputDevice;
- class AudioOutputDevice;
- class BlockingUrlProtocol;
- class PaintCanvasVideoRenderer;
- }
- namespace memory_instrumentation {
- class OSMetrics;
- }
- namespace metrics {
- class AndroidMetricsServiceClient;
- }
- namespace midi {
- class TaskService;
- }
- namespace module_installer {
- class ScopedAllowModulePakLoad;
- }
- namespace mojo {
- class CoreLibraryInitializer;
- class SyncCallRestrictions;
- namespace core {
- class ScopedIPCSupport;
- }
- }
- namespace printing {
- class LocalPrinterHandlerDefault;
- class PrintJobWorker;
- class PrinterQuery;
- }
- namespace rlz_lib {
- class FinancialPing;
- }
- namespace syncer {
- class GetLocalChangesRequest;
- class HttpBridge;
- class ModelSafeWorker;
- }
- namespace ui {
- class CommandBufferClientImpl;
- class CommandBufferLocal;
- class DrmThreadProxy;
- class GpuState;
- }
- namespace weblayer {
- class BrowserContextImpl;
- class ContentBrowserClientImpl;
- class ProfileImpl;
- class WebLayerPathProvider;
- }
- namespace net {
- class MultiThreadedCertVerifierScopedAllowBaseSyncPrimitives;
- class MultiThreadedProxyResolverScopedAllowJoinOnIO;
- class NetworkChangeNotifierMac;
- class NetworkConfigWatcherMacThread;
- namespace internal {
- class AddressTrackerLinux;
- }
- }
- namespace proxy_resolver {
- class ScopedAllowThreadJoinForProxyResolverV8Tracing;
- }
- namespace remoting {
- class AutoThread;
- namespace protocol {
- class ScopedAllowThreadJoinForWebRtcTransport;
- }
- }
- namespace resource_coordinator {
- class TabManagerDelegate;
- }
- namespace service_manager {
- class ServiceProcessLauncher;
- }
- namespace shell_integration_linux {
- class LaunchXdgUtilityScopedAllowBaseSyncPrimitives;
- }
- namespace ui {
- class WindowResizeHelperMac;
- }
- namespace viz {
- class HostGpuMemoryBufferManager;
- }
- namespace vr {
- class VrShell;
- }
- namespace web {
- class WebMainLoop;
- class WebSubThread;
- }
- namespace webrtc {
- class DesktopConfigurationMonitor;
- }
- namespace base {
- namespace sequence_manager {
- namespace internal {
- class TaskQueueImpl;
- }
- }
- namespace android {
- class JavaHandlerThread;
- }
- namespace internal {
- class JobTaskSource;
- class TaskTracker;
- }
- class AdjustOOMScoreHelper;
- class FileDescriptorWatcher;
- class FilePath;
- class GetAppOutputScopedAllowBaseSyncPrimitives;
- class ScopedAllowThreadRecallForStackSamplingProfiler;
- class SimpleThread;
- class StackSamplingProfiler;
- class Thread;
- class WaitableEvent;
- bool PathProviderWin(int, FilePath*);
- #if DCHECK_IS_ON()
- #define INLINE_IF_DCHECK_IS_OFF BASE_EXPORT
- #define EMPTY_BODY_IF_DCHECK_IS_OFF
- #else
- #define INLINE_IF_DCHECK_IS_OFF inline
- #define EMPTY_BODY_IF_DCHECK_IS_OFF \
- {} \
- static_assert(true, "")
- #endif
- namespace internal {
- INLINE_IF_DCHECK_IS_OFF void AssertBlockingAllowed()
- EMPTY_BODY_IF_DCHECK_IS_OFF;
- }
- INLINE_IF_DCHECK_IS_OFF void DisallowBlocking() EMPTY_BODY_IF_DCHECK_IS_OFF;
- class BASE_EXPORT ScopedDisallowBlocking {
- public:
- ScopedDisallowBlocking() EMPTY_BODY_IF_DCHECK_IS_OFF;
- ~ScopedDisallowBlocking() EMPTY_BODY_IF_DCHECK_IS_OFF;
- private:
- #if DCHECK_IS_ON()
- const bool was_disallowed_;
- #endif
- DISALLOW_COPY_AND_ASSIGN(ScopedDisallowBlocking);
- };
- class BASE_EXPORT ScopedAllowBlocking {
- private:
- FRIEND_TEST_ALL_PREFIXES(ThreadRestrictionsTest, ScopedAllowBlocking);
- friend class ScopedAllowBlockingForTesting;
-
-
- friend class AdjustOOMScoreHelper;
- friend class StackSamplingProfiler;
- friend class android_webview::ScopedAllowInitGLBindings;
- friend class blink::DiskDataAllocator;
- friend class chromeos::MojoUtils;
- friend class content::BrowserProcessSubThread;
- friend class content::NetworkServiceInstancePrivate;
- friend class content::PepperPrintSettingsManagerImpl;
- friend class content::RenderProcessHostImpl;
- friend class content::RenderWidgetHostViewMac;
- friend class content::WebContentsViewMac;
- friend class cronet::CronetPrefsManager;
- friend class cronet::CronetURLRequestContext;
- friend class memory_instrumentation::OSMetrics;
- friend class metrics::AndroidMetricsServiceClient;
- friend class module_installer::ScopedAllowModulePakLoad;
- friend class mojo::CoreLibraryInitializer;
- friend class printing::LocalPrinterHandlerDefault;
- friend class printing::PrintJobWorker;
- friend class resource_coordinator::TabManagerDelegate;
- friend class web::WebSubThread;
- friend class weblayer::BrowserContextImpl;
- friend class weblayer::ContentBrowserClientImpl;
- friend class weblayer::ProfileImpl;
- friend class weblayer::WebLayerPathProvider;
- friend bool PathProviderWin(int, FilePath*);
- ScopedAllowBlocking(const Location& from_here = Location::Current());
- ~ScopedAllowBlocking();
- #if DCHECK_IS_ON()
- const bool was_disallowed_;
- #endif
- DISALLOW_COPY_AND_ASSIGN(ScopedAllowBlocking);
- };
- class ScopedAllowBlockingForTesting {
- public:
- ScopedAllowBlockingForTesting() {}
- ~ScopedAllowBlockingForTesting() {}
- private:
- #if DCHECK_IS_ON()
- ScopedAllowBlocking scoped_allow_blocking_;
- #endif
- DISALLOW_COPY_AND_ASSIGN(ScopedAllowBlockingForTesting);
- };
- INLINE_IF_DCHECK_IS_OFF void DisallowBaseSyncPrimitives()
- EMPTY_BODY_IF_DCHECK_IS_OFF;
- class BASE_EXPORT ScopedAllowBaseSyncPrimitives {
- private:
-
-
-
- FRIEND_TEST_ALL_PREFIXES(ThreadRestrictionsTest,
- ScopedAllowBaseSyncPrimitives);
- FRIEND_TEST_ALL_PREFIXES(ThreadRestrictionsTest,
- ScopedAllowBaseSyncPrimitivesResetsState);
- FRIEND_TEST_ALL_PREFIXES(ThreadRestrictionsTest,
- ScopedAllowBaseSyncPrimitivesWithBlockingDisallowed);
-
- friend class SimpleThread;
- friend class ::ChromeNSSCryptoModuleDelegate;
- friend class base::GetAppOutputScopedAllowBaseSyncPrimitives;
- friend class blink::SourceStream;
- friend class blink::WorkerThread;
- friend class blink::scheduler::WorkerThread;
- friend class chrome_cleaner::SystemReportComponent;
- friend class content::BrowserMainLoop;
- friend class content::BrowserProcessSubThread;
- friend class content::ServiceWorkerContextClient;
- friend class functions::ExecScriptScopedAllowBaseSyncPrimitives;
- friend class history_report::HistoryReportJniBridge;
- friend class internal::TaskTracker;
- friend class leveldb_env::DBTracker;
- friend class location::nearby::chrome::ScheduledExecutor;
- friend class location::nearby::chrome::SubmittableExecutor;
- friend class media::BlockingUrlProtocol;
- friend class mojo::core::ScopedIPCSupport;
- friend class net::MultiThreadedCertVerifierScopedAllowBaseSyncPrimitives;
- friend class rlz_lib::FinancialPing;
- friend class shell_integration_linux::
- LaunchXdgUtilityScopedAllowBaseSyncPrimitives;
- friend class syncer::HttpBridge;
- friend class syncer::GetLocalChangesRequest;
- friend class syncer::ModelSafeWorker;
- friend class webrtc::DesktopConfigurationMonitor;
-
- friend class ::NativeBackendKWallet;
- friend class ::chromeos::system::
- StatisticsProviderImpl;
- friend class blink::VideoFrameResourceProvider;
- ScopedAllowBaseSyncPrimitives() EMPTY_BODY_IF_DCHECK_IS_OFF;
- ~ScopedAllowBaseSyncPrimitives() EMPTY_BODY_IF_DCHECK_IS_OFF;
- #if DCHECK_IS_ON()
- const bool was_disallowed_;
- #endif
- DISALLOW_COPY_AND_ASSIGN(ScopedAllowBaseSyncPrimitives);
- };
- class BASE_EXPORT ScopedAllowBaseSyncPrimitivesOutsideBlockingScope {
- private:
-
-
-
- FRIEND_TEST_ALL_PREFIXES(ThreadRestrictionsTest,
- ScopedAllowBaseSyncPrimitivesOutsideBlockingScope);
- FRIEND_TEST_ALL_PREFIXES(
- ThreadRestrictionsTest,
- ScopedAllowBaseSyncPrimitivesOutsideBlockingScopeResetsState);
-
- friend class ::BrowserProcessImpl;
- friend class ::KeyStorageLinux;
- friend class ::NativeDesktopMediaList;
- friend class android::JavaHandlerThread;
- friend class android_webview::
- AwFormDatabaseService;
- friend class android_webview::CookieManager;
- friend class android_webview::VizCompositorThreadRunnerWebView;
- friend class audio::OutputDevice;
- friend class base::sequence_manager::internal::TaskQueueImpl;
- friend class base::FileDescriptorWatcher;
- friend class base::internal::JobTaskSource;
- friend class base::ScopedAllowThreadRecallForStackSamplingProfiler;
- friend class base::StackSamplingProfiler;
- friend class blink::RTCVideoDecoderAdapter;
- friend class blink::RTCVideoEncoder;
- friend class cc::TileTaskManagerImpl;
- friend class content::CategorizedWorkerPool;
- friend class content::DesktopCaptureDevice;
- friend class content::InProcessUtilityThread;
- friend class content::RTCVideoDecoder;
- friend class content::SandboxHostLinux;
- friend class content::ScopedAllowWaitForDebugURL;
- friend class content::SynchronousCompositor;
- friend class content::SynchronousCompositorHost;
- friend class content::SynchronousCompositorSyncCallBridge;
- friend class content::WaitForProcessesToDumpProfilingInfo;
- friend class media::AudioInputDevice;
- friend class media::AudioOutputDevice;
- friend class media::PaintCanvasVideoRenderer;
- friend class mojo::SyncCallRestrictions;
- friend class net::NetworkConfigWatcherMacThread;
- friend class ui::DrmThreadProxy;
- friend class viz::HostGpuMemoryBufferManager;
- friend class vr::VrShell;
-
- friend class ::chromeos::BlockingMethodCaller;
- friend class base::Thread;
- friend class cc::CompletionEvent;
- friend class content::
- BrowserGpuChannelHostFactory;
- friend class dbus::Bus;
- friend class disk_cache::BackendImpl;
- friend class disk_cache::InFlightIO;
- friend class gpu::GpuChannelHost;
- friend class remoting::protocol::
- ScopedAllowThreadJoinForWebRtcTransport;
- friend class midi::TaskService;
- friend class net::internal::AddressTrackerLinux;
- friend class net::
- MultiThreadedProxyResolverScopedAllowJoinOnIO;
- friend class net::NetworkChangeNotifierMac;
- friend class printing::PrinterQuery;
- friend class proxy_resolver::
- ScopedAllowThreadJoinForProxyResolverV8Tracing;
- friend class remoting::AutoThread;
-
- friend class service_manager::ServiceProcessLauncher;
- friend class ui::WindowResizeHelperMac;
- friend class content::TextInputClientMac;
- ScopedAllowBaseSyncPrimitivesOutsideBlockingScope(
- const Location& from_here = Location::Current());
- ~ScopedAllowBaseSyncPrimitivesOutsideBlockingScope();
- #if DCHECK_IS_ON()
- const bool was_disallowed_;
- #endif
-
-
-
- base::HangWatchScopeDisabled hang_watch_scope_disabled_;
- DISALLOW_COPY_AND_ASSIGN(ScopedAllowBaseSyncPrimitivesOutsideBlockingScope);
- };
- class BASE_EXPORT ScopedAllowBaseSyncPrimitivesForTesting {
- public:
- ScopedAllowBaseSyncPrimitivesForTesting() EMPTY_BODY_IF_DCHECK_IS_OFF;
- ~ScopedAllowBaseSyncPrimitivesForTesting() EMPTY_BODY_IF_DCHECK_IS_OFF;
- private:
- #if DCHECK_IS_ON()
- const bool was_disallowed_;
- #endif
- DISALLOW_COPY_AND_ASSIGN(ScopedAllowBaseSyncPrimitivesForTesting);
- };
- class BASE_EXPORT ScopedAllowUnresponsiveTasksForTesting {
- public:
- ScopedAllowUnresponsiveTasksForTesting() EMPTY_BODY_IF_DCHECK_IS_OFF;
- ~ScopedAllowUnresponsiveTasksForTesting() EMPTY_BODY_IF_DCHECK_IS_OFF;
- private:
- #if DCHECK_IS_ON()
- const bool was_disallowed_base_sync_;
- const bool was_disallowed_blocking_;
- const bool was_disallowed_cpu_;
- #endif
- DISALLOW_COPY_AND_ASSIGN(ScopedAllowUnresponsiveTasksForTesting);
- };
- namespace internal {
- INLINE_IF_DCHECK_IS_OFF void AssertBaseSyncPrimitivesAllowed()
- EMPTY_BODY_IF_DCHECK_IS_OFF;
- INLINE_IF_DCHECK_IS_OFF void ResetThreadRestrictionsForTesting()
- EMPTY_BODY_IF_DCHECK_IS_OFF;
- }
- INLINE_IF_DCHECK_IS_OFF void AssertLongCPUWorkAllowed()
- EMPTY_BODY_IF_DCHECK_IS_OFF;
- INLINE_IF_DCHECK_IS_OFF void DisallowUnresponsiveTasks()
- EMPTY_BODY_IF_DCHECK_IS_OFF;
- class BASE_EXPORT ThreadRestrictions {
- public:
-
-
-
-
- class BASE_EXPORT ScopedAllowIO {
- public:
- ScopedAllowIO(const Location& from_here = Location::Current());
- ~ScopedAllowIO();
- private:
- #if DCHECK_IS_ON()
- const bool was_allowed_;
- #endif
- DISALLOW_COPY_AND_ASSIGN(ScopedAllowIO);
- };
- #if DCHECK_IS_ON()
-
-
-
-
-
- static bool SetIOAllowed(bool allowed);
-
-
- static bool SetSingletonAllowed(bool allowed);
-
-
- static void AssertSingletonAllowed();
-
-
-
-
- static void DisallowWaiting();
- #else
-
-
- static bool SetIOAllowed(bool allowed) { return true; }
- static bool SetSingletonAllowed(bool allowed) { return true; }
- static void AssertSingletonAllowed() {}
- static void DisallowWaiting() {}
- #endif
- private:
-
-
- friend class content::BrowserMainLoop;
- friend class content::BrowserShutdownProfileDumper;
- friend class content::BrowserTestBase;
- friend class content::ScopedAllowWaitForDebugURL;
- friend class ::HistogramSynchronizer;
- friend class internal::TaskTracker;
- friend class web::WebMainLoop;
- friend class MessagePumpDefault;
- friend class PlatformThread;
- friend class ui::CommandBufferClientImpl;
- friend class ui::CommandBufferLocal;
- friend class ui::GpuState;
-
-
- friend class chrome_browser_net::Predictor;
- #if !defined(OFFICIAL_BUILD)
- friend class content::SoftwareOutputDeviceMus;
- #endif
- #if DCHECK_IS_ON()
-
- static bool SetWaitAllowed(bool allowed);
- #else
- static bool SetWaitAllowed(bool allowed) { return true; }
- #endif
- DISALLOW_IMPLICIT_CONSTRUCTORS(ThreadRestrictions);
- };
- #undef INLINE_IF_DCHECK_IS_OFF
- #undef EMPTY_BODY_IF_DCHECK_IS_OFF
- }
- #endif
|