Index: content/child/service_worker/scoped_service_worker_reference.cc |
diff --git a/content/child/service_worker/scoped_service_worker_reference.cc b/content/child/service_worker/scoped_service_worker_reference.cc |
new file mode 100644 |
index 0000000000000000000000000000000000000000..0f626782fc75425eb5fb19cc5e9d83eeadb69fe5 |
--- /dev/null |
+++ b/content/child/service_worker/scoped_service_worker_reference.cc |
@@ -0,0 +1,50 @@ |
+// 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/scoped_service_worker_reference.h" |
+ |
+#include "content/child/thread_safe_sender.h" |
+#include "content/common/service_worker/service_worker_messages.h" |
+ |
+namespace content { |
+ |
+scoped_ptr<ScopedServiceWorkerReference> |
+ScopedServiceWorkerReference::Create( |
+ const ServiceWorkerObjectInfo& info, |
+ ThreadSafeSender* sender) { |
+ DCHECK(sender); |
+ return make_scoped_ptr(new ScopedServiceWorkerReference(info, sender, true)); |
+} |
+ |
+scoped_ptr<ScopedServiceWorkerReference> |
+ScopedServiceWorkerReference::CreateForDeleter( |
+ const ServiceWorkerObjectInfo& info, |
+ ThreadSafeSender* sender) { |
+ DCHECK(sender); |
+ return make_scoped_ptr(new ScopedServiceWorkerReference(info, sender, false)); |
+} |
+ |
+ScopedServiceWorkerReference::ScopedServiceWorkerReference( |
+ const ServiceWorkerObjectInfo& info, |
+ ThreadSafeSender* sender, |
+ bool increment_ref_in_ctor) |
+ : info_(info), |
+ sender_(sender) { |
+ if (increment_ref_in_ctor && |
+ info_.handle_id != kInvalidServiceWorkerHandleId) { |
+ sender_->Send( |
+ new ServiceWorkerHostMsg_IncrementServiceWorkerRefCount( |
+ info_.handle_id)); |
+ } |
+} |
+ |
+ScopedServiceWorkerReference::~ScopedServiceWorkerReference() { |
+ if (info_.handle_id != kInvalidServiceWorkerHandleId) { |
+ sender_->Send( |
+ new ServiceWorkerHostMsg_DecrementServiceWorkerRefCount( |
+ info_.handle_id)); |
+ } |
+} |
+ |
+} // namespace content |