Chromium Code Reviews| Index: content/child/service_worker/service_worker_registration_handle_reference.cc |
| diff --git a/content/child/service_worker/service_worker_registration_handle_reference.cc b/content/child/service_worker/service_worker_registration_handle_reference.cc |
| new file mode 100644 |
| index 0000000000000000000000000000000000000000..11b48e8c90ddea7baf3442c37f040e55bb165ed5 |
| --- /dev/null |
| +++ b/content/child/service_worker/service_worker_registration_handle_reference.cc |
| @@ -0,0 +1,57 @@ |
| +// Copyright 2014 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/child/service_worker/service_worker_registration_handle_reference.h" |
| + |
| +#include "content/child/thread_safe_sender.h" |
| +#include "content/common/service_worker/service_worker_messages.h" |
| +#include "content/common/service_worker/service_worker_types.h" |
| + |
| +namespace content { |
| + |
| +scoped_ptr<ServiceWorkerRegistrationHandleReference> |
| +ServiceWorkerRegistrationHandleReference::Create( |
| + int registration_handle_id, |
| + const ServiceWorkerObjectInfo& info, |
| + ThreadSafeSender* sender) { |
| + DCHECK(sender); |
| + return make_scoped_ptr(new ServiceWorkerRegistrationHandleReference( |
| + registration_handle_id, info, sender, true)); |
| +} |
| + |
| +scoped_ptr<ServiceWorkerRegistrationHandleReference> |
| +ServiceWorkerRegistrationHandleReference::Adopt( |
| + int registration_handle_id, |
| + const ServiceWorkerObjectInfo& info, |
| + ThreadSafeSender* sender) { |
| + DCHECK(sender); |
| + return make_scoped_ptr(new ServiceWorkerRegistrationHandleReference( |
| + registration_handle_id, info, sender, false)); |
| +} |
| + |
| +ServiceWorkerRegistrationHandleReference:: |
| +ServiceWorkerRegistrationHandleReference( |
| + int registration_handle_id, |
| + const ServiceWorkerObjectInfo& info, |
| + ThreadSafeSender* sender, |
| + bool increment_ref_in_ctor) |
| + : handle_id_(registration_handle_id), |
| + scope_(info.scope), |
| + sender_(sender) { |
| + if (increment_ref_in_ctor && |
| + handle_id_ != kInvalidServiceWorkerRegistrationHandleId) { |
|
michaeln
2014/08/13 04:18:17
do we need an instance when handled_id_ is kInvali
nhiroki
2014/08/13 13:15:05
I don't think we need to make an instance for kInv
|
| + sender_->Send( |
| + new ServiceWorkerHostMsg_IncrementRegistrationRefCount(handle_id_)); |
| + } |
| +} |
| + |
| +ServiceWorkerRegistrationHandleReference:: |
| +~ServiceWorkerRegistrationHandleReference() { |
| + if (handle_id_ != kInvalidServiceWorkerRegistrationHandleId) { |
| + sender_->Send( |
| + new ServiceWorkerHostMsg_DecrementRegistrationRefCount(handle_id_)); |
| + } |
| +} |
| + |
| +} // namespace content |