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

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

Issue 2490623005: Remove InterfaceRegistry/Provider from service workers (Closed)
Patch Set: rebase/fix comment Created 4 years 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_status_code.h" 28 #include "content/common/service_worker/service_worker_status_code.h"
28 #include "content/public/common/console_message_level.h" 29 #include "content/public/common/console_message_level.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 service_manager {
41 class InterfaceProvider;
42 class InterfaceRegistry;
43 }
44
45 namespace content { 41 namespace content {
46 42
47 class EmbeddedWorkerRegistry; 43 class EmbeddedWorkerRegistry;
48 struct EmbeddedWorkerStartParams; 44 struct EmbeddedWorkerStartParams;
49 class MessagePortMessageFilter; 45 class MessagePortMessageFilter;
50 class ServiceWorkerContextCore; 46 class ServiceWorkerContextCore;
51 47
52 // This gives an interface to control one EmbeddedWorker instance, which 48 // This gives an interface to control one EmbeddedWorker instance, which
53 // may be 'in-waiting' or running in one of the child processes added by 49 // may be 'in-waiting' or running in one of the child processes added by
54 // AddProcessReference(). 50 // AddProcessReference().
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after
106 }; 102 };
107 103
108 ~EmbeddedWorkerInstance(); 104 ~EmbeddedWorkerInstance();
109 105
110 // 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
111 // STOPPED status. |callback| is invoked after the worker script has been 107 // STOPPED status. |callback| is invoked after the worker script has been
112 // started and evaluated, or when an error occurs. 108 // started and evaluated, or when an error occurs.
113 // |params| should be populated with service worker version info needed 109 // |params| should be populated with service worker version info needed
114 // to start the worker. 110 // to start the worker.
115 void Start(std::unique_ptr<EmbeddedWorkerStartParams> params, 111 void Start(std::unique_ptr<EmbeddedWorkerStartParams> params,
112 mojom::ServiceWorkerEventDispatcherRequest dispatcher_request,
116 const StatusCallback& callback); 113 const StatusCallback& callback);
117 114
118 // Stops the worker. It is invalid to call this when the worker is 115 // Stops the worker. It is invalid to call this when the worker is
119 // not in STARTING or RUNNING status. 116 // not in STARTING or RUNNING status.
120 // This returns false if stopping a worker fails immediately, e.g. when 117 // This returns false if stopping a worker fails immediately, e.g. when
121 // IPC couldn't be sent to the worker. 118 // IPC couldn't be sent to the worker.
122 ServiceWorkerStatusCode Stop(); 119 ServiceWorkerStatusCode Stop();
123 120
124 // Stops the worker if the worker is not being debugged (i.e. devtools is 121 // Stops the worker if the worker is not being debugged (i.e. devtools is
125 // not attached). This method is called by a stop-worker timer to kill 122 // not attached). This method is called by a stop-worker timer to kill
126 // idle workers. 123 // idle workers.
127 void StopIfIdle(); 124 void StopIfIdle();
128 125
129 // Sends |message| to the embedded worker running in the child process. 126 // Sends |message| to the embedded worker running in the child process.
130 // It is invalid to call this while the worker is not in STARTING or RUNNING 127 // It is invalid to call this while the worker is not in STARTING or RUNNING
131 // status. 128 // status.
132 ServiceWorkerStatusCode SendMessage(const IPC::Message& message); 129 ServiceWorkerStatusCode SendMessage(const IPC::Message& message);
133 130
134 // Resumes the worker if it paused after download. 131 // Resumes the worker if it paused after download.
135 void ResumeAfterDownload(); 132 void ResumeAfterDownload();
136 133
137 // Returns the service_manager::InterfaceRegistry and
138 // service_manager::InterfaceProvider for this
139 // worker. It is invalid to call this when the worker is not in STARTING or
140 // RUNNING status.
141 service_manager::InterfaceRegistry* GetInterfaceRegistry();
142 service_manager::InterfaceProvider* GetRemoteInterfaces();
143
144 int embedded_worker_id() const { return embedded_worker_id_; } 134 int embedded_worker_id() const { return embedded_worker_id_; }
145 EmbeddedWorkerStatus status() const { return status_; } 135 EmbeddedWorkerStatus status() const { return status_; }
146 StartingPhase starting_phase() const { 136 StartingPhase starting_phase() const {
147 DCHECK_EQ(EmbeddedWorkerStatus::STARTING, status()); 137 DCHECK_EQ(EmbeddedWorkerStatus::STARTING, status());
148 return starting_phase_; 138 return starting_phase_;
149 } 139 }
150 int process_id() const; 140 int process_id() const;
151 int thread_id() const { return thread_id_; } 141 int thread_id() const { return thread_id_; }
152 // This should be called only when the worker instance has a valid process, 142 // This should be called only when the worker instance has a valid process,
153 // that is, when |process_id()| returns a valid process id. 143 // that is, when |process_id()| returns a valid process id.
(...skipping 151 matching lines...) Expand 10 before | Expand all | Expand 10 after
305 // Unique within an EmbeddedWorkerRegistry. 295 // Unique within an EmbeddedWorkerRegistry.
306 const int embedded_worker_id_; 296 const int embedded_worker_id_;
307 297
308 EmbeddedWorkerStatus status_; 298 EmbeddedWorkerStatus status_;
309 StartingPhase starting_phase_; 299 StartingPhase starting_phase_;
310 300
311 // Current running information. 301 // Current running information.
312 std::unique_ptr<EmbeddedWorkerInstance::WorkerProcessHandle> process_handle_; 302 std::unique_ptr<EmbeddedWorkerInstance::WorkerProcessHandle> process_handle_;
313 int thread_id_; 303 int thread_id_;
314 304
315 // These are connected to the renderer process after OnThreadStarted.
316 std::unique_ptr<service_manager::InterfaceRegistry> interface_registry_;
317 std::unique_ptr<service_manager::InterfaceProvider> remote_interfaces_;
318 // |client_| is used to send messages to the renderer process. 305 // |client_| is used to send messages to the renderer process.
319 mojom::EmbeddedWorkerInstanceClientPtr client_; 306 mojom::EmbeddedWorkerInstanceClientPtr client_;
320 307
308 // TODO(shimazu): Remove this after non-mojo StartWorker is removed.
309 mojom::ServiceWorkerEventDispatcherRequest pending_dispatcher_request_;
310
321 // Whether devtools is attached or not. 311 // Whether devtools is attached or not.
322 bool devtools_attached_; 312 bool devtools_attached_;
323 313
324 // True if the script load request accessed the network. If the script was 314 // True if the script load request accessed the network. If the script was
325 // served from HTTPCache or ServiceWorkerDatabase this value is false. 315 // served from HTTPCache or ServiceWorkerDatabase this value is false.
326 bool network_accessed_for_script_; 316 bool network_accessed_for_script_;
327 317
328 ListenerList listener_list_; 318 ListenerList listener_list_;
329 std::unique_ptr<DevToolsProxy> devtools_proxy_; 319 std::unique_ptr<DevToolsProxy> devtools_proxy_;
330 320
331 std::unique_ptr<StartTask> inflight_start_task_; 321 std::unique_ptr<StartTask> inflight_start_task_;
332 322
333 // This is valid only after a process is allocated for the worker. 323 // This is valid only after a process is allocated for the worker.
334 ServiceWorkerMetrics::StartSituation start_situation_ = 324 ServiceWorkerMetrics::StartSituation start_situation_ =
335 ServiceWorkerMetrics::StartSituation::UNKNOWN; 325 ServiceWorkerMetrics::StartSituation::UNKNOWN;
336 326
337 // Used for UMA. The start time of the current start sequence step. 327 // Used for UMA. The start time of the current start sequence step.
338 base::TimeTicks step_time_; 328 base::TimeTicks step_time_;
339 329
340 base::WeakPtrFactory<EmbeddedWorkerInstance> weak_factory_; 330 base::WeakPtrFactory<EmbeddedWorkerInstance> weak_factory_;
341 331
342 DISALLOW_COPY_AND_ASSIGN(EmbeddedWorkerInstance); 332 DISALLOW_COPY_AND_ASSIGN(EmbeddedWorkerInstance);
343 }; 333 };
344 334
345 } // namespace content 335 } // namespace content
346 336
347 #endif // CONTENT_BROWSER_SERVICE_WORKER_EMBEDDED_WORKER_INSTANCE_H_ 337 #endif // CONTENT_BROWSER_SERVICE_WORKER_EMBEDDED_WORKER_INSTANCE_H_
OLDNEW
« no previous file with comments | « content/browser/background_sync/background_sync_manager.cc ('k') | content/browser/service_worker/embedded_worker_instance.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698