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

Side by Side Diff: chrome/browser/extensions/lazy_background_task_queue.cc

Issue 10804020: Introduce runtime.onSuspendCanceled() event. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: respond to comments Created 8 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 | Annotate | Revision Log
OLDNEW
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 "base/message_loop.h" 8 #include "base/message_loop.h"
9 #include "chrome/browser/extensions/extension_host.h" 9 #include "chrome/browser/extensions/extension_host.h"
10 #include "chrome/browser/extensions/extension_process_manager.h" 10 #include "chrome/browser/extensions/extension_process_manager.h"
(...skipping 30 matching lines...) Expand all
41 } 41 }
42 42
43 bool LazyBackgroundTaskQueue::ShouldEnqueueTask( 43 bool LazyBackgroundTaskQueue::ShouldEnqueueTask(
44 Profile* profile, const Extension* extension) { 44 Profile* profile, const Extension* extension) {
45 DCHECK(extension); 45 DCHECK(extension);
46 if (extension->has_lazy_background_page()) { 46 if (extension->has_lazy_background_page()) {
47 ExtensionProcessManager* pm = 47 ExtensionProcessManager* pm =
48 ExtensionSystem::Get(profile)->process_manager(); 48 ExtensionSystem::Get(profile)->process_manager();
49 ExtensionHost* background_host = 49 ExtensionHost* background_host =
50 pm->GetBackgroundHostForExtension(extension->id()); 50 pm->GetBackgroundHostForExtension(extension->id());
51 if (!background_host || !background_host->did_stop_loading() || 51 if (!background_host || !background_host->did_stop_loading())
52 pm->IsBackgroundHostClosing(extension->id()))
53 return true; 52 return true;
54 } 53 }
55 54
56 return false; 55 return false;
57 } 56 }
58 57
59 void LazyBackgroundTaskQueue::AddPendingTask( 58 void LazyBackgroundTaskQueue::AddPendingTask(
60 Profile* profile, 59 Profile* profile,
61 const std::string& extension_id, 60 const std::string& extension_id,
62 const PendingTask& task) { 61 const PendingTask& task) {
63 PendingTasksList* tasks_list = NULL; 62 PendingTasksList* tasks_list = NULL;
64 PendingTasksKey key(profile, extension_id); 63 PendingTasksKey key(profile, extension_id);
65 PendingTasksMap::iterator it = pending_tasks_.find(key); 64 PendingTasksMap::iterator it = pending_tasks_.find(key);
66 if (it == pending_tasks_.end()) { 65 if (it == pending_tasks_.end()) {
67 tasks_list = new PendingTasksList(); 66 tasks_list = new PendingTasksList();
68 pending_tasks_[key] = linked_ptr<PendingTasksList>(tasks_list); 67 pending_tasks_[key] = linked_ptr<PendingTasksList>(tasks_list);
69 68
70 // If this is the first enqueued task, and we're not waiting for the 69 // If this is the first enqueued task, and we're not waiting for the
71 // background page to unload, ensure the background page is loaded. 70 // background page to unload, ensure the background page is loaded.
72 if (pending_page_loads_.count(key) == 0) 71 if (pending_page_loads_.count(key) == 0)
73 StartLazyBackgroundPage(profile, extension_id); 72 StartLazyBackgroundPage(profile, extension_id);
74 } else { 73 } else {
75 tasks_list = it->second.get(); 74 tasks_list = it->second.get();
76 } 75 }
77 76
78 tasks_list->push_back(task); 77 tasks_list->push_back(task);
78 ExtensionProcessManager* pm =
79 ExtensionSystem::Get(profile)->process_manager();
80 pm->CancelSuspend(extension_id);
79 } 81 }
80 82
81 void LazyBackgroundTaskQueue::StartLazyBackgroundPage( 83 void LazyBackgroundTaskQueue::StartLazyBackgroundPage(
82 Profile* profile, const std::string& extension_id) { 84 Profile* profile, const std::string& extension_id) {
83 ExtensionProcessManager* pm = 85 ExtensionProcessManager* pm =
84 ExtensionSystem::Get(profile)->process_manager(); 86 ExtensionSystem::Get(profile)->process_manager();
85 if (pm->IsBackgroundHostClosing(extension_id)) { 87 if (pm->IsBackgroundHostClosing(extension_id)) {
86 // When the background host finishes closing, we will reload it. 88 // When the background host finishes closing, we will reload it.
87 pending_page_loads_.insert(PendingTasksKey(profile, extension_id)); 89 pending_page_loads_.insert(PendingTasksKey(profile, extension_id));
88 return; 90 return;
(...skipping 93 matching lines...) Expand 10 before | Expand all | Expand 10 after
182 } 184 }
183 break; 185 break;
184 } 186 }
185 default: 187 default:
186 NOTREACHED(); 188 NOTREACHED();
187 break; 189 break;
188 } 190 }
189 } 191 }
190 192
191 } // namespace extensions 193 } // namespace extensions
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698