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

Side by Side Diff: extensions/browser/api/runtime/runtime_api.cc

Issue 1129063011: Extract LazyBackgroundTaskQueue from ExtensionSystem. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: rebased from master Created 5 years, 7 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
OLDNEW
1 // Copyright 2014 The Chromium Authors. All rights reserved. 1 // Copyright 2014 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 "extensions/browser/api/runtime/runtime_api.h" 5 #include "extensions/browser/api/runtime/runtime_api.h"
6 6
7 #include <utility> 7 #include <utility>
8 8
9 #include "base/lazy_instance.h" 9 #include "base/lazy_instance.h"
10 #include "base/logging.h" 10 #include "base/logging.h"
(...skipping 77 matching lines...) Expand 10 before | Expand all | Expand 10 after
88 return; 88 return;
89 89
90 // If this is a persistent background page, we want to wait for it to load 90 // If this is a persistent background page, we want to wait for it to load
91 // (it might not be ready, since this is startup). But only enqueue once. 91 // (it might not be ready, since this is startup). But only enqueue once.
92 // If it fails to load the first time, don't bother trying again. 92 // If it fails to load the first time, don't bother trying again.
93 const Extension* extension = 93 const Extension* extension =
94 ExtensionRegistry::Get(browser_context)->enabled_extensions().GetByID( 94 ExtensionRegistry::Get(browser_context)->enabled_extensions().GetByID(
95 extension_id); 95 extension_id);
96 if (extension && BackgroundInfo::HasPersistentBackgroundPage(extension) && 96 if (extension && BackgroundInfo::HasPersistentBackgroundPage(extension) &&
97 first_call && 97 first_call &&
98 system->lazy_background_task_queue()->ShouldEnqueueTask(browser_context, 98 LazyBackgroundTaskQueue::Get(browser_context)
99 extension)) { 99 ->ShouldEnqueueTask(browser_context, extension)) {
100 system->lazy_background_task_queue()->AddPendingTask( 100 LazyBackgroundTaskQueue::Get(browser_context)
101 browser_context, 101 ->AddPendingTask(browser_context, extension_id,
102 extension_id, 102 base::Bind(&DispatchOnStartupEventImpl,
103 base::Bind( 103 browser_context, extension_id, false));
104 &DispatchOnStartupEventImpl, browser_context, extension_id, false));
105 return; 104 return;
106 } 105 }
107 106
108 scoped_ptr<base::ListValue> event_args(new base::ListValue()); 107 scoped_ptr<base::ListValue> event_args(new base::ListValue());
109 scoped_ptr<Event> event( 108 scoped_ptr<Event> event(
110 new Event(runtime::OnStartup::kEventName, event_args.Pass())); 109 new Event(runtime::OnStartup::kEventName, event_args.Pass()));
111 system->event_router()->DispatchEventToExtension(extension_id, event.Pass()); 110 system->event_router()->DispatchEventToExtension(extension_id, event.Pass());
112 } 111 }
113 112
114 void SetUninstallURL(ExtensionPrefs* prefs, 113 void SetUninstallURL(ExtensionPrefs* prefs,
(...skipping 282 matching lines...) Expand 10 before | Expand all | Expand 10 after
397 GURL uninstall_url( 396 GURL uninstall_url(
398 GetUninstallURL(ExtensionPrefs::Get(context), extension_id)); 397 GetUninstallURL(ExtensionPrefs::Get(context), extension_id));
399 398
400 if (uninstall_url.is_empty()) 399 if (uninstall_url.is_empty())
401 return; 400 return;
402 401
403 RuntimeAPI::GetFactoryInstance()->Get(context)->OpenURL(uninstall_url); 402 RuntimeAPI::GetFactoryInstance()->Get(context)->OpenURL(uninstall_url);
404 } 403 }
405 404
406 ExtensionFunction::ResponseAction RuntimeGetBackgroundPageFunction::Run() { 405 ExtensionFunction::ResponseAction RuntimeGetBackgroundPageFunction::Run() {
407 ExtensionSystem* system = ExtensionSystem::Get(browser_context());
408 ExtensionHost* host = ProcessManager::Get(browser_context()) 406 ExtensionHost* host = ProcessManager::Get(browser_context())
409 ->GetBackgroundHostForExtension(extension_id()); 407 ->GetBackgroundHostForExtension(extension_id());
410 if (system->lazy_background_task_queue()->ShouldEnqueueTask(browser_context(), 408 if (LazyBackgroundTaskQueue::Get(browser_context())
411 extension())) { 409 ->ShouldEnqueueTask(browser_context(), extension())) {
412 system->lazy_background_task_queue()->AddPendingTask( 410 LazyBackgroundTaskQueue::Get(browser_context())
413 browser_context(), 411 ->AddPendingTask(
414 extension_id(), 412 browser_context(), extension_id(),
415 base::Bind(&RuntimeGetBackgroundPageFunction::OnPageLoaded, this)); 413 base::Bind(&RuntimeGetBackgroundPageFunction::OnPageLoaded, this));
416 } else if (host) { 414 } else if (host) {
417 OnPageLoaded(host); 415 OnPageLoaded(host);
418 } else { 416 } else {
419 return RespondNow(Error(kNoBackgroundPageError)); 417 return RespondNow(Error(kNoBackgroundPageError));
420 } 418 }
421 419
422 return RespondLater(); 420 return RespondLater();
423 } 421 }
424 422
425 void RuntimeGetBackgroundPageFunction::OnPageLoaded(ExtensionHost* host) { 423 void RuntimeGetBackgroundPageFunction::OnPageLoaded(ExtensionHost* host) {
(...skipping 92 matching lines...) Expand 10 before | Expand all | Expand 10 after
518 content::ChildProcessSecurityPolicy* policy = 516 content::ChildProcessSecurityPolicy* policy =
519 content::ChildProcessSecurityPolicy::GetInstance(); 517 content::ChildProcessSecurityPolicy::GetInstance();
520 policy->GrantReadFileSystem(renderer_id, filesystem_id); 518 policy->GrantReadFileSystem(renderer_id, filesystem_id);
521 base::DictionaryValue* dict = new base::DictionaryValue(); 519 base::DictionaryValue* dict = new base::DictionaryValue();
522 dict->SetString("fileSystemId", filesystem_id); 520 dict->SetString("fileSystemId", filesystem_id);
523 dict->SetString("baseName", relative_path); 521 dict->SetString("baseName", relative_path);
524 return RespondNow(OneArgument(dict)); 522 return RespondNow(OneArgument(dict));
525 } 523 }
526 524
527 } // namespace extensions 525 } // namespace extensions
OLDNEW
« no previous file with comments | « chrome/browser/signin/easy_unlock_app_manager_unittest.cc ('k') | extensions/browser/event_router.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698