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 #include "chrome/browser/extensions/lazy_background_task_queue.h" | 5 #include "chrome/browser/extensions/lazy_background_task_queue.h" |
6 | 6 |
7 #include "base/callback.h" | 7 #include "base/callback.h" |
8 #include "chrome/browser/extensions/extension_host.h" | 8 #include "chrome/browser/extensions/extension_host.h" |
9 #include "chrome/browser/extensions/extension_process_manager.h" | 9 #include "chrome/browser/extensions/extension_process_manager.h" |
10 #include "chrome/browser/extensions/extension_service.h" | 10 #include "chrome/browser/extensions/extension_service.h" |
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
43 PendingTasksMap::iterator it = pending_tasks_.find(key); | 43 PendingTasksMap::iterator it = pending_tasks_.find(key); |
44 if (it == pending_tasks_.end()) { | 44 if (it == pending_tasks_.end()) { |
45 tasks_list = new PendingTasksList(); | 45 tasks_list = new PendingTasksList(); |
46 pending_tasks_[key] = linked_ptr<PendingTasksList>(tasks_list); | 46 pending_tasks_[key] = linked_ptr<PendingTasksList>(tasks_list); |
47 | 47 |
48 // If this is the first enqueued task, ensure the background page | 48 // If this is the first enqueued task, ensure the background page |
49 // is loaded. | 49 // is loaded. |
50 const Extension* extension = profile->GetExtensionService()-> | 50 const Extension* extension = profile->GetExtensionService()-> |
51 extensions()->GetByID(extension_id); | 51 extensions()->GetByID(extension_id); |
52 DCHECK(extension->has_lazy_background_page()); | 52 DCHECK(extension->has_lazy_background_page()); |
53 ExtensionProcessManager* pm = profile->GetExtensionProcessManager(); | 53 ExtensionProcessManager* pm = profile->GetExtensionProcessManager(); |
54 pm->IncrementLazyKeepaliveCount(extension); | 54 pm->IncrementLazyKeepaliveCount(extension); |
55 pm->CreateBackgroundHost(extension, extension->GetBackgroundURL()); | 55 pm->CreateBackgroundHost(extension, extension->GetBackgroundURL()); |
56 } else { | 56 } else { |
57 tasks_list = it->second.get(); | 57 tasks_list = it->second.get(); |
58 } | 58 } |
59 | 59 |
60 tasks_list->push_back(task); | 60 tasks_list->push_back(task); |
61 } | 61 } |
62 | 62 |
63 void LazyBackgroundTaskQueue::ProcessPendingTasks( | 63 void LazyBackgroundTaskQueue::ProcessPendingTasks(ExtensionHost* host) { |
64 ExtensionHost* host) { | |
65 PendingTasksKey key(host->profile(), host->extension()->id()); | 64 PendingTasksKey key(host->profile(), host->extension()->id()); |
66 PendingTasksMap::iterator map_it = pending_tasks_.find(key); | 65 PendingTasksMap::iterator map_it = pending_tasks_.find(key); |
67 if (map_it == pending_tasks_.end()) { | 66 if (map_it == pending_tasks_.end()) { |
68 NOTREACHED(); // lazy page should not load without any pending tasks | 67 NOTREACHED(); // lazy page should not load without any pending tasks |
69 return; | 68 return; |
70 } | 69 } |
71 | 70 |
72 PendingTasksList* tasks = map_it->second.get(); | 71 PendingTasksList* tasks = map_it->second.get(); |
73 for (PendingTasksList::const_iterator it = tasks->begin(); | 72 for (PendingTasksList::const_iterator it = tasks->begin(); |
74 it != tasks->end(); ++it) { | 73 it != tasks->end(); ++it) { |
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
111 if (profile->HasOffTheRecordProfile()) | 110 if (profile->HasOffTheRecordProfile()) |
112 pending_tasks_.erase(PendingTasksKey( | 111 pending_tasks_.erase(PendingTasksKey( |
113 profile->GetOffTheRecordProfile(), unloaded->extension->id())); | 112 profile->GetOffTheRecordProfile(), unloaded->extension->id())); |
114 break; | 113 break; |
115 } | 114 } |
116 default: | 115 default: |
117 NOTREACHED(); | 116 NOTREACHED(); |
118 break; | 117 break; |
119 } | 118 } |
120 } | 119 } |
OLD | NEW |