| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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 CHROME_BROWSER_EXTENSIONS_LAZY_BACKGROUND_TASK_QUEUE_H_ | 5 #ifndef CHROME_BROWSER_EXTENSIONS_LAZY_BACKGROUND_TASK_QUEUE_H_ |
| 6 #define CHROME_BROWSER_EXTENSIONS_LAZY_BACKGROUND_TASK_QUEUE_H_ | 6 #define CHROME_BROWSER_EXTENSIONS_LAZY_BACKGROUND_TASK_QUEUE_H_ |
| 7 #pragma once | 7 #pragma once |
| 8 | 8 |
| 9 #include <map> | 9 #include <map> |
| 10 #include <string> | 10 #include <string> |
| (...skipping 22 matching lines...) Expand all Loading... |
| 33 | 33 |
| 34 explicit LazyBackgroundTaskQueue(Profile* profile); | 34 explicit LazyBackgroundTaskQueue(Profile* profile); |
| 35 virtual ~LazyBackgroundTaskQueue(); | 35 virtual ~LazyBackgroundTaskQueue(); |
| 36 | 36 |
| 37 // Returns true if the task should be added to the queue (that is, if the | 37 // Returns true if the task should be added to the queue (that is, if the |
| 38 // extension has a lazy background page that isn't ready yet). | 38 // extension has a lazy background page that isn't ready yet). |
| 39 bool ShouldEnqueueTask(Profile* profile, const Extension* extension); | 39 bool ShouldEnqueueTask(Profile* profile, const Extension* extension); |
| 40 | 40 |
| 41 // Adds a task to the queue for a given extension. If this is the first | 41 // Adds a task to the queue for a given extension. If this is the first |
| 42 // task added for the extension, its lazy background page will be loaded. | 42 // task added for the extension, its lazy background page will be loaded. |
| 43 // The task will be called either when the page is loaded, or when the |
| 44 // page fails to load for some reason (e.g. a crash). In the latter case, |
| 45 // the ExtensionHost parameter is NULL. |
| 43 void AddPendingTask( | 46 void AddPendingTask( |
| 44 Profile* profile, | 47 Profile* profile, |
| 45 const std::string& extension_id, | 48 const std::string& extension_id, |
| 46 const PendingTask& task); | 49 const PendingTask& task); |
| 47 | 50 |
| 48 private: | 51 private: |
| 49 // A map between an extension_id,Profile pair and the queue of tasks pending | 52 // A map between an extension_id,Profile pair and the queue of tasks pending |
| 50 // the load of its background page. | 53 // the load of its background page. |
| 51 typedef std::string ExtensionID; | 54 typedef std::string ExtensionID; |
| 52 typedef std::pair<Profile*, ExtensionID> PendingTasksKey; | 55 typedef std::pair<Profile*, ExtensionID> PendingTasksKey; |
| 53 typedef std::vector<PendingTask> PendingTasksList; | 56 typedef std::vector<PendingTask> PendingTasksList; |
| 54 typedef std::map<PendingTasksKey, | 57 typedef std::map<PendingTasksKey, |
| 55 linked_ptr<PendingTasksList> > PendingTasksMap; | 58 linked_ptr<PendingTasksList> > PendingTasksMap; |
| 56 | 59 |
| 57 // content::NotificationObserver interface. | 60 // content::NotificationObserver interface. |
| 58 virtual void Observe(int type, | 61 virtual void Observe(int type, |
| 59 const content::NotificationSource& source, | 62 const content::NotificationSource& source, |
| 60 const content::NotificationDetails& details) OVERRIDE; | 63 const content::NotificationDetails& details) OVERRIDE; |
| 61 | 64 |
| 62 // Called when a lazy background page has finished loading. All enqueued | 65 // Called when a lazy background page has finished loading, or has failed to |
| 63 // tasks are run in order. | 66 // load (host is NULL in that case). All enqueued tasks are run in order. |
| 64 void ProcessPendingTasks(ExtensionHost* host); | 67 void ProcessPendingTasks( |
| 68 ExtensionHost* host, |
| 69 Profile* profile, |
| 70 const Extension* extension); |
| 65 | 71 |
| 66 Profile* profile_; | 72 Profile* profile_; |
| 67 content::NotificationRegistrar registrar_; | 73 content::NotificationRegistrar registrar_; |
| 68 PendingTasksMap pending_tasks_; | 74 PendingTasksMap pending_tasks_; |
| 69 }; | 75 }; |
| 70 | 76 |
| 71 } // namespace extensions | 77 } // namespace extensions |
| 72 | 78 |
| 73 #endif // CHROME_BROWSER_EXTENSIONS_LAZY_BACKGROUND_TASK_QUEUE_H_ | 79 #endif // CHROME_BROWSER_EXTENSIONS_LAZY_BACKGROUND_TASK_QUEUE_H_ |
| OLD | NEW |