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

Unified Diff: content/browser/service_worker/service_worker_internals_ui.cc

Issue 761923004: Keep alive ServiceWorkers when devtools is attached (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: updated comments Created 6 years 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 side-by-side diff with in-line comments
Download patch
Index: content/browser/service_worker/service_worker_internals_ui.cc
diff --git a/content/browser/service_worker/service_worker_internals_ui.cc b/content/browser/service_worker/service_worker_internals_ui.cc
index a7c8d71681356b90951808a176feef67971efce7..e9fa8463743d814816a58a4f8b31be5ee3000118 100644
--- a/content/browser/service_worker/service_worker_internals_ui.cc
+++ b/content/browser/service_worker/service_worker_internals_ui.cc
@@ -295,6 +295,28 @@ void OnAllRegistrations(
args.get());
}
+void SetKeepAliveMode(
+ ServiceWorkerContextWrapper* wrapper,
+ bool keep_alive_mode) {
+ DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
+ if (!wrapper->context())
+ return;
+ wrapper->context()->SetKeepAliveMode(keep_alive_mode);
+}
+
+void SetKeepAliveModeForStoragePartition(
+ bool keep_alive_mode,
+ StoragePartition* storage_partition) {
+ DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
+ scoped_refptr<ServiceWorkerContextWrapper> wrapper =
+ static_cast<ServiceWorkerContextWrapper*>(
+ storage_partition->GetServiceWorkerContext());
+ BrowserThread::PostTask(
+ BrowserThread::IO,
+ FROM_HERE,
+ base::Bind(&SetKeepAliveMode, wrapper, keep_alive_mode));
+}
+
} // namespace
class ServiceWorkerInternalsUI::PartitionObserver
@@ -459,18 +481,29 @@ void ServiceWorkerInternalsUI::GetOptions(const ListValue* args) {
options.SetBoolean("debug_on_start",
EmbeddedWorkerDevToolsManager::GetInstance()
->debug_service_worker_on_start());
+ options.SetBoolean("keep_alive",
+ EmbeddedWorkerDevToolsManager::GetInstance()
+ ->keep_alive_service_workers());
web_ui()->CallJavascriptFunction("serviceworker.onOptions", options);
}
void ServiceWorkerInternalsUI::SetOption(const ListValue* args) {
std::string option_name;
bool option_boolean;
- if (!args->GetString(0, &option_name) || option_name != "debug_on_start" ||
+ if (!args->GetString(0, &option_name) ||
!args->GetBoolean(1, &option_boolean)) {
return;
}
- EmbeddedWorkerDevToolsManager::GetInstance()
- ->set_debug_service_worker_on_start(option_boolean);
+ if (option_name == "debug_on_start") {
+ EmbeddedWorkerDevToolsManager::GetInstance()
+ ->set_debug_service_worker_on_start(option_boolean);
+ } else if (option_name == "keep_alive") {
+ EmbeddedWorkerDevToolsManager::GetInstance()
+ ->set_keep_alive_service_workers(option_boolean);
+ BrowserContext::ForEachStoragePartition(
+ web_ui()->GetWebContents()->GetBrowserContext(),
+ base::Bind(&SetKeepAliveModeForStoragePartition, option_boolean));
+ }
}
void ServiceWorkerInternalsUI::GetAllRegistrations(const ListValue* args) {

Powered by Google App Engine
This is Rietveld 408576698