1 // Copyright 2014 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4
5 #include "content/child/service_worker/service_worker_handle_reference.h"
6
7 #include "content/child/thread_safe_sender.h"
8 #include "content/common/service_worker/service_worker_messages.h"
9
10 namespace content {
11
12 scoped_ptr<ServiceWorkerHandleReference>
Create(const ServiceWorkerObjectInfo & info,ThreadSafeSender * sender)13 ServiceWorkerHandleReference::Create(
14 const ServiceWorkerObjectInfo& info,
15 ThreadSafeSender* sender) {
16 DCHECK(sender);
17 return make_scoped_ptr(new ServiceWorkerHandleReference(info, sender, true));
18 }
19
Adopt(const ServiceWorkerObjectInfo & info,ThreadSafeSender * sender)20 scoped_ptr<ServiceWorkerHandleReference> ServiceWorkerHandleReference::Adopt(
21 const ServiceWorkerObjectInfo& info,
22 ThreadSafeSender* sender) {
23 DCHECK(sender);
24 return make_scoped_ptr(new ServiceWorkerHandleReference(info, sender, false));
25 }
26
ServiceWorkerHandleReference(const ServiceWorkerObjectInfo & info,ThreadSafeSender * sender,bool increment_ref_in_ctor)27 ServiceWorkerHandleReference::ServiceWorkerHandleReference(
28 const ServiceWorkerObjectInfo& info,
29 ThreadSafeSender* sender,
30 bool increment_ref_in_ctor)
31 : info_(info),
32 sender_(sender) {
33 if (increment_ref_in_ctor &&
34 info_.handle_id != kInvalidServiceWorkerHandleId) {
35 sender_->Send(
36 new ServiceWorkerHostMsg_IncrementServiceWorkerRefCount(
37 info_.handle_id));
38 }
39 }
40
~ServiceWorkerHandleReference()41 ServiceWorkerHandleReference::~ServiceWorkerHandleReference() {
42 if (info_.handle_id != kInvalidServiceWorkerHandleId) {
43 sender_->Send(
44 new ServiceWorkerHostMsg_DecrementServiceWorkerRefCount(
45 info_.handle_id));
46 }
47 }
48
49 } // namespace content
50