Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(418)

Side by Side Diff: extensions/browser/lazy_context_task_queue.h

Issue 2924213002: Draft: Dispatching extension events to stopped extension SW.
Patch Set: rebase @tott Created 3 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « extensions/browser/lazy_context_id.cc ('k') | extensions/browser/service_worker_task_queue.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(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 }
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 struct ContextInfo {
28 const ExtensionId extension_id;
29 content::RenderProcessHost* const render_process_host;
30 const int worker_thread_id;
31 const GURL url;
32 ContextInfo(const ExtensionId& extension_id,
33 content::RenderProcessHost* render_process_host,
34 int worker_thread_id,
35 const GURL& url)
36 : extension_id(extension_id),
37 render_process_host(render_process_host),
38 worker_thread_id(worker_thread_id),
39 url(url) {}
40 };
41 using PendingTask = base::Callback<void(std::unique_ptr<ContextInfo> params)>;
42
43 // Returns true if the task should be added to the queue (that is, if the
44 // extension has a lazy background page or service worker that isn't ready
45 // yet).
46 virtual bool ShouldEnqueueTask(content::BrowserContext* context,
47 const Extension* extension) = 0;
48
49 // Adds a task to the queue for a given extension. If this is the first
50 // task added for the extension, its "lazy context" (i.e. lazy background
51 // page for event pages, service worker for extension service workers) should
52 // be loaded. The task will be called either when the page is loaded,
53 // or when the page fails to load for some reason (e.g. a crash or browser
54 // shutdown). In the latter case, the ContextInfo will be nullptr.
55 //
56 // TODO(lazyboy): Remove "ToDispatchEvent" suffix and simply call this
57 // AddPendingTask. Issues:
58 // 1. We already have LazyBackgroundTaskQueue::AddPendingTask. Moreover, that
59 // is heavily used thoughout the codebase.
60 // 2. LazyBackgroundTaskQueue::AddPendingTask is tied to ExtensionHost. This
61 // class should be ExtensionHost agnostic.
62 virtual void AddPendingTaskToDispatchEvent(LazyContextId* context_id,
63 const PendingTask& task) = 0;
64 };
65
66 } // namespace extensions
67
68 #endif // EXTENSIONS_BROWSER_LAZY_CONTEXT_TASK_QUEUE_H_
OLDNEW
« no previous file with comments | « extensions/browser/lazy_context_id.cc ('k') | extensions/browser/service_worker_task_queue.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698