OLD | NEW |
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/memory/linked_ptr.h" | |
17 #include "base/scoped_observer.h" | 16 #include "base/scoped_observer.h" |
18 #include "components/keyed_service/core/keyed_service.h" | 17 #include "components/keyed_service/core/keyed_service.h" |
19 #include "content/public/browser/notification_observer.h" | 18 #include "content/public/browser/notification_observer.h" |
20 #include "content/public/browser/notification_registrar.h" | 19 #include "content/public/browser/notification_registrar.h" |
21 #include "extensions/browser/extension_registry_observer.h" | 20 #include "extensions/browser/extension_registry_observer.h" |
22 | 21 |
23 namespace content { | 22 namespace content { |
24 class BrowserContext; | 23 class BrowserContext; |
25 } | 24 } |
26 | 25 |
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
69 const PendingTask& task); | 68 const PendingTask& task); |
70 | 69 |
71 private: | 70 private: |
72 FRIEND_TEST_ALL_PREFIXES(LazyBackgroundTaskQueueTest, ProcessPendingTasks); | 71 FRIEND_TEST_ALL_PREFIXES(LazyBackgroundTaskQueueTest, ProcessPendingTasks); |
73 | 72 |
74 // A map between a BrowserContext/extension_id pair and the queue of tasks | 73 // A map between a BrowserContext/extension_id pair and the queue of tasks |
75 // pending the load of its background page. | 74 // pending the load of its background page. |
76 typedef std::string ExtensionID; | 75 typedef std::string ExtensionID; |
77 typedef std::pair<content::BrowserContext*, ExtensionID> PendingTasksKey; | 76 typedef std::pair<content::BrowserContext*, ExtensionID> PendingTasksKey; |
78 typedef std::vector<PendingTask> PendingTasksList; | 77 typedef std::vector<PendingTask> PendingTasksList; |
79 typedef std::map<PendingTasksKey, | 78 using PendingTasksMap = |
80 linked_ptr<PendingTasksList> > PendingTasksMap; | 79 std::map<PendingTasksKey, std::unique_ptr<PendingTasksList>>; |
81 | 80 |
82 // content::NotificationObserver interface. | 81 // content::NotificationObserver interface. |
83 void Observe(int type, | 82 void Observe(int type, |
84 const content::NotificationSource& source, | 83 const content::NotificationSource& source, |
85 const content::NotificationDetails& details) override; | 84 const content::NotificationDetails& details) override; |
86 | 85 |
87 // ExtensionRegistryObserver interface. | 86 // ExtensionRegistryObserver interface. |
88 void OnExtensionUnloaded(content::BrowserContext* browser_context, | 87 void OnExtensionUnloaded(content::BrowserContext* browser_context, |
89 const Extension* extension, | 88 const Extension* extension, |
90 UnloadedExtensionInfo::Reason reason) override; | 89 UnloadedExtensionInfo::Reason reason) override; |
91 | 90 |
92 // Called when a lazy background page has finished loading, or has failed to | 91 // Called when a lazy background page has finished loading, or has failed to |
93 // load (host is NULL in that case). All enqueued tasks are run in order. | 92 // load (host is NULL in that case). All enqueued tasks are run in order. |
94 void ProcessPendingTasks( | 93 void ProcessPendingTasks( |
95 ExtensionHost* host, | 94 ExtensionHost* host, |
96 content::BrowserContext* context, | 95 content::BrowserContext* context, |
97 const Extension* extension); | 96 const Extension* extension); |
98 | 97 |
99 content::BrowserContext* browser_context_; | 98 content::BrowserContext* browser_context_; |
100 content::NotificationRegistrar registrar_; | 99 content::NotificationRegistrar registrar_; |
101 PendingTasksMap pending_tasks_; | 100 PendingTasksMap pending_tasks_; |
102 | 101 |
103 ScopedObserver<ExtensionRegistry, ExtensionRegistryObserver> | 102 ScopedObserver<ExtensionRegistry, ExtensionRegistryObserver> |
104 extension_registry_observer_; | 103 extension_registry_observer_; |
105 }; | 104 }; |
106 | 105 |
107 } // namespace extensions | 106 } // namespace extensions |
108 | 107 |
109 #endif // EXTENSIONS_BROWSER_LAZY_BACKGROUND_TASK_QUEUE_H_ | 108 #endif // EXTENSIONS_BROWSER_LAZY_BACKGROUND_TASK_QUEUE_H_ |
OLD | NEW |