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

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

Issue 2787883003: [ServiceWorker] Add EmbeddedWorkerInstanceHost Interface. (Closed)
Patch Set: Created 3 years, 8 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 <memory> 10 #include <memory>
11 #include <string> 11 #include <string>
12 12
13 #include "base/callback.h" 13 #include "base/callback.h"
14 #include "base/callback_forward.h" 14 #include "base/callback_forward.h"
15 #include "base/gtest_prod_util.h" 15 #include "base/gtest_prod_util.h"
16 #include "base/logging.h" 16 #include "base/logging.h"
17 #include "base/macros.h" 17 #include "base/macros.h"
18 #include "base/memory/ref_counted.h" 18 #include "base/memory/ref_counted.h"
19 #include "base/memory/weak_ptr.h" 19 #include "base/memory/weak_ptr.h"
20 #include "base/observer_list.h" 20 #include "base/observer_list.h"
21 #include "base/strings/string16.h" 21 #include "base/strings/string16.h"
22 #include "base/time/time.h" 22 #include "base/time/time.h"
23 #include "content/browser/service_worker/embedded_worker_status.h" 23 #include "content/browser/service_worker/embedded_worker_status.h"
24 #include "content/browser/service_worker/service_worker_metrics.h" 24 #include "content/browser/service_worker/service_worker_metrics.h"
25 #include "content/common/content_export.h" 25 #include "content/common/content_export.h"
26 #include "content/common/service_worker/embedded_worker.mojom.h" 26 #include "content/common/service_worker/embedded_worker.mojom.h"
27 #include "content/common/service_worker/service_worker_event_dispatcher.mojom.h" 27 #include "content/common/service_worker/service_worker_event_dispatcher.mojom.h"
28 #include "content/common/service_worker/service_worker_status_code.h" 28 #include "content/common/service_worker/service_worker_status_code.h"
29 #include "mojo/public/cpp/bindings/associated_binding.h"
29 #include "url/gurl.h" 30 #include "url/gurl.h"
30 31
31 // Windows headers will redefine SendMessage. 32 // Windows headers will redefine SendMessage.
32 #ifdef SendMessage 33 #ifdef SendMessage
33 #undef SendMessage 34 #undef SendMessage
34 #endif 35 #endif
35 36
36 namespace IPC { 37 namespace IPC {
37 class Message; 38 class Message;
38 } 39 }
39 40
40 namespace content { 41 namespace content {
41 42
42 class EmbeddedWorkerRegistry; 43 class EmbeddedWorkerRegistry;
43 struct EmbeddedWorkerStartParams; 44 struct EmbeddedWorkerStartParams;
44 class ServiceWorkerContextCore; 45 class ServiceWorkerContextCore;
45 46
46 // This gives an interface to control one EmbeddedWorker instance, which 47 // This gives an interface to control one EmbeddedWorker instance, which
47 // may be 'in-waiting' or running in one of the child processes added by 48 // may be 'in-waiting' or running in one of the child processes added by
48 // AddProcessReference(). 49 // AddProcessReference().
49 class CONTENT_EXPORT EmbeddedWorkerInstance { 50 class CONTENT_EXPORT EmbeddedWorkerInstance
51 : NON_EXPORTED_BASE(public mojom::EmbeddedWorkerInstanceHost) {
50 public: 52 public:
51 typedef base::Callback<void(ServiceWorkerStatusCode)> StatusCallback; 53 typedef base::Callback<void(ServiceWorkerStatusCode)> StatusCallback;
52 54
53 // This enum is used in UMA histograms. Append-only. 55 // This enum is used in UMA histograms. Append-only.
54 enum StartingPhase { 56 enum StartingPhase {
55 NOT_STARTING, 57 NOT_STARTING,
56 ALLOCATING_PROCESS, 58 ALLOCATING_PROCESS,
57 REGISTERING_TO_DEVTOOLS, 59 REGISTERING_TO_DEVTOOLS,
58 SENT_START_WORKER, 60 SENT_START_WORKER,
59 SCRIPT_DOWNLOADING, 61 SCRIPT_DOWNLOADING,
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after
92 const GURL& source_url) {} 94 const GURL& source_url) {}
93 virtual void OnReportConsoleMessage(int source_identifier, 95 virtual void OnReportConsoleMessage(int source_identifier,
94 int message_level, 96 int message_level,
95 const base::string16& message, 97 const base::string16& message,
96 int line_number, 98 int line_number,
97 const GURL& source_url) {} 99 const GURL& source_url) {}
98 // Returns false if the message is not handled by this listener. 100 // Returns false if the message is not handled by this listener.
99 CONTENT_EXPORT virtual bool OnMessageReceived(const IPC::Message& message); 101 CONTENT_EXPORT virtual bool OnMessageReceived(const IPC::Message& message);
100 }; 102 };
101 103
102 ~EmbeddedWorkerInstance(); 104 ~EmbeddedWorkerInstance() override;
103 105
104 // Starts the worker. It is invalid to call this when the worker is not in 106 // Starts the worker. It is invalid to call this when the worker is not in
105 // STOPPED status. |callback| is invoked after the worker script has been 107 // STOPPED status. |callback| is invoked after the worker script has been
106 // started and evaluated, or when an error occurs. 108 // started and evaluated, or when an error occurs.
107 // |params| should be populated with service worker version info needed 109 // |params| should be populated with service worker version info needed
108 // to start the worker. 110 // to start the worker.
109 void Start(std::unique_ptr<EmbeddedWorkerStartParams> params, 111 void Start(std::unique_ptr<EmbeddedWorkerStartParams> params,
110 mojom::ServiceWorkerEventDispatcherRequest dispatcher_request, 112 mojom::ServiceWorkerEventDispatcherRequest dispatcher_request,
111 const StatusCallback& callback); 113 const StatusCallback& callback);
112 114
(...skipping 82 matching lines...) Expand 10 before | Expand all | Expand 10 after
195 friend class EmbeddedWorkerRegistry; 197 friend class EmbeddedWorkerRegistry;
196 FRIEND_TEST_ALL_PREFIXES(EmbeddedWorkerInstanceTest, StartAndStop); 198 FRIEND_TEST_ALL_PREFIXES(EmbeddedWorkerInstanceTest, StartAndStop);
197 FRIEND_TEST_ALL_PREFIXES(EmbeddedWorkerInstanceTest, DetachDuringStart); 199 FRIEND_TEST_ALL_PREFIXES(EmbeddedWorkerInstanceTest, DetachDuringStart);
198 FRIEND_TEST_ALL_PREFIXES(EmbeddedWorkerInstanceTest, StopDuringStart); 200 FRIEND_TEST_ALL_PREFIXES(EmbeddedWorkerInstanceTest, StopDuringStart);
199 201
200 // Constructor is called via EmbeddedWorkerRegistry::CreateWorker(). 202 // Constructor is called via EmbeddedWorkerRegistry::CreateWorker().
201 // This instance holds a ref of |registry|. 203 // This instance holds a ref of |registry|.
202 EmbeddedWorkerInstance(base::WeakPtr<ServiceWorkerContextCore> context, 204 EmbeddedWorkerInstance(base::WeakPtr<ServiceWorkerContextCore> context,
203 int embedded_worker_id); 205 int embedded_worker_id);
204 206
207 // mojom::EmbeddedWorkerInstanceHost
208 // Be called when the worker instance has ack'ed that
209 // it is ready for inspection.
210 void OnReadyForInspection() override;
211
205 // Called back from StartTask after a process is allocated on the UI thread. 212 // Called back from StartTask after a process is allocated on the UI thread.
206 void OnProcessAllocated(std::unique_ptr<WorkerProcessHandle> handle, 213 void OnProcessAllocated(std::unique_ptr<WorkerProcessHandle> handle,
207 ServiceWorkerMetrics::StartSituation start_situation); 214 ServiceWorkerMetrics::StartSituation start_situation);
208 215
209 // Called back from StartTask after the worker is registered to 216 // Called back from StartTask after the worker is registered to
210 // WorkerDevToolsManager. 217 // WorkerDevToolsManager.
211 void OnRegisteredToDevToolsManager(bool is_new_process, 218 void OnRegisteredToDevToolsManager(bool is_new_process,
212 int worker_devtools_agent_route_id, 219 int worker_devtools_agent_route_id,
213 bool wait_for_debugger); 220 bool wait_for_debugger);
214 221
215 // Sends StartWorker message via Mojo. 222 // Sends StartWorker message via Mojo.
216 ServiceWorkerStatusCode SendStartWorker( 223 ServiceWorkerStatusCode SendStartWorker(
217 std::unique_ptr<EmbeddedWorkerStartParams> params); 224 std::unique_ptr<EmbeddedWorkerStartParams> params);
218 225
219 // Called back from StartTask after a start worker message is sent. 226 // Called back from StartTask after a start worker message is sent.
220 void OnStartWorkerMessageSent(); 227 void OnStartWorkerMessageSent();
221 228
222 // Called back from Registry when the worker instance has ack'ed that 229 // Called back from Registry when the worker instance has ack'ed that
223 // it is ready for inspection.
224 void OnReadyForInspection();
225
226 // Called back from Registry when the worker instance has ack'ed that
227 // it finished loading the script. 230 // it finished loading the script.
228 void OnScriptLoaded(); 231 void OnScriptLoaded();
229 232
230 // Called back from Registry when the worker instance has ack'ed that 233 // Called back from Registry when the worker instance has ack'ed that
231 // it has started a worker thread. 234 // it has started a worker thread.
232 void OnThreadStarted(int thread_id); 235 void OnThreadStarted(int thread_id);
233 236
234 // Called back from Registry when the worker instance has ack'ed that 237 // Called back from Registry when the worker instance has ack'ed that
235 // it failed to load the script. 238 // it failed to load the script.
236 void OnScriptLoadFailed(); 239 void OnScriptLoadFailed();
(...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after
296 StartingPhase starting_phase_; 299 StartingPhase starting_phase_;
297 int restart_count_; 300 int restart_count_;
298 301
299 // Current running information. 302 // Current running information.
300 std::unique_ptr<EmbeddedWorkerInstance::WorkerProcessHandle> process_handle_; 303 std::unique_ptr<EmbeddedWorkerInstance::WorkerProcessHandle> process_handle_;
301 int thread_id_; 304 int thread_id_;
302 305
303 // |client_| is used to send messages to the renderer process. 306 // |client_| is used to send messages to the renderer process.
304 mojom::EmbeddedWorkerInstanceClientPtr client_; 307 mojom::EmbeddedWorkerInstanceClientPtr client_;
305 308
309 // Binding for EmbeddedWorkerInstanceHost, runs on IO thread.
310 mojo::AssociatedBinding<EmbeddedWorkerInstanceHost> instance_host_binding_;
311
306 // TODO(shimazu): Remove this after EmbeddedWorkerStartParams is changed to 312 // TODO(shimazu): Remove this after EmbeddedWorkerStartParams is changed to
307 // a mojo struct. 313 // a mojo struct.
308 mojom::ServiceWorkerEventDispatcherRequest pending_dispatcher_request_; 314 mojom::ServiceWorkerEventDispatcherRequest pending_dispatcher_request_;
309 315
310 // Whether devtools is attached or not. 316 // Whether devtools is attached or not.
311 bool devtools_attached_; 317 bool devtools_attached_;
312 318
313 // True if the script load request accessed the network. If the script was 319 // True if the script load request accessed the network. If the script was
314 // served from HTTPCache or ServiceWorkerDatabase this value is false. 320 // served from HTTPCache or ServiceWorkerDatabase this value is false.
315 bool network_accessed_for_script_; 321 bool network_accessed_for_script_;
(...skipping 11 matching lines...) Expand all
327 base::TimeTicks step_time_; 333 base::TimeTicks step_time_;
328 334
329 base::WeakPtrFactory<EmbeddedWorkerInstance> weak_factory_; 335 base::WeakPtrFactory<EmbeddedWorkerInstance> weak_factory_;
330 336
331 DISALLOW_COPY_AND_ASSIGN(EmbeddedWorkerInstance); 337 DISALLOW_COPY_AND_ASSIGN(EmbeddedWorkerInstance);
332 }; 338 };
333 339
334 } // namespace content 340 } // namespace content
335 341
336 #endif // CONTENT_BROWSER_SERVICE_WORKER_EMBEDDED_WORKER_INSTANCE_H_ 342 #endif // CONTENT_BROWSER_SERVICE_WORKER_EMBEDDED_WORKER_INSTANCE_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698