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"
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"
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
));
70 BrowserThread::PostTask(BrowserThread::UI
, FROM_HERE
,
71 base::Bind(callback
, SERVICE_WORKER_ERROR_NOT_FOUND
));
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(),
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())
101 return handler
->context()->wrapper_
;
104 ServiceWorkerContextWrapper::ServiceWorkerContextWrapper(
105 BrowserContext
* browser_context
)
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(),
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(
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
153 LOG(ERROR
) << "ServiceWorkerContextCore is no longer alive.";
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(
180 base::Bind(continuation
, status
== SERVICE_WORKER_OK
));
183 void ServiceWorkerContextWrapper::RegisterServiceWorker(
185 const GURL
& script_url
,
186 const ResultCallback
& continuation
) {
187 if (!BrowserThread::CurrentlyOn(BrowserThread::IO
)) {
188 BrowserThread::PostTask(
191 base::Bind(&ServiceWorkerContextWrapper::RegisterServiceWorker
,
198 if (!context_core_
.get()) {
199 LOG(ERROR
) << "ServiceWorkerContextCore is no longer alive.";
200 BrowserThread::PostTask(
203 base::Bind(continuation
, false));
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(
219 base::Bind(continuation
, status
== SERVICE_WORKER_OK
));
222 void ServiceWorkerContextWrapper::UnregisterServiceWorker(
224 const ResultCallback
& continuation
) {
225 if (!BrowserThread::CurrentlyOn(BrowserThread::IO
)) {
226 BrowserThread::PostTask(
229 base::Bind(&ServiceWorkerContextWrapper::UnregisterServiceWorker
,
235 if (!context_core_
.get()) {
236 LOG(ERROR
) << "ServiceWorkerContextCore is no longer alive.";
237 BrowserThread::PostTask(
240 base::Bind(continuation
, false));
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,
257 if (!context_core_
.get()) {
258 LOG(ERROR
) << "ServiceWorkerContextCore is no longer alive.";
261 context_core_
->storage()->FindRegistrationForPattern(
262 net::SimplifyUrlForRequest(pattern
),
263 base::Bind(&ServiceWorkerContextWrapper::DidFindRegistrationForUpdate
,
267 void ServiceWorkerContextWrapper::StartServiceWorker(
269 const StatusCallback
& callback
) {
270 if (!BrowserThread::CurrentlyOn(BrowserThread::IO
)) {
271 BrowserThread::PostTask(
272 BrowserThread::IO
, FROM_HERE
,
273 base::Bind(&ServiceWorkerContextWrapper::StartServiceWorker
, this,
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
));
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,
296 if (!context_core_
.get()) {
297 LOG(ERROR
) << "ServiceWorkerContextCore is no longer alive.";
300 ServiceWorkerVersion
* version
= GetLiveVersion(version_id
);
301 if (!version
|| version
->skip_waiting())
303 ServiceWorkerRegistration
* registration
=
304 GetLiveRegistration(version
->registration_id());
305 if (!registration
|| version
!= registration
->waiting_version())
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(
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(
339 base::Bind(callback
, std::vector
<ServiceWorkerUsageInfo
>()));
342 context()->storage()->GetAllRegistrations(base::Bind(
343 &ServiceWorkerContextWrapper::DidGetAllRegistrationsForGetAllOrigins
,
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));
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
)
399 if (!context_core_
.get()) {
400 LOG(ERROR
) << "ServiceWorkerContextCore is no longer alive.";
403 DCHECK(registration
);
404 context_core_
->UpdateServiceWorker(registration
.get(),
405 true /* force_bypass_cache */);
409 void StatusCodeToBoolCallbackAdapter(
410 const ServiceWorkerContext::ResultCallback
& callback
,
411 ServiceWorkerStatusCode code
) {
412 callback
.Run(code
== ServiceWorkerStatusCode::SERVICE_WORKER_OK
);
415 void EmptySuccessCallback(bool success
) {
419 void ServiceWorkerContextWrapper::DeleteForOrigin(
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(
428 base::Bind(result
, false));
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(
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
));
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));
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
);
468 return context_core_
->GetLiveRegistration(registration_id
);
471 ServiceWorkerVersion
* ServiceWorkerContextWrapper::GetLiveVersion(
472 int64_t version_id
) {
473 DCHECK_CURRENTLY_ON(BrowserThread::IO
);
476 return context_core_
->GetLiveVersion(version_id
);
479 std::vector
<ServiceWorkerRegistrationInfo
>
480 ServiceWorkerContextWrapper::GetAllLiveRegistrationInfo() {
481 DCHECK_CURRENTLY_ON(BrowserThread::IO
);
483 return std::vector
<ServiceWorkerRegistrationInfo
>();
484 return context_core_
->GetAllLiveRegistrationInfo();
487 std::vector
<ServiceWorkerVersionInfo
>
488 ServiceWorkerContextWrapper::GetAllLiveVersionInfo() {
489 DCHECK_CURRENTLY_ON(BrowserThread::IO
);
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);
504 context_core_
->storage()->FindRegistrationForDocument(
505 net::SimplifyUrlForRequest(document_url
), callback
);
508 void ServiceWorkerContextWrapper::FindRegistrationForId(
509 int64_t registration_id
,
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);
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
>()));
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
));
541 context_core_
->storage()->GetUserData(registration_id
, key
, callback
);
544 void ServiceWorkerContextWrapper::StoreRegistrationUserData(
545 int64_t registration_id
,
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
));
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
));
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
));
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(
603 base::Bind(&ServiceWorkerContextWrapper::InitInternal
,
606 base::Passed(&database_task_manager
),
608 make_scoped_refptr(quota_manager_proxy
),
609 make_scoped_refptr(special_storage_policy
)));
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(),
624 special_storage_policy
,
625 observer_list_
.get(),
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();
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