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..eb6e2dc1463118359fa4bb46cb39440515b84938 |
--- /dev/null |
+++ b/content/browser/service_worker/service_worker_navigation_handle_core.cc |
@@ -0,0 +1,72 @@ |
+// 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); |
+} |
+ |
+void ServiceWorkerNavigationHandleCore::Destroy() { |
+ DCHECK_CURRENTLY_ON(BrowserThread::IO); |
+ if (precreated_host_.get() && context_wrapper_->context()) { |
+ context_wrapper_->context()->GetNavigationHandleCores().erase( |
+ precreated_host_->provider_id()); |
+ } |
+ delete this; |
+} |
+ |
+void ServiceWorkerNavigationHandleCore::DidPreCreateProviderHost( |
+ scoped_ptr<ServiceWorkerProviderHost> precreated_host) { |
+ DCHECK_CURRENTLY_ON(BrowserThread::IO); |
+ DCHECK(precreated_host.get()); |
+ if (!context_wrapper_->context()) |
kinuko
2015/10/20 14:46:07
could this happen? looks like this could be DCHECK
clamy
2015/10/21 16:33:48
Done.
|
+ return; |
+ |
+ precreated_host_ = precreated_host.Pass(); |
+ auto result = context_wrapper_->context()->GetNavigationHandleCores().insert( |
+ std::pair<int, ServiceWorkerNavigationHandleCore*>( |
+ precreated_host_->provider_id(), this)); |
+ DCHECK(result.second) |
+ << "Inserting a duplicate ServiceWorkerNavigationHandleCore"; |
+ BrowserThread::PostTask( |
+ BrowserThread::UI, FROM_HERE, |
+ base::Bind( |
+ &ServiceWorkerNavigationHandle::DidCreateServiceWorkerProviderHost, |
kinuko
2015/10/20 14:46:07
This part made me feel a bit unsure but looks like
michaeln
2015/10/20 22:12:53
What guarantees that it does?
clamy
2015/10/21 16:33:48
We call that before we start the URLRequest, so th
michaeln
2015/10/21 20:07:28
thnx, got it, NavigationResourceHandler::OnRespons
|
+ 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()->GetNavigationHandleCores().erase( |
+ precreated_host_->provider_id()); |
+ return precreated_host_.Pass(); |
+} |
+ |
+} // namespace content |