16e8cce623b6e4fe0c9e4af605d675dd9d0338c38Torne (Richard Coles)// Copyright 2014 The Chromium Authors. All rights reserved. 26e8cce623b6e4fe0c9e4af605d675dd9d0338c38Torne (Richard Coles)// Use of this source code is governed by a BSD-style license that can be 36e8cce623b6e4fe0c9e4af605d675dd9d0338c38Torne (Richard Coles)// found in the LICENSE file. 46e8cce623b6e4fe0c9e4af605d675dd9d0338c38Torne (Richard Coles) 56e8cce623b6e4fe0c9e4af605d675dd9d0338c38Torne (Richard Coles)#include "content/child/service_worker/service_worker_registration_handle_reference.h" 66e8cce623b6e4fe0c9e4af605d675dd9d0338c38Torne (Richard Coles) 76e8cce623b6e4fe0c9e4af605d675dd9d0338c38Torne (Richard Coles)#include "content/child/thread_safe_sender.h" 86e8cce623b6e4fe0c9e4af605d675dd9d0338c38Torne (Richard Coles)#include "content/common/service_worker/service_worker_messages.h" 96e8cce623b6e4fe0c9e4af605d675dd9d0338c38Torne (Richard Coles) 106e8cce623b6e4fe0c9e4af605d675dd9d0338c38Torne (Richard Coles)namespace content { 116e8cce623b6e4fe0c9e4af605d675dd9d0338c38Torne (Richard Coles) 126e8cce623b6e4fe0c9e4af605d675dd9d0338c38Torne (Richard Coles)scoped_ptr<ServiceWorkerRegistrationHandleReference> 136e8cce623b6e4fe0c9e4af605d675dd9d0338c38Torne (Richard Coles)ServiceWorkerRegistrationHandleReference::Create( 1403b57e008b61dfcb1fbad3aea950ae0e001748b0Torne (Richard Coles) const ServiceWorkerRegistrationObjectInfo& info, 156e8cce623b6e4fe0c9e4af605d675dd9d0338c38Torne (Richard Coles) ThreadSafeSender* sender) { 166e8cce623b6e4fe0c9e4af605d675dd9d0338c38Torne (Richard Coles) return make_scoped_ptr(new ServiceWorkerRegistrationHandleReference( 1703b57e008b61dfcb1fbad3aea950ae0e001748b0Torne (Richard Coles) info, sender, true)); 186e8cce623b6e4fe0c9e4af605d675dd9d0338c38Torne (Richard Coles)} 196e8cce623b6e4fe0c9e4af605d675dd9d0338c38Torne (Richard Coles) 206e8cce623b6e4fe0c9e4af605d675dd9d0338c38Torne (Richard Coles)scoped_ptr<ServiceWorkerRegistrationHandleReference> 216e8cce623b6e4fe0c9e4af605d675dd9d0338c38Torne (Richard Coles)ServiceWorkerRegistrationHandleReference::Adopt( 2203b57e008b61dfcb1fbad3aea950ae0e001748b0Torne (Richard Coles) const ServiceWorkerRegistrationObjectInfo& info, 236e8cce623b6e4fe0c9e4af605d675dd9d0338c38Torne (Richard Coles) ThreadSafeSender* sender) { 246e8cce623b6e4fe0c9e4af605d675dd9d0338c38Torne (Richard Coles) return make_scoped_ptr(new ServiceWorkerRegistrationHandleReference( 2503b57e008b61dfcb1fbad3aea950ae0e001748b0Torne (Richard Coles) info, sender, false)); 266e8cce623b6e4fe0c9e4af605d675dd9d0338c38Torne (Richard Coles)} 276e8cce623b6e4fe0c9e4af605d675dd9d0338c38Torne (Richard Coles) 286e8cce623b6e4fe0c9e4af605d675dd9d0338c38Torne (Richard Coles)ServiceWorkerRegistrationHandleReference:: 296e8cce623b6e4fe0c9e4af605d675dd9d0338c38Torne (Richard Coles)ServiceWorkerRegistrationHandleReference( 3003b57e008b61dfcb1fbad3aea950ae0e001748b0Torne (Richard Coles) const ServiceWorkerRegistrationObjectInfo& info, 316e8cce623b6e4fe0c9e4af605d675dd9d0338c38Torne (Richard Coles) ThreadSafeSender* sender, 326e8cce623b6e4fe0c9e4af605d675dd9d0338c38Torne (Richard Coles) bool increment_ref_in_ctor) 3303b57e008b61dfcb1fbad3aea950ae0e001748b0Torne (Richard Coles) : info_(info), 346e8cce623b6e4fe0c9e4af605d675dd9d0338c38Torne (Richard Coles) sender_(sender) { 3503b57e008b61dfcb1fbad3aea950ae0e001748b0Torne (Richard Coles) DCHECK_NE(kInvalidServiceWorkerRegistrationHandleId, info_.handle_id); 361320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci DCHECK(sender_.get()); 376e8cce623b6e4fe0c9e4af605d675dd9d0338c38Torne (Richard Coles) if (increment_ref_in_ctor) 386e8cce623b6e4fe0c9e4af605d675dd9d0338c38Torne (Richard Coles) return; 396e8cce623b6e4fe0c9e4af605d675dd9d0338c38Torne (Richard Coles) sender_->Send( 4003b57e008b61dfcb1fbad3aea950ae0e001748b0Torne (Richard Coles) new ServiceWorkerHostMsg_IncrementRegistrationRefCount(info_.handle_id)); 416e8cce623b6e4fe0c9e4af605d675dd9d0338c38Torne (Richard Coles)} 426e8cce623b6e4fe0c9e4af605d675dd9d0338c38Torne (Richard Coles) 436e8cce623b6e4fe0c9e4af605d675dd9d0338c38Torne (Richard Coles)ServiceWorkerRegistrationHandleReference:: 446e8cce623b6e4fe0c9e4af605d675dd9d0338c38Torne (Richard Coles)~ServiceWorkerRegistrationHandleReference() { 456e8cce623b6e4fe0c9e4af605d675dd9d0338c38Torne (Richard Coles) sender_->Send( 4603b57e008b61dfcb1fbad3aea950ae0e001748b0Torne (Richard Coles) new ServiceWorkerHostMsg_DecrementRegistrationRefCount(info_.handle_id)); 476e8cce623b6e4fe0c9e4af605d675dd9d0338c38Torne (Richard Coles)} 486e8cce623b6e4fe0c9e4af605d675dd9d0338c38Torne (Richard Coles) 496e8cce623b6e4fe0c9e4af605d675dd9d0338c38Torne (Richard Coles)} // namespace content 50