OLD | NEW |
(Empty) | |
| 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 |
| 3 // found in the LICENSE file. |
| 4 |
| 5 #include "base/lazy_instance.h" |
| 6 #include "base/message_loop/message_loop_proxy_impl.h" |
| 7 #include "base/time/time.h" |
| 8 #include "base/threading/thread_restrictions.h" |
| 9 #include "content/renderer/renderer_high_priority_task_queue.h" |
| 10 |
| 11 #include <stdio.h> |
| 12 |
| 13 namespace content { |
| 14 class RendererHighPriorityTaskQueueImpl { |
| 15 public: |
| 16 RendererHighPriorityTaskQueueImpl(); |
| 17 ~RendererHighPriorityTaskQueueImpl(); |
| 18 |
| 19 void Init(scoped_refptr<base::MessageLoopProxy> proxy); |
| 20 bool PostTask(const tracked_objects::Location& from_here, |
| 21 const base::Closure& task); |
| 22 |
| 23 private: |
| 24 scoped_refptr<base::MessageLoopProxy> high_priority_message_loop_proxy_; |
| 25 }; |
| 26 |
| 27 namespace { |
| 28 base::LazyInstance<RendererHighPriorityTaskQueueImpl>::Leaky g_lazy_instance; |
| 29 } // namespace |
| 30 |
| 31 |
| 32 MessageLoopRendererMainThread::MessageLoopRendererMainThread() { |
| 33 high_priority_incoming_task_queue_ = |
| 34 new base::internal::IncomingTaskQueue(this); |
| 35 high_priority_message_loop_proxy_ = |
| 36 new base::internal::MessageLoopProxyImpl( |
| 37 high_priority_incoming_task_queue_); |
| 38 g_lazy_instance.Get().Init(high_priority_message_loop_proxy_); |
| 39 } |
| 40 |
| 41 void MessageLoopRendererMainThread::ReloadHighPriorityWorkQueue() { |
| 42 if (high_priority_work_queue_.empty()) |
| 43 high_priority_incoming_task_queue_->ReloadWorkQueue( |
| 44 &high_priority_work_queue_); |
| 45 } |
| 46 |
| 47 void MessageLoopRendererMainThread::ReloadAllWorkQueues() { |
| 48 MessageLoop::ReloadAllWorkQueues(); |
| 49 ReloadHighPriorityWorkQueue(); |
| 50 } |
| 51 |
| 52 base::TaskQueue& MessageLoopRendererMainThread::GetNextWorkQueue() { |
| 53 base::TaskQueue& current_task_queue = !high_priority_work_queue_.empty() ? |
| 54 high_priority_work_queue_ : MessageLoop::GetNextWorkQueue(); |
| 55 return current_task_queue; |
| 56 } |
| 57 |
| 58 bool MessageLoopRendererMainThread::HasWorkAvailable() const { |
| 59 return !high_priority_work_queue_.empty() || MessageLoop::HasWorkAvailable(); |
| 60 } |
| 61 |
| 62 |
| 63 RendererHighPriorityTaskQueueImpl::RendererHighPriorityTaskQueueImpl() { |
| 64 } |
| 65 |
| 66 RendererHighPriorityTaskQueueImpl::~RendererHighPriorityTaskQueueImpl() { |
| 67 } |
| 68 |
| 69 void RendererHighPriorityTaskQueueImpl::Init( |
| 70 scoped_refptr<base::MessageLoopProxy> proxy) { |
| 71 high_priority_message_loop_proxy_ = proxy; |
| 72 } |
| 73 |
| 74 bool RendererHighPriorityTaskQueueImpl::PostTask( |
| 75 const tracked_objects::Location& from_here, |
| 76 const base::Closure& task) { |
| 77 return high_priority_message_loop_proxy_->PostTask(from_here, task); |
| 78 } |
| 79 |
| 80 // static |
| 81 bool RendererHighPriorityTaskQueue::PostTask( |
| 82 const tracked_objects::Location& from_here, |
| 83 const base::Closure& task) { |
| 84 return g_lazy_instance.Get().PostTask(from_here, task); |
| 85 } |
| 86 |
| 87 } // namespace content |
OLD | NEW |