OLD | NEW |
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 "content/browser/service_worker/service_worker_internals_ui.h" | 5 #include "content/browser/service_worker/service_worker_internals_ui.h" |
6 | 6 |
7 #include <string> | 7 #include <string> |
8 #include <vector> | 8 #include <vector> |
9 | 9 |
10 #include "base/bind.h" | 10 #include "base/bind.h" |
(...skipping 277 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
288 ScopedVector<const Value> args; | 288 ScopedVector<const Value> args; |
289 args.push_back(GetRegistrationListValue(live_registrations)); | 289 args.push_back(GetRegistrationListValue(live_registrations)); |
290 args.push_back(GetVersionListValue(live_versions)); | 290 args.push_back(GetVersionListValue(live_versions)); |
291 args.push_back(GetRegistrationListValue(stored_registrations)); | 291 args.push_back(GetRegistrationListValue(stored_registrations)); |
292 args.push_back(new FundamentalValue(partition_id)); | 292 args.push_back(new FundamentalValue(partition_id)); |
293 args.push_back(new StringValue(context_path.value())); | 293 args.push_back(new StringValue(context_path.value())); |
294 internals->web_ui()->CallJavascriptFunction("serviceworker.onPartitionData", | 294 internals->web_ui()->CallJavascriptFunction("serviceworker.onPartitionData", |
295 args.get()); | 295 args.get()); |
296 } | 296 } |
297 | 297 |
| 298 void SetKeepAliveMode( |
| 299 ServiceWorkerContextWrapper* wrapper, |
| 300 bool keep_alive_mode) { |
| 301 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); |
| 302 if (!wrapper->context()) |
| 303 return; |
| 304 wrapper->context()->SetKeepAliveMode(keep_alive_mode); |
| 305 } |
| 306 |
| 307 void SetKeepAliveModeForStoragePartition( |
| 308 bool keep_alive_mode, |
| 309 StoragePartition* storage_partition) { |
| 310 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| 311 scoped_refptr<ServiceWorkerContextWrapper> wrapper = |
| 312 static_cast<ServiceWorkerContextWrapper*>( |
| 313 storage_partition->GetServiceWorkerContext()); |
| 314 BrowserThread::PostTask( |
| 315 BrowserThread::IO, |
| 316 FROM_HERE, |
| 317 base::Bind(&SetKeepAliveMode, wrapper, keep_alive_mode)); |
| 318 } |
| 319 |
298 } // namespace | 320 } // namespace |
299 | 321 |
300 class ServiceWorkerInternalsUI::PartitionObserver | 322 class ServiceWorkerInternalsUI::PartitionObserver |
301 : public ServiceWorkerContextObserver { | 323 : public ServiceWorkerContextObserver { |
302 public: | 324 public: |
303 PartitionObserver(int partition_id, WebUI* web_ui) | 325 PartitionObserver(int partition_id, WebUI* web_ui) |
304 : partition_id_(partition_id), web_ui_(web_ui) {} | 326 : partition_id_(partition_id), web_ui_(web_ui) {} |
305 ~PartitionObserver() override {} | 327 ~PartitionObserver() override {} |
306 // ServiceWorkerContextObserver overrides: | 328 // ServiceWorkerContextObserver overrides: |
307 void OnWorkerStarted(int64 version_id, | 329 void OnWorkerStarted(int64 version_id, |
(...skipping 144 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
452 base::Bind(&ServiceWorkerInternalsUI::RemoveObserverFromStoragePartition, | 474 base::Bind(&ServiceWorkerInternalsUI::RemoveObserverFromStoragePartition, |
453 base::Unretained(this)); | 475 base::Unretained(this)); |
454 BrowserContext::ForEachStoragePartition(browser_context, remove_observer_cb); | 476 BrowserContext::ForEachStoragePartition(browser_context, remove_observer_cb); |
455 } | 477 } |
456 | 478 |
457 void ServiceWorkerInternalsUI::GetOptions(const ListValue* args) { | 479 void ServiceWorkerInternalsUI::GetOptions(const ListValue* args) { |
458 DictionaryValue options; | 480 DictionaryValue options; |
459 options.SetBoolean("debug_on_start", | 481 options.SetBoolean("debug_on_start", |
460 EmbeddedWorkerDevToolsManager::GetInstance() | 482 EmbeddedWorkerDevToolsManager::GetInstance() |
461 ->debug_service_worker_on_start()); | 483 ->debug_service_worker_on_start()); |
| 484 options.SetBoolean("keep_alive", |
| 485 EmbeddedWorkerDevToolsManager::GetInstance() |
| 486 ->keep_alive_service_workers()); |
462 web_ui()->CallJavascriptFunction("serviceworker.onOptions", options); | 487 web_ui()->CallJavascriptFunction("serviceworker.onOptions", options); |
463 } | 488 } |
464 | 489 |
465 void ServiceWorkerInternalsUI::SetOption(const ListValue* args) { | 490 void ServiceWorkerInternalsUI::SetOption(const ListValue* args) { |
466 std::string option_name; | 491 std::string option_name; |
467 bool option_boolean; | 492 bool option_boolean; |
468 if (!args->GetString(0, &option_name) || option_name != "debug_on_start" || | 493 if (!args->GetString(0, &option_name) || |
469 !args->GetBoolean(1, &option_boolean)) { | 494 !args->GetBoolean(1, &option_boolean)) { |
470 return; | 495 return; |
471 } | 496 } |
472 EmbeddedWorkerDevToolsManager::GetInstance() | 497 if (option_name == "debug_on_start") { |
473 ->set_debug_service_worker_on_start(option_boolean); | 498 EmbeddedWorkerDevToolsManager::GetInstance() |
| 499 ->set_debug_service_worker_on_start(option_boolean); |
| 500 } else if (option_name == "keep_alive") { |
| 501 EmbeddedWorkerDevToolsManager::GetInstance() |
| 502 ->set_keep_alive_service_workers(option_boolean); |
| 503 BrowserContext::ForEachStoragePartition( |
| 504 web_ui()->GetWebContents()->GetBrowserContext(), |
| 505 base::Bind(&SetKeepAliveModeForStoragePartition, option_boolean)); |
| 506 } |
474 } | 507 } |
475 | 508 |
476 void ServiceWorkerInternalsUI::GetAllRegistrations(const ListValue* args) { | 509 void ServiceWorkerInternalsUI::GetAllRegistrations(const ListValue* args) { |
477 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 510 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
478 BrowserContext* browser_context = | 511 BrowserContext* browser_context = |
479 web_ui()->GetWebContents()->GetBrowserContext(); | 512 web_ui()->GetWebContents()->GetBrowserContext(); |
480 // Safe to use base::Unretained(this) because | 513 // Safe to use base::Unretained(this) because |
481 // ForEachStoragePartition is synchronous. | 514 // ForEachStoragePartition is synchronous. |
482 BrowserContext::StoragePartitionCallback add_context_cb = | 515 BrowserContext::StoragePartitionCallback add_context_cb = |
483 base::Bind(&ServiceWorkerInternalsUI::AddContextFromStoragePartition, | 516 base::Bind(&ServiceWorkerInternalsUI::AddContextFromStoragePartition, |
(...skipping 184 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
668 return; | 701 return; |
669 } | 702 } |
670 | 703 |
671 base::Callback<void(ServiceWorkerStatusCode)> callback = | 704 base::Callback<void(ServiceWorkerStatusCode)> callback = |
672 base::Bind(OperationCompleteCallback, AsWeakPtr(), callback_id); | 705 base::Bind(OperationCompleteCallback, AsWeakPtr(), callback_id); |
673 FindRegistrationForPattern( | 706 FindRegistrationForPattern( |
674 context, GURL(scope_string), base::Bind(StartActiveWorker, callback)); | 707 context, GURL(scope_string), base::Bind(StartActiveWorker, callback)); |
675 } | 708 } |
676 | 709 |
677 } // namespace content | 710 } // namespace content |
OLD | NEW |