| 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 | 8 |
| 9 #include "base/barrier_closure.h" |
| 9 #include "base/files/file_path.h" | 10 #include "base/files/file_path.h" |
| 10 #include "base/logging.h" | 11 #include "base/logging.h" |
| 11 #include "base/threading/sequenced_worker_pool.h" | 12 #include "base/threading/sequenced_worker_pool.h" |
| 12 #include "content/browser/fileapi/chrome_blob_storage_context.h" | 13 #include "content/browser/fileapi/chrome_blob_storage_context.h" |
| 13 #include "content/browser/service_worker/service_worker_context_core.h" | 14 #include "content/browser/service_worker/service_worker_context_core.h" |
| 14 #include "content/browser/service_worker/service_worker_context_observer.h" | 15 #include "content/browser/service_worker/service_worker_context_observer.h" |
| 15 #include "content/browser/service_worker/service_worker_process_manager.h" | 16 #include "content/browser/service_worker/service_worker_process_manager.h" |
| 17 #include "content/browser/service_worker/service_worker_quota_client.h" |
| 16 #include "content/public/browser/browser_context.h" | 18 #include "content/public/browser/browser_context.h" |
| 17 #include "content/public/browser/browser_thread.h" | 19 #include "content/public/browser/browser_thread.h" |
| 18 #include "net/url_request/url_request_context_getter.h" | 20 #include "net/url_request/url_request_context_getter.h" |
| 19 #include "storage/browser/blob/blob_storage_context.h" | 21 #include "storage/browser/blob/blob_storage_context.h" |
| 20 #include "storage/browser/quota/quota_manager_proxy.h" | 22 #include "storage/browser/quota/quota_manager_proxy.h" |
| 21 #include "storage/browser/quota/special_storage_policy.h" | 23 #include "storage/browser/quota/special_storage_policy.h" |
| 22 | 24 |
| 23 namespace content { | 25 namespace content { |
| 24 | 26 |
| 25 ServiceWorkerContextWrapper::ServiceWorkerContextWrapper( | 27 ServiceWorkerContextWrapper::ServiceWorkerContextWrapper( |
| (...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 57 | 59 |
| 58 void ServiceWorkerContextWrapper::Shutdown() { | 60 void ServiceWorkerContextWrapper::Shutdown() { |
| 59 DCHECK_CURRENTLY_ON(BrowserThread::UI); | 61 DCHECK_CURRENTLY_ON(BrowserThread::UI); |
| 60 process_manager_->Shutdown(); | 62 process_manager_->Shutdown(); |
| 61 BrowserThread::PostTask( | 63 BrowserThread::PostTask( |
| 62 BrowserThread::IO, | 64 BrowserThread::IO, |
| 63 FROM_HERE, | 65 FROM_HERE, |
| 64 base::Bind(&ServiceWorkerContextWrapper::ShutdownOnIO, this)); | 66 base::Bind(&ServiceWorkerContextWrapper::ShutdownOnIO, this)); |
| 65 } | 67 } |
| 66 | 68 |
| 69 bool ServiceWorkerContextWrapper::IsAlive() const { |
| 70 return context_core_.get() != nullptr; |
| 71 } |
| 72 |
| 67 void ServiceWorkerContextWrapper::DeleteAndStartOver() { | 73 void ServiceWorkerContextWrapper::DeleteAndStartOver() { |
| 68 DCHECK_CURRENTLY_ON(BrowserThread::IO); | 74 DCHECK_CURRENTLY_ON(BrowserThread::IO); |
| 69 context_core_->DeleteAndStartOver( | 75 context_core_->DeleteAndStartOver( |
| 70 base::Bind(&ServiceWorkerContextWrapper::DidDeleteAndStartOver, this)); | 76 base::Bind(&ServiceWorkerContextWrapper::DidDeleteAndStartOver, this)); |
| 71 } | 77 } |
| 72 | 78 |
| 73 ServiceWorkerContextCore* ServiceWorkerContextWrapper::context() { | 79 ServiceWorkerContextCore* ServiceWorkerContextWrapper::context() { |
| 74 DCHECK_CURRENTLY_ON(BrowserThread::IO); | 80 DCHECK_CURRENTLY_ON(BrowserThread::IO); |
| 75 return context_core_.get(); | 81 return context_core_.get(); |
| 76 } | 82 } |
| (...skipping 99 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 176 origins.begin(); | 182 origins.begin(); |
| 177 it != origins.end(); | 183 it != origins.end(); |
| 178 ++it) { | 184 ++it) { |
| 179 usage_infos.push_back(it->second); | 185 usage_infos.push_back(it->second); |
| 180 } | 186 } |
| 181 | 187 |
| 182 callback.Run(usage_infos); | 188 callback.Run(usage_infos); |
| 183 } | 189 } |
| 184 | 190 |
| 185 namespace { | 191 namespace { |
| 192 void StatusCodeToBoolCallbackAdapter( |
| 193 const ServiceWorkerContext::ResultCallback& callback, |
| 194 ServiceWorkerStatusCode code) { |
| 195 callback.Run(code == ServiceWorkerStatusCode::SERVICE_WORKER_OK); |
| 196 } |
| 186 | 197 |
| 187 void EmptySuccessCallback(bool success) { | 198 void EmptySuccessCallback(bool success) { |
| 188 } | 199 } |
| 189 | |
| 190 } // namespace | 200 } // namespace |
| 191 | 201 |
| 192 void ServiceWorkerContextWrapper::DeleteForOrigin(const GURL& origin_url) { | 202 void ServiceWorkerContextWrapper::DeleteForOrigin( |
| 203 const GURL& origin_url, |
| 204 const ResultCallback& result) { |
| 193 DCHECK_CURRENTLY_ON(BrowserThread::IO); | 205 DCHECK_CURRENTLY_ON(BrowserThread::IO); |
| 194 context_core_->storage()->GetAllRegistrations(base::Bind( | 206 context_core_->UnregisterServiceWorkers( |
| 195 &ServiceWorkerContextWrapper::DidGetAllRegistrationsForDeleteForOrigin, | 207 origin_url, base::Bind(&StatusCodeToBoolCallbackAdapter, result)); |
| 196 this, | |
| 197 origin_url)); | |
| 198 } | 208 } |
| 199 | 209 |
| 200 void ServiceWorkerContextWrapper::DidGetAllRegistrationsForDeleteForOrigin( | 210 void ServiceWorkerContextWrapper::DeleteForOrigin(const GURL& origin_url) { |
| 201 const GURL& origin, | 211 DeleteForOrigin(origin_url, base::Bind(&EmptySuccessCallback)); |
| 202 const std::vector<ServiceWorkerRegistrationInfo>& registrations) { | |
| 203 DCHECK_CURRENTLY_ON(BrowserThread::IO); | |
| 204 | |
| 205 for (std::vector<ServiceWorkerRegistrationInfo>::const_iterator it = | |
| 206 registrations.begin(); | |
| 207 it != registrations.end(); | |
| 208 ++it) { | |
| 209 const ServiceWorkerRegistrationInfo& registration_info = *it; | |
| 210 if (origin == registration_info.pattern.GetOrigin()) { | |
| 211 UnregisterServiceWorker(registration_info.pattern, | |
| 212 base::Bind(&EmptySuccessCallback)); | |
| 213 } | |
| 214 } | |
| 215 } | 212 } |
| 216 | 213 |
| 217 void ServiceWorkerContextWrapper::AddObserver( | 214 void ServiceWorkerContextWrapper::AddObserver( |
| 218 ServiceWorkerContextObserver* observer) { | 215 ServiceWorkerContextObserver* observer) { |
| 219 observer_list_->AddObserver(observer); | 216 observer_list_->AddObserver(observer); |
| 220 } | 217 } |
| 221 | 218 |
| 222 void ServiceWorkerContextWrapper::RemoveObserver( | 219 void ServiceWorkerContextWrapper::RemoveObserver( |
| 223 ServiceWorkerContextObserver* observer) { | 220 ServiceWorkerContextObserver* observer) { |
| 224 observer_list_->RemoveObserver(observer); | 221 observer_list_->RemoveObserver(observer); |
| (...skipping 26 matching lines...) Expand all Loading... |
| 251 this, | 248 this, |
| 252 user_data_directory, | 249 user_data_directory, |
| 253 stores_task_runner, | 250 stores_task_runner, |
| 254 base::Passed(&database_task_manager), | 251 base::Passed(&database_task_manager), |
| 255 disk_cache_thread, | 252 disk_cache_thread, |
| 256 make_scoped_refptr(quota_manager_proxy), | 253 make_scoped_refptr(quota_manager_proxy), |
| 257 make_scoped_refptr(special_storage_policy))); | 254 make_scoped_refptr(special_storage_policy))); |
| 258 return; | 255 return; |
| 259 } | 256 } |
| 260 DCHECK(!context_core_); | 257 DCHECK(!context_core_); |
| 258 if (quota_manager_proxy) { |
| 259 quota_manager_proxy->RegisterClient(new ServiceWorkerQuotaClient(this)); |
| 260 } |
| 261 context_core_.reset(new ServiceWorkerContextCore(user_data_directory, | 261 context_core_.reset(new ServiceWorkerContextCore(user_data_directory, |
| 262 stores_task_runner, | 262 stores_task_runner, |
| 263 database_task_manager.Pass(), | 263 database_task_manager.Pass(), |
| 264 disk_cache_thread, | 264 disk_cache_thread, |
| 265 quota_manager_proxy, | 265 quota_manager_proxy, |
| 266 special_storage_policy, | 266 special_storage_policy, |
| 267 observer_list_.get(), | 267 observer_list_.get(), |
| 268 this)); | 268 this)); |
| 269 } | 269 } |
| 270 | 270 |
| 271 void ServiceWorkerContextWrapper::ShutdownOnIO() { | 271 void ServiceWorkerContextWrapper::ShutdownOnIO() { |
| 272 DCHECK_CURRENTLY_ON(BrowserThread::IO); | 272 DCHECK_CURRENTLY_ON(BrowserThread::IO); |
| 273 context_core_.reset(); | 273 context_core_.reset(); |
| 274 } | 274 } |
| 275 | 275 |
| 276 void ServiceWorkerContextWrapper::DidDeleteAndStartOver( | 276 void ServiceWorkerContextWrapper::DidDeleteAndStartOver( |
| 277 ServiceWorkerStatusCode status) { | 277 ServiceWorkerStatusCode status) { |
| 278 DCHECK_CURRENTLY_ON(BrowserThread::IO); | 278 DCHECK_CURRENTLY_ON(BrowserThread::IO); |
| 279 if (status != SERVICE_WORKER_OK) { | 279 if (status != SERVICE_WORKER_OK) { |
| 280 context_core_.reset(); | 280 context_core_.reset(); |
| 281 return; | 281 return; |
| 282 } | 282 } |
| 283 context_core_.reset(new ServiceWorkerContextCore(context_core_.get(), this)); | 283 context_core_.reset(new ServiceWorkerContextCore(context_core_.get(), this)); |
| 284 DVLOG(1) << "Restarted ServiceWorkerContextCore successfully."; | 284 DVLOG(1) << "Restarted ServiceWorkerContextCore successfully."; |
| 285 } | 285 } |
| 286 | 286 |
| 287 } // namespace content | 287 } // namespace content |
| OLD | NEW |