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/basictypes.h" | 9 #include "base/basictypes.h" |
10 | 10 |
(...skipping 102 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
113 ScopedAllowSingleton() { previous_value_ = SetSingletonAllowed(true); } | 113 ScopedAllowSingleton() { previous_value_ = SetSingletonAllowed(true); } |
114 ~ScopedAllowSingleton() { SetSingletonAllowed(previous_value_); } | 114 ~ScopedAllowSingleton() { SetSingletonAllowed(previous_value_); } |
115 private: | 115 private: |
116 // Whether singleton use is allowed when the ScopedAllowSingleton was | 116 // Whether singleton use is allowed when the ScopedAllowSingleton was |
117 // constructed. | 117 // constructed. |
118 bool previous_value_; | 118 bool previous_value_; |
119 | 119 |
120 DISALLOW_COPY_AND_ASSIGN(ScopedAllowSingleton); | 120 DISALLOW_COPY_AND_ASSIGN(ScopedAllowSingleton); |
121 }; | 121 }; |
122 | 122 |
123 #if defined(ENABLE_THREAD_RESTRICTIONS) | 123 #if ENABLE_THREAD_RESTRICTIONS |
124 // Set whether the current thread to make IO calls. | 124 // Set whether the current thread to make IO calls. |
125 // Threads start out in the *allowed* state. | 125 // Threads start out in the *allowed* state. |
126 // Returns the previous value. | 126 // Returns the previous value. |
127 static bool SetIOAllowed(bool allowed); | 127 static bool SetIOAllowed(bool allowed); |
128 | 128 |
129 // Check whether the current thread is allowed to make IO calls, | 129 // Check whether the current thread is allowed to make IO calls, |
130 // and DCHECK if not. See the block comment above the class for | 130 // and DCHECK if not. See the block comment above the class for |
131 // a discussion of where to add these checks. | 131 // a discussion of where to add these checks. |
132 static void AssertIOAllowed(); | 132 static void AssertIOAllowed(); |
133 | 133 |
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
185 friend class net::FileStreamWin; // http://crbug.com/115067 | 185 friend class net::FileStreamWin; // http://crbug.com/115067 |
186 friend class net::NetworkManagerApi; // http://crbug.com/125097 | 186 friend class net::NetworkManagerApi; // http://crbug.com/125097 |
187 friend class ::AcceleratedPresenter; // http://crbug.com/125391 | 187 friend class ::AcceleratedPresenter; // http://crbug.com/125391 |
188 friend class ::BrowserProcessImpl; // http://crbug.com/125207 | 188 friend class ::BrowserProcessImpl; // http://crbug.com/125207 |
189 friend class ::GpuChannelHost; // http://crbug.com/125264 | 189 friend class ::GpuChannelHost; // http://crbug.com/125264 |
190 friend class ::MetricsService; // http://crbug.com/124954 | 190 friend class ::MetricsService; // http://crbug.com/124954 |
191 friend class ::TextInputClientMac; // http://crbug.com/121917 | 191 friend class ::TextInputClientMac; // http://crbug.com/121917 |
192 friend class ::NativeBackendKWallet; // http://crbug.com/125331 | 192 friend class ::NativeBackendKWallet; // http://crbug.com/125331 |
193 // END USAGE THAT NEEDS TO BE FIXED. | 193 // END USAGE THAT NEEDS TO BE FIXED. |
194 | 194 |
195 #if defined(ENABLE_THREAD_RESTRICTIONS) | 195 #if ENABLE_THREAD_RESTRICTIONS |
196 static bool SetWaitAllowed(bool allowed); | 196 static bool SetWaitAllowed(bool allowed); |
197 #else | 197 #else |
198 static bool SetWaitAllowed(bool allowed) { return true; } | 198 static bool SetWaitAllowed(bool allowed) { return true; } |
199 #endif | 199 #endif |
200 | 200 |
201 // Constructing a ScopedAllowWait temporarily allows waiting on the current | 201 // Constructing a ScopedAllowWait temporarily allows waiting on the current |
202 // thread. Doing this is almost always incorrect, which is why we limit who | 202 // thread. Doing this is almost always incorrect, which is why we limit who |
203 // can use this through friend. If you find yourself needing to use this, find | 203 // can use this through friend. If you find yourself needing to use this, find |
204 // another way. Talk to jam or brettw. | 204 // another way. Talk to jam or brettw. |
205 class BASE_EXPORT ScopedAllowWait { | 205 class BASE_EXPORT ScopedAllowWait { |
206 public: | 206 public: |
207 ScopedAllowWait() { previous_value_ = SetWaitAllowed(true); } | 207 ScopedAllowWait() { previous_value_ = SetWaitAllowed(true); } |
208 ~ScopedAllowWait() { SetWaitAllowed(previous_value_); } | 208 ~ScopedAllowWait() { SetWaitAllowed(previous_value_); } |
209 private: | 209 private: |
210 // Whether singleton use is allowed when the ScopedAllowWait was | 210 // Whether singleton use is allowed when the ScopedAllowWait was |
211 // constructed. | 211 // constructed. |
212 bool previous_value_; | 212 bool previous_value_; |
213 | 213 |
214 DISALLOW_COPY_AND_ASSIGN(ScopedAllowWait); | 214 DISALLOW_COPY_AND_ASSIGN(ScopedAllowWait); |
215 }; | 215 }; |
216 | 216 |
217 DISALLOW_IMPLICIT_CONSTRUCTORS(ThreadRestrictions); | 217 DISALLOW_IMPLICIT_CONSTRUCTORS(ThreadRestrictions); |
218 }; | 218 }; |
219 | 219 |
Ryan Sleevi
2012/06/26 19:18:31
missing #undef
jam
2012/06/26 19:32:51
they're all matched...
Ryan Sleevi
2012/06/26 20:26:14
not #endif, #undef.
You #define ENABLE_THREAD_RES
jabdelmalek
2012/06/26 20:28:56
ah, I misunderstood.
apart from being harmless, i
| |
220 } // namespace base | 220 } // namespace base |
221 | 221 |
222 #endif // BASE_THREADING_THREAD_RESTRICTIONS_H_ | 222 #endif // BASE_THREADING_THREAD_RESTRICTIONS_H_ |
OLD | NEW |