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_PROVIDER_CONTEXT_H_
6 #define CONTENT_CHILD_SERVICE_WORKER_SERVICE_WORKER_PROVIDER_CONTEXT_H_
11 #include "base/memory/ref_counted.h"
12 #include "base/sequenced_task_runner_helpers.h"
13 #include "base/synchronization/lock.h"
14 #include "content/common/service_worker/service_worker_types.h"
17 class MessageLoopProxy
;
26 class ServiceWorkerHandleReference
;
27 class ServiceWorkerRegistrationHandleReference
;
28 struct ServiceWorkerProviderContextDeleter
;
29 class ThreadSafeSender
;
31 // An instance of this class holds document-related information (e.g.
32 // .controller). Created and destructed on the main thread.
33 // TODO(kinuko): To support navigator.serviceWorker in dedicated workers
34 // this needs to be RefCountedThreadSafe and .controller info needs to be
35 // handled in a thread-safe manner (e.g. by a lock etc).
36 class ServiceWorkerProviderContext
37 : public base::RefCounted
<ServiceWorkerProviderContext
> {
39 explicit ServiceWorkerProviderContext(int provider_id
);
41 // Called from ServiceWorkerDispatcher.
42 void OnAssociateRegistration(const ServiceWorkerRegistrationObjectInfo
& info
,
43 const ServiceWorkerVersionAttributes
& attrs
);
44 void OnDisassociateRegistration();
45 void OnServiceWorkerStateChanged(int handle_id
,
46 blink::WebServiceWorkerState state
);
47 void OnSetInstallingServiceWorker(int registration_handle_id
,
48 const ServiceWorkerObjectInfo
& info
);
49 void OnSetWaitingServiceWorker(int registration_handle_id
,
50 const ServiceWorkerObjectInfo
& info
);
51 void OnSetActiveServiceWorker(int registration_handle_id
,
52 const ServiceWorkerObjectInfo
& info
);
53 void OnSetControllerServiceWorker(int registration_handle_id
,
54 const ServiceWorkerObjectInfo
& info
);
56 int provider_id() const { return provider_id_
; }
58 ServiceWorkerHandleReference
* installing();
59 ServiceWorkerHandleReference
* waiting();
60 ServiceWorkerHandleReference
* active();
61 ServiceWorkerHandleReference
* controller();
62 ServiceWorkerRegistrationHandleReference
* registration();
64 ServiceWorkerVersionAttributes
GetVersionAttributes();
66 // Gets the handle ID of the installing Service Worker, or
67 // kInvalidServiceWorkerHandleId if the provider does not have a
68 // installing Service Worker.
69 int installing_handle_id() const;
71 // Gets the handle ID of the waiting Service Worker, or
72 // kInvalidServiceWorkerHandleId if the provider does not have a
73 // waiting Service Worker.
74 int waiting_handle_id() const;
76 // Gets the handle ID of the active Service Worker, or
77 // kInvalidServiceWorkerHandleId if the provider does not have an active
79 int active_handle_id() const;
81 // Gets the handle ID of the controller Service Worker, or
82 // kInvalidServiceWorkerHandleId if the provider is not controlled
83 // by a Service Worker.
84 int controller_handle_id() const;
86 // Gets the handle ID of the associated registration, or
87 // kInvalidRegistrationHandleId if the provider is not associated with any
89 int registration_handle_id() const;
92 friend class base::RefCounted
<ServiceWorkerProviderContext
>;
93 ~ServiceWorkerProviderContext();
95 bool IsAssociatedWithRegistration(int registration_handle_id
) const;
97 const int provider_id_
;
98 scoped_refptr
<base::MessageLoopProxy
> main_thread_loop_proxy_
;
99 scoped_refptr
<ThreadSafeSender
> thread_safe_sender_
;
100 scoped_ptr
<ServiceWorkerHandleReference
> installing_
;
101 scoped_ptr
<ServiceWorkerHandleReference
> waiting_
;
102 scoped_ptr
<ServiceWorkerHandleReference
> active_
;
103 scoped_ptr
<ServiceWorkerHandleReference
> controller_
;
104 scoped_ptr
<ServiceWorkerRegistrationHandleReference
> registration_
;
106 DISALLOW_COPY_AND_ASSIGN(ServiceWorkerProviderContext
);
109 } // namespace content
111 #endif // CONTENT_CHILD_SERVICE_WORKER_SERVICE_WORKER_PROVIDER_CONTEXT_H_