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

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

Issue 2943583002: [extension SW] Support lazy events from extension service workers. (Closed)
Patch Set: sync @tott Created 3 years, 5 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
OLDNEW
1 // Copyright 2013 The Chromium Authors. All rights reserved. 1 // Copyright 2013 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 #ifndef EXTENSIONS_BROWSER_LAZY_BACKGROUND_TASK_QUEUE_H_ 5 #ifndef EXTENSIONS_BROWSER_LAZY_BACKGROUND_TASK_QUEUE_H_
6 #define EXTENSIONS_BROWSER_LAZY_BACKGROUND_TASK_QUEUE_H_ 6 #define EXTENSIONS_BROWSER_LAZY_BACKGROUND_TASK_QUEUE_H_
7 7
8 #include <stddef.h> 8 #include <stddef.h>
9 9
10 #include <map> 10 #include <map>
11 #include <string> 11 #include <string>
12 12
13 #include "base/callback_forward.h" 13 #include "base/callback_forward.h"
14 #include "base/compiler_specific.h" 14 #include "base/compiler_specific.h"
15 #include "base/gtest_prod_util.h" 15 #include "base/gtest_prod_util.h"
16 #include "base/scoped_observer.h" 16 #include "base/scoped_observer.h"
17 #include "components/keyed_service/core/keyed_service.h" 17 #include "components/keyed_service/core/keyed_service.h"
18 #include "content/public/browser/notification_observer.h" 18 #include "content/public/browser/notification_observer.h"
19 #include "content/public/browser/notification_registrar.h" 19 #include "content/public/browser/notification_registrar.h"
20 #include "extensions/browser/extension_registry_observer.h" 20 #include "extensions/browser/extension_registry_observer.h"
21 #include "extensions/browser/lazy_context_task_queue.h"
21 #include "extensions/common/extension_id.h" 22 #include "extensions/common/extension_id.h"
22 23
23 namespace content { 24 namespace content {
24 class BrowserContext; 25 class BrowserContext;
25 } 26 }
26 27
27 namespace extensions { 28 namespace extensions {
28 class Extension; 29 class Extension;
29 class ExtensionHost; 30 class ExtensionHost;
30 class ExtensionRegistry; 31 class ExtensionRegistry;
32 class LazyContextId;
31 33
32 // This class maintains a queue of tasks that should execute when an 34 // This class maintains a queue of tasks that should execute when an
33 // extension's lazy background page is loaded. It is also in charge of loading 35 // extension's lazy background page is loaded. It is also in charge of loading
34 // the page when the first task is queued. 36 // the page when the first task is queued.
35 // 37 //
36 // It is the consumer's responsibility to use this class when appropriate, i.e. 38 // It is the consumer's responsibility to use this class when appropriate, i.e.
37 // only with extensions that have not-yet-loaded lazy background pages. 39 // only with extensions that have not-yet-loaded lazy background pages.
38 class LazyBackgroundTaskQueue : public KeyedService, 40 class LazyBackgroundTaskQueue : public KeyedService,
41 public LazyContextTaskQueue,
39 public content::NotificationObserver, 42 public content::NotificationObserver,
40 public ExtensionRegistryObserver { 43 public ExtensionRegistryObserver {
41 public: 44 public:
42 typedef base::Callback<void(ExtensionHost*)> PendingTask; 45 typedef base::Callback<void(ExtensionHost*)> PendingTask;
43 46
44 explicit LazyBackgroundTaskQueue(content::BrowserContext* browser_context); 47 explicit LazyBackgroundTaskQueue(content::BrowserContext* browser_context);
45 ~LazyBackgroundTaskQueue() override; 48 ~LazyBackgroundTaskQueue() override;
46 49
47 // Convenience method to return the LazyBackgroundTaskQueue for a given 50 // Convenience method to return the LazyBackgroundTaskQueue for a given
48 // |context|. 51 // |context|.
49 static LazyBackgroundTaskQueue* Get(content::BrowserContext* context); 52 static LazyBackgroundTaskQueue* Get(content::BrowserContext* context);
50 53
51 // Returns true if the task should be added to the queue (that is, if the 54 // Returns true if the task should be added to the queue (that is, if the
52 // extension has a lazy background page that isn't ready yet). If the 55 // extension has a lazy background page that isn't ready yet). If the
53 // extension has a lazy background page that is being suspended this method 56 // extension has a lazy background page that is being suspended this method
54 // cancels that suspension. 57 // cancels that suspension.
55 bool ShouldEnqueueTask(content::BrowserContext* context, 58 bool ShouldEnqueueTask(content::BrowserContext* context,
56 const Extension* extension); 59 const Extension* extension) override;
60 // TODO(lazyboy): Find a better way to use AddPendingTask instead of this.
61 // Currently AddPendingTask has lots of consumers that depend on
62 // ExtensionHost.
63 void AddPendingTaskToDispatchEvent(
64 LazyContextId* context_id,
65 const LazyContextTaskQueue::PendingTask& task) override;
57 66
58 // Adds a task to the queue for a given extension. If this is the first 67 // Adds a task to the queue for a given extension. If this is the first
59 // task added for the extension, its lazy background page will be loaded. 68 // task added for the extension, its lazy background page will be loaded.
60 // The task will be called either when the page is loaded, or when the 69 // The task will be called either when the page is loaded, or when the
61 // page fails to load for some reason (e.g. a crash or browser 70 // page fails to load for some reason (e.g. a crash or browser
62 // shutdown). In the latter case, the ExtensionHost parameter is NULL. 71 // shutdown). In the latter case, the ExtensionHost parameter is NULL.
63 void AddPendingTask( 72 void AddPendingTask(
64 content::BrowserContext* context, 73 content::BrowserContext* context,
65 const std::string& extension_id, 74 const std::string& extension_id,
66 const PendingTask& task); 75 const PendingTask& task);
(...skipping 30 matching lines...) Expand all
97 content::NotificationRegistrar registrar_; 106 content::NotificationRegistrar registrar_;
98 PendingTasksMap pending_tasks_; 107 PendingTasksMap pending_tasks_;
99 108
100 ScopedObserver<ExtensionRegistry, ExtensionRegistryObserver> 109 ScopedObserver<ExtensionRegistry, ExtensionRegistryObserver>
101 extension_registry_observer_; 110 extension_registry_observer_;
102 }; 111 };
103 112
104 } // namespace extensions 113 } // namespace extensions
105 114
106 #endif // EXTENSIONS_BROWSER_LAZY_BACKGROUND_TASK_QUEUE_H_ 115 #endif // EXTENSIONS_BROWSER_LAZY_BACKGROUND_TASK_QUEUE_H_
OLDNEW
« no previous file with comments | « extensions/browser/extension_message_filter.cc ('k') | extensions/browser/lazy_background_task_queue.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698