| 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 <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 "base/scoped_observer.h" |
| 16 #include "components/keyed_service/core/keyed_service.h" |
| 16 #include "content/public/browser/notification_observer.h" | 17 #include "content/public/browser/notification_observer.h" |
| 17 #include "content/public/browser/notification_registrar.h" | 18 #include "content/public/browser/notification_registrar.h" |
| 18 #include "extensions/browser/extension_registry_observer.h" | 19 #include "extensions/browser/extension_registry_observer.h" |
| 19 | 20 |
| 20 namespace content { | 21 namespace content { |
| 21 class BrowserContext; | 22 class BrowserContext; |
| 22 } | 23 } |
| 23 | 24 |
| 24 namespace extensions { | 25 namespace extensions { |
| 25 class Extension; | 26 class Extension; |
| 26 class ExtensionHost; | 27 class ExtensionHost; |
| 27 class ExtensionRegistry; | 28 class ExtensionRegistry; |
| 28 | 29 |
| 29 // This class maintains a queue of tasks that should execute when an | 30 // This class maintains a queue of tasks that should execute when an |
| 30 // extension's lazy background page is loaded. It is also in charge of loading | 31 // extension's lazy background page is loaded. It is also in charge of loading |
| 31 // the page when the first task is queued. | 32 // the page when the first task is queued. |
| 32 // | 33 // |
| 33 // It is the consumer's responsibility to use this class when appropriate, i.e. | 34 // It is the consumer's responsibility to use this class when appropriate, i.e. |
| 34 // only with extensions that have not-yet-loaded lazy background pages. | 35 // only with extensions that have not-yet-loaded lazy background pages. |
| 35 class LazyBackgroundTaskQueue : public content::NotificationObserver, | 36 class LazyBackgroundTaskQueue : public KeyedService, |
| 37 public content::NotificationObserver, |
| 36 public ExtensionRegistryObserver { | 38 public ExtensionRegistryObserver { |
| 37 public: | 39 public: |
| 38 typedef base::Callback<void(ExtensionHost*)> PendingTask; | 40 typedef base::Callback<void(ExtensionHost*)> PendingTask; |
| 39 | 41 |
| 40 explicit LazyBackgroundTaskQueue(content::BrowserContext* browser_context); | 42 explicit LazyBackgroundTaskQueue(content::BrowserContext* browser_context); |
| 41 ~LazyBackgroundTaskQueue() override; | 43 ~LazyBackgroundTaskQueue() override; |
| 42 | 44 |
| 45 // Convenience method to return the LazyBackgroundTaskQueue for a given |
| 46 // |context|. |
| 47 static LazyBackgroundTaskQueue* Get(content::BrowserContext* context); |
| 48 |
| 43 // Returns the number of extensions having pending tasks. | 49 // Returns the number of extensions having pending tasks. |
| 44 size_t extensions_with_pending_tasks() { return pending_tasks_.size(); } | 50 size_t extensions_with_pending_tasks() { return pending_tasks_.size(); } |
| 45 | 51 |
| 46 // Returns true if the task should be added to the queue (that is, if the | 52 // Returns true if the task should be added to the queue (that is, if the |
| 47 // extension has a lazy background page that isn't ready yet). If the | 53 // extension has a lazy background page that isn't ready yet). If the |
| 48 // extension has a lazy background page that is being suspended this method | 54 // extension has a lazy background page that is being suspended this method |
| 49 // cancels that suspension. | 55 // cancels that suspension. |
| 50 bool ShouldEnqueueTask(content::BrowserContext* context, | 56 bool ShouldEnqueueTask(content::BrowserContext* context, |
| 51 const Extension* extension); | 57 const Extension* extension); |
| 52 | 58 |
| (...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 92 content::NotificationRegistrar registrar_; | 98 content::NotificationRegistrar registrar_; |
| 93 PendingTasksMap pending_tasks_; | 99 PendingTasksMap pending_tasks_; |
| 94 | 100 |
| 95 ScopedObserver<ExtensionRegistry, ExtensionRegistryObserver> | 101 ScopedObserver<ExtensionRegistry, ExtensionRegistryObserver> |
| 96 extension_registry_observer_; | 102 extension_registry_observer_; |
| 97 }; | 103 }; |
| 98 | 104 |
| 99 } // namespace extensions | 105 } // namespace extensions |
| 100 | 106 |
| 101 #endif // EXTENSIONS_BROWSER_LAZY_BACKGROUND_TASK_QUEUE_H_ | 107 #endif // EXTENSIONS_BROWSER_LAZY_BACKGROUND_TASK_QUEUE_H_ |
| OLD | NEW |