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/macros.h" | 9 #include "base/macros.h" |
10 | 10 |
(...skipping 162 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
173 | 173 |
174 // Disable waiting on the current thread. Threads start out in the *allowed* | 174 // Disable waiting on the current thread. Threads start out in the *allowed* |
175 // state. Returns the previous value. | 175 // state. Returns the previous value. |
176 static void DisallowWaiting(); | 176 static void DisallowWaiting(); |
177 | 177 |
178 // Check whether the current thread is allowed to wait, and DCHECK if not. | 178 // Check whether the current thread is allowed to wait, and DCHECK if not. |
179 static void AssertWaitAllowed(); | 179 static void AssertWaitAllowed(); |
180 #else | 180 #else |
181 // Inline the empty definitions of these functions so that they can be | 181 // Inline the empty definitions of these functions so that they can be |
182 // compiled out. | 182 // compiled out. |
183 static bool SetIOAllowed(bool allowed) { return true; } | 183 static bool SetIOAllowed(bool) { return true; } |
184 static void AssertIOAllowed() {} | 184 static void AssertIOAllowed() {} |
185 static bool SetSingletonAllowed(bool allowed) { return true; } | 185 static bool SetSingletonAllowed(bool) { return true; } |
186 static void AssertSingletonAllowed() {} | 186 static void AssertSingletonAllowed() {} |
187 static void DisallowWaiting() {} | 187 static void DisallowWaiting() {} |
188 static void AssertWaitAllowed() {} | 188 static void AssertWaitAllowed() {} |
189 #endif | 189 #endif |
190 | 190 |
191 private: | 191 private: |
192 // DO NOT ADD ANY OTHER FRIEND STATEMENTS, talk to jam or brettw first. | 192 // DO NOT ADD ANY OTHER FRIEND STATEMENTS, talk to jam or brettw first. |
193 // BEGIN ALLOWED USAGE. | 193 // BEGIN ALLOWED USAGE. |
194 friend class content::BrowserShutdownProfileDumper; | 194 friend class content::BrowserShutdownProfileDumper; |
195 friend class content::BrowserSurfaceViewManager; | 195 friend class content::BrowserSurfaceViewManager; |
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
236 friend class ::NativeBackendKWallet; // http://crbug.com/125331 | 236 friend class ::NativeBackendKWallet; // http://crbug.com/125331 |
237 #if !defined(OFFICIAL_BUILD) | 237 #if !defined(OFFICIAL_BUILD) |
238 friend class content::SoftwareOutputDeviceMus; // Interim non-production code | 238 friend class content::SoftwareOutputDeviceMus; // Interim non-production code |
239 #endif | 239 #endif |
240 friend class views::ScreenMus; | 240 friend class views::ScreenMus; |
241 // END USAGE THAT NEEDS TO BE FIXED. | 241 // END USAGE THAT NEEDS TO BE FIXED. |
242 | 242 |
243 #if ENABLE_THREAD_RESTRICTIONS | 243 #if ENABLE_THREAD_RESTRICTIONS |
244 static bool SetWaitAllowed(bool allowed); | 244 static bool SetWaitAllowed(bool allowed); |
245 #else | 245 #else |
246 static bool SetWaitAllowed(bool allowed) { return true; } | 246 static bool SetWaitAllowed(bool) { return true; } |
247 #endif | 247 #endif |
248 | 248 |
249 // Constructing a ScopedAllowWait temporarily allows waiting on the current | 249 // Constructing a ScopedAllowWait temporarily allows waiting on the current |
250 // thread. Doing this is almost always incorrect, which is why we limit who | 250 // 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 | 251 // can use this through friend. If you find yourself needing to use this, find |
252 // another way. Talk to jam or brettw. | 252 // another way. Talk to jam or brettw. |
253 class BASE_EXPORT ScopedAllowWait { | 253 class BASE_EXPORT ScopedAllowWait { |
254 public: | 254 public: |
255 ScopedAllowWait() { previous_value_ = SetWaitAllowed(true); } | 255 ScopedAllowWait() { previous_value_ = SetWaitAllowed(true); } |
256 ~ScopedAllowWait() { SetWaitAllowed(previous_value_); } | 256 ~ScopedAllowWait() { SetWaitAllowed(previous_value_); } |
257 private: | 257 private: |
258 // Whether singleton use is allowed when the ScopedAllowWait was | 258 // Whether singleton use is allowed when the ScopedAllowWait was |
259 // constructed. | 259 // constructed. |
260 bool previous_value_; | 260 bool previous_value_; |
261 | 261 |
262 DISALLOW_COPY_AND_ASSIGN(ScopedAllowWait); | 262 DISALLOW_COPY_AND_ASSIGN(ScopedAllowWait); |
263 }; | 263 }; |
264 | 264 |
265 DISALLOW_IMPLICIT_CONSTRUCTORS(ThreadRestrictions); | 265 DISALLOW_IMPLICIT_CONSTRUCTORS(ThreadRestrictions); |
266 }; | 266 }; |
267 | 267 |
268 } // namespace base | 268 } // namespace base |
269 | 269 |
270 #endif // BASE_THREADING_THREAD_RESTRICTIONS_H_ | 270 #endif // BASE_THREADING_THREAD_RESTRICTIONS_H_ |
OLD | NEW |