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.
5 #ifndef CONTENT_CHILD_SERVICE_WORKER_SERVICE_WORKER_HANDLE_REFERENCE_H_
6 #define CONTENT_CHILD_SERVICE_WORKER_SERVICE_WORKER_HANDLE_REFERENCE_H_
8 #include "base/memory/ref_counted.h"
9 #include "base/memory/scoped_ptr.h"
10 #include "content/common/service_worker/service_worker_types.h"
14 class ThreadSafeSender
;
16 // Represents an interprocess reference to ServiceWorkerHandle managed in the
17 // browser process. The constructor and destructor sends a message to increment
18 // or decrement the reference count to the browser process.
19 class ServiceWorkerHandleReference
{
21 // Creates a new ServiceWorkerHandleReference and increments ref-count.
22 static scoped_ptr
<ServiceWorkerHandleReference
> Create(
23 const ServiceWorkerObjectInfo
& info
,
24 ThreadSafeSender
* sender
);
26 // Creates a new ServiceWorkerHandleReference by adopting a ref-count.
27 static scoped_ptr
<ServiceWorkerHandleReference
> Adopt(
28 const ServiceWorkerObjectInfo
& info
,
29 ThreadSafeSender
* sender
);
31 ~ServiceWorkerHandleReference();
33 const ServiceWorkerObjectInfo
& info() const { return info_
; }
34 int handle_id() const { return info_
.handle_id
; }
35 const GURL
& url() const { return info_
.url
; }
36 blink::WebServiceWorkerState
state() const { return info_
.state
; }
37 void set_state(blink::WebServiceWorkerState state
) { info_
.state
= state
; }
38 int64
version_id() const { return info_
.version_id
; }
41 ServiceWorkerHandleReference(const ServiceWorkerObjectInfo
& info
,
42 ThreadSafeSender
* sender
,
43 bool increment_ref_in_ctor
);
44 ServiceWorkerObjectInfo info_
;
45 scoped_refptr
<ThreadSafeSender
> sender_
;
46 DISALLOW_COPY_AND_ASSIGN(ServiceWorkerHandleReference
);
49 } // namespace content
51 #endif // CONTENT_CHILD_SERVICE_WORKER_SERVICE_WORKER_HANDLE_REFERENCE_H_