| 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 64 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 75 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); | 75 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); |
| 76 scoped_refptr<ServiceWorkerVersion> version = | 76 scoped_refptr<ServiceWorkerVersion> version = |
| 77 context->context()->GetLiveVersion(version_id); | 77 context->context()->GetLiveVersion(version_id); |
| 78 if (!version) { | 78 if (!version) { |
| 79 callback.Run(SERVICE_WORKER_ERROR_NOT_FOUND); | 79 callback.Run(SERVICE_WORKER_ERROR_NOT_FOUND); |
| 80 return; | 80 return; |
| 81 } | 81 } |
| 82 (*version.*method)(callback); | 82 (*version.*method)(callback); |
| 83 } | 83 } |
| 84 | 84 |
| 85 void DispatchPushEventWithVersionID( |
| 86 scoped_refptr<ServiceWorkerContextWrapper> context, |
| 87 int64 version_id, |
| 88 const ServiceWorkerInternalsUI::StatusCallback& callback) { |
| 89 if (!BrowserThread::CurrentlyOn(BrowserThread::IO)) { |
| 90 BrowserThread::PostTask( |
| 91 BrowserThread::IO, |
| 92 FROM_HERE, |
| 93 base::Bind(DispatchPushEventWithVersionID, |
| 94 context, |
| 95 version_id, |
| 96 callback)); |
| 97 return; |
| 98 } |
| 99 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); |
| 100 scoped_refptr<ServiceWorkerVersion> version = |
| 101 context->context()->GetLiveVersion(version_id); |
| 102 if (!version) { |
| 103 callback.Run(SERVICE_WORKER_ERROR_NOT_FOUND); |
| 104 return; |
| 105 } |
| 106 std::string data = "Test push message from ServiceWorkerInternals."; |
| 107 version->DispatchPushEvent(callback, data); |
| 108 } |
| 109 |
| 85 void UnregisterWithScope( | 110 void UnregisterWithScope( |
| 86 scoped_refptr<ServiceWorkerContextWrapper> context, | 111 scoped_refptr<ServiceWorkerContextWrapper> context, |
| 87 const GURL& scope, | 112 const GURL& scope, |
| 88 const ServiceWorkerInternalsUI::StatusCallback& callback) { | 113 const ServiceWorkerInternalsUI::StatusCallback& callback) { |
| 89 if (!BrowserThread::CurrentlyOn(BrowserThread::IO)) { | 114 if (!BrowserThread::CurrentlyOn(BrowserThread::IO)) { |
| 90 BrowserThread::PostTask( | 115 BrowserThread::PostTask( |
| 91 BrowserThread::IO, | 116 BrowserThread::IO, |
| 92 FROM_HERE, | 117 FROM_HERE, |
| 93 base::Bind(UnregisterWithScope, context, scope, callback)); | 118 base::Bind(UnregisterWithScope, context, scope, callback)); |
| 94 return; | 119 return; |
| (...skipping 298 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 393 "stop", | 418 "stop", |
| 394 base::Bind(&ServiceWorkerInternalsUI::CallServiceWorkerVersionMethod, | 419 base::Bind(&ServiceWorkerInternalsUI::CallServiceWorkerVersionMethod, |
| 395 base::Unretained(this), | 420 base::Unretained(this), |
| 396 &ServiceWorkerVersion::StopWorker)); | 421 &ServiceWorkerVersion::StopWorker)); |
| 397 web_ui->RegisterMessageCallback( | 422 web_ui->RegisterMessageCallback( |
| 398 "sync", | 423 "sync", |
| 399 base::Bind(&ServiceWorkerInternalsUI::CallServiceWorkerVersionMethod, | 424 base::Bind(&ServiceWorkerInternalsUI::CallServiceWorkerVersionMethod, |
| 400 base::Unretained(this), | 425 base::Unretained(this), |
| 401 &ServiceWorkerVersion::DispatchSyncEvent)); | 426 &ServiceWorkerVersion::DispatchSyncEvent)); |
| 402 web_ui->RegisterMessageCallback( | 427 web_ui->RegisterMessageCallback( |
| 428 "push", |
| 429 base::Bind(&ServiceWorkerInternalsUI::DispatchPushEvent, |
| 430 base::Unretained(this))); |
| 431 web_ui->RegisterMessageCallback( |
| 403 "inspect", | 432 "inspect", |
| 404 base::Bind(&ServiceWorkerInternalsUI::InspectWorker, | 433 base::Bind(&ServiceWorkerInternalsUI::InspectWorker, |
| 405 base::Unretained(this))); | 434 base::Unretained(this))); |
| 406 web_ui->RegisterMessageCallback( | 435 web_ui->RegisterMessageCallback( |
| 407 "unregister", | 436 "unregister", |
| 408 base::Bind(&ServiceWorkerInternalsUI::Unregister, | 437 base::Bind(&ServiceWorkerInternalsUI::Unregister, |
| 409 base::Unretained(this))); | 438 base::Unretained(this))); |
| 410 web_ui->RegisterMessageCallback( | 439 web_ui->RegisterMessageCallback( |
| 411 "start", | 440 "start", |
| 412 base::Bind(&ServiceWorkerInternalsUI::StartWorker, | 441 base::Bind(&ServiceWorkerInternalsUI::StartWorker, |
| (...skipping 131 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 544 !base::StringToInt64(version_id_string, &version_id)) { | 573 !base::StringToInt64(version_id_string, &version_id)) { |
| 545 return; | 574 return; |
| 546 } | 575 } |
| 547 | 576 |
| 548 base::Callback<void(ServiceWorkerStatusCode)> callback = | 577 base::Callback<void(ServiceWorkerStatusCode)> callback = |
| 549 base::Bind(OperationCompleteCallback, AsWeakPtr(), callback_id); | 578 base::Bind(OperationCompleteCallback, AsWeakPtr(), callback_id); |
| 550 CallServiceWorkerVersionMethodWithVersionID( | 579 CallServiceWorkerVersionMethodWithVersionID( |
| 551 method, context, version_id, callback); | 580 method, context, version_id, callback); |
| 552 } | 581 } |
| 553 | 582 |
| 583 void ServiceWorkerInternalsUI::DispatchPushEvent( |
| 584 const ListValue* args) { |
| 585 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| 586 int callback_id; |
| 587 int partition_id; |
| 588 int64 version_id; |
| 589 std::string version_id_string; |
| 590 const DictionaryValue* cmd_args = NULL; |
| 591 scoped_refptr<ServiceWorkerContextWrapper> context; |
| 592 if (!args->GetInteger(0, &callback_id) || |
| 593 !args->GetDictionary(1, &cmd_args) || |
| 594 !cmd_args->GetInteger("partition_id", &partition_id) || |
| 595 !GetServiceWorkerContext(partition_id, &context) || |
| 596 !cmd_args->GetString("version_id", &version_id_string) || |
| 597 !base::StringToInt64(version_id_string, &version_id)) { |
| 598 return; |
| 599 } |
| 600 |
| 601 base::Callback<void(ServiceWorkerStatusCode)> callback = |
| 602 base::Bind(OperationCompleteCallback, AsWeakPtr(), callback_id); |
| 603 DispatchPushEventWithVersionID(context, version_id, callback); |
| 604 } |
| 605 |
| 554 void ServiceWorkerInternalsUI::InspectWorker(const ListValue* args) { | 606 void ServiceWorkerInternalsUI::InspectWorker(const ListValue* args) { |
| 555 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 607 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| 556 int callback_id; | 608 int callback_id; |
| 557 int process_id; | 609 int process_id; |
| 558 int devtools_agent_route_id; | 610 int devtools_agent_route_id; |
| 559 const DictionaryValue* cmd_args = NULL; | 611 const DictionaryValue* cmd_args = NULL; |
| 560 scoped_refptr<ServiceWorkerContextWrapper> context; | 612 scoped_refptr<ServiceWorkerContextWrapper> context; |
| 561 if (!args->GetInteger(0, &callback_id) || | 613 if (!args->GetInteger(0, &callback_id) || |
| 562 !args->GetDictionary(1, &cmd_args) || | 614 !args->GetDictionary(1, &cmd_args) || |
| 563 !cmd_args->GetInteger("process_id", &process_id) || | 615 !cmd_args->GetInteger("process_id", &process_id) || |
| (...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 614 return; | 666 return; |
| 615 } | 667 } |
| 616 | 668 |
| 617 base::Callback<void(ServiceWorkerStatusCode)> callback = | 669 base::Callback<void(ServiceWorkerStatusCode)> callback = |
| 618 base::Bind(OperationCompleteCallback, AsWeakPtr(), callback_id); | 670 base::Bind(OperationCompleteCallback, AsWeakPtr(), callback_id); |
| 619 FindRegistrationForPattern( | 671 FindRegistrationForPattern( |
| 620 context, GURL(scope_string), base::Bind(StartActiveWorker, callback)); | 672 context, GURL(scope_string), base::Bind(StartActiveWorker, callback)); |
| 621 } | 673 } |
| 622 | 674 |
| 623 } // namespace content | 675 } // namespace content |
| OLD | NEW |