OLD | NEW |
(Empty) | |
| 1 // Copyright 2014 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 "content/renderer/renderer_message_loop.h" |
| 6 |
| 7 #include "base/message_loop/high_priority_task_runner.h" |
| 8 #include "content/renderer/render_thread_impl.h" |
| 9 |
| 10 namespace content { |
| 11 |
| 12 RendererMessageLoop::RendererMessageLoop() |
| 13 : normal_work_queue_deficit_(0) { |
| 14 high_priority_task_runner_ = new base::HighPriorityTaskRunner(this); |
| 15 } |
| 16 |
| 17 RendererMessageLoop::RendererMessageLoop(scoped_ptr<base::MessagePump> pump) |
| 18 : MessageLoop(pump.Pass()), |
| 19 normal_work_queue_deficit_(0) { |
| 20 high_priority_task_runner_ = new base::HighPriorityTaskRunner(this); |
| 21 } |
| 22 |
| 23 RendererMessageLoop::~RendererMessageLoop() { |
| 24 } |
| 25 |
| 26 void RendererMessageLoop::EnableHighPriorityIncomingTaskQueue() { |
| 27 DCHECK(RenderThreadImpl::current()); |
| 28 DCHECK(!is_running()); |
| 29 |
| 30 RenderThreadImpl::current()->UseHighPriorityTaskRunner( |
| 31 high_priority_task_runner_); |
| 32 } |
| 33 |
| 34 void RendererMessageLoop::ReloadWorkQueue() { |
| 35 MessageLoop::ReloadWorkQueue(); |
| 36 if (high_priority_work_queue_.empty()) |
| 37 high_priority_task_runner_->ReloadWorkQueue(&high_priority_work_queue_); |
| 38 } |
| 39 |
| 40 base::TaskQueue& RendererMessageLoop::SelectNextWorkQueue() { |
| 41 // TODO(bashi): Need to be tuned. |
| 42 static const int kMaxDeficit = 1000; |
| 43 if (!high_priority_work_queue_.empty() && |
| 44 normal_work_queue_deficit_ <= kMaxDeficit) { |
| 45 ++normal_work_queue_deficit_; |
| 46 return high_priority_work_queue_; |
| 47 } |
| 48 |
| 49 normal_work_queue_deficit_ = 0; |
| 50 return MessageLoop::SelectNextWorkQueue(); |
| 51 } |
| 52 |
| 53 } // namespace content |
OLD | NEW |