Fix link in German terms of service.
[chromium-blink-merge.git] / content / child / service_worker / service_worker_provider_context.h
blob8f8f1b87d21c6cc56a6aaed9a39d7ea91c49a03e
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_
8 #include <set>
9 #include <vector>
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"
16 namespace base {
17 class SingleThreadTaskRunner;
20 namespace IPC {
21 class Message;
24 namespace content {
26 class ServiceWorkerHandleReference;
27 class ServiceWorkerRegistrationHandleReference;
28 struct ServiceWorkerProviderContextDeleter;
29 class ThreadSafeSender;
31 // An instance of this class holds information related to Document/Worker.
32 // Created and destructed on the main thread. Some functions can be called
33 // on the worker thread (eg. GetVersionAttributes).
34 class ServiceWorkerProviderContext
35 : public base::RefCountedThreadSafe<ServiceWorkerProviderContext,
36 ServiceWorkerProviderContextDeleter> {
37 public:
38 explicit ServiceWorkerProviderContext(int provider_id);
40 // Called from ServiceWorkerDispatcher.
41 void OnAssociateRegistration(const ServiceWorkerRegistrationObjectInfo& info,
42 const ServiceWorkerVersionAttributes& attrs);
43 void OnDisassociateRegistration();
44 void OnServiceWorkerStateChanged(int handle_id,
45 blink::WebServiceWorkerState state);
46 void OnSetControllerServiceWorker(const ServiceWorkerObjectInfo& info);
48 int provider_id() const { return provider_id_; }
50 ServiceWorkerHandleReference* controller();
52 bool GetRegistrationInfoAndVersionAttributes(
53 ServiceWorkerRegistrationObjectInfo* info,
54 ServiceWorkerVersionAttributes* attrs);
55 void SetVersionAttributes(ChangedVersionAttributesMask mask,
56 const ServiceWorkerVersionAttributes& attrs);
58 // Gets the handle ID of the installing Service Worker, or
59 // kInvalidServiceWorkerHandleId if the provider does not have a
60 // installing Service Worker.
61 int installing_handle_id() const;
63 // Gets the handle ID of the waiting Service Worker, or
64 // kInvalidServiceWorkerHandleId if the provider does not have a
65 // waiting Service Worker.
66 int waiting_handle_id() const;
68 // Gets the handle ID of the active Service Worker, or
69 // kInvalidServiceWorkerHandleId if the provider does not have an active
70 // Service Worker.
71 int active_handle_id() const;
73 // Gets the handle ID of the controller Service Worker, or
74 // kInvalidServiceWorkerHandleId if the provider is not controlled
75 // by a Service Worker.
76 int controller_handle_id() const;
78 // Gets the handle ID of the associated registration, or
79 // kInvalidRegistrationHandleId if the provider is not associated with any
80 // registration.
81 int registration_handle_id() const;
83 private:
84 friend class base::DeleteHelper<ServiceWorkerProviderContext>;
85 friend class base::RefCountedThreadSafe<ServiceWorkerProviderContext,
86 ServiceWorkerProviderContextDeleter>;
87 friend struct ServiceWorkerProviderContextDeleter;
89 ~ServiceWorkerProviderContext();
90 void DestructOnMainThread() const;
92 const int provider_id_;
93 scoped_refptr<base::SingleThreadTaskRunner> main_thread_task_runner_;
94 scoped_refptr<ThreadSafeSender> thread_safe_sender_;
96 // Protects (installing, waiting, active) worker and registration references.
97 base::Lock lock_;
99 // Used on both the main thread and the worker thread.
100 scoped_ptr<ServiceWorkerHandleReference> installing_;
101 scoped_ptr<ServiceWorkerHandleReference> waiting_;
102 scoped_ptr<ServiceWorkerHandleReference> active_;
103 scoped_ptr<ServiceWorkerRegistrationHandleReference> registration_;
105 // Used only on the main thread.
106 scoped_ptr<ServiceWorkerHandleReference> controller_;
108 DISALLOW_COPY_AND_ASSIGN(ServiceWorkerProviderContext);
111 struct ServiceWorkerProviderContextDeleter {
112 static void Destruct(const ServiceWorkerProviderContext* context) {
113 context->DestructOnMainThread();
117 } // namespace content
119 #endif // CONTENT_CHILD_SERVICE_WORKER_SERVICE_WORKER_PROVIDER_CONTEXT_H_