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 <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/service_worker_metrics.h" | 24 #include "content/browser/service_worker/service_worker_metrics.h" |
24 #include "content/common/content_export.h" | 25 #include "content/common/content_export.h" |
25 #include "content/common/service_worker/service_worker_status_code.h" | 26 #include "content/common/service_worker/service_worker_status_code.h" |
26 #include "content/public/common/console_message_level.h" | 27 #include "content/public/common/console_message_level.h" |
27 #include "url/gurl.h" | 28 #include "url/gurl.h" |
28 | 29 |
29 // Windows headers will redefine SendMessage. | 30 // Windows headers will redefine SendMessage. |
30 #ifdef SendMessage | 31 #ifdef SendMessage |
31 #undef SendMessage | 32 #undef SendMessage |
32 #endif | 33 #endif |
(...skipping 11 matching lines...) Expand all Loading... | |
44 class ServiceRegistry; | 45 class ServiceRegistry; |
45 class ServiceRegistryImpl; | 46 class ServiceRegistryImpl; |
46 class ServiceWorkerContextCore; | 47 class ServiceWorkerContextCore; |
47 | 48 |
48 // This gives an interface to control one EmbeddedWorker instance, which | 49 // This gives an interface to control one EmbeddedWorker instance, which |
49 // may be 'in-waiting' or running in one of the child processes added by | 50 // may be 'in-waiting' or running in one of the child processes added by |
50 // AddProcessReference(). | 51 // AddProcessReference(). |
51 class CONTENT_EXPORT EmbeddedWorkerInstance { | 52 class CONTENT_EXPORT EmbeddedWorkerInstance { |
52 public: | 53 public: |
53 typedef base::Callback<void(ServiceWorkerStatusCode)> StatusCallback; | 54 typedef base::Callback<void(ServiceWorkerStatusCode)> StatusCallback; |
54 enum Status { | 55 typedef EmbeddedWorkerStatus Status; |
falken
2016/06/07 03:46:12
I think it's now:
using EmbeddedWorkerStatus = Sta
horo
2016/06/07 05:58:12
Done.
| |
55 STOPPED, | |
56 STARTING, | |
57 RUNNING, | |
58 STOPPING, | |
59 }; | |
60 | 56 |
61 // This enum is used in UMA histograms. Append-only. | 57 // This enum is used in UMA histograms. Append-only. |
62 enum StartingPhase { | 58 enum StartingPhase { |
63 NOT_STARTING, | 59 NOT_STARTING, |
64 ALLOCATING_PROCESS, | 60 ALLOCATING_PROCESS, |
65 REGISTERING_TO_DEVTOOLS, | 61 REGISTERING_TO_DEVTOOLS, |
66 SENT_START_WORKER, | 62 SENT_START_WORKER, |
67 SCRIPT_DOWNLOADING, | 63 SCRIPT_DOWNLOADING, |
68 SCRIPT_LOADED, | 64 SCRIPT_LOADED, |
69 SCRIPT_EVALUATED, | 65 SCRIPT_EVALUATED, |
(...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
135 // Resumes the worker if it paused after download. | 131 // Resumes the worker if it paused after download. |
136 void ResumeAfterDownload(); | 132 void ResumeAfterDownload(); |
137 | 133 |
138 // Returns the ServiceRegistry for this worker. It is invalid to call this | 134 // Returns the ServiceRegistry for this worker. It is invalid to call this |
139 // when the worker is not in STARTING or RUNNING status. | 135 // when the worker is not in STARTING or RUNNING status. |
140 ServiceRegistry* GetServiceRegistry(); | 136 ServiceRegistry* GetServiceRegistry(); |
141 | 137 |
142 int embedded_worker_id() const { return embedded_worker_id_; } | 138 int embedded_worker_id() const { return embedded_worker_id_; } |
143 Status status() const { return status_; } | 139 Status status() const { return status_; } |
144 StartingPhase starting_phase() const { | 140 StartingPhase starting_phase() const { |
145 DCHECK_EQ(STARTING, status()); | 141 DCHECK_EQ(Status::STARTING, status()); |
146 return starting_phase_; | 142 return starting_phase_; |
147 } | 143 } |
148 int process_id() const; | 144 int process_id() const; |
149 int thread_id() const { return thread_id_; } | 145 int thread_id() const { return thread_id_; } |
150 // This should be called only when the worker instance has a valid process, | 146 // This should be called only when the worker instance has a valid process, |
151 // that is, when |process_id()| returns a valid process id. | 147 // that is, when |process_id()| returns a valid process id. |
152 bool is_new_process() const; | 148 bool is_new_process() const; |
153 int worker_devtools_agent_route_id() const; | 149 int worker_devtools_agent_route_id() const; |
154 MessagePortMessageFilter* message_port_message_filter() const; | 150 MessagePortMessageFilter* message_port_message_filter() const; |
155 | 151 |
156 void AddListener(Listener* listener); | 152 void AddListener(Listener* listener); |
157 void RemoveListener(Listener* listener); | 153 void RemoveListener(Listener* listener); |
158 | 154 |
159 void set_devtools_attached(bool attached) { devtools_attached_ = attached; } | 155 void set_devtools_attached(bool attached) { devtools_attached_ = attached; } |
160 bool devtools_attached() const { return devtools_attached_; } | 156 bool devtools_attached() const { return devtools_attached_; } |
161 | 157 |
162 bool network_accessed_for_script() const { | 158 bool network_accessed_for_script() const { |
163 return network_accessed_for_script_; | 159 return network_accessed_for_script_; |
164 } | 160 } |
165 | 161 |
162 ServiceWorkerMetrics::StartSituation start_situation() const { | |
falken
2016/06/07 03:46:12
Does it make sense to have DCHECK(STARTING || RUNN
horo
2016/06/07 05:58:12
Done.
| |
163 return start_situation_; | |
164 } | |
165 | |
166 // Called when the main script load accessed the network. | 166 // Called when the main script load accessed the network. |
167 void OnNetworkAccessedForScriptLoad(); | 167 void OnNetworkAccessedForScriptLoad(); |
168 | 168 |
169 // Called when reading the main script from the service worker script cache | 169 // Called when reading the main script from the service worker script cache |
170 // begins and ends. | 170 // begins and ends. |
171 void OnScriptReadStarted(); | 171 void OnScriptReadStarted(); |
172 void OnScriptReadFinished(); | 172 void OnScriptReadFinished(); |
173 | 173 |
174 // Called when the worker is installed. | 174 // Called when the worker is installed. |
175 void OnWorkerVersionInstalled(); | 175 void OnWorkerVersionInstalled(); |
(...skipping 25 matching lines...) Expand all Loading... | |
201 FRIEND_TEST_ALL_PREFIXES(EmbeddedWorkerInstanceTest, StartAndStop); | 201 FRIEND_TEST_ALL_PREFIXES(EmbeddedWorkerInstanceTest, StartAndStop); |
202 FRIEND_TEST_ALL_PREFIXES(EmbeddedWorkerInstanceTest, DetachDuringStart); | 202 FRIEND_TEST_ALL_PREFIXES(EmbeddedWorkerInstanceTest, DetachDuringStart); |
203 FRIEND_TEST_ALL_PREFIXES(EmbeddedWorkerInstanceTest, StopDuringStart); | 203 FRIEND_TEST_ALL_PREFIXES(EmbeddedWorkerInstanceTest, StopDuringStart); |
204 | 204 |
205 // Constructor is called via EmbeddedWorkerRegistry::CreateWorker(). | 205 // Constructor is called via EmbeddedWorkerRegistry::CreateWorker(). |
206 // This instance holds a ref of |registry|. | 206 // This instance holds a ref of |registry|. |
207 EmbeddedWorkerInstance(base::WeakPtr<ServiceWorkerContextCore> context, | 207 EmbeddedWorkerInstance(base::WeakPtr<ServiceWorkerContextCore> context, |
208 int embedded_worker_id); | 208 int embedded_worker_id); |
209 | 209 |
210 // Called back from StartTask after a process is allocated on the UI thread. | 210 // Called back from StartTask after a process is allocated on the UI thread. |
211 void OnProcessAllocated(std::unique_ptr<WorkerProcessHandle> handle); | 211 void OnProcessAllocated(std::unique_ptr<WorkerProcessHandle> handle, |
212 ServiceWorkerMetrics::StartSituation start_situation); | |
212 | 213 |
213 // Called back from StartTask after the worker is registered to | 214 // Called back from StartTask after the worker is registered to |
214 // WorkerDevToolsManager. | 215 // WorkerDevToolsManager. |
215 void OnRegisteredToDevToolsManager(bool is_new_process, | 216 void OnRegisteredToDevToolsManager(bool is_new_process, |
216 int worker_devtools_agent_route_id, | 217 int worker_devtools_agent_route_id, |
217 bool wait_for_debugger); | 218 bool wait_for_debugger); |
218 | 219 |
219 // Called back from StartTask after a start worker message is sent. | 220 // Called back from StartTask after a start worker message is sent. |
220 void OnStartWorkerMessageSent(); | 221 void OnStartWorkerMessageSent(); |
221 | 222 |
(...skipping 80 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
302 | 303 |
303 // True if the script load request accessed the network. If the script was | 304 // True if the script load request accessed the network. If the script was |
304 // served from HTTPCache or ServiceWorkerDatabase this value is false. | 305 // served from HTTPCache or ServiceWorkerDatabase this value is false. |
305 bool network_accessed_for_script_; | 306 bool network_accessed_for_script_; |
306 | 307 |
307 ListenerList listener_list_; | 308 ListenerList listener_list_; |
308 std::unique_ptr<DevToolsProxy> devtools_proxy_; | 309 std::unique_ptr<DevToolsProxy> devtools_proxy_; |
309 | 310 |
310 std::unique_ptr<StartTask> inflight_start_task_; | 311 std::unique_ptr<StartTask> inflight_start_task_; |
311 | 312 |
313 ServiceWorkerMetrics::StartSituation start_situation_ = | |
314 ServiceWorkerMetrics::StartSituation::UNKNOWN; | |
falken
2016/06/07 03:46:12
It's a little unfortunate this state has to move o
horo
2016/06/07 05:58:12
Done.
| |
315 | |
312 // Used for UMA. The start time of the current start sequence step. | 316 // Used for UMA. The start time of the current start sequence step. |
313 base::TimeTicks step_time_; | 317 base::TimeTicks step_time_; |
314 | 318 |
315 base::WeakPtrFactory<EmbeddedWorkerInstance> weak_factory_; | 319 base::WeakPtrFactory<EmbeddedWorkerInstance> weak_factory_; |
316 | 320 |
317 DISALLOW_COPY_AND_ASSIGN(EmbeddedWorkerInstance); | 321 DISALLOW_COPY_AND_ASSIGN(EmbeddedWorkerInstance); |
318 }; | 322 }; |
319 | 323 |
320 } // namespace content | 324 } // namespace content |
321 | 325 |
322 #endif // CONTENT_BROWSER_SERVICE_WORKER_EMBEDDED_WORKER_INSTANCE_H_ | 326 #endif // CONTENT_BROWSER_SERVICE_WORKER_EMBEDDED_WORKER_INSTANCE_H_ |
OLD | NEW |