| 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_BROWSER_SERVICE_WORKER_EMBEDDED_WORKER_INSTANCE_H_ | 5 #ifndef CONTENT_BROWSER_SERVICE_WORKER_EMBEDDED_WORKER_INSTANCE_H_ |
| 6 #define CONTENT_BROWSER_SERVICE_WORKER_EMBEDDED_WORKER_INSTANCE_H_ | 6 #define CONTENT_BROWSER_SERVICE_WORKER_EMBEDDED_WORKER_INSTANCE_H_ |
| 7 | 7 |
| 8 #include <map> | 8 #include <map> |
| 9 #include <vector> | 9 #include <vector> |
| 10 | 10 |
| (...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 79 const GURL& script_url, | 79 const GURL& script_url, |
| 80 bool pause_after_download, | 80 bool pause_after_download, |
| 81 const StatusCallback& callback); | 81 const StatusCallback& callback); |
| 82 | 82 |
| 83 // Stops the worker. It is invalid to call this when the worker is | 83 // Stops the worker. It is invalid to call this when the worker is |
| 84 // not in STARTING or RUNNING status. | 84 // not in STARTING or RUNNING status. |
| 85 // This returns false if stopping a worker fails immediately, e.g. when | 85 // This returns false if stopping a worker fails immediately, e.g. when |
| 86 // IPC couldn't be sent to the worker. | 86 // IPC couldn't be sent to the worker. |
| 87 ServiceWorkerStatusCode Stop(); | 87 ServiceWorkerStatusCode Stop(); |
| 88 | 88 |
| 89 // Stops the worker if the worker is not being debugged (i.e. devtools is |
| 90 // not attached). This method is called by a stop-worker timer to kill |
| 91 // idle workers. |
| 92 void StopIfIdle(); |
| 93 |
| 89 // Sends |message| to the embedded worker running in the child process. | 94 // Sends |message| to the embedded worker running in the child process. |
| 90 // It is invalid to call this while the worker is not in RUNNING status. | 95 // It is invalid to call this while the worker is not in RUNNING status. |
| 91 ServiceWorkerStatusCode SendMessage(const IPC::Message& message); | 96 ServiceWorkerStatusCode SendMessage(const IPC::Message& message); |
| 92 | 97 |
| 93 void ResumeAfterDownload(); | 98 void ResumeAfterDownload(); |
| 94 | 99 |
| 95 int embedded_worker_id() const { return embedded_worker_id_; } | 100 int embedded_worker_id() const { return embedded_worker_id_; } |
| 96 Status status() const { return status_; } | 101 Status status() const { return status_; } |
| 97 int process_id() const { return process_id_; } | 102 int process_id() const { return process_id_; } |
| 98 int thread_id() const { return thread_id_; } | 103 int thread_id() const { return thread_id_; } |
| 99 int worker_devtools_agent_route_id() const { | 104 int worker_devtools_agent_route_id() const { |
| 100 return worker_devtools_agent_route_id_; | 105 return worker_devtools_agent_route_id_; |
| 101 } | 106 } |
| 102 MessagePortMessageFilter* message_port_message_filter() const; | 107 MessagePortMessageFilter* message_port_message_filter() const; |
| 103 | 108 |
| 104 void AddListener(Listener* listener); | 109 void AddListener(Listener* listener); |
| 105 void RemoveListener(Listener* listener); | 110 void RemoveListener(Listener* listener); |
| 106 | 111 |
| 112 void set_devtools_attached(bool attached) { devtools_attached_ = attached; } |
| 113 |
| 107 private: | 114 private: |
| 108 typedef ObserverList<Listener> ListenerList; | 115 typedef ObserverList<Listener> ListenerList; |
| 109 | 116 |
| 110 friend class EmbeddedWorkerRegistry; | 117 friend class EmbeddedWorkerRegistry; |
| 111 FRIEND_TEST_ALL_PREFIXES(EmbeddedWorkerInstanceTest, StartAndStop); | 118 FRIEND_TEST_ALL_PREFIXES(EmbeddedWorkerInstanceTest, StartAndStop); |
| 112 | 119 |
| 113 // Constructor is called via EmbeddedWorkerRegistry::CreateWorker(). | 120 // Constructor is called via EmbeddedWorkerRegistry::CreateWorker(). |
| 114 // This instance holds a ref of |registry|. | 121 // This instance holds a ref of |registry|. |
| 115 EmbeddedWorkerInstance(base::WeakPtr<ServiceWorkerContextCore> context, | 122 EmbeddedWorkerInstance(base::WeakPtr<ServiceWorkerContextCore> context, |
| 116 int embedded_worker_id); | 123 int embedded_worker_id); |
| (...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 185 base::WeakPtr<ServiceWorkerContextCore> context_; | 192 base::WeakPtr<ServiceWorkerContextCore> context_; |
| 186 scoped_refptr<EmbeddedWorkerRegistry> registry_; | 193 scoped_refptr<EmbeddedWorkerRegistry> registry_; |
| 187 const int embedded_worker_id_; | 194 const int embedded_worker_id_; |
| 188 Status status_; | 195 Status status_; |
| 189 | 196 |
| 190 // Current running information. -1 indicates the worker is not running. | 197 // Current running information. -1 indicates the worker is not running. |
| 191 int process_id_; | 198 int process_id_; |
| 192 int thread_id_; | 199 int thread_id_; |
| 193 int worker_devtools_agent_route_id_; | 200 int worker_devtools_agent_route_id_; |
| 194 | 201 |
| 202 // Whether devtools is attached or not. |
| 203 bool devtools_attached_; |
| 204 |
| 195 StatusCallback start_callback_; | 205 StatusCallback start_callback_; |
| 196 | 206 |
| 197 ListenerList listener_list_; | 207 ListenerList listener_list_; |
| 198 | 208 |
| 199 base::WeakPtrFactory<EmbeddedWorkerInstance> weak_factory_; | 209 base::WeakPtrFactory<EmbeddedWorkerInstance> weak_factory_; |
| 200 | 210 |
| 201 DISALLOW_COPY_AND_ASSIGN(EmbeddedWorkerInstance); | 211 DISALLOW_COPY_AND_ASSIGN(EmbeddedWorkerInstance); |
| 202 }; | 212 }; |
| 203 | 213 |
| 204 } // namespace content | 214 } // namespace content |
| 205 | 215 |
| 206 #endif // CONTENT_BROWSER_SERVICE_WORKER_EMBEDDED_WORKER_INSTANCE_H_ | 216 #endif // CONTENT_BROWSER_SERVICE_WORKER_EMBEDDED_WORKER_INSTANCE_H_ |
| OLD | NEW |