kalman | fcece45 | 2015-02-18 18:20:42 | [diff] [blame] | 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 |
| 3 | // found in the LICENSE file. |
| 4 | |
| 5 | #ifndef EXTENSIONS_BROWSER_SERIAL_EXTENSION_HOST_QUEUE_H_ |
| 6 | #define EXTENSIONS_BROWSER_SERIAL_EXTENSION_HOST_QUEUE_H_ |
| 7 | |
| 8 | #include <list> |
| 9 | |
| 10 | #include "base/macros.h" |
| 11 | #include "base/memory/weak_ptr.h" |
| 12 | #include "extensions/browser/extension_host_queue.h" |
| 13 | |
| 14 | namespace extensions { |
| 15 | |
yoz | d61dfe19 | 2015-02-21 01:30:37 | [diff] [blame] | 16 | class DeferredStartRenderHost; |
kalman | fcece45 | 2015-02-18 18:20:42 | [diff] [blame] | 17 | |
yoz | d61dfe19 | 2015-02-21 01:30:37 | [diff] [blame] | 18 | // An ExtensionHostQueue which initializes DeferredStartRenderHosts in the order |
| 19 | // they're Add()ed, with simple rate limiting logic that re-posts each task to |
| 20 | // the UI thread, to avoid clogging it for a long period of time. |
kalman | fcece45 | 2015-02-18 18:20:42 | [diff] [blame] | 21 | class SerialExtensionHostQueue : public ExtensionHostQueue { |
| 22 | public: |
| 23 | SerialExtensionHostQueue(); |
| 24 | ~SerialExtensionHostQueue() override; |
| 25 | |
| 26 | private: |
| 27 | // ExtensionHostQueue: |
yoz | d61dfe19 | 2015-02-21 01:30:37 | [diff] [blame] | 28 | void Add(DeferredStartRenderHost* host) override; |
| 29 | void Remove(DeferredStartRenderHost* host) override; |
kalman | fcece45 | 2015-02-18 18:20:42 | [diff] [blame] | 30 | |
yoz | d61dfe19 | 2015-02-21 01:30:37 | [diff] [blame] | 31 | // Queues up a delayed task to process the next DeferredStartRenderHost in |
| 32 | // the queue. |
kalman | fcece45 | 2015-02-18 18:20:42 | [diff] [blame] | 33 | void PostTask(); |
| 34 | |
| 35 | // Creates the RenderView for the next host in the queue. |
| 36 | void ProcessOneHost(); |
| 37 | |
| 38 | // True if this queue is currently in the process of starting an |
yoz | d61dfe19 | 2015-02-21 01:30:37 | [diff] [blame] | 39 | // DeferredStartRenderHost. |
kalman | fcece45 | 2015-02-18 18:20:42 | [diff] [blame] | 40 | bool pending_create_; |
| 41 | |
yoz | d61dfe19 | 2015-02-21 01:30:37 | [diff] [blame] | 42 | // The list of DeferredStartRenderHosts waiting to be started. |
| 43 | std::list<DeferredStartRenderHost*> queue_; |
kalman | fcece45 | 2015-02-18 18:20:42 | [diff] [blame] | 44 | |
Jeremy Roman | 9fc2de6 | 2019-07-12 14:15:03 | [diff] [blame] | 45 | base::WeakPtrFactory<SerialExtensionHostQueue> ptr_factory_{this}; |
kalman | fcece45 | 2015-02-18 18:20:42 | [diff] [blame] | 46 | |
| 47 | DISALLOW_COPY_AND_ASSIGN(SerialExtensionHostQueue); |
| 48 | }; |
| 49 | |
| 50 | } // namespace extensions |
| 51 | |
| 52 | #endif // EXTENSIONS_BROWSER_SERIAL_EXTENSION_HOST_QUEUE_H_ |