| Index: content/browser/service_worker/service_worker_navigation_handle_core.cc
|
| diff --git a/content/browser/service_worker/service_worker_navigation_handle_core.cc b/content/browser/service_worker/service_worker_navigation_handle_core.cc
|
| new file mode 100644
|
| index 0000000000000000000000000000000000000000..f1dc1eeffd9a59cc421df1e438528a8d6993a726
|
| --- /dev/null
|
| +++ b/content/browser/service_worker/service_worker_navigation_handle_core.cc
|
| @@ -0,0 +1,63 @@
|
| +// Copyright 2015 The Chromium Authors. All rights reserved.
|
| +// Use of this source code is governed by a BSD-style license that can be
|
| +// found in the LICENSE file.
|
| +
|
| +#include "content/browser/service_worker/service_worker_navigation_handle_core.h"
|
| +
|
| +#include "base/bind.h"
|
| +#include "content/browser/service_worker/service_worker_context_core.h"
|
| +#include "content/browser/service_worker/service_worker_context_wrapper.h"
|
| +#include "content/browser/service_worker/service_worker_navigation_handle.h"
|
| +#include "content/browser/service_worker/service_worker_provider_host.h"
|
| +#include "content/common/service_worker/service_worker_types.h"
|
| +#include "content/public/browser/browser_thread.h"
|
| +
|
| +namespace content {
|
| +
|
| +ServiceWorkerNavigationHandleCore::ServiceWorkerNavigationHandleCore(
|
| + base::WeakPtr<ServiceWorkerNavigationHandle> ui_handle,
|
| + ServiceWorkerContextWrapper* context_wrapper)
|
| + : context_wrapper_(context_wrapper), ui_handle_(ui_handle) {
|
| + // The ServiceWorkerNavigationHandleCore is created on the UI thread but
|
| + // should only be accessed from the IO thread afterwards.
|
| + DCHECK_CURRENTLY_ON(BrowserThread::UI);
|
| +}
|
| +
|
| +ServiceWorkerNavigationHandleCore::~ServiceWorkerNavigationHandleCore() {
|
| + DCHECK_CURRENTLY_ON(BrowserThread::IO);
|
| + if (precreated_host_.get() && context_wrapper_->context()) {
|
| + context_wrapper_->context()->RemoveNavigationHandleCore(
|
| + precreated_host_->provider_id());
|
| + }
|
| +}
|
| +
|
| +void ServiceWorkerNavigationHandleCore::DidPreCreateProviderHost(
|
| + scoped_ptr<ServiceWorkerProviderHost> precreated_host) {
|
| + DCHECK_CURRENTLY_ON(BrowserThread::IO);
|
| + DCHECK(precreated_host.get());
|
| + DCHECK(context_wrapper_->context());
|
| +
|
| + precreated_host_ = precreated_host.Pass();
|
| + context_wrapper_->context()->AddNavigationHandleCore(
|
| + precreated_host_->provider_id(), this);
|
| + BrowserThread::PostTask(
|
| + BrowserThread::UI, FROM_HERE,
|
| + base::Bind(
|
| + &ServiceWorkerNavigationHandle::DidCreateServiceWorkerProviderHost,
|
| + ui_handle_, precreated_host_->provider_id()));
|
| +}
|
| +
|
| +scoped_ptr<ServiceWorkerProviderHost>
|
| +ServiceWorkerNavigationHandleCore::RetrievePreCreatedHost() {
|
| + DCHECK_CURRENTLY_ON(BrowserThread::IO);
|
| + DCHECK(precreated_host_);
|
| + // Remove the ServiceWorkerNavigationHandleCore from the list of
|
| + // ServiceWorkerNavigationHandleCores since it will no longer hold a
|
| + // ServiceWorkerProviderHost.
|
| + DCHECK(context_wrapper_->context());
|
| + context_wrapper_->context()->RemoveNavigationHandleCore(
|
| + precreated_host_->provider_id());
|
| + return precreated_host_.Pass();
|
| +}
|
| +
|
| +} // namespace content
|
|
|