| OLD | NEW |
| 1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 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_context_wrapper.h" | 5 #include "content/browser/service_worker/service_worker_context_wrapper.h" |
| 6 | 6 |
| 7 #include <map> | 7 #include <map> |
| 8 #include <set> | 8 #include <set> |
| 9 #include <string> | 9 #include <string> |
| 10 #include <vector> | 10 #include <vector> |
| (...skipping 129 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 140 FROM_HERE, | 140 FROM_HERE, |
| 141 base::Bind(&ServiceWorkerContextWrapper::ShutdownOnIO, this)); | 141 base::Bind(&ServiceWorkerContextWrapper::ShutdownOnIO, this)); |
| 142 } | 142 } |
| 143 | 143 |
| 144 void ServiceWorkerContextWrapper::DeleteAndStartOver() { | 144 void ServiceWorkerContextWrapper::DeleteAndStartOver() { |
| 145 DCHECK_CURRENTLY_ON(BrowserThread::IO); | 145 DCHECK_CURRENTLY_ON(BrowserThread::IO); |
| 146 context_core_->DeleteAndStartOver( | 146 context_core_->DeleteAndStartOver( |
| 147 base::Bind(&ServiceWorkerContextWrapper::DidDeleteAndStartOver, this)); | 147 base::Bind(&ServiceWorkerContextWrapper::DidDeleteAndStartOver, this)); |
| 148 } | 148 } |
| 149 | 149 |
| 150 ServiceWorkerContextCore* ServiceWorkerContextWrapper::context() { | |
| 151 DCHECK_CURRENTLY_ON(BrowserThread::IO); | |
| 152 return context_core_.get(); | |
| 153 } | |
| 154 | |
| 155 StoragePartitionImpl* ServiceWorkerContextWrapper::storage_partition() const { | 150 StoragePartitionImpl* ServiceWorkerContextWrapper::storage_partition() const { |
| 156 DCHECK_CURRENTLY_ON(BrowserThread::UI); | 151 DCHECK_CURRENTLY_ON(BrowserThread::UI); |
| 157 return storage_partition_; | 152 return storage_partition_; |
| 158 } | 153 } |
| 159 | 154 |
| 160 void ServiceWorkerContextWrapper::set_storage_partition( | 155 void ServiceWorkerContextWrapper::set_storage_partition( |
| 161 StoragePartitionImpl* storage_partition) { | 156 StoragePartitionImpl* storage_partition) { |
| 162 DCHECK_CURRENTLY_ON(BrowserThread::UI); | 157 DCHECK_CURRENTLY_ON(BrowserThread::UI); |
| 163 storage_partition_ = storage_partition; | 158 storage_partition_ = storage_partition; |
| 164 } | 159 } |
| (...skipping 260 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 425 base::Bind(callback, false)); | 420 base::Bind(callback, false)); |
| 426 return; | 421 return; |
| 427 } | 422 } |
| 428 GURL stripped_url = net::SimplifyUrlForRequest(url); | 423 GURL stripped_url = net::SimplifyUrlForRequest(url); |
| 429 context()->storage()->FindRegistrationForDocument( | 424 context()->storage()->FindRegistrationForDocument( |
| 430 stripped_url, base::Bind(&ServiceWorkerContextWrapper:: | 425 stripped_url, base::Bind(&ServiceWorkerContextWrapper:: |
| 431 DidFindRegistrationForCheckHasServiceWorker, | 426 DidFindRegistrationForCheckHasServiceWorker, |
| 432 this, other_url, callback)); | 427 this, other_url, callback)); |
| 433 } | 428 } |
| 434 | 429 |
| 430 ServiceWorkerRegistration* ServiceWorkerContextWrapper::GetLiveRegistration( |
| 431 int64_t registration_id) { |
| 432 DCHECK_CURRENTLY_ON(BrowserThread::IO); |
| 433 if (!context_core_) |
| 434 return nullptr; |
| 435 return context_core_->GetLiveRegistration(registration_id); |
| 436 } |
| 437 |
| 438 ServiceWorkerVersion* ServiceWorkerContextWrapper::GetLiveVersion( |
| 439 int64_t version_id) { |
| 440 DCHECK_CURRENTLY_ON(BrowserThread::IO); |
| 441 if (!context_core_) |
| 442 return nullptr; |
| 443 return context_core_->GetLiveVersion(version_id); |
| 444 } |
| 445 |
| 446 std::vector<ServiceWorkerRegistrationInfo> |
| 447 ServiceWorkerContextWrapper::GetAllLiveRegistrationInfo() { |
| 448 DCHECK_CURRENTLY_ON(BrowserThread::IO); |
| 449 if (!context_core_) |
| 450 return std::vector<ServiceWorkerRegistrationInfo>(); |
| 451 return context_core_->GetAllLiveRegistrationInfo(); |
| 452 } |
| 453 |
| 454 std::vector<ServiceWorkerVersionInfo> |
| 455 ServiceWorkerContextWrapper::GetAllLiveVersionInfo() { |
| 456 DCHECK_CURRENTLY_ON(BrowserThread::IO); |
| 457 if (!context_core_) |
| 458 return std::vector<ServiceWorkerVersionInfo>(); |
| 459 return context_core_->GetAllLiveVersionInfo(); |
| 460 } |
| 461 |
| 462 void ServiceWorkerContextWrapper::FindRegistrationForDocument( |
| 463 const GURL& document_url, |
| 464 const FindRegistrationCallback& callback) { |
| 465 DCHECK_CURRENTLY_ON(BrowserThread::IO); |
| 466 if (!context_core_) { |
| 467 // FindRegistrationForDocument() can run the callback synchronously. |
| 468 callback.Run(SERVICE_WORKER_ERROR_ABORT, nullptr); |
| 469 return; |
| 470 } |
| 471 context_core_->storage()->FindRegistrationForDocument(document_url, callback); |
| 472 } |
| 473 |
| 474 void ServiceWorkerContextWrapper::FindRegistrationForId( |
| 475 int64_t registration_id, |
| 476 const GURL& origin, |
| 477 const FindRegistrationCallback& callback) { |
| 478 DCHECK_CURRENTLY_ON(BrowserThread::IO); |
| 479 if (!context_core_) { |
| 480 // FindRegistrationForId() can run the callback synchronously. |
| 481 callback.Run(SERVICE_WORKER_ERROR_ABORT, nullptr); |
| 482 return; |
| 483 } |
| 484 context_core_->storage()->FindRegistrationForId(registration_id, origin, |
| 485 callback); |
| 486 } |
| 487 |
| 488 void ServiceWorkerContextWrapper::GetAllRegistrations( |
| 489 const GetRegistrationsInfosCallback& callback) { |
| 490 DCHECK_CURRENTLY_ON(BrowserThread::IO); |
| 491 if (!context_core_) { |
| 492 RunSoon(base::Bind(callback, std::vector<ServiceWorkerRegistrationInfo>())); |
| 493 return; |
| 494 } |
| 495 context_core_->storage()->GetAllRegistrations(callback); |
| 496 } |
| 497 |
| 498 void ServiceWorkerContextWrapper::GetRegistrationUserData( |
| 499 int64_t registration_id, |
| 500 const std::string& key, |
| 501 const GetUserDataCallback& callback) { |
| 502 DCHECK_CURRENTLY_ON(BrowserThread::IO); |
| 503 if (!context_core_) { |
| 504 RunSoon(base::Bind(callback, std::string(), SERVICE_WORKER_ERROR_ABORT)); |
| 505 return; |
| 506 } |
| 507 context_core_->storage()->GetUserData(registration_id, key, callback); |
| 508 } |
| 509 |
| 510 void ServiceWorkerContextWrapper::StoreRegistrationUserData( |
| 511 int64_t registration_id, |
| 512 const GURL& origin, |
| 513 const std::string& key, |
| 514 const std::string& data, |
| 515 const StatusCallback& callback) { |
| 516 DCHECK_CURRENTLY_ON(BrowserThread::IO); |
| 517 if (!context_core_) { |
| 518 RunSoon(base::Bind(callback, SERVICE_WORKER_ERROR_ABORT)); |
| 519 return; |
| 520 } |
| 521 context_core_->storage()->StoreUserData(registration_id, origin, key, data, |
| 522 callback); |
| 523 } |
| 524 |
| 525 void ServiceWorkerContextWrapper::ClearRegistrationUserData( |
| 526 int64_t registration_id, |
| 527 const std::string& key, |
| 528 const StatusCallback& callback) { |
| 529 DCHECK_CURRENTLY_ON(BrowserThread::IO); |
| 530 if (!context_core_) { |
| 531 RunSoon(base::Bind(callback, SERVICE_WORKER_ERROR_ABORT)); |
| 532 return; |
| 533 } |
| 534 context_core_->storage()->ClearUserData(registration_id, key, callback); |
| 535 } |
| 536 |
| 537 void ServiceWorkerContextWrapper::GetUserDataForAllRegistrations( |
| 538 const std::string& key, |
| 539 const GetUserDataForAllRegistrationsCallback& callback) { |
| 540 DCHECK_CURRENTLY_ON(BrowserThread::IO); |
| 541 if (!context_core_) { |
| 542 RunSoon(base::Bind(callback, std::vector<std::pair<int64_t, std::string>>(), |
| 543 SERVICE_WORKER_ERROR_ABORT)); |
| 544 return; |
| 545 } |
| 546 context_core_->storage()->GetUserDataForAllRegistrations(key, callback); |
| 547 } |
| 548 |
| 435 void ServiceWorkerContextWrapper::AddObserver( | 549 void ServiceWorkerContextWrapper::AddObserver( |
| 436 ServiceWorkerContextObserver* observer) { | 550 ServiceWorkerContextObserver* observer) { |
| 437 observer_list_->AddObserver(observer); | 551 observer_list_->AddObserver(observer); |
| 438 } | 552 } |
| 439 | 553 |
| 440 void ServiceWorkerContextWrapper::RemoveObserver( | 554 void ServiceWorkerContextWrapper::RemoveObserver( |
| 441 ServiceWorkerContextObserver* observer) { | 555 ServiceWorkerContextObserver* observer) { |
| 442 observer_list_->RemoveObserver(observer); | 556 observer_list_->RemoveObserver(observer); |
| 443 } | 557 } |
| 444 | 558 |
| (...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 490 context_core_.reset(); | 604 context_core_.reset(); |
| 491 return; | 605 return; |
| 492 } | 606 } |
| 493 context_core_.reset(new ServiceWorkerContextCore(context_core_.get(), this)); | 607 context_core_.reset(new ServiceWorkerContextCore(context_core_.get(), this)); |
| 494 DVLOG(1) << "Restarted ServiceWorkerContextCore successfully."; | 608 DVLOG(1) << "Restarted ServiceWorkerContextCore successfully."; |
| 495 | 609 |
| 496 observer_list_->Notify(FROM_HERE, | 610 observer_list_->Notify(FROM_HERE, |
| 497 &ServiceWorkerContextObserver::OnStorageWiped); | 611 &ServiceWorkerContextObserver::OnStorageWiped); |
| 498 } | 612 } |
| 499 | 613 |
| 614 ServiceWorkerContextCore* ServiceWorkerContextWrapper::context() { |
| 615 DCHECK_CURRENTLY_ON(BrowserThread::IO); |
| 616 return context_core_.get(); |
| 617 } |
| 618 |
| 500 } // namespace content | 619 } // namespace content |
| OLD | NEW |