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 #include "config.h" | 5 #include "config.h" |
6 | 6 |
7 #include "cc/scoped_thread_proxy.h" | 7 #include "cc/scoped_thread_proxy.h" |
8 | 8 |
| 9 #include "base/bind.h" |
| 10 |
9 namespace cc { | 11 namespace cc { |
10 | 12 |
11 ScopedThreadProxy::ScopedThreadProxy(Thread* targetThread) | 13 ScopedThreadProxy::ScopedThreadProxy(cc::Thread* targetThread) |
12 : m_targetThread(targetThread) | 14 : m_targetThread(targetThread) |
13 , m_shutdown(false) | 15 , m_shutdown(false) |
14 { | 16 { |
15 } | 17 } |
16 | 18 |
17 ScopedThreadProxy::~ScopedThreadProxy() | 19 ScopedThreadProxy::~ScopedThreadProxy() |
18 { | 20 { |
19 } | 21 } |
20 | 22 |
| 23 void ScopedThreadProxy::postTask(const tracked_objects::Location& location, base
::Closure cb) |
| 24 { |
| 25 m_targetThread->postTask(base::Bind(&ScopedThreadProxy::runTaskIfNotShutdown
, this, cb)); |
21 } | 26 } |
| 27 |
| 28 void ScopedThreadProxy::shutdown() |
| 29 { |
| 30 DCHECK(m_targetThread->belongsToCurrentThread()); |
| 31 DCHECK(!m_shutdown); |
| 32 m_shutdown = true; |
| 33 } |
| 34 |
| 35 void ScopedThreadProxy::runTaskIfNotShutdown(base::Closure cb) |
| 36 { |
| 37 // If our shutdown flag is set, it's possible that m_targetThread has alread
y been destroyed so don't |
| 38 // touch it. |
| 39 if (m_shutdown) { |
| 40 return; |
| 41 } |
| 42 DCHECK(m_targetThread->belongsToCurrentThread()); |
| 43 cb.Run(); |
| 44 } |
| 45 |
| 46 } |
OLD | NEW |