[SyncFS] Build indexes from FileTracker entries on disk.
[chromium-blink-merge.git] / content / child / service_worker / service_worker_provider_context.h
blobee294d99293a7297c9df4da71a058b32c8587b52
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 MessageLoopProxy;
20 namespace IPC {
21 class Message;
24 namespace content {
26 class ServiceWorkerHandleReference;
27 struct ServiceWorkerProviderContextDeleter;
28 class ThreadSafeSender;
30 // An instance of this class holds document-related information (e.g.
31 // .controller). Created and destructed on the main thread.
32 // TODO(kinuko): To support navigator.serviceWorker in dedicated workers
33 // this needs to be RefCountedThreadSafe and .controller info needs to be
34 // handled in a thread-safe manner (e.g. by a lock etc).
35 class ServiceWorkerProviderContext
36 : public base::RefCounted<ServiceWorkerProviderContext> {
37 public:
38 explicit ServiceWorkerProviderContext(int provider_id);
40 // Called from ServiceWorkerDispatcher.
41 void OnServiceWorkerStateChanged(int handle_id,
42 blink::WebServiceWorkerState state);
43 void OnSetInstallingServiceWorker(int provider_id,
44 const ServiceWorkerObjectInfo& info);
45 void OnSetWaitingServiceWorker(int provider_id,
46 const ServiceWorkerObjectInfo& info);
47 void OnSetActiveServiceWorker(int provider_id,
48 const ServiceWorkerObjectInfo& info);
49 void OnSetControllerServiceWorker(int provider_id,
50 const ServiceWorkerObjectInfo& info);
52 int provider_id() const { return provider_id_; }
54 ServiceWorkerHandleReference* installing();
55 ServiceWorkerHandleReference* waiting();
56 ServiceWorkerHandleReference* active();
57 ServiceWorkerHandleReference* controller();
59 // Gets the handle ID of the installing Service Worker, or
60 // kInvalidServiceWorkerHandleId if the provider does not have a
61 // installing Service Worker.
62 int installing_handle_id() const;
64 // Gets the handle ID of the waiting Service Worker, or
65 // kInvalidServiceWorkerHandleId if the provider does not have a
66 // waiting Service Worker.
67 int waiting_handle_id() const;
69 // Gets the handle ID of the active Service Worker, or
70 // kInvalidServiceWorkerHandleId if the provider does not have an active
71 // Service Worker.
72 int active_handle_id() const;
74 // Gets the handle ID of the controller Service Worker, or
75 // kInvalidServiceWorkerHandleId if the provider is not controlled
76 // by a Service Worker.
77 int controller_handle_id() const;
79 private:
80 friend class base::RefCounted<ServiceWorkerProviderContext>;
81 ~ServiceWorkerProviderContext();
83 const int provider_id_;
84 scoped_refptr<base::MessageLoopProxy> main_thread_loop_proxy_;
85 scoped_refptr<ThreadSafeSender> thread_safe_sender_;
86 scoped_ptr<ServiceWorkerHandleReference> installing_;
87 scoped_ptr<ServiceWorkerHandleReference> waiting_;
88 scoped_ptr<ServiceWorkerHandleReference> active_;
89 scoped_ptr<ServiceWorkerHandleReference> controller_;
91 DISALLOW_COPY_AND_ASSIGN(ServiceWorkerProviderContext);
94 } // namespace content
96 #endif // CONTENT_CHILD_SERVICE_WORKER_SERVICE_WORKER_PROVIDER_CONTEXT_H_