| 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_core.h" | 5 #include "content/browser/service_worker/service_worker_context_core.h" |
| 6 | 6 |
| 7 #include "base/barrier_closure.h" | 7 #include "base/barrier_closure.h" |
| 8 #include "base/bind.h" | 8 #include "base/bind.h" |
| 9 #include "base/bind_helpers.h" | 9 #include "base/bind_helpers.h" |
| 10 #include "base/files/file_path.h" | 10 #include "base/files/file_path.h" |
| 11 #include "base/single_thread_task_runner.h" | 11 #include "base/single_thread_task_runner.h" |
| 12 #include "base/strings/string_util.h" | 12 #include "base/strings/string_util.h" |
| 13 #include "content/browser/service_worker/embedded_worker_registry.h" | 13 #include "content/browser/service_worker/embedded_worker_registry.h" |
| 14 #include "content/browser/service_worker/service_worker_cache_storage_manager.h" | |
| 15 #include "content/browser/service_worker/service_worker_context_observer.h" | 14 #include "content/browser/service_worker/service_worker_context_observer.h" |
| 16 #include "content/browser/service_worker/service_worker_context_wrapper.h" | 15 #include "content/browser/service_worker/service_worker_context_wrapper.h" |
| 17 #include "content/browser/service_worker/service_worker_database_task_manager.h" | 16 #include "content/browser/service_worker/service_worker_database_task_manager.h" |
| 18 #include "content/browser/service_worker/service_worker_info.h" | 17 #include "content/browser/service_worker/service_worker_info.h" |
| 19 #include "content/browser/service_worker/service_worker_job_coordinator.h" | 18 #include "content/browser/service_worker/service_worker_job_coordinator.h" |
| 20 #include "content/browser/service_worker/service_worker_process_manager.h" | 19 #include "content/browser/service_worker/service_worker_process_manager.h" |
| 21 #include "content/browser/service_worker/service_worker_provider_host.h" | 20 #include "content/browser/service_worker/service_worker_provider_host.h" |
| 22 #include "content/browser/service_worker/service_worker_register_job.h" | 21 #include "content/browser/service_worker/service_worker_register_job.h" |
| 23 #include "content/browser/service_worker/service_worker_registration.h" | 22 #include "content/browser/service_worker/service_worker_registration.h" |
| 24 #include "content/browser/service_worker/service_worker_storage.h" | 23 #include "content/browser/service_worker/service_worker_storage.h" |
| (...skipping 94 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 119 while (!provider_host_iterator_->IsAtEnd()) { | 118 while (!provider_host_iterator_->IsAtEnd()) { |
| 120 if (predicate_.is_null() || predicate_.Run(GetProviderHost())) | 119 if (predicate_.is_null() || predicate_.Run(GetProviderHost())) |
| 121 return true; | 120 return true; |
| 122 provider_host_iterator_->Advance(); | 121 provider_host_iterator_->Advance(); |
| 123 } | 122 } |
| 124 return false; | 123 return false; |
| 125 } | 124 } |
| 126 | 125 |
| 127 ServiceWorkerContextCore::ServiceWorkerContextCore( | 126 ServiceWorkerContextCore::ServiceWorkerContextCore( |
| 128 const base::FilePath& path, | 127 const base::FilePath& path, |
| 129 const scoped_refptr<base::SequencedTaskRunner>& cache_task_runner, | |
| 130 scoped_ptr<ServiceWorkerDatabaseTaskManager> database_task_manager, | 128 scoped_ptr<ServiceWorkerDatabaseTaskManager> database_task_manager, |
| 131 const scoped_refptr<base::SingleThreadTaskRunner>& disk_cache_thread, | 129 const scoped_refptr<base::SingleThreadTaskRunner>& disk_cache_thread, |
| 132 storage::QuotaManagerProxy* quota_manager_proxy, | 130 storage::QuotaManagerProxy* quota_manager_proxy, |
| 133 storage::SpecialStoragePolicy* special_storage_policy, | 131 storage::SpecialStoragePolicy* special_storage_policy, |
| 134 ObserverListThreadSafe<ServiceWorkerContextObserver>* observer_list, | 132 ObserverListThreadSafe<ServiceWorkerContextObserver>* observer_list, |
| 135 ServiceWorkerContextWrapper* wrapper) | 133 ServiceWorkerContextWrapper* wrapper) |
| 136 : wrapper_(wrapper), | 134 : wrapper_(wrapper), |
| 137 providers_(new ProcessToProviderMap), | 135 providers_(new ProcessToProviderMap), |
| 138 provider_by_uuid_(new ProviderByClientUUIDMap), | 136 provider_by_uuid_(new ProviderByClientUUIDMap), |
| 139 cache_manager_(ServiceWorkerCacheStorageManager::Create( | |
| 140 path, | |
| 141 cache_task_runner.get(), | |
| 142 make_scoped_refptr(quota_manager_proxy))), | |
| 143 next_handle_id_(0), | 137 next_handle_id_(0), |
| 144 next_registration_handle_id_(0), | 138 next_registration_handle_id_(0), |
| 145 observer_list_(observer_list), | 139 observer_list_(observer_list), |
| 146 weak_factory_(this) { | 140 weak_factory_(this) { |
| 147 // These get a WeakPtr from weak_factory_, so must be set after weak_factory_ | 141 // These get a WeakPtr from weak_factory_, so must be set after weak_factory_ |
| 148 // is initialized. | 142 // is initialized. |
| 149 storage_ = ServiceWorkerStorage::Create(path, | 143 storage_ = ServiceWorkerStorage::Create(path, |
| 150 AsWeakPtr(), | 144 AsWeakPtr(), |
| 151 database_task_manager.Pass(), | 145 database_task_manager.Pass(), |
| 152 disk_cache_thread, | 146 disk_cache_thread, |
| 153 quota_manager_proxy, | 147 quota_manager_proxy, |
| 154 special_storage_policy); | 148 special_storage_policy); |
| 155 embedded_worker_registry_ = EmbeddedWorkerRegistry::Create(AsWeakPtr()); | 149 embedded_worker_registry_ = EmbeddedWorkerRegistry::Create(AsWeakPtr()); |
| 156 job_coordinator_.reset(new ServiceWorkerJobCoordinator(AsWeakPtr())); | 150 job_coordinator_.reset(new ServiceWorkerJobCoordinator(AsWeakPtr())); |
| 157 } | 151 } |
| 158 | 152 |
| 159 ServiceWorkerContextCore::ServiceWorkerContextCore( | 153 ServiceWorkerContextCore::ServiceWorkerContextCore( |
| 160 ServiceWorkerContextCore* old_context, | 154 ServiceWorkerContextCore* old_context, |
| 161 ServiceWorkerContextWrapper* wrapper) | 155 ServiceWorkerContextWrapper* wrapper) |
| 162 : wrapper_(wrapper), | 156 : wrapper_(wrapper), |
| 163 providers_(old_context->providers_.release()), | 157 providers_(old_context->providers_.release()), |
| 164 provider_by_uuid_(old_context->provider_by_uuid_.release()), | 158 provider_by_uuid_(old_context->provider_by_uuid_.release()), |
| 165 cache_manager_(ServiceWorkerCacheStorageManager::Create( | |
| 166 old_context->cache_manager())), | |
| 167 next_handle_id_(old_context->next_handle_id_), | 159 next_handle_id_(old_context->next_handle_id_), |
| 168 next_registration_handle_id_(old_context->next_registration_handle_id_), | 160 next_registration_handle_id_(old_context->next_registration_handle_id_), |
| 169 observer_list_(old_context->observer_list_), | 161 observer_list_(old_context->observer_list_), |
| 170 weak_factory_(this) { | 162 weak_factory_(this) { |
| 171 // These get a WeakPtr from weak_factory_, so must be set after weak_factory_ | 163 // These get a WeakPtr from weak_factory_, so must be set after weak_factory_ |
| 172 // is initialized. | 164 // is initialized. |
| 173 storage_ = ServiceWorkerStorage::Create(AsWeakPtr(), old_context->storage()); | 165 storage_ = ServiceWorkerStorage::Create(AsWeakPtr(), old_context->storage()); |
| 174 embedded_worker_registry_ = EmbeddedWorkerRegistry::Create( | 166 embedded_worker_registry_ = EmbeddedWorkerRegistry::Create( |
| 175 AsWeakPtr(), | 167 AsWeakPtr(), |
| 176 old_context->embedded_worker_registry()); | 168 old_context->embedded_worker_registry()); |
| (...skipping 275 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 452 FROM_HERE, | 444 FROM_HERE, |
| 453 base::Bind(&ServiceWorkerContextWrapper::DeleteAndStartOver, wrapper_)); | 445 base::Bind(&ServiceWorkerContextWrapper::DeleteAndStartOver, wrapper_)); |
| 454 } | 446 } |
| 455 | 447 |
| 456 void ServiceWorkerContextCore::DeleteAndStartOver( | 448 void ServiceWorkerContextCore::DeleteAndStartOver( |
| 457 const StatusCallback& callback) { | 449 const StatusCallback& callback) { |
| 458 job_coordinator_->AbortAll(); | 450 job_coordinator_->AbortAll(); |
| 459 storage_->DeleteAndStartOver(callback); | 451 storage_->DeleteAndStartOver(callback); |
| 460 } | 452 } |
| 461 | 453 |
| 462 void ServiceWorkerContextCore::SetBlobParametersForCache( | |
| 463 net::URLRequestContext* request_context, | |
| 464 base::WeakPtr<storage::BlobStorageContext> blob_storage_context) { | |
| 465 DCHECK_CURRENTLY_ON(BrowserThread::IO); | |
| 466 | |
| 467 cache_manager_->SetBlobParametersForCache(request_context, | |
| 468 blob_storage_context); | |
| 469 } | |
| 470 | |
| 471 scoped_ptr<ServiceWorkerProviderHost> | 454 scoped_ptr<ServiceWorkerProviderHost> |
| 472 ServiceWorkerContextCore::TransferProviderHostOut( | 455 ServiceWorkerContextCore::TransferProviderHostOut( |
| 473 int process_id, int provider_id) { | 456 int process_id, int provider_id) { |
| 474 ProviderMap* map = GetProviderMapForProcess(process_id); | 457 ProviderMap* map = GetProviderMapForProcess(process_id); |
| 475 ServiceWorkerProviderHost* transferee = map->Lookup(provider_id); | 458 ServiceWorkerProviderHost* transferee = map->Lookup(provider_id); |
| 476 ServiceWorkerProviderHost* replacement = | 459 ServiceWorkerProviderHost* replacement = |
| 477 new ServiceWorkerProviderHost(process_id, | 460 new ServiceWorkerProviderHost(process_id, |
| 478 transferee->frame_id(), | 461 transferee->frame_id(), |
| 479 provider_id, | 462 provider_id, |
| 480 transferee->provider_type(), | 463 transferee->provider_type(), |
| (...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 549 version->embedded_worker()->thread_id(), | 532 version->embedded_worker()->thread_id(), |
| 550 ServiceWorkerContextObserver::ConsoleMessage( | 533 ServiceWorkerContextObserver::ConsoleMessage( |
| 551 source_identifier, message_level, message, line_number, source_url)); | 534 source_identifier, message_level, message, line_number, source_url)); |
| 552 } | 535 } |
| 553 | 536 |
| 554 ServiceWorkerProcessManager* ServiceWorkerContextCore::process_manager() { | 537 ServiceWorkerProcessManager* ServiceWorkerContextCore::process_manager() { |
| 555 return wrapper_->process_manager(); | 538 return wrapper_->process_manager(); |
| 556 } | 539 } |
| 557 | 540 |
| 558 } // namespace content | 541 } // namespace content |
| OLD | NEW |