| 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 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 49 enum Status { | 49 enum Status { |
| 50 STOPPED, | 50 STOPPED, |
| 51 STARTING, | 51 STARTING, |
| 52 RUNNING, | 52 RUNNING, |
| 53 STOPPING, | 53 STOPPING, |
| 54 }; | 54 }; |
| 55 | 55 |
| 56 class Listener { | 56 class Listener { |
| 57 public: | 57 public: |
| 58 virtual ~Listener() {} | 58 virtual ~Listener() {} |
| 59 virtual void OnScriptLoaded() {} |
| 59 virtual void OnStarted() {} | 60 virtual void OnStarted() {} |
| 60 virtual void OnStopped(Status old_status) {} | 61 virtual void OnStopped(Status old_status) {} |
| 61 virtual void OnPausedAfterDownload() {} | 62 virtual void OnPausedAfterDownload() {} |
| 62 virtual void OnReportException(const base::string16& error_message, | 63 virtual void OnReportException(const base::string16& error_message, |
| 63 int line_number, | 64 int line_number, |
| 64 int column_number, | 65 int column_number, |
| 65 const GURL& source_url) {} | 66 const GURL& source_url) {} |
| 66 virtual void OnReportConsoleMessage(int source_identifier, | 67 virtual void OnReportConsoleMessage(int source_identifier, |
| 67 int message_level, | 68 int message_level, |
| 68 const base::string16& message, | 69 const base::string16& message, |
| 69 int line_number, | 70 int line_number, |
| 70 const GURL& source_url) {} | 71 const GURL& source_url) {} |
| 71 // These should return false if the message is not handled by this | 72 // These should return false if the message is not handled by this |
| 72 // listener. (TODO(kinuko): consider using IPC::Listener interface) | 73 // listener. (TODO(kinuko): consider using IPC::Listener interface) |
| 73 // TODO(kinuko): Deprecate OnReplyReceived. | 74 // TODO(kinuko): Deprecate OnReplyReceived. |
| 74 virtual bool OnMessageReceived(const IPC::Message& message) = 0; | 75 virtual bool OnMessageReceived(const IPC::Message& message) = 0; |
| 75 }; | 76 }; |
| 76 | 77 |
| 77 ~EmbeddedWorkerInstance(); | 78 ~EmbeddedWorkerInstance(); |
| 78 | 79 |
| 79 // Starts the worker. It is invalid to call this when the worker is not in | 80 // Starts the worker. It is invalid to call this when the worker is not in |
| 80 // STOPPED status. |callback| is invoked when the worker's process is created | 81 // STOPPED status. |callback| is invoked after the worker script has been |
| 81 // if necessary and the IPC to evaluate the worker's script is sent. | 82 // started and evaluated, or when an error occurs. |
| 82 // Observer::OnStarted() is run when the worker is actually started. | |
| 83 void Start(int64 service_worker_version_id, | 83 void Start(int64 service_worker_version_id, |
| 84 const GURL& scope, | 84 const GURL& scope, |
| 85 const GURL& script_url, | 85 const GURL& script_url, |
| 86 bool pause_after_download, | 86 bool pause_after_download, |
| 87 const StatusCallback& callback); | 87 const StatusCallback& callback); |
| 88 | 88 |
| 89 // Stops the worker. It is invalid to call this when the worker is | 89 // Stops the worker. It is invalid to call this when the worker is |
| 90 // not in STARTING or RUNNING status. | 90 // not in STARTING or RUNNING status. |
| 91 // This returns false if stopping a worker fails immediately, e.g. when | 91 // This returns false if stopping a worker fails immediately, e.g. when |
| 92 // IPC couldn't be sent to the worker. | 92 // IPC couldn't be sent to the worker. |
| 93 ServiceWorkerStatusCode Stop(); | 93 ServiceWorkerStatusCode Stop(); |
| 94 | 94 |
| 95 // Stops the worker if the worker is not being debugged (i.e. devtools is | 95 // Stops the worker if the worker is not being debugged (i.e. devtools is |
| 96 // not attached). This method is called by a stop-worker timer to kill | 96 // not attached). This method is called by a stop-worker timer to kill |
| 97 // idle workers. | 97 // idle workers. |
| 98 void StopIfIdle(); | 98 void StopIfIdle(); |
| 99 | 99 |
| 100 // Sends |message| to the embedded worker running in the child process. | 100 // Sends |message| to the embedded worker running in the child process. |
| 101 // It is invalid to call this while the worker is not in RUNNING status. | 101 // It is invalid to call this while the worker is not in STARTING or RUNNING |
| 102 // status. |
| 102 ServiceWorkerStatusCode SendMessage(const IPC::Message& message); | 103 ServiceWorkerStatusCode SendMessage(const IPC::Message& message); |
| 103 | 104 |
| 104 void ResumeAfterDownload(); | 105 void ResumeAfterDownload(); |
| 105 | 106 |
| 106 int embedded_worker_id() const { return embedded_worker_id_; } | 107 int embedded_worker_id() const { return embedded_worker_id_; } |
| 107 Status status() const { return status_; } | 108 Status status() const { return status_; } |
| 108 int process_id() const { return process_id_; } | 109 int process_id() const { return process_id_; } |
| 109 int thread_id() const { return thread_id_; } | 110 int thread_id() const { return thread_id_; } |
| 110 int worker_devtools_agent_route_id() const; | 111 int worker_devtools_agent_route_id() const; |
| 111 MessagePortMessageFilter* message_port_message_filter() const; | 112 MessagePortMessageFilter* message_port_message_filter() const; |
| (...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 155 | 156 |
| 156 // Called back from Registry when the worker instance has ack'ed that | 157 // Called back from Registry when the worker instance has ack'ed that |
| 157 // it finished loading the script and has started a worker thread. | 158 // it finished loading the script and has started a worker thread. |
| 158 void OnScriptLoaded(int thread_id); | 159 void OnScriptLoaded(int thread_id); |
| 159 | 160 |
| 160 // Called back from Registry when the worker instance has ack'ed that | 161 // Called back from Registry when the worker instance has ack'ed that |
| 161 // it failed to load the script. | 162 // it failed to load the script. |
| 162 void OnScriptLoadFailed(); | 163 void OnScriptLoadFailed(); |
| 163 | 164 |
| 164 // Called back from Registry when the worker instance has ack'ed that | 165 // Called back from Registry when the worker instance has ack'ed that |
| 165 // it finished evaluating the script. | 166 // it finished evaluating the script. This is called before OnStarted. |
| 166 void OnScriptEvaluated(bool success); | 167 void OnScriptEvaluated(bool success); |
| 167 | 168 |
| 168 // Called back from Registry when the worker instance has ack'ed that | 169 // Called back from Registry when the worker instance has ack'ed that its |
| 169 // its WorkerGlobalScope is actually started and parsed. | 170 // WorkerGlobalScope has actually started and evaluated the script. This is |
| 171 // called after OnScriptEvaluated. |
| 170 // This will change the internal status from STARTING to RUNNING. | 172 // This will change the internal status from STARTING to RUNNING. |
| 171 void OnStarted(); | 173 void OnStarted(); |
| 172 | 174 |
| 173 void OnPausedAfterDownload(); | 175 void OnPausedAfterDownload(); |
| 174 | 176 |
| 175 // Called back from Registry when the worker instance has ack'ed that | 177 // Called back from Registry when the worker instance has ack'ed that |
| 176 // its WorkerGlobalScope is actually stopped in the child process. | 178 // its WorkerGlobalScope is actually stopped in the child process. |
| 177 // This will change the internal status from STARTING or RUNNING to | 179 // This will change the internal status from STARTING or RUNNING to |
| 178 // STOPPED. | 180 // STOPPED. |
| 179 void OnStopped(); | 181 void OnStopped(); |
| (...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 219 base::TimeTicks start_timing_; | 221 base::TimeTicks start_timing_; |
| 220 | 222 |
| 221 base::WeakPtrFactory<EmbeddedWorkerInstance> weak_factory_; | 223 base::WeakPtrFactory<EmbeddedWorkerInstance> weak_factory_; |
| 222 | 224 |
| 223 DISALLOW_COPY_AND_ASSIGN(EmbeddedWorkerInstance); | 225 DISALLOW_COPY_AND_ASSIGN(EmbeddedWorkerInstance); |
| 224 }; | 226 }; |
| 225 | 227 |
| 226 } // namespace content | 228 } // namespace content |
| 227 | 229 |
| 228 #endif // CONTENT_BROWSER_SERVICE_WORKER_EMBEDDED_WORKER_INSTANCE_H_ | 230 #endif // CONTENT_BROWSER_SERVICE_WORKER_EMBEDDED_WORKER_INSTANCE_H_ |
| OLD | NEW |