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 #ifndef NDEBUG
     24   DCHECK(main_task_runner_.get());
     25   if (impl_thread_is_overridden_)
     26     return false;
     27   return main_task_runner_->BelongsToCurrentThread();
     28 #else
     29   return true;
     30 #endif
     31 }
     32 
     33 bool Proxy::IsImplThread() const {
     34 #ifndef NDEBUG
     35   if (impl_thread_is_overridden_)
     36     return true;
     37   if (!impl_task_runner_.get())
     38     return false;
     39   return impl_task_runner_->BelongsToCurrentThread();
     40 #else
     41   return true;
     42 #endif
     43 }
     44 
     45 #ifndef NDEBUG
     46 void Proxy::SetCurrentThreadIsImplThread(bool is_impl_thread) {
     47   impl_thread_is_overridden_ = is_impl_thread;
     48 }
     49 #endif
     50 
     51 bool Proxy::IsMainThreadBlocked() const {
     52 #ifndef NDEBUG
     53   return is_main_thread_blocked_;
     54 #else
     55   return true;
     56 #endif
     57 }
     58 
     59 #ifndef NDEBUG
     60 void Proxy::SetMainThreadBlocked(bool is_main_thread_blocked) {
     61   is_main_thread_blocked_ = is_main_thread_blocked;
     62 }
     63 #endif
     64 
     65 Proxy::Proxy(
     66     scoped_refptr<base::SingleThreadTaskRunner> impl_task_runner)
     67     : main_task_runner_(base::MessageLoopProxy::current()),
     68 #ifdef NDEBUG
     69       impl_task_runner_(impl_task_runner) {}
     70 #else
     71       impl_task_runner_(impl_task_runner),
     72       impl_thread_is_overridden_(false),
     73       is_main_thread_blocked_(false) {}
     74 #endif
     75 
     76 Proxy::~Proxy() {
     77   DCHECK(IsMainThread());
     78 }
     79 
     80 std::string Proxy::SchedulerStateAsStringForTesting() {
     81   return "";
     82 }
     83 
     84 }  // namespace cc
     85