| 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 <utility> | 10 #include <utility> |
| (...skipping 83 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 94 : observer_list_( | 94 : observer_list_( |
| 95 new base::ObserverListThreadSafe<ServiceWorkerContextObserver>()), | 95 new base::ObserverListThreadSafe<ServiceWorkerContextObserver>()), |
| 96 process_manager_(new ServiceWorkerProcessManager(browser_context)), | 96 process_manager_(new ServiceWorkerProcessManager(browser_context)), |
| 97 is_incognito_(false), | 97 is_incognito_(false), |
| 98 storage_partition_(nullptr), | 98 storage_partition_(nullptr), |
| 99 resource_context_(nullptr) { | 99 resource_context_(nullptr) { |
| 100 DCHECK_CURRENTLY_ON(BrowserThread::UI); | 100 DCHECK_CURRENTLY_ON(BrowserThread::UI); |
| 101 } | 101 } |
| 102 | 102 |
| 103 ServiceWorkerContextWrapper::~ServiceWorkerContextWrapper() { | 103 ServiceWorkerContextWrapper::~ServiceWorkerContextWrapper() { |
| 104 DCHECK(!resource_context_); |
| 105 DCHECK(!request_context_getter_); |
| 104 } | 106 } |
| 105 | 107 |
| 106 void ServiceWorkerContextWrapper::Init( | 108 void ServiceWorkerContextWrapper::Init( |
| 107 const base::FilePath& user_data_directory, | 109 const base::FilePath& user_data_directory, |
| 108 storage::QuotaManagerProxy* quota_manager_proxy, | 110 storage::QuotaManagerProxy* quota_manager_proxy, |
| 109 storage::SpecialStoragePolicy* special_storage_policy) { | 111 storage::SpecialStoragePolicy* special_storage_policy) { |
| 110 DCHECK_CURRENTLY_ON(BrowserThread::UI); | 112 DCHECK_CURRENTLY_ON(BrowserThread::UI); |
| 111 | 113 |
| 112 is_incognito_ = user_data_directory.empty(); | 114 is_incognito_ = user_data_directory.empty(); |
| 113 base::SequencedWorkerPool* pool = BrowserThread::GetBlockingPool(); | 115 base::SequencedWorkerPool* pool = BrowserThread::GetBlockingPool(); |
| (...skipping 22 matching lines...) Expand all Loading... |
| 136 DCHECK_CURRENTLY_ON(BrowserThread::IO); | 138 DCHECK_CURRENTLY_ON(BrowserThread::IO); |
| 137 resource_context_ = resource_context; | 139 resource_context_ = resource_context; |
| 138 request_context_getter_ = request_context_getter; | 140 request_context_getter_ = request_context_getter; |
| 139 // Can be null in tests. | 141 // Can be null in tests. |
| 140 if (request_context_getter_) | 142 if (request_context_getter_) |
| 141 request_context_getter_->AddObserver(this); | 143 request_context_getter_->AddObserver(this); |
| 142 } | 144 } |
| 143 | 145 |
| 144 void ServiceWorkerContextWrapper::OnContextShuttingDown() { | 146 void ServiceWorkerContextWrapper::OnContextShuttingDown() { |
| 145 DCHECK_CURRENTLY_ON(BrowserThread::IO); | 147 DCHECK_CURRENTLY_ON(BrowserThread::IO); |
| 146 request_context_getter_->RemoveObserver(this); | |
| 147 | 148 |
| 148 // OnContextShuttingDown is called when the ProfileIOData (ResourceContext) is | 149 // OnContextShuttingDown is called when the ProfileIOData (ResourceContext) is |
| 149 // shutting down, so call ShutdownOnIO() to clear resource_context_. | 150 // shutting down, so call ShutdownOnIO() to clear resource_context_. |
| 150 // This doesn't seem to be called when using content_shell, so we still must | 151 // This doesn't seem to be called when using content_shell, so we still must |
| 151 // also call ShutdownOnIO() in Shutdown(), which is called when the storage | 152 // also call ShutdownOnIO() in Shutdown(), which is called when the storage |
| 152 // partition is destroyed. | 153 // partition is destroyed. |
| 153 ShutdownOnIO(); | 154 ShutdownOnIO(); |
| 154 } | 155 } |
| 155 | 156 |
| 156 void ServiceWorkerContextWrapper::DeleteAndStartOver() { | 157 void ServiceWorkerContextWrapper::DeleteAndStartOver() { |
| (...skipping 538 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 695 if (quota_manager_proxy) { | 696 if (quota_manager_proxy) { |
| 696 quota_manager_proxy->RegisterClient(new ServiceWorkerQuotaClient(this)); | 697 quota_manager_proxy->RegisterClient(new ServiceWorkerQuotaClient(this)); |
| 697 } | 698 } |
| 698 context_core_.reset(new ServiceWorkerContextCore( | 699 context_core_.reset(new ServiceWorkerContextCore( |
| 699 user_data_directory, std::move(database_task_manager), disk_cache_thread, | 700 user_data_directory, std::move(database_task_manager), disk_cache_thread, |
| 700 quota_manager_proxy, special_storage_policy, observer_list_.get(), this)); | 701 quota_manager_proxy, special_storage_policy, observer_list_.get(), this)); |
| 701 } | 702 } |
| 702 | 703 |
| 703 void ServiceWorkerContextWrapper::ShutdownOnIO() { | 704 void ServiceWorkerContextWrapper::ShutdownOnIO() { |
| 704 DCHECK_CURRENTLY_ON(BrowserThread::IO); | 705 DCHECK_CURRENTLY_ON(BrowserThread::IO); |
| 706 // Can be null in tests. |
| 707 if (request_context_getter_) |
| 708 request_context_getter_->RemoveObserver(this); |
| 709 request_context_getter_ = nullptr; |
| 705 resource_context_ = nullptr; | 710 resource_context_ = nullptr; |
| 706 context_core_.reset(); | 711 context_core_.reset(); |
| 707 } | 712 } |
| 708 | 713 |
| 709 void ServiceWorkerContextWrapper::DidDeleteAndStartOver( | 714 void ServiceWorkerContextWrapper::DidDeleteAndStartOver( |
| 710 ServiceWorkerStatusCode status) { | 715 ServiceWorkerStatusCode status) { |
| 711 DCHECK_CURRENTLY_ON(BrowserThread::IO); | 716 DCHECK_CURRENTLY_ON(BrowserThread::IO); |
| 712 if (status != SERVICE_WORKER_OK) { | 717 if (status != SERVICE_WORKER_OK) { |
| 713 context_core_.reset(); | 718 context_core_.reset(); |
| 714 return; | 719 return; |
| 715 } | 720 } |
| 716 context_core_.reset(new ServiceWorkerContextCore(context_core_.get(), this)); | 721 context_core_.reset(new ServiceWorkerContextCore(context_core_.get(), this)); |
| 717 DVLOG(1) << "Restarted ServiceWorkerContextCore successfully."; | 722 DVLOG(1) << "Restarted ServiceWorkerContextCore successfully."; |
| 718 | 723 |
| 719 observer_list_->Notify(FROM_HERE, | 724 observer_list_->Notify(FROM_HERE, |
| 720 &ServiceWorkerContextObserver::OnStorageWiped); | 725 &ServiceWorkerContextObserver::OnStorageWiped); |
| 721 } | 726 } |
| 722 | 727 |
| 723 ServiceWorkerContextCore* ServiceWorkerContextWrapper::context() { | 728 ServiceWorkerContextCore* ServiceWorkerContextWrapper::context() { |
| 724 DCHECK_CURRENTLY_ON(BrowserThread::IO); | 729 DCHECK_CURRENTLY_ON(BrowserThread::IO); |
| 725 return context_core_.get(); | 730 return context_core_.get(); |
| 726 } | 731 } |
| 727 | 732 |
| 728 } // namespace content | 733 } // namespace content |
| OLD | NEW |