OLD | NEW |
(Empty) | |
| 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. |
| 4 |
| 5 #ifndef CONTENT_CHILD_SERVICE_WORKER_SERVICE_WORKER_PROVIDER_CONTEXT_H_ |
| 6 #define CONTENT_CHILD_SERVICE_WORKER_SERVICE_WORKER_PROVIDER_CONTEXT_H_ |
| 7 |
| 8 #include <set> |
| 9 #include <vector> |
| 10 |
| 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" |
| 15 |
| 16 namespace base { |
| 17 class MessageLoopProxy; |
| 18 } |
| 19 |
| 20 namespace IPC { |
| 21 class Message; |
| 22 } |
| 23 |
| 24 namespace content { |
| 25 |
| 26 class ServiceWorkerHandleReference; |
| 27 struct ServiceWorkerProviderContextDeleter; |
| 28 class ThreadSafeSender; |
| 29 |
| 30 // An instance of this class holds document-related information (e.g. |
| 31 // .current). Created and destructed on the main thread. |
| 32 // TODO(kinuko): To support navigator.serviceWorker in dedicated workers |
| 33 // this needs to be RefCountedThreadSafe and .current 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); |
| 39 |
| 40 // Returns a new handle reference for .current. |
| 41 scoped_ptr<ServiceWorkerHandleReference> GetCurrentServiceWorkerHandle(); |
| 42 |
| 43 // Called from ServiceWorkerDispatcher. |
| 44 void OnServiceWorkerStateChanged(int handle_id, |
| 45 blink::WebServiceWorkerState state); |
| 46 void OnSetCurrentServiceWorker(int provider_id, |
| 47 const ServiceWorkerObjectInfo& info); |
| 48 |
| 49 int provider_id() const { return provider_id_; } |
| 50 int current_handle_id() const; |
| 51 |
| 52 private: |
| 53 friend class base::RefCounted<ServiceWorkerProviderContext>; |
| 54 ~ServiceWorkerProviderContext(); |
| 55 |
| 56 const int provider_id_; |
| 57 scoped_refptr<base::MessageLoopProxy> main_thread_loop_proxy_; |
| 58 scoped_refptr<ThreadSafeSender> thread_safe_sender_; |
| 59 scoped_ptr<ServiceWorkerHandleReference> current_; |
| 60 |
| 61 DISALLOW_COPY_AND_ASSIGN(ServiceWorkerProviderContext); |
| 62 }; |
| 63 |
| 64 } // namespace content |
| 65 |
| 66 #endif // CONTENT_CHILD_SERVICE_WORKER_SERVICE_WORKER_PROVIDER_CONTEXT_H_ |
OLD | NEW |