| 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/memory/weak_ptr.h" | 9 #include "base/memory/weak_ptr.h" |
| 10 #include "base/strings/string16.h" | 10 #include "base/strings/string16.h" |
| (...skipping 30 matching lines...) Expand all Loading... |
| 41 // WebServiceWorkerContextClient if we want to separate them more cleanly, | 41 // WebServiceWorkerContextClient if we want to separate them more cleanly, |
| 42 // or ServiceWorkerScriptContext should be merged into this class | 42 // or ServiceWorkerScriptContext should be merged into this class |
| 43 // if we consider EW == SW script context. | 43 // if we consider EW == SW script context. |
| 44 class EmbeddedWorkerContextClient | 44 class EmbeddedWorkerContextClient |
| 45 : public blink::WebServiceWorkerContextClient { | 45 : public blink::WebServiceWorkerContextClient { |
| 46 public: | 46 public: |
| 47 // Returns a thread-specific client instance. This does NOT create a | 47 // Returns a thread-specific client instance. This does NOT create a |
| 48 // new instance. | 48 // new instance. |
| 49 static EmbeddedWorkerContextClient* ThreadSpecificInstance(); | 49 static EmbeddedWorkerContextClient* ThreadSpecificInstance(); |
| 50 | 50 |
| 51 EmbeddedWorkerContextClient(int embedded_worker_id, | 51 EmbeddedWorkerContextClient(int worker_route_id, |
| 52 int embedded_worker_id, |
| 52 int64 service_worker_version_id, | 53 int64 service_worker_version_id, |
| 53 const GURL& service_worker_scope, | 54 const GURL& service_worker_scope, |
| 54 const GURL& script_url); | 55 const GURL& script_url); |
| 55 | 56 |
| 56 virtual ~EmbeddedWorkerContextClient(); | 57 virtual ~EmbeddedWorkerContextClient(); |
| 57 | 58 |
| 58 bool OnMessageReceived(const IPC::Message& msg); | 59 bool OnMessageReceived(const IPC::Message& msg); |
| 59 | 60 |
| 60 void Send(IPC::Message* message); | 61 void Send(IPC::Message* message); |
| 61 | 62 |
| 62 // TODO(kinuko): Deprecate this. | 63 // TODO(kinuko): Deprecate this. |
| 63 void SendReplyToBrowser(int request_id, const IPC::Message& message); | 64 void SendReplyToBrowser(int request_id, const IPC::Message& message); |
| 64 | 65 |
| 65 // WebServiceWorkerContextClient overrides, some of them are just dispatched | 66 // WebServiceWorkerContextClient overrides, some of them are just dispatched |
| 66 // on to script_context_. | 67 // on to script_context_. |
| 67 virtual blink::WebURL scope() const; | 68 virtual blink::WebURL scope() const; |
| 68 virtual void getClients(blink::WebServiceWorkerClientsCallbacks*); | 69 virtual void getClients(blink::WebServiceWorkerClientsCallbacks*); |
| 69 virtual void workerContextFailedToStart(); | 70 virtual void workerContextFailedToStart(); |
| 70 virtual void workerContextStarted(blink::WebServiceWorkerContextProxy* proxy); | 71 virtual void workerContextStarted(blink::WebServiceWorkerContextProxy* proxy); |
| 71 virtual void willDestroyWorkerContext(); | 72 virtual void willDestroyWorkerContext(); |
| 72 virtual void reportException(const blink::WebString& error_message, | 73 virtual void reportException(const blink::WebString& error_message, |
| 73 int line_number, | 74 int line_number, |
| 74 int column_number, | 75 int column_number, |
| 75 const blink::WebString& source_url); | 76 const blink::WebString& source_url); |
| 76 virtual void reportConsoleMessage(int source, | 77 virtual void reportConsoleMessage(int source, |
| 77 int level, | 78 int level, |
| 78 const blink::WebString& message, | 79 const blink::WebString& message, |
| 79 int line_number, | 80 int line_number, |
| 80 const blink::WebString& source_url); | 81 const blink::WebString& source_url); |
| 82 virtual void dispatchDevToolsMessage(const blink::WebString&); |
| 83 virtual void saveDevToolsAgentState(const blink::WebString&); |
| 81 virtual void didHandleActivateEvent(int request_id, | 84 virtual void didHandleActivateEvent(int request_id, |
| 82 blink::WebServiceWorkerEventResult); | 85 blink::WebServiceWorkerEventResult); |
| 83 virtual void didHandleInstallEvent(int request_id, | 86 virtual void didHandleInstallEvent(int request_id, |
| 84 blink::WebServiceWorkerEventResult result); | 87 blink::WebServiceWorkerEventResult result); |
| 85 virtual void didHandleFetchEvent(int request_id); | 88 virtual void didHandleFetchEvent(int request_id); |
| 86 virtual void didHandleFetchEvent( | 89 virtual void didHandleFetchEvent( |
| 87 int request_id, | 90 int request_id, |
| 88 const blink::WebServiceWorkerResponse& response); | 91 const blink::WebServiceWorkerResponse& response); |
| 89 virtual void didHandleSyncEvent(int request_id); | 92 virtual void didHandleSyncEvent(int request_id); |
| 90 virtual blink::WebServiceWorkerNetworkProvider* | 93 virtual blink::WebServiceWorkerNetworkProvider* |
| 91 createServiceWorkerNetworkProvider(blink::WebDataSource* data_source); | 94 createServiceWorkerNetworkProvider(blink::WebDataSource* data_source); |
| 92 | 95 |
| 93 // TODO: Implement DevTools related method overrides. | 96 // TODO: Implement DevTools related method overrides. |
| 94 | 97 |
| 95 int embedded_worker_id() const { return embedded_worker_id_; } | 98 int embedded_worker_id() const { return embedded_worker_id_; } |
| 96 base::MessageLoopProxy* main_thread_proxy() const { | 99 base::MessageLoopProxy* main_thread_proxy() const { |
| 97 return main_thread_proxy_; | 100 return main_thread_proxy_; |
| 98 } | 101 } |
| 99 | 102 |
| 100 private: | 103 private: |
| 101 void OnMessageToWorker(int thread_id, | 104 void OnMessageToWorker(int thread_id, |
| 102 int embedded_worker_id, | 105 int embedded_worker_id, |
| 103 const IPC::Message& message); | 106 const IPC::Message& message); |
| 104 void SendWorkerStarted(); | 107 void SendWorkerStarted(); |
| 105 | 108 |
| 109 const int worker_route_id_; |
| 106 const int embedded_worker_id_; | 110 const int embedded_worker_id_; |
| 107 const int64 service_worker_version_id_; | 111 const int64 service_worker_version_id_; |
| 108 const GURL service_worker_scope_; | 112 const GURL service_worker_scope_; |
| 109 const GURL script_url_; | 113 const GURL script_url_; |
| 110 scoped_refptr<ThreadSafeSender> sender_; | 114 scoped_refptr<ThreadSafeSender> sender_; |
| 111 scoped_refptr<base::MessageLoopProxy> main_thread_proxy_; | 115 scoped_refptr<base::MessageLoopProxy> main_thread_proxy_; |
| 112 scoped_refptr<base::TaskRunner> worker_task_runner_; | 116 scoped_refptr<base::TaskRunner> worker_task_runner_; |
| 113 | 117 |
| 114 scoped_ptr<ServiceWorkerScriptContext> script_context_; | 118 scoped_ptr<ServiceWorkerScriptContext> script_context_; |
| 115 | 119 |
| 116 base::WeakPtrFactory<EmbeddedWorkerContextClient> weak_factory_; | 120 base::WeakPtrFactory<EmbeddedWorkerContextClient> weak_factory_; |
| 117 | 121 |
| 118 DISALLOW_COPY_AND_ASSIGN(EmbeddedWorkerContextClient); | 122 DISALLOW_COPY_AND_ASSIGN(EmbeddedWorkerContextClient); |
| 119 }; | 123 }; |
| 120 | 124 |
| 121 } // namespace content | 125 } // namespace content |
| 122 | 126 |
| 123 #endif // CONTENT_CHILD_SERVICE_WORKER_EMBEDDED_WORKER_CLIENT_H_ | 127 #endif // CONTENT_CHILD_SERVICE_WORKER_EMBEDDED_WORKER_CLIENT_H_ |
| OLD | NEW |