| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #ifndef BASE_THREADING_THREAD_RESTRICTIONS_H_ | 5 #ifndef BASE_THREADING_THREAD_RESTRICTIONS_H_ |
| 6 #define BASE_THREADING_THREAD_RESTRICTIONS_H_ | 6 #define BASE_THREADING_THREAD_RESTRICTIONS_H_ |
| 7 | 7 |
| 8 #include "base/base_export.h" | 8 #include "base/base_export.h" |
| 9 #include "base/logging.h" |
| 9 #include "base/macros.h" | 10 #include "base/macros.h" |
| 10 | 11 |
| 11 // See comment at top of thread_checker.h | |
| 12 #if (!defined(NDEBUG) || defined(DCHECK_ALWAYS_ON)) | |
| 13 #define ENABLE_THREAD_RESTRICTIONS 1 | |
| 14 #else | |
| 15 #define ENABLE_THREAD_RESTRICTIONS 0 | |
| 16 #endif | |
| 17 | |
| 18 class BrowserProcessImpl; | 12 class BrowserProcessImpl; |
| 19 class HistogramSynchronizer; | 13 class HistogramSynchronizer; |
| 20 class NativeBackendKWallet; | 14 class NativeBackendKWallet; |
| 21 class ScopedAllowWaitForLegacyWebViewApi; | 15 class ScopedAllowWaitForLegacyWebViewApi; |
| 22 | 16 |
| 23 namespace cc { | 17 namespace cc { |
| 24 class CompletionEvent; | 18 class CompletionEvent; |
| 25 class SingleThreadTaskGraphRunner; | 19 class SingleThreadTaskGraphRunner; |
| 26 } | 20 } |
| 27 namespace chromeos { | 21 namespace chromeos { |
| (...skipping 116 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 144 ScopedAllowSingleton() { previous_value_ = SetSingletonAllowed(true); } | 138 ScopedAllowSingleton() { previous_value_ = SetSingletonAllowed(true); } |
| 145 ~ScopedAllowSingleton() { SetSingletonAllowed(previous_value_); } | 139 ~ScopedAllowSingleton() { SetSingletonAllowed(previous_value_); } |
| 146 private: | 140 private: |
| 147 // Whether singleton use is allowed when the ScopedAllowSingleton was | 141 // Whether singleton use is allowed when the ScopedAllowSingleton was |
| 148 // constructed. | 142 // constructed. |
| 149 bool previous_value_; | 143 bool previous_value_; |
| 150 | 144 |
| 151 DISALLOW_COPY_AND_ASSIGN(ScopedAllowSingleton); | 145 DISALLOW_COPY_AND_ASSIGN(ScopedAllowSingleton); |
| 152 }; | 146 }; |
| 153 | 147 |
| 154 #if ENABLE_THREAD_RESTRICTIONS | 148 #if DCHECK_IS_ON() |
| 155 // Set whether the current thread to make IO calls. | 149 // Set whether the current thread to make IO calls. |
| 156 // Threads start out in the *allowed* state. | 150 // Threads start out in the *allowed* state. |
| 157 // Returns the previous value. | 151 // Returns the previous value. |
| 158 static bool SetIOAllowed(bool allowed); | 152 static bool SetIOAllowed(bool allowed); |
| 159 | 153 |
| 160 // Check whether the current thread is allowed to make IO calls, | 154 // Check whether the current thread is allowed to make IO calls, |
| 161 // and DCHECK if not. See the block comment above the class for | 155 // and DCHECK if not. See the block comment above the class for |
| 162 // a discussion of where to add these checks. | 156 // a discussion of where to add these checks. |
| 163 static void AssertIOAllowed(); | 157 static void AssertIOAllowed(); |
| 164 | 158 |
| (...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 233 friend class net::internal::AddressTrackerLinux; // http://crbug.com/125097 | 227 friend class net::internal::AddressTrackerLinux; // http://crbug.com/125097 |
| 234 friend class net::NetworkChangeNotifierMac; // http://crbug.com/125097 | 228 friend class net::NetworkChangeNotifierMac; // http://crbug.com/125097 |
| 235 friend class ::BrowserProcessImpl; // http://crbug.com/125207 | 229 friend class ::BrowserProcessImpl; // http://crbug.com/125207 |
| 236 friend class ::NativeBackendKWallet; // http://crbug.com/125331 | 230 friend class ::NativeBackendKWallet; // http://crbug.com/125331 |
| 237 #if !defined(OFFICIAL_BUILD) | 231 #if !defined(OFFICIAL_BUILD) |
| 238 friend class content::SoftwareOutputDeviceMus; // Interim non-production code | 232 friend class content::SoftwareOutputDeviceMus; // Interim non-production code |
| 239 #endif | 233 #endif |
| 240 friend class views::ScreenMus; | 234 friend class views::ScreenMus; |
| 241 // END USAGE THAT NEEDS TO BE FIXED. | 235 // END USAGE THAT NEEDS TO BE FIXED. |
| 242 | 236 |
| 243 #if ENABLE_THREAD_RESTRICTIONS | 237 #if DCHECK_IS_ON() |
| 244 static bool SetWaitAllowed(bool allowed); | 238 static bool SetWaitAllowed(bool allowed); |
| 245 #else | 239 #else |
| 246 static bool SetWaitAllowed(bool allowed) { return true; } | 240 static bool SetWaitAllowed(bool allowed) { return true; } |
| 247 #endif | 241 #endif |
| 248 | 242 |
| 249 // Constructing a ScopedAllowWait temporarily allows waiting on the current | 243 // Constructing a ScopedAllowWait temporarily allows waiting on the current |
| 250 // thread. Doing this is almost always incorrect, which is why we limit who | 244 // thread. Doing this is almost always incorrect, which is why we limit who |
| 251 // can use this through friend. If you find yourself needing to use this, find | 245 // can use this through friend. If you find yourself needing to use this, find |
| 252 // another way. Talk to jam or brettw. | 246 // another way. Talk to jam or brettw. |
| 253 class BASE_EXPORT ScopedAllowWait { | 247 class BASE_EXPORT ScopedAllowWait { |
| 254 public: | 248 public: |
| 255 ScopedAllowWait() { previous_value_ = SetWaitAllowed(true); } | 249 ScopedAllowWait() { previous_value_ = SetWaitAllowed(true); } |
| 256 ~ScopedAllowWait() { SetWaitAllowed(previous_value_); } | 250 ~ScopedAllowWait() { SetWaitAllowed(previous_value_); } |
| 257 private: | 251 private: |
| 258 // Whether singleton use is allowed when the ScopedAllowWait was | 252 // Whether singleton use is allowed when the ScopedAllowWait was |
| 259 // constructed. | 253 // constructed. |
| 260 bool previous_value_; | 254 bool previous_value_; |
| 261 | 255 |
| 262 DISALLOW_COPY_AND_ASSIGN(ScopedAllowWait); | 256 DISALLOW_COPY_AND_ASSIGN(ScopedAllowWait); |
| 263 }; | 257 }; |
| 264 | 258 |
| 265 DISALLOW_IMPLICIT_CONSTRUCTORS(ThreadRestrictions); | 259 DISALLOW_IMPLICIT_CONSTRUCTORS(ThreadRestrictions); |
| 266 }; | 260 }; |
| 267 | 261 |
| 268 } // namespace base | 262 } // namespace base |
| 269 | 263 |
| 270 #endif // BASE_THREADING_THREAD_RESTRICTIONS_H_ | 264 #endif // BASE_THREADING_THREAD_RESTRICTIONS_H_ |
| OLD | NEW |