Linux: Depend on liberation-fonts package for RPMs.
[chromium-blink-merge.git] / content / child / service_worker / service_worker_provider_context.h
blobca623fbd846b5e7fa8e4f2dee7962b31d5fcd842
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 content {
22 class ServiceWorkerHandleReference;
23 class ServiceWorkerRegistrationHandleReference;
24 struct ServiceWorkerProviderContextDeleter;
25 class ThreadSafeSender;
27 // An instance of this class holds information related to Document/Worker.
28 // Created and destructed on the main thread. Unless otherwise noted, all
29 // methods are called on the main thread.
30 class ServiceWorkerProviderContext
31 : public base::RefCountedThreadSafe<ServiceWorkerProviderContext,
32 ServiceWorkerProviderContextDeleter> {
33 public:
34 explicit ServiceWorkerProviderContext(int provider_id);
36 // Called from ServiceWorkerDispatcher.
37 void OnAssociateRegistration(const ServiceWorkerRegistrationObjectInfo& info,
38 const ServiceWorkerVersionAttributes& attrs);
39 void OnDisassociateRegistration();
40 void OnSetControllerServiceWorker(const ServiceWorkerObjectInfo& info);
42 int provider_id() const { return provider_id_; }
44 ServiceWorkerHandleReference* controller();
46 // Called on the worker thread.
47 bool GetRegistrationInfoAndVersionAttributes(
48 ServiceWorkerRegistrationObjectInfo* info,
49 ServiceWorkerVersionAttributes* attrs);
51 private:
52 friend class base::DeleteHelper<ServiceWorkerProviderContext>;
53 friend class base::RefCountedThreadSafe<ServiceWorkerProviderContext,
54 ServiceWorkerProviderContextDeleter>;
55 friend struct ServiceWorkerProviderContextDeleter;
57 ~ServiceWorkerProviderContext();
58 void DestructOnMainThread() const;
60 const int provider_id_;
61 scoped_refptr<base::SingleThreadTaskRunner> main_thread_task_runner_;
62 scoped_refptr<ThreadSafeSender> thread_safe_sender_;
64 // Protects (installing, waiting, active) worker and registration references.
65 base::Lock lock_;
67 // Used on both the main thread and the worker thread.
68 scoped_ptr<ServiceWorkerHandleReference> installing_;
69 scoped_ptr<ServiceWorkerHandleReference> waiting_;
70 scoped_ptr<ServiceWorkerHandleReference> active_;
71 scoped_ptr<ServiceWorkerRegistrationHandleReference> registration_;
73 // Used only on the main thread.
74 scoped_ptr<ServiceWorkerHandleReference> controller_;
76 DISALLOW_COPY_AND_ASSIGN(ServiceWorkerProviderContext);
79 struct ServiceWorkerProviderContextDeleter {
80 static void Destruct(const ServiceWorkerProviderContext* context) {
81 context->DestructOnMainThread();
85 } // namespace content
87 #endif // CONTENT_CHILD_SERVICE_WORKER_SERVICE_WORKER_PROVIDER_CONTEXT_H_