Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(64)

Side by Side Diff: base/threading/thread_restrictions.h

Issue 2536803002: Remove ThreadRestrictions::ScopedAllowSingleton. (Closed)
Patch Set: Created 4 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « no previous file | ios/web/web_thread_impl.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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/logging.h"
10 #include "base/macros.h" 10 #include "base/macros.h"
(...skipping 117 matching lines...) Expand 10 before | Expand all | Expand 10 after
128 public: 128 public:
129 ScopedAllowIO() { previous_value_ = SetIOAllowed(true); } 129 ScopedAllowIO() { previous_value_ = SetIOAllowed(true); }
130 ~ScopedAllowIO() { SetIOAllowed(previous_value_); } 130 ~ScopedAllowIO() { SetIOAllowed(previous_value_); }
131 private: 131 private:
132 // Whether IO is allowed when the ScopedAllowIO was constructed. 132 // Whether IO is allowed when the ScopedAllowIO was constructed.
133 bool previous_value_; 133 bool previous_value_;
134 134
135 DISALLOW_COPY_AND_ASSIGN(ScopedAllowIO); 135 DISALLOW_COPY_AND_ASSIGN(ScopedAllowIO);
136 }; 136 };
137 137
138 // Constructing a ScopedAllowSingleton temporarily allows accessing for the
139 // current thread. Doing this is almost always incorrect.
140 class BASE_EXPORT ScopedAllowSingleton {
141 public:
142 ScopedAllowSingleton() { previous_value_ = SetSingletonAllowed(true); }
143 ~ScopedAllowSingleton() { SetSingletonAllowed(previous_value_); }
144 private:
145 // Whether singleton use is allowed when the ScopedAllowSingleton was
146 // constructed.
147 bool previous_value_;
148
149 DISALLOW_COPY_AND_ASSIGN(ScopedAllowSingleton);
150 };
151
152 #if DCHECK_IS_ON() 138 #if DCHECK_IS_ON()
153 // Set whether the current thread to make IO calls. 139 // Set whether the current thread to make IO calls.
154 // Threads start out in the *allowed* state. 140 // Threads start out in the *allowed* state.
155 // Returns the previous value. 141 // Returns the previous value.
156 static bool SetIOAllowed(bool allowed); 142 static bool SetIOAllowed(bool allowed);
157 143
158 // Check whether the current thread is allowed to make IO calls, 144 // Check whether the current thread is allowed to make IO calls,
159 // and DCHECK if not. See the block comment above the class for 145 // and DCHECK if not. See the block comment above the class for
160 // a discussion of where to add these checks. 146 // a discussion of where to add these checks.
161 static void AssertIOAllowed(); 147 static void AssertIOAllowed();
(...skipping 98 matching lines...) Expand 10 before | Expand all | Expand 10 after
260 246
261 DISALLOW_COPY_AND_ASSIGN(ScopedAllowWait); 247 DISALLOW_COPY_AND_ASSIGN(ScopedAllowWait);
262 }; 248 };
263 249
264 DISALLOW_IMPLICIT_CONSTRUCTORS(ThreadRestrictions); 250 DISALLOW_IMPLICIT_CONSTRUCTORS(ThreadRestrictions);
265 }; 251 };
266 252
267 } // namespace base 253 } // namespace base
268 254
269 #endif // BASE_THREADING_THREAD_RESTRICTIONS_H_ 255 #endif // BASE_THREADING_THREAD_RESTRICTIONS_H_
OLDNEW
« no previous file with comments | « no previous file | ios/web/web_thread_impl.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698