| OLD | NEW |
| 1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 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 "extensions/browser/serial_extension_host_queue.h" | 5 #include "extensions/browser/serial_extension_host_queue.h" |
| 6 | 6 |
| 7 #include "base/bind.h" | 7 #include "base/bind.h" |
| 8 #include "base/message_loop/message_loop.h" | 8 #include "base/message_loop/message_loop.h" |
| 9 #include "extensions/browser/extension_host.h" | 9 #include "extensions/browser/deferred_start_render_host.h" |
| 10 | 10 |
| 11 namespace extensions { | 11 namespace extensions { |
| 12 | 12 |
| 13 SerialExtensionHostQueue::SerialExtensionHostQueue() | 13 SerialExtensionHostQueue::SerialExtensionHostQueue() |
| 14 : pending_create_(false), ptr_factory_(this) { | 14 : pending_create_(false), ptr_factory_(this) { |
| 15 } | 15 } |
| 16 | 16 |
| 17 SerialExtensionHostQueue::~SerialExtensionHostQueue() { | 17 SerialExtensionHostQueue::~SerialExtensionHostQueue() { |
| 18 } | 18 } |
| 19 | 19 |
| 20 void SerialExtensionHostQueue::Add(ExtensionHost* host) { | 20 void SerialExtensionHostQueue::Add(DeferredStartRenderHost* host) { |
| 21 queue_.push_back(host); | 21 queue_.push_back(host); |
| 22 PostTask(); | 22 PostTask(); |
| 23 } | 23 } |
| 24 | 24 |
| 25 void SerialExtensionHostQueue::Remove(ExtensionHost* host) { | 25 void SerialExtensionHostQueue::Remove(DeferredStartRenderHost* host) { |
| 26 std::list<ExtensionHost*>::iterator it = | 26 std::list<DeferredStartRenderHost*>::iterator it = |
| 27 std::find(queue_.begin(), queue_.end(), host); | 27 std::find(queue_.begin(), queue_.end(), host); |
| 28 if (it != queue_.end()) | 28 if (it != queue_.end()) |
| 29 queue_.erase(it); | 29 queue_.erase(it); |
| 30 } | 30 } |
| 31 | 31 |
| 32 void SerialExtensionHostQueue::PostTask() { | 32 void SerialExtensionHostQueue::PostTask() { |
| 33 if (!pending_create_) { | 33 if (!pending_create_) { |
| 34 base::MessageLoop::current()->PostTask( | 34 base::MessageLoop::current()->PostTask( |
| 35 FROM_HERE, base::Bind(&SerialExtensionHostQueue::ProcessOneHost, | 35 FROM_HERE, base::Bind(&SerialExtensionHostQueue::ProcessOneHost, |
| 36 ptr_factory_.GetWeakPtr())); | 36 ptr_factory_.GetWeakPtr())); |
| 37 pending_create_ = true; | 37 pending_create_ = true; |
| 38 } | 38 } |
| 39 } | 39 } |
| 40 | 40 |
| 41 void SerialExtensionHostQueue::ProcessOneHost() { | 41 void SerialExtensionHostQueue::ProcessOneHost() { |
| 42 pending_create_ = false; | 42 pending_create_ = false; |
| 43 if (queue_.empty()) | 43 if (queue_.empty()) |
| 44 return; // can happen on shutdown | 44 return; // can happen on shutdown |
| 45 | 45 |
| 46 queue_.front()->CreateRenderViewNow(); | 46 queue_.front()->CreateRenderViewNow(); |
| 47 queue_.pop_front(); | 47 queue_.pop_front(); |
| 48 | 48 |
| 49 if (!queue_.empty()) | 49 if (!queue_.empty()) |
| 50 PostTask(); | 50 PostTask(); |
| 51 } | 51 } |
| 52 | 52 |
| 53 } // namespace extensions | 53 } // namespace extensions |
| OLD | NEW |