Chromium Code Reviews| OLD | NEW |
|---|---|
| (Empty) | |
| 1 // Copyright 2017 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_LAZY_CONTEXT_TASK_QUEUE_H_ | |
| 6 #define EXTENSIONS_BROWSER_LAZY_CONTEXT_TASK_QUEUE_H_ | |
| 7 | |
| 8 #include "extensions/common/extension_id.h" | |
| 9 #include "url/gurl.h" | |
| 10 | |
| 11 namespace content { | |
| 12 class BrowserContext; | |
| 13 class RenderProcessHost; | |
| 14 } // namespace content | |
| 15 | |
| 16 namespace extensions { | |
| 17 class Extension; | |
| 18 class LazyContextId; | |
| 19 | |
| 20 // Interface for performing tasks after loading lazy contexts of an extension. | |
| 21 // | |
| 22 // Lazy contexts are non-persistent, so they can unload any time and this | |
| 23 // interface exposes an async mechanism to perform tasks after loading the | |
| 24 // context. | |
| 25 class LazyContextTaskQueue { | |
| 26 public: | |
| 27 // Represents information about an extension lazy context, which is passed to | |
| 28 // consumers that add tasks to LazyContextTaskQueue. | |
| 29 struct ContextInfo { | |
| 30 const ExtensionId extension_id; | |
| 31 content::RenderProcessHost* const render_process_host; | |
| 32 const int worker_thread_id; | |
| 33 const GURL url; | |
| 34 ContextInfo(const ExtensionId& extension_id, | |
| 35 content::RenderProcessHost* render_process_host, | |
| 36 int worker_thread_id, | |
| 37 const GURL& url) | |
| 38 : extension_id(extension_id), | |
| 39 render_process_host(render_process_host), | |
| 40 worker_thread_id(worker_thread_id), | |
| 41 url(url) {} | |
| 42 }; | |
| 43 using PendingTask = base::Callback<void(std::unique_ptr<ContextInfo> params)>; | |
|
Devlin
2017/06/20 20:31:20
iwyu callback
lazyboy
2017/06/22 02:46:56
Done.
| |
| 44 | |
| 45 // Returns true if the task should be added to the queue (that is, if the | |
| 46 // extension has a lazy background page or service worker that isn't ready | |
| 47 // yet). | |
| 48 virtual bool ShouldEnqueueTask(content::BrowserContext* context, | |
| 49 const Extension* extension) = 0; | |
| 50 | |
| 51 // Adds a task to the queue for a given extension. If this is the first | |
| 52 // task added for the extension, its "lazy context" (i.e. lazy background | |
| 53 // page for event pages, service worker for extension service workers) should | |
|
Devlin
2017/06/20 20:31:20
s/should be loaded/will be loaded?
lazyboy
2017/06/22 02:46:56
Done.
| |
| 54 // be loaded. The task will be called either when the page is loaded, | |
| 55 // or when the page fails to load for some reason (e.g. a crash or browser | |
| 56 // shutdown). In the latter case, the ContextInfo will be nullptr. | |
| 57 // | |
| 58 // TODO(lazyboy): Remove "ToDispatchEvent" suffix and simply call this | |
| 59 // AddPendingTask. Issues: | |
| 60 // 1. We already have LazyBackgroundTaskQueue::AddPendingTask. Moreover, that | |
| 61 // is heavily used thoughout the codebase. | |
| 62 // 2. LazyBackgroundTaskQueue::AddPendingTask is tied to ExtensionHost. This | |
| 63 // class should be ExtensionHost agnostic. | |
| 64 virtual void AddPendingTaskToDispatchEvent(LazyContextId* context_id, | |
| 65 const PendingTask& task) = 0; | |
| 66 }; | |
| 67 | |
| 68 } // namespace extensions | |
| 69 | |
| 70 #endif // EXTENSIONS_BROWSER_LAZY_CONTEXT_TASK_QUEUE_H_ | |
| OLD | NEW |