summaryrefslogtreecommitdiff
path: root/base/threading/thread_restrictions.h
diff options
context:
space:
mode:
authorLuis Hector Chavez <lhchavez@google.com>2017-07-26 17:33:47 +0000
committerLuis Hector Chavez <lhchavez@google.com>2017-07-26 17:33:47 +0000
commite5b2c6fa6f923f3a2f66346c2f169d9f0fceb3dc (patch)
tree26593cf846dcf61fbaa2d04558e4984333832351 /base/threading/thread_restrictions.h
parent0601274935e7f632eb0d6ce0fd223b744349d20b (diff)
downloadlibchrome-e5b2c6fa6f923f3a2f66346c2f169d9f0fceb3dc.tar.gz
Revert "libchrome: Uprev the library to r456626 from Chromium"android-o-iot-preview-5o-iot-preview-5
This reverts commit 0601274935e7f632eb0d6ce0fd223b744349d20b. Reason for revert: Broke the mac_sdk Exempt-From-Owner-Approval: Fixing mac_sdk Change-Id: I2cab1818261f3b75dcf7dfc3edf6d6b7bab541a8
Diffstat (limited to 'base/threading/thread_restrictions.h')
-rw-r--r--base/threading/thread_restrictions.h39
1 files changed, 27 insertions, 12 deletions
diff --git a/base/threading/thread_restrictions.h b/base/threading/thread_restrictions.h
index a86dd452b8..4212a4b6eb 100644
--- a/base/threading/thread_restrictions.h
+++ b/base/threading/thread_restrictions.h
@@ -6,9 +6,15 @@
#define BASE_THREADING_THREAD_RESTRICTIONS_H_
#include "base/base_export.h"
-#include "base/logging.h"
#include "base/macros.h"
+// See comment at top of thread_checker.h
+#if (!defined(NDEBUG) || defined(DCHECK_ALWAYS_ON))
+#define ENABLE_THREAD_RESTRICTIONS 1
+#else
+#define ENABLE_THREAD_RESTRICTIONS 0
+#endif
+
class BrowserProcessImpl;
class HistogramSynchronizer;
class NativeBackendKWallet;
@@ -51,10 +57,10 @@ namespace gpu {
class GpuChannelHost;
}
namespace mojo {
-class SyncCallRestrictions;
-namespace edk {
-class ScopedIPCSupport;
+namespace common {
+class MessagePumpMojo;
}
+class SyncCallRestrictions;
}
namespace ui {
class CommandBufferClientImpl;
@@ -86,10 +92,6 @@ namespace android {
class JavaHandlerThread;
}
-namespace internal {
-class TaskTracker;
-}
-
class SequencedWorkerPool;
class SimpleThread;
class Thread;
@@ -135,7 +137,21 @@ class BASE_EXPORT ThreadRestrictions {
DISALLOW_COPY_AND_ASSIGN(ScopedAllowIO);
};
-#if DCHECK_IS_ON()
+ // Constructing a ScopedAllowSingleton temporarily allows accessing for the
+ // current thread. Doing this is almost always incorrect.
+ class BASE_EXPORT ScopedAllowSingleton {
+ public:
+ ScopedAllowSingleton() { previous_value_ = SetSingletonAllowed(true); }
+ ~ScopedAllowSingleton() { SetSingletonAllowed(previous_value_); }
+ private:
+ // Whether singleton use is allowed when the ScopedAllowSingleton was
+ // constructed.
+ bool previous_value_;
+
+ DISALLOW_COPY_AND_ASSIGN(ScopedAllowSingleton);
+ };
+
+#if ENABLE_THREAD_RESTRICTIONS
// Set whether the current thread to make IO calls.
// Threads start out in the *allowed* state.
// Returns the previous value.
@@ -181,7 +197,6 @@ class BASE_EXPORT ThreadRestrictions {
friend class content::ScopedAllowWaitForAndroidLayoutTests;
friend class content::ScopedAllowWaitForDebugURL;
friend class ::HistogramSynchronizer;
- friend class internal::TaskTracker;
friend class ::ScopedAllowWaitForLegacyWebViewApi;
friend class cc::CompletionEvent;
friend class cc::SingleThreadTaskGraphRunner;
@@ -195,8 +210,8 @@ class BASE_EXPORT ThreadRestrictions {
friend class ThreadTestHelper;
friend class PlatformThread;
friend class android::JavaHandlerThread;
+ friend class mojo::common::MessagePumpMojo;
friend class mojo::SyncCallRestrictions;
- friend class mojo::edk::ScopedIPCSupport;
friend class ui::CommandBufferClientImpl;
friend class ui::CommandBufferLocal;
friend class ui::GpuState;
@@ -225,7 +240,7 @@ class BASE_EXPORT ThreadRestrictions {
friend class views::ScreenMus;
// END USAGE THAT NEEDS TO BE FIXED.
-#if DCHECK_IS_ON()
+#if ENABLE_THREAD_RESTRICTIONS
static bool SetWaitAllowed(bool allowed);
#else
static bool SetWaitAllowed(bool) { return true; }