Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(303)

Side by Side Diff: content/browser/service_worker/embedded_worker_instance.h

Issue 1569773002: ServiceWorker: Make start worker sequence cancelable (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: fix test failures Created 4 years, 11 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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 <stdint.h> 8 #include <stdint.h>
9 9
10 #include <string> 10 #include <string>
(...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after
69 // (installed scripts only) 69 // (installed scripts only)
70 SCRIPT_READ_STARTED, 70 SCRIPT_READ_STARTED,
71 SCRIPT_READ_FINISHED, 71 SCRIPT_READ_FINISHED,
72 // Add new values here. 72 // Add new values here.
73 STARTING_PHASE_MAX_VALUE, 73 STARTING_PHASE_MAX_VALUE,
74 }; 74 };
75 75
76 class Listener { 76 class Listener {
77 public: 77 public:
78 virtual ~Listener() {} 78 virtual ~Listener() {}
79
80 virtual void OnStarting() {}
81 virtual void OnProcessAllocated() {}
82 virtual void OnStartWorkerMessageSent() {}
79 virtual void OnThreadStarted() {} 83 virtual void OnThreadStarted() {}
80 virtual void OnStarting() {}
81 virtual void OnStarted() {} 84 virtual void OnStarted() {}
85
82 virtual void OnStopping() {} 86 virtual void OnStopping() {}
83 // Received ACK from renderer that the worker context terminated. 87 // Received ACK from renderer that the worker context terminated.
84 virtual void OnStopped(Status old_status) {} 88 virtual void OnStopped(Status old_status) {}
85 // The browser-side IPC endpoint for communication with the worker died. 89 // The browser-side IPC endpoint for communication with the worker died.
86 virtual void OnDetached(Status old_status) {} 90 virtual void OnDetached(Status old_status) {}
87 virtual void OnScriptLoaded() {} 91 virtual void OnScriptLoaded() {}
88 virtual void OnScriptLoadFailed() {} 92 virtual void OnScriptLoadFailed() {}
89 virtual void OnReportException(const base::string16& error_message, 93 virtual void OnReportException(const base::string16& error_message,
90 int line_number, 94 int line_number,
91 int column_number, 95 int column_number,
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after
128 // Returns the ServiceRegistry for this worker. It is invalid to call this 132 // Returns the ServiceRegistry for this worker. It is invalid to call this
129 // when the worker is not in STARTING or RUNNING status. 133 // when the worker is not in STARTING or RUNNING status.
130 ServiceRegistry* GetServiceRegistry(); 134 ServiceRegistry* GetServiceRegistry();
131 135
132 int embedded_worker_id() const { return embedded_worker_id_; } 136 int embedded_worker_id() const { return embedded_worker_id_; }
133 Status status() const { return status_; } 137 Status status() const { return status_; }
134 StartingPhase starting_phase() const { 138 StartingPhase starting_phase() const {
135 DCHECK_EQ(STARTING, status()); 139 DCHECK_EQ(STARTING, status());
136 return starting_phase_; 140 return starting_phase_;
137 } 141 }
138 int process_id() const { return process_id_; } 142 int process_id() const;
139 int thread_id() const { return thread_id_; } 143 int thread_id() const { return thread_id_; }
140 int worker_devtools_agent_route_id() const; 144 int worker_devtools_agent_route_id() const;
141 MessagePortMessageFilter* message_port_message_filter() const; 145 MessagePortMessageFilter* message_port_message_filter() const;
142 146
143 void AddListener(Listener* listener); 147 void AddListener(Listener* listener);
144 void RemoveListener(Listener* listener); 148 void RemoveListener(Listener* listener);
145 149
146 void set_devtools_attached(bool attached) { devtools_attached_ = attached; } 150 void set_devtools_attached(bool attached) { devtools_attached_ = attached; }
147 bool devtools_attached() const { return devtools_attached_; } 151 bool devtools_attached() const { return devtools_attached_; }
148 152
149 // Called when the script load request accessed the network. 153 // Called when the script load request accessed the network.
150 void OnNetworkAccessedForScriptLoad(); 154 void OnNetworkAccessedForScriptLoad();
151 155
152 // Called when reading the main script from the service worker script cache 156 // Called when reading the main script from the service worker script cache
153 // begins and ends. 157 // begins and ends.
154 void OnScriptReadStarted(); 158 void OnScriptReadStarted();
155 void OnScriptReadFinished(); 159 void OnScriptReadFinished();
156 160
157 static std::string StatusToString(Status status); 161 static std::string StatusToString(Status status);
158 static std::string StartingPhaseToString(StartingPhase phase); 162 static std::string StartingPhaseToString(StartingPhase phase);
159 163
160 void Detach(); 164 void Detach();
161 165
162 private: 166 private:
163 typedef base::ObserverList<Listener> ListenerList; 167 typedef base::ObserverList<Listener> ListenerList;
164 class DevToolsProxy; 168 class DevToolsProxy;
169 class StartTask;
170 class WorkerProcessHandle;
165 friend class EmbeddedWorkerRegistry; 171 friend class EmbeddedWorkerRegistry;
166 FRIEND_TEST_ALL_PREFIXES(EmbeddedWorkerInstanceTest, StartAndStop); 172 FRIEND_TEST_ALL_PREFIXES(EmbeddedWorkerInstanceTest, StartAndStop);
167 FRIEND_TEST_ALL_PREFIXES(EmbeddedWorkerInstanceTest, DetachDuringStart); 173 FRIEND_TEST_ALL_PREFIXES(EmbeddedWorkerInstanceTest, DetachDuringStart);
168 FRIEND_TEST_ALL_PREFIXES(EmbeddedWorkerInstanceTest, StopDuringStart); 174 FRIEND_TEST_ALL_PREFIXES(EmbeddedWorkerInstanceTest, StopDuringStart);
169 175
170 // Constructor is called via EmbeddedWorkerRegistry::CreateWorker(). 176 // Constructor is called via EmbeddedWorkerRegistry::CreateWorker().
171 // This instance holds a ref of |registry|. 177 // This instance holds a ref of |registry|.
172 EmbeddedWorkerInstance(base::WeakPtr<ServiceWorkerContextCore> context, 178 EmbeddedWorkerInstance(base::WeakPtr<ServiceWorkerContextCore> context,
173 int embedded_worker_id); 179 int embedded_worker_id);
174 180
175 // Called back from ServiceWorkerProcessManager after Start() passes control 181 // Called back from StartTask after a process is allocated on the UI thread.
176 // to the UI thread to acquire a reference to the process. 182 void OnProcessAllocated(scoped_ptr<WorkerProcessHandle> handle);
177 static void RunProcessAllocated( 183
178 base::WeakPtr<EmbeddedWorkerInstance> instance, 184 // Called back from StartTask after the worker is registered to
179 base::WeakPtr<ServiceWorkerContextCore> context, 185 // WorkerDevToolsManager.
180 scoped_ptr<EmbeddedWorkerMsg_StartWorker_Params> params, 186 void OnRegisteredToDevToolsManager(bool is_new_process,
181 const EmbeddedWorkerInstance::StatusCallback& callback, 187 int worker_devtools_agent_route_id,
182 ServiceWorkerStatusCode status, 188 bool wait_for_debugger);
183 int process_id, 189
184 bool is_new_process); 190 // Called back from StartTask after a start worker message is sent.
185 void ProcessAllocated(scoped_ptr<EmbeddedWorkerMsg_StartWorker_Params> params, 191 void OnStartWorkerMessageSent();
186 const StatusCallback& callback,
187 int process_id,
188 bool is_new_process,
189 ServiceWorkerStatusCode status);
190 // Called back after ProcessAllocated() passes control to the UI thread to
191 // register to WorkerDevToolsManager.
192 void SendStartWorker(scoped_ptr<EmbeddedWorkerMsg_StartWorker_Params> params,
193 const StatusCallback& callback,
194 bool is_new_process,
195 int worker_devtools_agent_route_id,
196 bool wait_for_debugger);
197 192
198 // Called back from Registry when the worker instance has ack'ed that 193 // Called back from Registry when the worker instance has ack'ed that
199 // it is ready for inspection. 194 // it is ready for inspection.
200 void OnReadyForInspection(); 195 void OnReadyForInspection();
201 196
202 // Called back from Registry when the worker instance has ack'ed that 197 // Called back from Registry when the worker instance has ack'ed that
203 // it finished loading the script. 198 // it finished loading the script.
204 void OnScriptLoaded(); 199 void OnScriptLoaded();
205 200
206 // Called back from Registry when the worker instance has ack'ed that 201 // Called back from Registry when the worker instance has ack'ed that
(...skipping 12 matching lines...) Expand all
219 // WorkerGlobalScope has actually started and evaluated the script. This is 214 // WorkerGlobalScope has actually started and evaluated the script. This is
220 // called after OnScriptEvaluated. 215 // called after OnScriptEvaluated.
221 // This will change the internal status from STARTING to RUNNING. 216 // This will change the internal status from STARTING to RUNNING.
222 void OnStarted(); 217 void OnStarted();
223 218
224 // Called back from Registry when the worker instance has ack'ed that 219 // Called back from Registry when the worker instance has ack'ed that
225 // its WorkerGlobalScope is actually stopped in the child process. 220 // its WorkerGlobalScope is actually stopped in the child process.
226 // This will change the internal status from STARTING or RUNNING to 221 // This will change the internal status from STARTING or RUNNING to
227 // STOPPED. 222 // STOPPED.
228 void OnStopped(); 223 void OnStopped();
224
229 // Called when ServiceWorkerDispatcherHost for the worker died while it was 225 // Called when ServiceWorkerDispatcherHost for the worker died while it was
230 // running. 226 // running.
231 void OnDetached(); 227 void OnDetached();
232 228
233 // Called back from Registry when the worker instance sends message 229 // Called back from Registry when the worker instance sends message
234 // to the browser (i.e. EmbeddedWorker observers). 230 // to the browser (i.e. EmbeddedWorker observers).
235 // Returns false if the message is not handled. 231 // Returns false if the message is not handled.
236 bool OnMessageReceived(const IPC::Message& message); 232 bool OnMessageReceived(const IPC::Message& message);
237 233
238 // Called back from Registry when the worker instance reports the exception. 234 // Called back from Registry when the worker instance reports the exception.
239 void OnReportException(const base::string16& error_message, 235 void OnReportException(const base::string16& error_message,
240 int line_number, 236 int line_number,
241 int column_number, 237 int column_number,
242 const GURL& source_url); 238 const GURL& source_url);
243 239
244 // Called back from Registry when the worker instance reports to the console. 240 // Called back from Registry when the worker instance reports to the console.
245 void OnReportConsoleMessage(int source_identifier, 241 void OnReportConsoleMessage(int source_identifier,
246 int message_level, 242 int message_level,
247 const base::string16& message, 243 const base::string16& message,
248 int line_number, 244 int line_number,
249 const GURL& source_url); 245 const GURL& source_url);
250 246
251 // Resets all running state. After this function is called, |status_| is 247 // Resets all running state. After this function is called, |status_| is
252 // STOPPED. 248 // STOPPED.
253 void ReleaseProcess(); 249 void ReleaseProcess();
254 // Called when the startup sequence failed. Calls ReleaseProcess() and invokes 250
255 // |callback| with |status|. May destroy |this|. 251 // Called back from StartTask when the startup sequence failed. Calls
252 // ReleaseProcess() and invokes |callback| with |status|. May destroy |this|.
256 void OnStartFailed(const StatusCallback& callback, 253 void OnStartFailed(const StatusCallback& callback,
257 ServiceWorkerStatusCode status); 254 ServiceWorkerStatusCode status);
258 255
259 base::WeakPtr<ServiceWorkerContextCore> context_; 256 base::WeakPtr<ServiceWorkerContextCore> context_;
260 scoped_refptr<EmbeddedWorkerRegistry> registry_; 257 scoped_refptr<EmbeddedWorkerRegistry> registry_;
261 const int embedded_worker_id_; 258 const int embedded_worker_id_;
262 Status status_; 259 Status status_;
263 StartingPhase starting_phase_; 260 StartingPhase starting_phase_;
264 261
265 // Current running information. 262 // Current running information.
266 int process_id_; 263 scoped_ptr<EmbeddedWorkerInstance::WorkerProcessHandle> process_handle_;
267 int thread_id_; 264 int thread_id_;
268 scoped_ptr<ServiceRegistryImpl> service_registry_; 265 scoped_ptr<ServiceRegistryImpl> service_registry_;
269 266
270 // Whether devtools is attached or not. 267 // Whether devtools is attached or not.
271 bool devtools_attached_; 268 bool devtools_attached_;
272 269
273 // True if the script load request accessed the network. If the script was 270 // True if the script load request accessed the network. If the script was
274 // served from HTTPCache or ServiceWorkerDatabase this value is false. 271 // served from HTTPCache or ServiceWorkerDatabase this value is false.
275 bool network_accessed_for_script_; 272 bool network_accessed_for_script_;
276 273
277 StatusCallback start_callback_;
278 ListenerList listener_list_; 274 ListenerList listener_list_;
279 scoped_ptr<DevToolsProxy> devtools_proxy_; 275 scoped_ptr<DevToolsProxy> devtools_proxy_;
280 276
277 scoped_ptr<StartTask> inflight_start_task_;
281 base::TimeTicks start_timing_; 278 base::TimeTicks start_timing_;
282 279
283 base::WeakPtrFactory<EmbeddedWorkerInstance> weak_factory_; 280 base::WeakPtrFactory<EmbeddedWorkerInstance> weak_factory_;
284 281
285 DISALLOW_COPY_AND_ASSIGN(EmbeddedWorkerInstance); 282 DISALLOW_COPY_AND_ASSIGN(EmbeddedWorkerInstance);
286 }; 283 };
287 284
288 } // namespace content 285 } // namespace content
289 286
290 #endif // CONTENT_BROWSER_SERVICE_WORKER_EMBEDDED_WORKER_INSTANCE_H_ 287 #endif // CONTENT_BROWSER_SERVICE_WORKER_EMBEDDED_WORKER_INSTANCE_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698