Commit 21d4e036 authored by nhiroki's avatar nhiroki Committed by Commit bot

ServiceWorker: Make GetOrCreateRegistrationHandle for refactoring

BUG=399533
TEST=n/a (no behavioral change)
NOTRY=true

Review URL: https://codereview.chromium.org/552693002

Cr-Commit-Position: refs/heads/master@{#293708}
parent 820765f8
......@@ -169,6 +169,25 @@ bool ServiceWorkerDispatcherHost::Send(IPC::Message* message) {
return true;
}
ServiceWorkerRegistrationHandle*
ServiceWorkerDispatcherHost::GetOrCreateRegistrationHandle(
int provider_id,
ServiceWorkerRegistration* registration) {
ServiceWorkerRegistrationHandle* handle =
FindRegistrationHandle(provider_id, registration->id());
if (handle) {
handle->IncrementRefCount();
return handle;
}
scoped_ptr<ServiceWorkerRegistrationHandle> new_handle(
new ServiceWorkerRegistrationHandle(
GetContext()->AsWeakPtr(), this, provider_id, registration));
handle = new_handle.get();
RegisterServiceWorkerRegistrationHandle(new_handle.Pass());
return handle;
}
void ServiceWorkerDispatcherHost::RegisterServiceWorkerHandle(
scoped_ptr<ServiceWorkerHandle> handle) {
int handle_id = handle->handle_id();
......@@ -391,19 +410,7 @@ void ServiceWorkerDispatcherHost::RegistrationComplete(
DCHECK(registration);
ServiceWorkerRegistrationHandle* handle =
FindRegistrationHandle(provider_id, registration_id);
ServiceWorkerRegistrationObjectInfo info;
if (handle) {
handle->IncrementRefCount();
info = handle->GetObjectInfo();
} else {
scoped_ptr<ServiceWorkerRegistrationHandle> new_handle(
new ServiceWorkerRegistrationHandle(
GetContext()->AsWeakPtr(), this, provider_id, registration));
info = new_handle->GetObjectInfo();
handle = new_handle.get();
RegisterServiceWorkerRegistrationHandle(new_handle.Pass());
}
GetOrCreateRegistrationHandle(provider_id, registration);
ServiceWorkerVersionAttributes attrs;
attrs.installing = handle->CreateServiceWorkerHandleAndPass(
......@@ -414,7 +421,7 @@ void ServiceWorkerDispatcherHost::RegistrationComplete(
registration->active_version());
Send(new ServiceWorkerMsg_ServiceWorkerRegistered(
thread_id, request_id, info, attrs));
thread_id, request_id, handle->GetObjectInfo(), attrs));
TRACE_EVENT_ASYNC_END2("ServiceWorker",
"ServiceWorkerDispatcherHost::RegisterServiceWorker",
request_id,
......
......@@ -47,6 +47,12 @@ class CONTENT_EXPORT ServiceWorkerDispatcherHost : public BrowserMessageFilter {
// be destroyed.
virtual bool Send(IPC::Message* message) OVERRIDE;
// Returns the existing registration handle whose reference count is
// incremented or newly created one if it doesn't exist.
ServiceWorkerRegistrationHandle* GetOrCreateRegistrationHandle(
int provider_id,
ServiceWorkerRegistration* registration);
void RegisterServiceWorkerHandle(scoped_ptr<ServiceWorkerHandle> handle);
void RegisterServiceWorkerRegistrationHandle(
scoped_ptr<ServiceWorkerRegistrationHandle> handle);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment