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