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 // Automatically increments and decrements ServiceWorkerHandle's ref-count
17 // (in the browser side) in ctor and dtor.
18 class ServiceWorkerHandleReference
{
20 // Creates a new ServiceWorkerHandleReference and increments ref-count.
21 static scoped_ptr
<ServiceWorkerHandleReference
> Create(
22 const ServiceWorkerObjectInfo
& info
,
23 ThreadSafeSender
* sender
);
25 // Creates a new ServiceWorkerHandleReference by adopting a
26 // ref-count. ServiceWorkerHandleReferences created this way must
28 // ServiceWorkerDispatcherHost::RegisterServiceWorkerHandle call on
30 static scoped_ptr
<ServiceWorkerHandleReference
> Adopt(
31 const ServiceWorkerObjectInfo
& info
,
32 ThreadSafeSender
* sender
);
34 ~ServiceWorkerHandleReference();
36 const ServiceWorkerObjectInfo
& info() const { return info_
; }
37 int handle_id() const { return info_
.handle_id
; }
38 const GURL
& scope() const { return info_
.scope
; }
39 const GURL
& url() const { return info_
.url
; }
40 blink::WebServiceWorkerState
state() const { return info_
.state
; }
41 void set_state(blink::WebServiceWorkerState state
) { info_
.state
= state
; }
42 int64
version_id() const { return info_
.version_id
; }
45 ServiceWorkerHandleReference(const ServiceWorkerObjectInfo
& info
,
46 ThreadSafeSender
* sender
,
47 bool increment_ref_in_ctor
);
48 ServiceWorkerObjectInfo info_
;
49 scoped_refptr
<ThreadSafeSender
> sender_
;
50 DISALLOW_COPY_AND_ASSIGN(ServiceWorkerHandleReference
);
53 } // namespace content
55 #endif // CONTENT_CHILD_SERVICE_WORKER_SERVICE_WORKER_HANDLE_REFERENCE_H_