Chromium Code Reviews| Index: content/browser/service_worker/service_worker_context_wrapper.cc |
| diff --git a/content/browser/service_worker/service_worker_context_wrapper.cc b/content/browser/service_worker/service_worker_context_wrapper.cc |
| index 0c32d7168594bb9f4070c13c35cdde1da532f790..3b5698839afc4453e9786f5a2a4c4a7388540ddb 100644 |
| --- a/content/browser/service_worker/service_worker_context_wrapper.cc |
| +++ b/content/browser/service_worker/service_worker_context_wrapper.cc |
| @@ -20,6 +20,7 @@ |
| #include "base/single_thread_task_runner.h" |
| #include "base/threading/sequenced_worker_pool.h" |
| #include "base/threading/thread_task_runner_handle.h" |
| +#include "content/browser/renderer_host/render_process_host_impl.h" |
| #include "content/browser/service_worker/service_worker_context_core.h" |
| #include "content/browser/service_worker/service_worker_context_observer.h" |
| #include "content/browser/service_worker/service_worker_process_manager.h" |
| @@ -29,9 +30,11 @@ |
| #include "content/common/service_worker/service_worker_utils.h" |
| #include "content/public/browser/browser_context.h" |
| #include "content/public/browser/browser_thread.h" |
| +#include "content/public/browser/render_process_host.h" |
| #include "net/base/url_util.h" |
| #include "storage/browser/quota/quota_manager_proxy.h" |
| #include "storage/browser/quota/special_storage_policy.h" |
| +#include "third_party/WebKit/public/platform/WebNavigationHintType.h" |
| namespace content { |
| @@ -81,6 +84,22 @@ void SkipWaitingWorkerOnIO( |
| registration->ActivateWaitingVersionWhenReady(); |
| } |
| +ServiceWorkerMetrics::EventType GetNavigationHintEventType( |
| + blink::WebNavigationHintType type) { |
| + switch (type) { |
| + case blink::WebNavigationHintType::LinkMouseDown: |
| + return ServiceWorkerMetrics::EventType::NAVIGATION_HINT_LINK_MOUSE_DOWN; |
| + case blink::WebNavigationHintType::LinkTapUnconfirmed: |
| + return ServiceWorkerMetrics::EventType:: |
| + NAVIGATION_HINT_LINK_TAP_UNCONFIRMED; |
| + case blink::WebNavigationHintType::LinkTapDown: |
| + return ServiceWorkerMetrics::EventType::NAVIGATION_HINT_LINK_TAP_DOWN; |
| + default: |
|
nhiroki
2016/07/25 06:15:13
I'd prefer to list all enum types on switch-statem
horo
2016/07/25 08:24:27
Done.
|
| + NOTREACHED() << "Unexpected navigation hint" << static_cast<int>(type); |
| + return ServiceWorkerMetrics::EventType::UNKNOWN; |
| + } |
| +} |
| + |
| } // namespace |
| void ServiceWorkerContext::AddExcludedHeadersForFetchEvent( |
| @@ -282,6 +301,81 @@ void ServiceWorkerContextWrapper::UpdateRegistration(const GURL& pattern) { |
| this)); |
| } |
| +void ServiceWorkerContextWrapper::StartServiceWorkerForNavigationHint( |
| + const GURL& document_url, |
| + blink::WebNavigationHintType type, |
| + int render_process_id, |
| + const ResultCallback& callback) { |
| + DCHECK_CURRENTLY_ON(BrowserThread::UI); |
| + RenderProcessHost* host = RenderProcessHost::FromID(render_process_id); |
| + if (!host || |
| + !RenderProcessHostImpl::IsSuitableHost(host, host->GetBrowserContext(), |
| + document_url)) { |
| + callback.Run(false); |
| + return; |
| + } |
| + |
| + BrowserThread::PostTask( |
| + BrowserThread::IO, FROM_HERE, |
| + base::Bind( |
| + &ServiceWorkerContextWrapper::DidCheckRenderProcessForNavigationHint, |
| + this, document_url, type, render_process_id, callback)); |
| +} |
| + |
| +void ServiceWorkerContextWrapper::DidCheckRenderProcessForNavigationHint( |
| + const GURL& document_url, |
| + blink::WebNavigationHintType type, |
| + int render_process_id, |
| + const ResultCallback& callback) { |
| + DCHECK_CURRENTLY_ON(BrowserThread::IO); |
| + if (!context_core_) { |
| + BrowserThread::PostTask(BrowserThread::UI, FROM_HERE, |
| + base::Bind(callback, false)); |
| + return; |
| + } |
| + context_core_->storage()->FindRegistrationForDocument( |
|
nhiroki
2016/07/25 06:15:13
ServiceWorkerContextWrapper::FindReadyRegistration
horo
2016/07/25 08:24:26
Done.
|
| + document_url, |
| + base::Bind( |
| + &ServiceWorkerContextWrapper::DidFindRegistrationForNavigationHint, |
| + this, type, render_process_id, callback)); |
| +} |
| + |
| +void ServiceWorkerContextWrapper::DidFindRegistrationForNavigationHint( |
| + blink::WebNavigationHintType type, |
| + int render_process_id, |
| + const ResultCallback& callback, |
| + ServiceWorkerStatusCode status, |
| + const scoped_refptr<ServiceWorkerRegistration>& registration) { |
| + DCHECK_CURRENTLY_ON(BrowserThread::IO); |
| + if (status != SERVICE_WORKER_OK || !registration->active_version()) { |
| + BrowserThread::PostTask(BrowserThread::UI, FROM_HERE, |
| + base::Bind(callback, false)); |
| + return; |
| + } |
| + |
| + context_core_->process_manager()->AddProcessReferenceToPattern( |
|
nhiroki
2016/07/25 06:15:13
Let me check my understanding... we add a process
horo
2016/07/25 08:24:26
Done.
|
| + registration->pattern(), render_process_id); |
| + |
| + registration->active_version()->StartWorker( |
| + GetNavigationHintEventType(type), |
| + base::Bind( |
| + &ServiceWorkerContextWrapper::DidStartServiceWorkerForNavigationHint, |
| + this, registration->pattern(), render_process_id, callback)); |
| +} |
| + |
| +void ServiceWorkerContextWrapper::DidStartServiceWorkerForNavigationHint( |
| + const GURL& pattern, |
| + int render_process_id, |
| + const ResultCallback& callback, |
| + ServiceWorkerStatusCode code) { |
| + DCHECK_CURRENTLY_ON(BrowserThread::IO); |
| + |
| + context_core_->process_manager()->RemoveProcessReferenceFromPattern( |
| + pattern, render_process_id); |
| + BrowserThread::PostTask(BrowserThread::UI, FROM_HERE, |
| + base::Bind(callback, code == SERVICE_WORKER_OK)); |
| +} |
| + |
| void ServiceWorkerContextWrapper::StartServiceWorker( |
| const GURL& pattern, |
| const StatusCallback& callback) { |