content: Remove use of MessageLoopProxy and deprecated MessageLoop APIs
[chromium-blink-merge.git] / content / browser / service_worker / service_worker_context_wrapper.cc
blob264c9ce5a91c00f16995077314e9119b1e0d3d24
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
3 // found in the LICENSE file.
5 #include "content/browser/service_worker/service_worker_context_wrapper.h"
7 #include <map>
8 #include <set>
9 #include <string>
10 #include <vector>
12 #include "base/barrier_closure.h"
13 #include "base/bind.h"
14 #include "base/files/file_path.h"
15 #include "base/lazy_instance.h"
16 #include "base/location.h"
17 #include "base/logging.h"
18 #include "base/profiler/scoped_tracker.h"
19 #include "base/single_thread_task_runner.h"
20 #include "base/thread_task_runner_handle.h"
21 #include "base/threading/sequenced_worker_pool.h"
22 #include "content/browser/service_worker/service_worker_context_core.h"
23 #include "content/browser/service_worker/service_worker_context_observer.h"
24 #include "content/browser/service_worker/service_worker_process_manager.h"
25 #include "content/browser/service_worker/service_worker_quota_client.h"
26 #include "content/browser/service_worker/service_worker_request_handler.h"
27 #include "content/browser/service_worker/service_worker_utils.h"
28 #include "content/browser/service_worker/service_worker_version.h"
29 #include "content/browser/storage_partition_impl.h"
30 #include "content/public/browser/browser_context.h"
31 #include "content/public/browser/browser_thread.h"
32 #include "content/public/browser/service_worker_context.h"
33 #include "net/base/net_errors.h"
34 #include "net/base/net_util.h"
35 #include "storage/browser/quota/quota_manager_proxy.h"
36 #include "storage/browser/quota/special_storage_policy.h"
38 namespace content {
40 namespace {
42 typedef std::set<std::string> HeaderNameSet;
43 base::LazyInstance<HeaderNameSet> g_excluded_header_name_set =
44 LAZY_INSTANCE_INITIALIZER;
46 void RunSoon(const base::Closure& closure) {
47 base::ThreadTaskRunnerHandle::Get()->PostTask(FROM_HERE, closure);
50 void WorkerStarted(const ServiceWorkerContextWrapper::StatusCallback& callback,
51 ServiceWorkerStatusCode status) {
52 DCHECK_CURRENTLY_ON(BrowserThread::IO);
53 BrowserThread::PostTask(BrowserThread::UI, FROM_HERE,
54 base::Bind(callback, status));
57 void StartActiveWorkerOnIO(
58 const ServiceWorkerContextWrapper::StatusCallback& callback,
59 ServiceWorkerStatusCode status,
60 const scoped_refptr<ServiceWorkerRegistration>& registration) {
61 DCHECK_CURRENTLY_ON(BrowserThread::IO);
62 if (status == SERVICE_WORKER_OK) {
63 // Pass the reference of |registration| to WorkerStarted callback to prevent
64 // it from being deleted while starting the worker. If the refcount of
65 // |registration| is 1, it will be deleted after WorkerStarted is called.
66 registration->active_version()->StartWorker(
67 base::Bind(WorkerStarted, callback));
68 return;
70 BrowserThread::PostTask(BrowserThread::UI, FROM_HERE,
71 base::Bind(callback, SERVICE_WORKER_ERROR_NOT_FOUND));
74 } // namespace
76 void ServiceWorkerContext::AddExcludedHeadersForFetchEvent(
77 const std::set<std::string>& header_names) {
78 // TODO(pkasting): Remove ScopedTracker below once crbug.com/477117 is fixed.
79 tracked_objects::ScopedTracker tracking_profile(
80 FROM_HERE_WITH_EXPLICIT_FUNCTION(
81 "477117 ServiceWorkerContext::AddExcludedHeadersForFetchEvent"));
82 DCHECK_CURRENTLY_ON(BrowserThread::IO);
83 g_excluded_header_name_set.Get().insert(header_names.begin(),
84 header_names.end());
87 bool ServiceWorkerContext::IsExcludedHeaderNameForFetchEvent(
88 const std::string& header_name) {
89 DCHECK_CURRENTLY_ON(BrowserThread::IO);
90 return g_excluded_header_name_set.Get().find(header_name) !=
91 g_excluded_header_name_set.Get().end();
94 ServiceWorkerContext* ServiceWorkerContext::GetServiceWorkerContext(
95 net::URLRequest* request) {
96 DCHECK_CURRENTLY_ON(BrowserThread::IO);
97 ServiceWorkerRequestHandler* handler =
98 ServiceWorkerRequestHandler::GetHandler(request);
99 if (!handler || !handler->context())
100 return nullptr;
101 return handler->context()->wrapper_;
104 ServiceWorkerContextWrapper::ServiceWorkerContextWrapper(
105 BrowserContext* browser_context)
106 : observer_list_(
107 new base::ObserverListThreadSafe<ServiceWorkerContextObserver>()),
108 process_manager_(new ServiceWorkerProcessManager(browser_context)),
109 is_incognito_(false),
110 storage_partition_(nullptr) {
111 DCHECK_CURRENTLY_ON(BrowserThread::UI);
114 ServiceWorkerContextWrapper::~ServiceWorkerContextWrapper() {
117 void ServiceWorkerContextWrapper::Init(
118 const base::FilePath& user_data_directory,
119 storage::QuotaManagerProxy* quota_manager_proxy,
120 storage::SpecialStoragePolicy* special_storage_policy) {
121 DCHECK_CURRENTLY_ON(BrowserThread::UI);
123 is_incognito_ = user_data_directory.empty();
124 base::SequencedWorkerPool* pool = BrowserThread::GetBlockingPool();
125 scoped_ptr<ServiceWorkerDatabaseTaskManager> database_task_manager(
126 new ServiceWorkerDatabaseTaskManagerImpl(pool));
127 scoped_refptr<base::SingleThreadTaskRunner> disk_cache_thread =
128 BrowserThread::GetMessageLoopProxyForThread(BrowserThread::CACHE);
129 InitInternal(user_data_directory,
130 database_task_manager.Pass(),
131 disk_cache_thread,
132 quota_manager_proxy,
133 special_storage_policy);
136 void ServiceWorkerContextWrapper::Shutdown() {
137 DCHECK_CURRENTLY_ON(BrowserThread::UI);
139 storage_partition_ = nullptr;
140 process_manager_->Shutdown();
141 BrowserThread::PostTask(
142 BrowserThread::IO,
143 FROM_HERE,
144 base::Bind(&ServiceWorkerContextWrapper::ShutdownOnIO, this));
147 void ServiceWorkerContextWrapper::DeleteAndStartOver() {
148 DCHECK_CURRENTLY_ON(BrowserThread::IO);
149 if (!context_core_) {
150 // The context could be null due to system shutdown or restart failure. In
151 // either case, we should not have to recover the system, so just return
152 // here.
153 LOG(ERROR) << "ServiceWorkerContextCore is no longer alive.";
154 return;
156 context_core_->DeleteAndStartOver(
157 base::Bind(&ServiceWorkerContextWrapper::DidDeleteAndStartOver, this));
160 StoragePartitionImpl* ServiceWorkerContextWrapper::storage_partition() const {
161 DCHECK_CURRENTLY_ON(BrowserThread::UI);
162 return storage_partition_;
165 void ServiceWorkerContextWrapper::set_storage_partition(
166 StoragePartitionImpl* storage_partition) {
167 DCHECK_CURRENTLY_ON(BrowserThread::UI);
168 storage_partition_ = storage_partition;
171 static void FinishRegistrationOnIO(
172 const ServiceWorkerContext::ResultCallback& continuation,
173 ServiceWorkerStatusCode status,
174 const std::string& status_message,
175 int64 registration_id) {
176 DCHECK_CURRENTLY_ON(BrowserThread::IO);
177 BrowserThread::PostTask(
178 BrowserThread::UI,
179 FROM_HERE,
180 base::Bind(continuation, status == SERVICE_WORKER_OK));
183 void ServiceWorkerContextWrapper::RegisterServiceWorker(
184 const GURL& pattern,
185 const GURL& script_url,
186 const ResultCallback& continuation) {
187 if (!BrowserThread::CurrentlyOn(BrowserThread::IO)) {
188 BrowserThread::PostTask(
189 BrowserThread::IO,
190 FROM_HERE,
191 base::Bind(&ServiceWorkerContextWrapper::RegisterServiceWorker,
192 this,
193 pattern,
194 script_url,
195 continuation));
196 return;
198 if (!context_core_.get()) {
199 LOG(ERROR) << "ServiceWorkerContextCore is no longer alive.";
200 BrowserThread::PostTask(
201 BrowserThread::IO,
202 FROM_HERE,
203 base::Bind(continuation, false));
204 return;
206 context()->RegisterServiceWorker(
207 net::SimplifyUrlForRequest(pattern),
208 net::SimplifyUrlForRequest(script_url), NULL /* provider_host */,
209 base::Bind(&FinishRegistrationOnIO, continuation));
212 static void FinishUnregistrationOnIO(
213 const ServiceWorkerContext::ResultCallback& continuation,
214 ServiceWorkerStatusCode status) {
215 DCHECK_CURRENTLY_ON(BrowserThread::IO);
216 BrowserThread::PostTask(
217 BrowserThread::UI,
218 FROM_HERE,
219 base::Bind(continuation, status == SERVICE_WORKER_OK));
222 void ServiceWorkerContextWrapper::UnregisterServiceWorker(
223 const GURL& pattern,
224 const ResultCallback& continuation) {
225 if (!BrowserThread::CurrentlyOn(BrowserThread::IO)) {
226 BrowserThread::PostTask(
227 BrowserThread::IO,
228 FROM_HERE,
229 base::Bind(&ServiceWorkerContextWrapper::UnregisterServiceWorker,
230 this,
231 pattern,
232 continuation));
233 return;
235 if (!context_core_.get()) {
236 LOG(ERROR) << "ServiceWorkerContextCore is no longer alive.";
237 BrowserThread::PostTask(
238 BrowserThread::IO,
239 FROM_HERE,
240 base::Bind(continuation, false));
241 return;
244 context()->UnregisterServiceWorker(
245 net::SimplifyUrlForRequest(pattern),
246 base::Bind(&FinishUnregistrationOnIO, continuation));
249 void ServiceWorkerContextWrapper::UpdateRegistration(const GURL& pattern) {
250 if (!BrowserThread::CurrentlyOn(BrowserThread::IO)) {
251 BrowserThread::PostTask(
252 BrowserThread::IO, FROM_HERE,
253 base::Bind(&ServiceWorkerContextWrapper::UpdateRegistration, this,
254 pattern));
255 return;
257 if (!context_core_.get()) {
258 LOG(ERROR) << "ServiceWorkerContextCore is no longer alive.";
259 return;
261 context_core_->storage()->FindRegistrationForPattern(
262 net::SimplifyUrlForRequest(pattern),
263 base::Bind(&ServiceWorkerContextWrapper::DidFindRegistrationForUpdate,
264 this));
267 void ServiceWorkerContextWrapper::StartServiceWorker(
268 const GURL& pattern,
269 const StatusCallback& callback) {
270 if (!BrowserThread::CurrentlyOn(BrowserThread::IO)) {
271 BrowserThread::PostTask(
272 BrowserThread::IO, FROM_HERE,
273 base::Bind(&ServiceWorkerContextWrapper::StartServiceWorker, this,
274 pattern, callback));
275 return;
277 if (!context_core_.get()) {
278 LOG(ERROR) << "ServiceWorkerContextCore is no longer alive.";
279 BrowserThread::PostTask(BrowserThread::UI, FROM_HERE,
280 base::Bind(callback, SERVICE_WORKER_ERROR_ABORT));
281 return;
283 context_core_->storage()->FindRegistrationForPattern(
284 net::SimplifyUrlForRequest(pattern),
285 base::Bind(&StartActiveWorkerOnIO, callback));
288 void ServiceWorkerContextWrapper::SimulateSkipWaiting(int64_t version_id) {
289 if (!BrowserThread::CurrentlyOn(BrowserThread::IO)) {
290 BrowserThread::PostTask(
291 BrowserThread::IO, FROM_HERE,
292 base::Bind(&ServiceWorkerContextWrapper::SimulateSkipWaiting, this,
293 version_id));
294 return;
296 if (!context_core_.get()) {
297 LOG(ERROR) << "ServiceWorkerContextCore is no longer alive.";
298 return;
300 ServiceWorkerVersion* version = GetLiveVersion(version_id);
301 if (!version || version->skip_waiting())
302 return;
303 ServiceWorkerRegistration* registration =
304 GetLiveRegistration(version->registration_id());
305 if (!registration || version != registration->waiting_version())
306 return;
307 version->set_skip_waiting(true);
308 registration->ActivateWaitingVersionWhenReady();
311 static void DidFindRegistrationForDocument(
312 const net::CompletionCallback& callback,
313 ServiceWorkerStatusCode status,
314 const scoped_refptr<ServiceWorkerRegistration>& registration) {
315 int rv = registration ? net::OK : net::ERR_CACHE_MISS;
316 // Use RunSoon here because FindRegistrationForDocument can complete
317 // immediately but CanHandleMainResourceOffline must be async.
318 RunSoon(base::Bind(callback, rv));
321 void ServiceWorkerContextWrapper::CanHandleMainResourceOffline(
322 const GURL& url,
323 const GURL& first_party,
324 const net::CompletionCallback& callback) {
325 DCHECK_CURRENTLY_ON(BrowserThread::IO);
326 context()->storage()->FindRegistrationForDocument(
327 net::SimplifyUrlForRequest(url),
328 base::Bind(&DidFindRegistrationForDocument, callback));
331 void ServiceWorkerContextWrapper::GetAllOriginsInfo(
332 const GetUsageInfoCallback& callback) {
333 DCHECK_CURRENTLY_ON(BrowserThread::IO);
334 if (!context_core_.get()) {
335 LOG(ERROR) << "ServiceWorkerContextCore is no longer alive.";
336 BrowserThread::PostTask(
337 BrowserThread::IO,
338 FROM_HERE,
339 base::Bind(callback, std::vector<ServiceWorkerUsageInfo>()));
340 return;
342 context()->storage()->GetAllRegistrations(base::Bind(
343 &ServiceWorkerContextWrapper::DidGetAllRegistrationsForGetAllOrigins,
344 this,
345 callback));
348 void ServiceWorkerContextWrapper::DidGetAllRegistrationsForGetAllOrigins(
349 const GetUsageInfoCallback& callback,
350 const std::vector<ServiceWorkerRegistrationInfo>& registrations) {
351 DCHECK_CURRENTLY_ON(BrowserThread::IO);
352 std::vector<ServiceWorkerUsageInfo> usage_infos;
354 std::map<GURL, ServiceWorkerUsageInfo> origins;
355 for (const auto& registration_info : registrations) {
356 GURL origin = registration_info.pattern.GetOrigin();
358 ServiceWorkerUsageInfo& usage_info = origins[origin];
359 if (usage_info.origin.is_empty())
360 usage_info.origin = origin;
361 usage_info.scopes.push_back(registration_info.pattern);
362 usage_info.total_size_bytes += registration_info.stored_version_size_bytes;
365 for (const auto& origin_info_pair : origins) {
366 usage_infos.push_back(origin_info_pair.second);
368 callback.Run(usage_infos);
371 void ServiceWorkerContextWrapper::DidFindRegistrationForCheckHasServiceWorker(
372 const GURL& other_url,
373 const CheckHasServiceWorkerCallback& callback,
374 ServiceWorkerStatusCode status,
375 const scoped_refptr<ServiceWorkerRegistration>& registration) {
376 DCHECK_CURRENTLY_ON(BrowserThread::IO);
378 if (status != SERVICE_WORKER_OK) {
379 BrowserThread::PostTask(BrowserThread::UI, FROM_HERE,
380 base::Bind(callback, false));
381 return;
384 DCHECK(registration);
385 BrowserThread::PostTask(
386 BrowserThread::UI, FROM_HERE,
387 base::Bind(callback, registration->active_version() &&
388 ServiceWorkerUtils::ScopeMatches(
389 registration->pattern(), other_url)));
392 void ServiceWorkerContextWrapper::DidFindRegistrationForUpdate(
393 ServiceWorkerStatusCode status,
394 const scoped_refptr<ServiceWorkerRegistration>& registration) {
395 DCHECK_CURRENTLY_ON(BrowserThread::IO);
397 if (status != SERVICE_WORKER_OK)
398 return;
399 if (!context_core_.get()) {
400 LOG(ERROR) << "ServiceWorkerContextCore is no longer alive.";
401 return;
403 DCHECK(registration);
404 context_core_->UpdateServiceWorker(registration.get(),
405 true /* force_bypass_cache */);
408 namespace {
409 void StatusCodeToBoolCallbackAdapter(
410 const ServiceWorkerContext::ResultCallback& callback,
411 ServiceWorkerStatusCode code) {
412 callback.Run(code == ServiceWorkerStatusCode::SERVICE_WORKER_OK);
415 void EmptySuccessCallback(bool success) {
417 } // namespace
419 void ServiceWorkerContextWrapper::DeleteForOrigin(
420 const GURL& origin,
421 const ResultCallback& result) {
422 DCHECK_CURRENTLY_ON(BrowserThread::IO);
423 if (!context_core_.get()) {
424 LOG(ERROR) << "ServiceWorkerContextCore is no longer alive.";
425 BrowserThread::PostTask(
426 BrowserThread::IO,
427 FROM_HERE,
428 base::Bind(result, false));
429 return;
431 context()->UnregisterServiceWorkers(
432 origin.GetOrigin(), base::Bind(&StatusCodeToBoolCallbackAdapter, result));
435 void ServiceWorkerContextWrapper::DeleteForOrigin(const GURL& origin) {
436 DeleteForOrigin(origin, base::Bind(&EmptySuccessCallback));
439 void ServiceWorkerContextWrapper::CheckHasServiceWorker(
440 const GURL& url,
441 const GURL& other_url,
442 const CheckHasServiceWorkerCallback& callback) {
443 if (!BrowserThread::CurrentlyOn(BrowserThread::IO)) {
444 BrowserThread::PostTask(
445 BrowserThread::IO, FROM_HERE,
446 base::Bind(&ServiceWorkerContextWrapper::CheckHasServiceWorker, this,
447 url, other_url, callback));
448 return;
450 if (!context_core_.get()) {
451 LOG(ERROR) << "ServiceWorkerContextCore is no longer alive.";
452 BrowserThread::PostTask(BrowserThread::IO, FROM_HERE,
453 base::Bind(callback, false));
454 return;
456 context()->storage()->FindRegistrationForDocument(
457 net::SimplifyUrlForRequest(url),
458 base::Bind(&ServiceWorkerContextWrapper::
459 DidFindRegistrationForCheckHasServiceWorker,
460 this, net::SimplifyUrlForRequest(other_url), callback));
463 ServiceWorkerRegistration* ServiceWorkerContextWrapper::GetLiveRegistration(
464 int64_t registration_id) {
465 DCHECK_CURRENTLY_ON(BrowserThread::IO);
466 if (!context_core_)
467 return nullptr;
468 return context_core_->GetLiveRegistration(registration_id);
471 ServiceWorkerVersion* ServiceWorkerContextWrapper::GetLiveVersion(
472 int64_t version_id) {
473 DCHECK_CURRENTLY_ON(BrowserThread::IO);
474 if (!context_core_)
475 return nullptr;
476 return context_core_->GetLiveVersion(version_id);
479 std::vector<ServiceWorkerRegistrationInfo>
480 ServiceWorkerContextWrapper::GetAllLiveRegistrationInfo() {
481 DCHECK_CURRENTLY_ON(BrowserThread::IO);
482 if (!context_core_)
483 return std::vector<ServiceWorkerRegistrationInfo>();
484 return context_core_->GetAllLiveRegistrationInfo();
487 std::vector<ServiceWorkerVersionInfo>
488 ServiceWorkerContextWrapper::GetAllLiveVersionInfo() {
489 DCHECK_CURRENTLY_ON(BrowserThread::IO);
490 if (!context_core_)
491 return std::vector<ServiceWorkerVersionInfo>();
492 return context_core_->GetAllLiveVersionInfo();
495 void ServiceWorkerContextWrapper::FindRegistrationForDocument(
496 const GURL& document_url,
497 const FindRegistrationCallback& callback) {
498 DCHECK_CURRENTLY_ON(BrowserThread::IO);
499 if (!context_core_) {
500 // FindRegistrationForDocument() can run the callback synchronously.
501 callback.Run(SERVICE_WORKER_ERROR_ABORT, nullptr);
502 return;
504 context_core_->storage()->FindRegistrationForDocument(
505 net::SimplifyUrlForRequest(document_url), callback);
508 void ServiceWorkerContextWrapper::FindRegistrationForId(
509 int64_t registration_id,
510 const GURL& origin,
511 const FindRegistrationCallback& callback) {
512 DCHECK_CURRENTLY_ON(BrowserThread::IO);
513 if (!context_core_) {
514 // FindRegistrationForId() can run the callback synchronously.
515 callback.Run(SERVICE_WORKER_ERROR_ABORT, nullptr);
516 return;
518 context_core_->storage()->FindRegistrationForId(registration_id,
519 origin.GetOrigin(), callback);
522 void ServiceWorkerContextWrapper::GetAllRegistrations(
523 const GetRegistrationsInfosCallback& callback) {
524 DCHECK_CURRENTLY_ON(BrowserThread::IO);
525 if (!context_core_) {
526 RunSoon(base::Bind(callback, std::vector<ServiceWorkerRegistrationInfo>()));
527 return;
529 context_core_->storage()->GetAllRegistrations(callback);
532 void ServiceWorkerContextWrapper::GetRegistrationUserData(
533 int64_t registration_id,
534 const std::string& key,
535 const GetUserDataCallback& callback) {
536 DCHECK_CURRENTLY_ON(BrowserThread::IO);
537 if (!context_core_) {
538 RunSoon(base::Bind(callback, std::string(), SERVICE_WORKER_ERROR_ABORT));
539 return;
541 context_core_->storage()->GetUserData(registration_id, key, callback);
544 void ServiceWorkerContextWrapper::StoreRegistrationUserData(
545 int64_t registration_id,
546 const GURL& origin,
547 const std::string& key,
548 const std::string& data,
549 const StatusCallback& callback) {
550 DCHECK_CURRENTLY_ON(BrowserThread::IO);
551 if (!context_core_) {
552 RunSoon(base::Bind(callback, SERVICE_WORKER_ERROR_ABORT));
553 return;
555 context_core_->storage()->StoreUserData(registration_id, origin.GetOrigin(),
556 key, data, callback);
559 void ServiceWorkerContextWrapper::ClearRegistrationUserData(
560 int64_t registration_id,
561 const std::string& key,
562 const StatusCallback& callback) {
563 DCHECK_CURRENTLY_ON(BrowserThread::IO);
564 if (!context_core_) {
565 RunSoon(base::Bind(callback, SERVICE_WORKER_ERROR_ABORT));
566 return;
568 context_core_->storage()->ClearUserData(registration_id, key, callback);
571 void ServiceWorkerContextWrapper::GetUserDataForAllRegistrations(
572 const std::string& key,
573 const GetUserDataForAllRegistrationsCallback& callback) {
574 DCHECK_CURRENTLY_ON(BrowserThread::IO);
575 if (!context_core_) {
576 RunSoon(base::Bind(callback, std::vector<std::pair<int64_t, std::string>>(),
577 SERVICE_WORKER_ERROR_ABORT));
578 return;
580 context_core_->storage()->GetUserDataForAllRegistrations(key, callback);
583 void ServiceWorkerContextWrapper::AddObserver(
584 ServiceWorkerContextObserver* observer) {
585 observer_list_->AddObserver(observer);
588 void ServiceWorkerContextWrapper::RemoveObserver(
589 ServiceWorkerContextObserver* observer) {
590 observer_list_->RemoveObserver(observer);
593 void ServiceWorkerContextWrapper::InitInternal(
594 const base::FilePath& user_data_directory,
595 scoped_ptr<ServiceWorkerDatabaseTaskManager> database_task_manager,
596 const scoped_refptr<base::SingleThreadTaskRunner>& disk_cache_thread,
597 storage::QuotaManagerProxy* quota_manager_proxy,
598 storage::SpecialStoragePolicy* special_storage_policy) {
599 if (!BrowserThread::CurrentlyOn(BrowserThread::IO)) {
600 BrowserThread::PostTask(
601 BrowserThread::IO,
602 FROM_HERE,
603 base::Bind(&ServiceWorkerContextWrapper::InitInternal,
604 this,
605 user_data_directory,
606 base::Passed(&database_task_manager),
607 disk_cache_thread,
608 make_scoped_refptr(quota_manager_proxy),
609 make_scoped_refptr(special_storage_policy)));
610 return;
612 // TODO(pkasting): Remove ScopedTracker below once crbug.com/477117 is fixed.
613 tracked_objects::ScopedTracker tracking_profile(
614 FROM_HERE_WITH_EXPLICIT_FUNCTION(
615 "477117 ServiceWorkerContextWrapper::InitInternal"));
616 DCHECK(!context_core_);
617 if (quota_manager_proxy) {
618 quota_manager_proxy->RegisterClient(new ServiceWorkerQuotaClient(this));
620 context_core_.reset(new ServiceWorkerContextCore(user_data_directory,
621 database_task_manager.Pass(),
622 disk_cache_thread,
623 quota_manager_proxy,
624 special_storage_policy,
625 observer_list_.get(),
626 this));
629 void ServiceWorkerContextWrapper::ShutdownOnIO() {
630 DCHECK_CURRENTLY_ON(BrowserThread::IO);
631 context_core_.reset();
634 void ServiceWorkerContextWrapper::DidDeleteAndStartOver(
635 ServiceWorkerStatusCode status) {
636 DCHECK_CURRENTLY_ON(BrowserThread::IO);
637 if (status != SERVICE_WORKER_OK) {
638 context_core_.reset();
639 return;
641 context_core_.reset(new ServiceWorkerContextCore(context_core_.get(), this));
642 DVLOG(1) << "Restarted ServiceWorkerContextCore successfully.";
644 observer_list_->Notify(FROM_HERE,
645 &ServiceWorkerContextObserver::OnStorageWiped);
648 ServiceWorkerContextCore* ServiceWorkerContextWrapper::context() {
649 DCHECK_CURRENTLY_ON(BrowserThread::IO);
650 return context_core_.get();
653 } // namespace content