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

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: fix chromeos call 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
58 const Extension* GetExtension(Profile* profile,
59 const std::string& extension_id) {
60 return ExtensionSystem::Get(profile)->extension_service()->
61 extensions()->GetByID(extension_id);
62 }
63
64 bool LazyBackgroundTaskQueue::ExecuteTaskNowIfPossible(
65 Profile* profile,
66 const std::string& extension_id,
67 const PendingTask& task) {
68 const Extension* extension = GetExtension(profile, extension_id);
69 if (ShouldEnqueueTask(profile, extension))
70 return false;
71
72 ExtensionProcessManager* pm =
73 ExtensionSystem::Get(profile)->process_manager();
74 ExtensionHost* host = pm->GetBackgroundHostForExtension(extension_id);
75
76 if (!host)
77 return true;
Matt Perry 2012/07/24 19:25:15 I think you still want to run the task with a NULL
78
79 if (pm->IsBackgroundHostClosing(extension_id))
80 pm->CancelSuspend(extension_id);
81
82 task.Run(host);
83 return true;
84 }
85
59 void LazyBackgroundTaskQueue::AddPendingTask( 86 void LazyBackgroundTaskQueue::AddPendingTask(
60 Profile* profile, 87 Profile* profile,
61 const std::string& extension_id, 88 const std::string& extension_id,
62 const PendingTask& task) { 89 const PendingTask& task) {
90 if (ExecuteTaskNowIfPossible(profile, extension_id, task))
91 return;
63 PendingTasksList* tasks_list = NULL; 92 PendingTasksList* tasks_list = NULL;
64 PendingTasksKey key(profile, extension_id); 93 PendingTasksKey key(profile, extension_id);
65 PendingTasksMap::iterator it = pending_tasks_.find(key); 94 PendingTasksMap::iterator it = pending_tasks_.find(key);
66 if (it == pending_tasks_.end()) { 95 if (it == pending_tasks_.end()) {
67 tasks_list = new PendingTasksList(); 96 tasks_list = new PendingTasksList();
68 pending_tasks_[key] = linked_ptr<PendingTasksList>(tasks_list); 97 pending_tasks_[key] = linked_ptr<PendingTasksList>(tasks_list);
69 98
70 // If this is the first enqueued task, and we're not waiting for the 99 // 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. 100 // background page to unload, ensure the background page is loaded.
72 if (pending_page_loads_.count(key) == 0) 101 if (pending_page_loads_.count(key) == 0)
(...skipping 109 matching lines...) Expand 10 before | Expand all | Expand 10 after
182 } 211 }
183 break; 212 break;
184 } 213 }
185 default: 214 default:
186 NOTREACHED(); 215 NOTREACHED();
187 break; 216 break;
188 } 217 }
189 } 218 }
190 219
191 } // namespace extensions 220 } // namespace extensions
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698