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 ScopedServiceWorkerReference; |
| 27 struct ServiceWorkerProviderContextDeleter; |
| 28 class ThreadSafeSender; |
| 29 |
| 30 // An instance of this class holds document-related information (e.g. .current) |
| 31 // and can be shared by multiple WebServiceWorkerProviderImpl's across threads |
| 32 // (e.g. for dedicated workers created for the document). |
| 33 // Created and destructed on the main thread. |
| 34 class ServiceWorkerProviderContext |
| 35 : public base::RefCountedThreadSafe<ServiceWorkerProviderContext, |
| 36 ServiceWorkerProviderContextDeleter> { |
| 37 public: |
| 38 explicit ServiceWorkerProviderContext(int provider_id); |
| 39 |
| 40 // Adds and removes a thread where a scriptable provider is running. |
| 41 // The Add method also returns information necessary to initialize |
| 42 // the provider (i.e. current ServiceWorker info). |
| 43 void AddProviderThreadAndGetInitializationInfo( |
| 44 int thread_id, |
| 45 scoped_ptr<ScopedServiceWorkerReference>* current); |
| 46 void RemoveProviderThread(int thread_id); |
| 47 |
| 48 // Called from ServiceWorkerDispatcher. |
| 49 void OnServiceWorkerStateChanged(int thread_id, |
| 50 int handle_id, |
| 51 blink::WebServiceWorkerState state); |
| 52 void OnSetCurrentServiceWorker(int thread_id, |
| 53 int provider_id, |
| 54 const ServiceWorkerObjectInfo& info); |
| 55 |
| 56 int provider_id() const { return provider_id_; } |
| 57 const ServiceWorkerObjectInfo& current() const; |
| 58 |
| 59 private: |
| 60 friend struct ServiceWorkerProviderContextDeleter; |
| 61 friend class base::DeleteHelper<ServiceWorkerProviderContext>; |
| 62 friend class base::RefCountedThreadSafe<ServiceWorkerProviderContext, |
| 63 ServiceWorkerProviderContextDeleter>; |
| 64 ~ServiceWorkerProviderContext(); |
| 65 void DestructOnMainThread() const; |
| 66 void ForwardMessageToProviderThreads(const IPC::Message& message, |
| 67 const std::set<int>& thread_ids); |
| 68 |
| 69 const int provider_id_; |
| 70 scoped_refptr<base::MessageLoopProxy> main_thread_loop_proxy_; |
| 71 scoped_refptr<ThreadSafeSender> thread_safe_sender_; |
| 72 mutable base::Lock lock_; // Protects |current_| and |provider_thread_ids_|. |
| 73 mutable scoped_ptr<ScopedServiceWorkerReference> current_; |
| 74 std::set<int> provider_thread_ids_; |
| 75 |
| 76 DISALLOW_COPY_AND_ASSIGN(ServiceWorkerProviderContext); |
| 77 }; |
| 78 |
| 79 struct ServiceWorkerProviderContextDeleter { |
| 80 static void Destruct(const ServiceWorkerProviderContext* context) { |
| 81 context->DestructOnMainThread(); |
| 82 } |
| 83 }; |
| 84 |
| 85 } // namespace content |
| 86 |
| 87 #endif // CONTENT_CHILD_SERVICE_WORKER_SERVICE_WORKER_PROVIDER_CONTEXT_H_ |
OLD | NEW |