| 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 124 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 135 FROM_HERE, | 135 FROM_HERE, |
| 136 base::Bind(&ServiceWorkerContextWrapper::ShutdownOnIO, this)); | 136 base::Bind(&ServiceWorkerContextWrapper::ShutdownOnIO, this)); |
| 137 } | 137 } |
| 138 | 138 |
| 139 void ServiceWorkerContextWrapper::DeleteAndStartOver() { | 139 void ServiceWorkerContextWrapper::DeleteAndStartOver() { |
| 140 DCHECK_CURRENTLY_ON(BrowserThread::IO); | 140 DCHECK_CURRENTLY_ON(BrowserThread::IO); |
| 141 context_core_->DeleteAndStartOver( | 141 context_core_->DeleteAndStartOver( |
| 142 base::Bind(&ServiceWorkerContextWrapper::DidDeleteAndStartOver, this)); | 142 base::Bind(&ServiceWorkerContextWrapper::DidDeleteAndStartOver, this)); |
| 143 } | 143 } |
| 144 | 144 |
| 145 ServiceWorkerContextCore* ServiceWorkerContextWrapper::context() { | |
| 146 DCHECK_CURRENTLY_ON(BrowserThread::IO); | |
| 147 return context_core_.get(); | |
| 148 } | |
| 149 | |
| 150 StoragePartitionImpl* ServiceWorkerContextWrapper::storage_partition() const { | 145 StoragePartitionImpl* ServiceWorkerContextWrapper::storage_partition() const { |
| 151 DCHECK_CURRENTLY_ON(BrowserThread::UI); | 146 DCHECK_CURRENTLY_ON(BrowserThread::UI); |
| 152 return storage_partition_; | 147 return storage_partition_; |
| 153 } | 148 } |
| 154 | 149 |
| 155 void ServiceWorkerContextWrapper::set_storage_partition( | 150 void ServiceWorkerContextWrapper::set_storage_partition( |
| 156 StoragePartitionImpl* storage_partition) { | 151 StoragePartitionImpl* storage_partition) { |
| 157 DCHECK_CURRENTLY_ON(BrowserThread::UI); | 152 DCHECK_CURRENTLY_ON(BrowserThread::UI); |
| 158 storage_partition_ = storage_partition; | 153 storage_partition_ = storage_partition; |
| 159 } | 154 } |
| (...skipping 227 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 387 base::Bind(callback, false)); | 382 base::Bind(callback, false)); |
| 388 return; | 383 return; |
| 389 } | 384 } |
| 390 GURL stripped_url = net::SimplifyUrlForRequest(url); | 385 GURL stripped_url = net::SimplifyUrlForRequest(url); |
| 391 context()->storage()->FindRegistrationForDocument( | 386 context()->storage()->FindRegistrationForDocument( |
| 392 stripped_url, base::Bind(&ServiceWorkerContextWrapper:: | 387 stripped_url, base::Bind(&ServiceWorkerContextWrapper:: |
| 393 DidFindRegistrationForCheckHasServiceWorker, | 388 DidFindRegistrationForCheckHasServiceWorker, |
| 394 this, other_url, callback)); | 389 this, other_url, callback)); |
| 395 } | 390 } |
| 396 | 391 |
| 392 ServiceWorkerRegistration* ServiceWorkerContextWrapper::GetLiveRegistration( |
| 393 int64_t registration_id) { |
| 394 DCHECK_CURRENTLY_ON(BrowserThread::IO); |
| 395 if (!context_core_) |
| 396 return nullptr; |
| 397 return context_core_->GetLiveRegistration(registration_id); |
| 398 } |
| 399 |
| 400 ServiceWorkerVersion* ServiceWorkerContextWrapper::GetLiveVersion( |
| 401 int64_t version_id) { |
| 402 DCHECK_CURRENTLY_ON(BrowserThread::IO); |
| 403 if (!context_core_) |
| 404 return nullptr; |
| 405 return context_core_->GetLiveVersion(version_id); |
| 406 } |
| 407 |
| 408 std::vector<ServiceWorkerRegistrationInfo> |
| 409 ServiceWorkerContextWrapper::GetAllLiveRegistrationInfo() { |
| 410 DCHECK_CURRENTLY_ON(BrowserThread::IO); |
| 411 if (!context_core_) |
| 412 return std::vector<ServiceWorkerRegistrationInfo>(); |
| 413 return context_core_->GetAllLiveRegistrationInfo(); |
| 414 } |
| 415 |
| 416 std::vector<ServiceWorkerVersionInfo> |
| 417 ServiceWorkerContextWrapper::GetAllLiveVersionInfo() { |
| 418 DCHECK_CURRENTLY_ON(BrowserThread::IO); |
| 419 if (!context_core_) |
| 420 return std::vector<ServiceWorkerVersionInfo>(); |
| 421 return context_core_->GetAllLiveVersionInfo(); |
| 422 } |
| 423 |
| 424 void ServiceWorkerContextWrapper::FindRegistrationForDocument( |
| 425 const GURL& document_url, |
| 426 const ServiceWorkerStorage::FindRegistrationCallback& callback) { |
| 427 DCHECK_CURRENTLY_ON(BrowserThread::IO); |
| 428 if (!context_core_) { |
| 429 // FindRegistrationForDocument() can run the callback synchronously. |
| 430 callback.Run(SERVICE_WORKER_ERROR_ABORT, nullptr); |
| 431 return; |
| 432 } |
| 433 context_core_->storage()->FindRegistrationForDocument(document_url, callback); |
| 434 } |
| 435 |
| 436 void ServiceWorkerContextWrapper::FindRegistrationForId( |
| 437 int64_t registration_id, |
| 438 const GURL& origin, |
| 439 const ServiceWorkerStorage::FindRegistrationCallback& callback) { |
| 440 DCHECK_CURRENTLY_ON(BrowserThread::IO); |
| 441 if (!context_core_) { |
| 442 // FindRegistrationForId() can run the callback synchronously. |
| 443 callback.Run(SERVICE_WORKER_ERROR_ABORT, nullptr); |
| 444 return; |
| 445 } |
| 446 context_core_->storage()->FindRegistrationForId(registration_id, origin, |
| 447 callback); |
| 448 } |
| 449 |
| 450 void ServiceWorkerContextWrapper::GetAllRegistrations( |
| 451 const ServiceWorkerStorage::GetRegistrationsInfosCallback& callback) { |
| 452 DCHECK_CURRENTLY_ON(BrowserThread::IO); |
| 453 if (!context_core_) { |
| 454 RunSoon(base::Bind(callback, std::vector<ServiceWorkerRegistrationInfo>())); |
| 455 return; |
| 456 } |
| 457 context_core_->storage()->GetAllRegistrations(callback); |
| 458 } |
| 459 |
| 460 void ServiceWorkerContextWrapper::GetRegistrationUserData( |
| 461 int64_t registration_id, |
| 462 const std::string& key, |
| 463 const ServiceWorkerStorage::GetUserDataCallback& callback) { |
| 464 DCHECK_CURRENTLY_ON(BrowserThread::IO); |
| 465 if (!context_core_) { |
| 466 RunSoon(base::Bind(callback, std::string(), SERVICE_WORKER_ERROR_ABORT)); |
| 467 return; |
| 468 } |
| 469 context_core_->storage()->GetUserData(registration_id, key, callback); |
| 470 } |
| 471 |
| 472 void ServiceWorkerContextWrapper::StoreRegistrationUserData( |
| 473 int64_t registration_id, |
| 474 const GURL& origin, |
| 475 const std::string& key, |
| 476 const std::string& data, |
| 477 const StatusCallback& callback) { |
| 478 DCHECK_CURRENTLY_ON(BrowserThread::IO); |
| 479 if (!context_core_) { |
| 480 RunSoon(base::Bind(callback, SERVICE_WORKER_ERROR_ABORT)); |
| 481 return; |
| 482 } |
| 483 context_core_->storage()->StoreUserData(registration_id, origin, key, data, |
| 484 callback); |
| 485 } |
| 486 |
| 487 void ServiceWorkerContextWrapper::ClearRegistrationUserData( |
| 488 int64_t registration_id, |
| 489 const std::string& key, |
| 490 const StatusCallback& callback) { |
| 491 DCHECK_CURRENTLY_ON(BrowserThread::IO); |
| 492 if (!context_core_) { |
| 493 RunSoon(base::Bind(callback, SERVICE_WORKER_ERROR_ABORT)); |
| 494 return; |
| 495 } |
| 496 context_core_->storage()->ClearUserData(registration_id, key, callback); |
| 497 } |
| 498 |
| 499 void ServiceWorkerContextWrapper::GetUserDataForAllRegistrations( |
| 500 const std::string& key, |
| 501 const ServiceWorkerStorage::GetUserDataForAllRegistrationsCallback& |
| 502 callback) { |
| 503 DCHECK_CURRENTLY_ON(BrowserThread::IO); |
| 504 if (!context_core_) { |
| 505 RunSoon(base::Bind(callback, std::vector<std::pair<int64_t, std::string>>(), |
| 506 SERVICE_WORKER_ERROR_ABORT)); |
| 507 return; |
| 508 } |
| 509 context_core_->storage()->GetUserDataForAllRegistrations(key, callback); |
| 510 } |
| 511 |
| 397 void ServiceWorkerContextWrapper::AddObserver( | 512 void ServiceWorkerContextWrapper::AddObserver( |
| 398 ServiceWorkerContextObserver* observer) { | 513 ServiceWorkerContextObserver* observer) { |
| 399 observer_list_->AddObserver(observer); | 514 observer_list_->AddObserver(observer); |
| 400 } | 515 } |
| 401 | 516 |
| 402 void ServiceWorkerContextWrapper::RemoveObserver( | 517 void ServiceWorkerContextWrapper::RemoveObserver( |
| 403 ServiceWorkerContextObserver* observer) { | 518 ServiceWorkerContextObserver* observer) { |
| 404 observer_list_->RemoveObserver(observer); | 519 observer_list_->RemoveObserver(observer); |
| 405 } | 520 } |
| 406 | 521 |
| (...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 448 context_core_.reset(); | 563 context_core_.reset(); |
| 449 return; | 564 return; |
| 450 } | 565 } |
| 451 context_core_.reset(new ServiceWorkerContextCore(context_core_.get(), this)); | 566 context_core_.reset(new ServiceWorkerContextCore(context_core_.get(), this)); |
| 452 DVLOG(1) << "Restarted ServiceWorkerContextCore successfully."; | 567 DVLOG(1) << "Restarted ServiceWorkerContextCore successfully."; |
| 453 | 568 |
| 454 observer_list_->Notify(FROM_HERE, | 569 observer_list_->Notify(FROM_HERE, |
| 455 &ServiceWorkerContextObserver::OnStorageWiped); | 570 &ServiceWorkerContextObserver::OnStorageWiped); |
| 456 } | 571 } |
| 457 | 572 |
| 573 ServiceWorkerContextCore* ServiceWorkerContextWrapper::context() { |
| 574 DCHECK_CURRENTLY_ON(BrowserThread::IO); |
| 575 return context_core_.get(); |
| 576 } |
| 577 |
| 458 } // namespace content | 578 } // namespace content |
| OLD | NEW |