OLD | NEW |
1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #ifndef CONTENT_CHILD_SERVICE_WORKER_EMBEDDED_WORKER_CLIENT_H_ | 5 #ifndef CONTENT_CHILD_SERVICE_WORKER_EMBEDDED_WORKER_CLIENT_H_ |
6 #define CONTENT_CHILD_SERVICE_WORKER_EMBEDDED_WORKER_CLIENT_H_ | 6 #define CONTENT_CHILD_SERVICE_WORKER_EMBEDDED_WORKER_CLIENT_H_ |
7 | 7 |
8 #include "base/memory/ref_counted.h" | 8 #include "base/memory/ref_counted.h" |
9 #include "base/strings/string16.h" | 9 #include "base/strings/string16.h" |
10 #include "ipc/ipc_listener.h" | 10 #include "ipc/ipc_listener.h" |
11 #include "third_party/WebKit/public/web/WebServiceWorkerContextClient.h" | 11 #include "third_party/WebKit/public/web/WebServiceWorkerContextClient.h" |
12 #include "url/gurl.h" | 12 #include "url/gurl.h" |
13 | 13 |
14 namespace base { | 14 namespace base { |
15 class MessageLoopProxy; | 15 class MessageLoopProxy; |
16 } | 16 } |
17 | 17 |
18 namespace content { | 18 namespace content { |
19 | 19 |
20 struct ServiceWorkerFetchRequest; | 20 class ServiceWorkerScriptContext; |
21 class ThreadSafeSender; | 21 class ThreadSafeSender; |
22 | 22 |
23 // This class provides access to/from an embedded worker's WorkerGlobalScope. | 23 // This class provides access to/from an embedded worker's WorkerGlobalScope. |
24 // All methods other than the constructor (it's created on the main thread) | 24 // All methods other than the constructor (it's created on the main thread) |
25 // are called on the worker thread. | 25 // are called on the worker thread. |
| 26 // |
| 27 // TODO(kinuko): Currently EW/SW separation is made a little hazily. |
| 28 // This should implement WebEmbeddedWorkerContextClient |
| 29 // or sort of it (which doesn't exist yet) rather than |
| 30 // WebServiceWorkerContextClient if we want to separate them more cleanly, |
| 31 // or ServiceWorkerScriptContext should be merged into this class |
| 32 // if we consider EW == SW script context. |
26 class EmbeddedWorkerContextClient | 33 class EmbeddedWorkerContextClient |
27 : public blink::WebServiceWorkerContextClient { | 34 : public blink::WebServiceWorkerContextClient { |
28 public: | 35 public: |
29 // Returns a thread-specific client instance. This does NOT create a | 36 // Returns a thread-specific client instance. This does NOT create a |
30 // new instance. | 37 // new instance. |
31 static EmbeddedWorkerContextClient* ThreadSpecificInstance(); | 38 static EmbeddedWorkerContextClient* ThreadSpecificInstance(); |
32 | 39 |
33 EmbeddedWorkerContextClient(int embedded_worker_id, | 40 EmbeddedWorkerContextClient(int embedded_worker_id, |
34 int64 service_worker_version_id, | 41 int64 service_worker_version_id, |
35 const GURL& script_url); | 42 const GURL& script_url); |
36 | 43 |
37 virtual ~EmbeddedWorkerContextClient(); | 44 virtual ~EmbeddedWorkerContextClient(); |
38 | 45 |
39 bool OnMessageReceived(const IPC::Message& msg); | 46 bool OnMessageReceived(const IPC::Message& msg); |
40 | 47 |
| 48 void SendMessageToBrowser(const IPC::Message& message); |
| 49 |
41 // WebServiceWorkerContextClient overrides. | 50 // WebServiceWorkerContextClient overrides. |
42 virtual void workerContextFailedToStart(); | 51 virtual void workerContextFailedToStart(); |
43 virtual void workerContextStarted(blink::WebServiceWorkerContextProxy* proxy); | 52 virtual void workerContextStarted(blink::WebServiceWorkerContextProxy* proxy); |
44 virtual void workerContextDestroyed(); | 53 virtual void workerContextDestroyed(); |
45 | 54 |
46 // TODO: Implement DevTools related method overrides. | 55 // TODO: Implement DevTools related method overrides. |
47 | 56 |
48 int embedded_worker_id() const { return embedded_worker_id_; } | 57 int embedded_worker_id() const { return embedded_worker_id_; } |
49 | 58 |
50 private: | 59 private: |
51 void OnFetchEvent(int thread_id, | 60 void OnSendMessageToWorker(int thread_id, |
52 int embedded_worker_id, | 61 int embedded_worker_id, |
53 const ServiceWorkerFetchRequest& request); | 62 const IPC::Message& message); |
54 | 63 |
55 const int embedded_worker_id_; | 64 const int embedded_worker_id_; |
56 const int64 service_worker_version_id_; | 65 const int64 service_worker_version_id_; |
57 const GURL script_url_; | 66 const GURL script_url_; |
58 scoped_refptr<ThreadSafeSender> sender_; | 67 scoped_refptr<ThreadSafeSender> sender_; |
59 scoped_refptr<base::MessageLoopProxy> main_thread_proxy_; | 68 scoped_refptr<base::MessageLoopProxy> main_thread_proxy_; |
60 | 69 |
61 blink::WebServiceWorkerContextProxy* proxy_; | 70 scoped_ptr<ServiceWorkerScriptContext> script_context_; |
62 | 71 |
63 DISALLOW_COPY_AND_ASSIGN(EmbeddedWorkerContextClient); | 72 DISALLOW_COPY_AND_ASSIGN(EmbeddedWorkerContextClient); |
64 }; | 73 }; |
65 | 74 |
66 } // namespace content | 75 } // namespace content |
67 | 76 |
68 #endif // CONTENT_CHILD_SERVICE_WORKER_EMBEDDED_WORKER_CLIENT_H_ | 77 #endif // CONTENT_CHILD_SERVICE_WORKER_EMBEDDED_WORKER_CLIENT_H_ |
OLD | NEW |