Home | History | Annotate | Download | only in trees
      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
      3 // found in the LICENSE file.
      4 
      5 #include "cc/trees/proxy.h"
      6 
      7 #include "base/message_loop/message_loop_proxy.h"
      8 #include "base/single_thread_task_runner.h"
      9 
     10 namespace cc {
     11 
     12 base::SingleThreadTaskRunner* Proxy::MainThreadTaskRunner() const {
     13   return main_task_runner_.get();
     14 }
     15 
     16 bool Proxy::HasImplThread() const { return !!impl_task_runner_.get(); }
     17 
     18 base::SingleThreadTaskRunner* Proxy::ImplThreadTaskRunner() const {
     19   return impl_task_runner_.get();
     20 }
     21 
     22 bool Proxy::IsMainThread() const {
     23 #if DCHECK_IS_ON
     24   if (impl_thread_is_overridden_)
     25     return false;
     26 
     27   bool is_main_thread = base::PlatformThread::CurrentId() == main_thread_id_;
     28   if (is_main_thread && main_task_runner_.get()) {
     29     DCHECK(main_task_runner_->BelongsToCurrentThread());
     30   }
     31   return is_main_thread;
     32 #else
     33   return true;
     34 #endif
     35 }
     36 
     37 bool Proxy::IsImplThread() const {
     38 #if DCHECK_IS_ON
     39   if (impl_thread_is_overridden_)
     40     return true;
     41   if (!impl_task_runner_.get())
     42     return false;
     43   return impl_task_runner_->BelongsToCurrentThread();
     44 #else
     45   return true;
     46 #endif
     47 }
     48 
     49 #if DCHECK_IS_ON
     50 void Proxy::SetCurrentThreadIsImplThread(bool is_impl_thread) {
     51   impl_thread_is_overridden_ = is_impl_thread;
     52 }
     53 #endif
     54 
     55 bool Proxy::IsMainThreadBlocked() const {
     56 #if DCHECK_IS_ON
     57   return is_main_thread_blocked_;
     58 #else
     59   return true;
     60 #endif
     61 }
     62 
     63 #if DCHECK_IS_ON
     64 void Proxy::SetMainThreadBlocked(bool is_main_thread_blocked) {
     65   is_main_thread_blocked_ = is_main_thread_blocked;
     66 }
     67 #endif
     68 
     69 Proxy::Proxy(scoped_refptr<base::SingleThreadTaskRunner> impl_task_runner)
     70     : main_task_runner_(base::MessageLoopProxy::current()),
     71 #if !DCHECK_IS_ON
     72       impl_task_runner_(impl_task_runner) {
     73 #else
     74       impl_task_runner_(impl_task_runner),
     75       main_thread_id_(base::PlatformThread::CurrentId()),
     76       impl_thread_is_overridden_(false),
     77       is_main_thread_blocked_(false) {
     78 #endif
     79 }
     80 
     81 Proxy::~Proxy() {
     82   DCHECK(IsMainThread());
     83 }
     84 
     85 scoped_ptr<base::Value> Proxy::SchedulerAsValueForTesting() {
     86   return make_scoped_ptr(base::Value::CreateNullValue());
     87 }
     88 
     89 }  // namespace cc
     90