| OLD | NEW |
| 1 // Copyright 2011 The Chromium Authors. All rights reserved. | 1 // Copyright 2011 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 CC_TREES_SINGLE_THREAD_PROXY_H_ | 5 #ifndef CC_TREES_SINGLE_THREAD_PROXY_H_ |
| 6 #define CC_TREES_SINGLE_THREAD_PROXY_H_ | 6 #define CC_TREES_SINGLE_THREAD_PROXY_H_ |
| 7 | 7 |
| 8 #include <limits> | 8 #include <limits> |
| 9 | 9 |
| 10 #include "base/cancelable_callback.h" | 10 #include "base/cancelable_callback.h" |
| (...skipping 157 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 168 | 168 |
| 169 base::WeakPtrFactory<SingleThreadProxy> weak_factory_; | 169 base::WeakPtrFactory<SingleThreadProxy> weak_factory_; |
| 170 | 170 |
| 171 DISALLOW_COPY_AND_ASSIGN(SingleThreadProxy); | 171 DISALLOW_COPY_AND_ASSIGN(SingleThreadProxy); |
| 172 }; | 172 }; |
| 173 | 173 |
| 174 // For use in the single-threaded case. In debug builds, it pretends that the | 174 // For use in the single-threaded case. In debug builds, it pretends that the |
| 175 // code is running on the impl thread to satisfy assertion checks. | 175 // code is running on the impl thread to satisfy assertion checks. |
| 176 class DebugScopedSetImplThread { | 176 class DebugScopedSetImplThread { |
| 177 public: | 177 public: |
| 178 #if DCHECK_IS_ON() |
| 178 explicit DebugScopedSetImplThread(TaskRunnerProvider* task_runner_provider) | 179 explicit DebugScopedSetImplThread(TaskRunnerProvider* task_runner_provider) |
| 179 : task_runner_provider_(task_runner_provider) { | 180 : task_runner_provider_(task_runner_provider) { |
| 180 #if DCHECK_IS_ON() | |
| 181 previous_value_ = task_runner_provider_->impl_thread_is_overridden_; | 181 previous_value_ = task_runner_provider_->impl_thread_is_overridden_; |
| 182 task_runner_provider_->SetCurrentThreadIsImplThread(true); | 182 task_runner_provider_->SetCurrentThreadIsImplThread(true); |
| 183 } |
| 184 #else |
| 185 explicit DebugScopedSetImplThread(TaskRunnerProvider* task_runner_provider) {} |
| 183 #endif | 186 #endif |
| 184 } | 187 |
| 185 ~DebugScopedSetImplThread() { | 188 ~DebugScopedSetImplThread() { |
| 186 #if DCHECK_IS_ON() | 189 #if DCHECK_IS_ON() |
| 187 task_runner_provider_->SetCurrentThreadIsImplThread(previous_value_); | 190 task_runner_provider_->SetCurrentThreadIsImplThread(previous_value_); |
| 188 #endif | 191 #endif |
| 189 } | 192 } |
| 190 | 193 |
| 191 private: | 194 private: |
| 195 #if DCHECK_IS_ON() |
| 192 bool previous_value_; | 196 bool previous_value_; |
| 193 TaskRunnerProvider* task_runner_provider_; | 197 TaskRunnerProvider* task_runner_provider_; |
| 198 #endif |
| 194 | 199 |
| 195 DISALLOW_COPY_AND_ASSIGN(DebugScopedSetImplThread); | 200 DISALLOW_COPY_AND_ASSIGN(DebugScopedSetImplThread); |
| 196 }; | 201 }; |
| 197 | 202 |
| 198 // For use in the single-threaded case. In debug builds, it pretends that the | 203 // For use in the single-threaded case. In debug builds, it pretends that the |
| 199 // code is running on the main thread to satisfy assertion checks. | 204 // code is running on the main thread to satisfy assertion checks. |
| 200 class DebugScopedSetMainThread { | 205 class DebugScopedSetMainThread { |
| 201 public: | 206 public: |
| 207 #if DCHECK_IS_ON() |
| 202 explicit DebugScopedSetMainThread(TaskRunnerProvider* task_runner_provider) | 208 explicit DebugScopedSetMainThread(TaskRunnerProvider* task_runner_provider) |
| 203 : task_runner_provider_(task_runner_provider) { | 209 : task_runner_provider_(task_runner_provider) { |
| 204 #if DCHECK_IS_ON() | |
| 205 previous_value_ = task_runner_provider_->impl_thread_is_overridden_; | 210 previous_value_ = task_runner_provider_->impl_thread_is_overridden_; |
| 206 task_runner_provider_->SetCurrentThreadIsImplThread(false); | 211 task_runner_provider_->SetCurrentThreadIsImplThread(false); |
| 212 } |
| 213 #else |
| 214 explicit DebugScopedSetMainThread(TaskRunnerProvider* task_runner_provider) {} |
| 207 #endif | 215 #endif |
| 208 } | 216 |
| 209 ~DebugScopedSetMainThread() { | 217 ~DebugScopedSetMainThread() { |
| 210 #if DCHECK_IS_ON() | 218 #if DCHECK_IS_ON() |
| 211 task_runner_provider_->SetCurrentThreadIsImplThread(previous_value_); | 219 task_runner_provider_->SetCurrentThreadIsImplThread(previous_value_); |
| 212 #endif | 220 #endif |
| 213 } | 221 } |
| 214 | 222 |
| 215 private: | 223 private: |
| 224 #if DCHECK_IS_ON() |
| 216 bool previous_value_; | 225 bool previous_value_; |
| 217 TaskRunnerProvider* task_runner_provider_; | 226 TaskRunnerProvider* task_runner_provider_; |
| 227 #endif |
| 218 | 228 |
| 219 DISALLOW_COPY_AND_ASSIGN(DebugScopedSetMainThread); | 229 DISALLOW_COPY_AND_ASSIGN(DebugScopedSetMainThread); |
| 220 }; | 230 }; |
| 221 | 231 |
| 222 // For use in the single-threaded case. In debug builds, it pretends that the | 232 // For use in the single-threaded case. In debug builds, it pretends that the |
| 223 // code is running on the impl thread and that the main thread is blocked to | 233 // code is running on the impl thread and that the main thread is blocked to |
| 224 // satisfy assertion checks | 234 // satisfy assertion checks |
| 225 class DebugScopedSetImplThreadAndMainThreadBlocked { | 235 class DebugScopedSetImplThreadAndMainThreadBlocked { |
| 226 public: | 236 public: |
| 227 explicit DebugScopedSetImplThreadAndMainThreadBlocked( | 237 explicit DebugScopedSetImplThreadAndMainThreadBlocked( |
| 228 TaskRunnerProvider* task_runner_provider) | 238 TaskRunnerProvider* task_runner_provider) |
| 229 : impl_thread_(task_runner_provider), | 239 : impl_thread_(task_runner_provider), |
| 230 main_thread_blocked_(task_runner_provider) {} | 240 main_thread_blocked_(task_runner_provider) {} |
| 231 | 241 |
| 232 private: | 242 private: |
| 233 DebugScopedSetImplThread impl_thread_; | 243 DebugScopedSetImplThread impl_thread_; |
| 234 DebugScopedSetMainThreadBlocked main_thread_blocked_; | 244 DebugScopedSetMainThreadBlocked main_thread_blocked_; |
| 235 | 245 |
| 236 DISALLOW_COPY_AND_ASSIGN(DebugScopedSetImplThreadAndMainThreadBlocked); | 246 DISALLOW_COPY_AND_ASSIGN(DebugScopedSetImplThreadAndMainThreadBlocked); |
| 237 }; | 247 }; |
| 238 | 248 |
| 239 } // namespace cc | 249 } // namespace cc |
| 240 | 250 |
| 241 #endif // CC_TREES_SINGLE_THREAD_PROXY_H_ | 251 #endif // CC_TREES_SINGLE_THREAD_PROXY_H_ |
| OLD | NEW |