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

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

Issue 391563002: Remove extension unload notification from LazyBackgroundLazyBackgroundTaskQueue (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: review Created 6 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
« no previous file with comments | « no previous file | extensions/browser/lazy_background_task_queue.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 <map> 8 #include <map>
9 #include <string> 9 #include <string>
10 10
11 #include "base/callback_forward.h" 11 #include "base/callback_forward.h"
12 #include "base/compiler_specific.h" 12 #include "base/compiler_specific.h"
13 #include "base/gtest_prod_util.h" 13 #include "base/gtest_prod_util.h"
14 #include "base/memory/linked_ptr.h" 14 #include "base/memory/linked_ptr.h"
15 #include "base/scoped_observer.h"
15 #include "content/public/browser/notification_observer.h" 16 #include "content/public/browser/notification_observer.h"
16 #include "content/public/browser/notification_registrar.h" 17 #include "content/public/browser/notification_registrar.h"
18 #include "extensions/browser/extension_registry_observer.h"
17 19
18 namespace content { 20 namespace content {
19 class BrowserContext; 21 class BrowserContext;
20 } 22 }
21 23
22 namespace extensions { 24 namespace extensions {
23 class Extension; 25 class Extension;
24 class ExtensionHost; 26 class ExtensionHost;
27 class ExtensionRegistry;
25 28
26 // This class maintains a queue of tasks that should execute when an 29 // This class maintains a queue of tasks that should execute when an
27 // extension's lazy background page is loaded. It is also in charge of loading 30 // extension's lazy background page is loaded. It is also in charge of loading
28 // the page when the first task is queued. 31 // the page when the first task is queued.
29 // 32 //
30 // It is the consumer's responsibility to use this class when appropriate, i.e. 33 // It is the consumer's responsibility to use this class when appropriate, i.e.
31 // only with extensions that have not-yet-loaded lazy background pages. 34 // only with extensions that have not-yet-loaded lazy background pages.
32 class LazyBackgroundTaskQueue : public content::NotificationObserver { 35 class LazyBackgroundTaskQueue : public content::NotificationObserver,
36 public ExtensionRegistryObserver {
33 public: 37 public:
34 typedef base::Callback<void(ExtensionHost*)> PendingTask; 38 typedef base::Callback<void(ExtensionHost*)> PendingTask;
35 39
36 explicit LazyBackgroundTaskQueue(content::BrowserContext* browser_context); 40 explicit LazyBackgroundTaskQueue(content::BrowserContext* browser_context);
37 virtual ~LazyBackgroundTaskQueue(); 41 virtual ~LazyBackgroundTaskQueue();
38 42
39 // Returns the number of extensions having pending tasks. 43 // Returns the number of extensions having pending tasks.
40 size_t extensions_with_pending_tasks() { return pending_tasks_.size(); } 44 size_t extensions_with_pending_tasks() { return pending_tasks_.size(); }
41 45
42 // Returns true if the task should be added to the queue (that is, if the 46 // Returns true if the task should be added to the queue (that is, if the
(...skipping 22 matching lines...) Expand all
65 typedef std::pair<content::BrowserContext*, ExtensionID> PendingTasksKey; 69 typedef std::pair<content::BrowserContext*, ExtensionID> PendingTasksKey;
66 typedef std::vector<PendingTask> PendingTasksList; 70 typedef std::vector<PendingTask> PendingTasksList;
67 typedef std::map<PendingTasksKey, 71 typedef std::map<PendingTasksKey,
68 linked_ptr<PendingTasksList> > PendingTasksMap; 72 linked_ptr<PendingTasksList> > PendingTasksMap;
69 73
70 // content::NotificationObserver interface. 74 // content::NotificationObserver interface.
71 virtual void Observe(int type, 75 virtual void Observe(int type,
72 const content::NotificationSource& source, 76 const content::NotificationSource& source,
73 const content::NotificationDetails& details) OVERRIDE; 77 const content::NotificationDetails& details) OVERRIDE;
74 78
79 // ExtensionRegistryObserver interface.
80 virtual void OnExtensionUnloaded(
81 content::BrowserContext* browser_context,
82 const Extension* extension,
83 UnloadedExtensionInfo::Reason reason) OVERRIDE;
84
75 // Called when a lazy background page has finished loading, or has failed to 85 // Called when a lazy background page has finished loading, or has failed to
76 // load (host is NULL in that case). All enqueued tasks are run in order. 86 // load (host is NULL in that case). All enqueued tasks are run in order.
77 void ProcessPendingTasks( 87 void ProcessPendingTasks(
78 ExtensionHost* host, 88 ExtensionHost* host,
79 content::BrowserContext* context, 89 content::BrowserContext* context,
80 const Extension* extension); 90 const Extension* extension);
81 91
82 content::BrowserContext* browser_context_; 92 content::BrowserContext* browser_context_;
83 content::NotificationRegistrar registrar_; 93 content::NotificationRegistrar registrar_;
84 PendingTasksMap pending_tasks_; 94 PendingTasksMap pending_tasks_;
95
96 ScopedObserver<ExtensionRegistry, ExtensionRegistryObserver>
97 extension_registry_observer_;
85 }; 98 };
86 99
87 } // namespace extensions 100 } // namespace extensions
88 101
89 #endif // EXTENSIONS_BROWSER_LAZY_BACKGROUND_TASK_QUEUE_H_ 102 #endif // EXTENSIONS_BROWSER_LAZY_BACKGROUND_TASK_QUEUE_H_
OLDNEW
« no previous file with comments | « no previous file | extensions/browser/lazy_background_task_queue.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698