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_SERVICE_WORKER_VERSION_H_ | 5 #ifndef CONTENT_BROWSER_SERVICE_WORKER_SERVICE_WORKER_VERSION_H_ |
6 #define CONTENT_BROWSER_SERVICE_WORKER_SERVICE_WORKER_VERSION_H_ | 6 #define CONTENT_BROWSER_SERVICE_WORKER_SERVICE_WORKER_VERSION_H_ |
7 | 7 |
8 #include <map> | 8 #include <map> |
9 #include <set> | 9 #include <set> |
10 #include <string> | 10 #include <string> |
(...skipping 298 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
309 private: | 309 private: |
310 class GetClientDocumentsCallback; | 310 class GetClientDocumentsCallback; |
311 | 311 |
312 friend class base::RefCounted<ServiceWorkerVersion>; | 312 friend class base::RefCounted<ServiceWorkerVersion>; |
313 friend class ServiceWorkerURLRequestJobTest; | 313 friend class ServiceWorkerURLRequestJobTest; |
314 FRIEND_TEST_ALL_PREFIXES(ServiceWorkerControlleeRequestHandlerTest, | 314 FRIEND_TEST_ALL_PREFIXES(ServiceWorkerControlleeRequestHandlerTest, |
315 ActivateWaitingVersion); | 315 ActivateWaitingVersion); |
316 FRIEND_TEST_ALL_PREFIXES(ServiceWorkerVersionTest, ScheduleStopWorker); | 316 FRIEND_TEST_ALL_PREFIXES(ServiceWorkerVersionTest, ScheduleStopWorker); |
317 FRIEND_TEST_ALL_PREFIXES(ServiceWorkerVersionTest, KeepAlive); | 317 FRIEND_TEST_ALL_PREFIXES(ServiceWorkerVersionTest, KeepAlive); |
318 FRIEND_TEST_ALL_PREFIXES(ServiceWorkerVersionTest, ListenerAvailability); | 318 FRIEND_TEST_ALL_PREFIXES(ServiceWorkerVersionTest, ListenerAvailability); |
| 319 FRIEND_TEST_ALL_PREFIXES(ServiceWorkerVersionBrowserTest, |
| 320 TimeoutStartingWorker); |
| 321 FRIEND_TEST_ALL_PREFIXES(ServiceWorkerVersionBrowserTest, |
| 322 TimeoutWorkerInEvent); |
| 323 friend class ServiceWorkerVersionBrowserTest; |
| 324 |
319 typedef ServiceWorkerVersion self; | 325 typedef ServiceWorkerVersion self; |
320 typedef std::map<ServiceWorkerProviderHost*, int> ControlleeMap; | 326 typedef std::map<ServiceWorkerProviderHost*, int> ControlleeMap; |
321 typedef IDMap<ServiceWorkerProviderHost> ControlleeByIDMap; | 327 typedef IDMap<ServiceWorkerProviderHost> ControlleeByIDMap; |
322 | 328 |
323 ~ServiceWorkerVersion() override; | 329 ~ServiceWorkerVersion() override; |
324 | 330 |
325 // EmbeddedWorkerInstance::Listener overrides: | 331 // EmbeddedWorkerInstance::Listener overrides: |
| 332 void OnScriptLoaded() override; |
326 void OnStarted() override; | 333 void OnStarted() override; |
327 void OnStopped(EmbeddedWorkerInstance::Status old_status) override; | 334 void OnStopped(EmbeddedWorkerInstance::Status old_status) override; |
328 void OnReportException(const base::string16& error_message, | 335 void OnReportException(const base::string16& error_message, |
329 int line_number, | 336 int line_number, |
330 int column_number, | 337 int column_number, |
331 const GURL& source_url) override; | 338 const GURL& source_url) override; |
332 void OnReportConsoleMessage(int source_identifier, | 339 void OnReportConsoleMessage(int source_identifier, |
333 int message_level, | 340 int message_level, |
334 const base::string16& message, | 341 const base::string16& message, |
335 int line_number, | 342 int line_number, |
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
373 | 380 |
374 void OnSetCachedMetadata(const GURL& url, const std::vector<char>& data); | 381 void OnSetCachedMetadata(const GURL& url, const std::vector<char>& data); |
375 void OnClearCachedMetadata(const GURL& url); | 382 void OnClearCachedMetadata(const GURL& url); |
376 | 383 |
377 void OnPostMessageToDocument(int client_id, | 384 void OnPostMessageToDocument(int client_id, |
378 const base::string16& message, | 385 const base::string16& message, |
379 const std::vector<int>& sent_message_port_ids); | 386 const std::vector<int>& sent_message_port_ids); |
380 void OnFocusClient(int request_id, int client_id); | 387 void OnFocusClient(int request_id, int client_id); |
381 void OnSkipWaiting(int request_id); | 388 void OnSkipWaiting(int request_id); |
382 void OnClaimClients(int request_id); | 389 void OnClaimClients(int request_id); |
| 390 void OnPongFromWorker(); |
383 | 391 |
384 void OnFocusClientFinished(int request_id, | 392 void OnFocusClientFinished(int request_id, |
385 int client_id, | 393 int client_id, |
386 const ServiceWorkerClientInfo& client); | 394 const ServiceWorkerClientInfo& client); |
387 | 395 |
388 void DidSkipWaiting(int request_id); | 396 void DidSkipWaiting(int request_id); |
389 void DidClaimClients(int request_id, ServiceWorkerStatusCode status); | 397 void DidClaimClients(int request_id, ServiceWorkerStatusCode status); |
390 void DidGetClientInfo(int client_id, | 398 void DidGetClientInfo(int client_id, |
391 scoped_refptr<GetClientDocumentsCallback> callback, | 399 scoped_refptr<GetClientDocumentsCallback> callback, |
392 const ServiceWorkerClientInfo& info); | 400 const ServiceWorkerClientInfo& info); |
393 | 401 |
| 402 // The ping protocol is for terminating workers that are taking excessively |
| 403 // long executing JavaScript (e.g., stuck in while(true) {}). Periodically a |
| 404 // ping IPC is sent to the worker context and if we timeout waiting for a |
| 405 // pong, the worker is terminated. |
| 406 void PingWorker(); |
| 407 void StartPingWorker(); |
| 408 void SchedulePingWorker(); |
| 409 void OnPingTimeout(); |
| 410 |
| 411 // ScheduleStopWorker is for terminating idle workers. It schedules an attempt |
| 412 // to stop: if the worker has no inflight requests when the attempt runs, the |
| 413 // worker is terminated, otherwise the attempt is rescheduled. |
394 void ScheduleStopWorker(); | 414 void ScheduleStopWorker(); |
395 void StopWorkerIfIdle(); | 415 void StopWorkerIfIdle(); |
396 bool HasInflightRequests() const; | 416 bool HasInflightRequests() const; |
397 | 417 |
398 void DoomInternal(); | 418 void DoomInternal(); |
399 | 419 |
400 template <typename IDMAP> | 420 template <typename IDMAP> |
401 void RemoveCallbackAndStopIfDoomed(IDMAP* callbacks, int request_id); | 421 void RemoveCallbackAndStopIfDoomed(IDMAP* callbacks, int request_id); |
402 | 422 |
403 const int64 version_id_; | 423 const int64 version_id_; |
(...skipping 22 matching lines...) Expand all Loading... |
426 std::set<const ServiceWorkerURLRequestJob*> streaming_url_request_jobs_; | 446 std::set<const ServiceWorkerURLRequestJob*> streaming_url_request_jobs_; |
427 | 447 |
428 ControlleeMap controllee_map_; | 448 ControlleeMap controllee_map_; |
429 ControlleeByIDMap controllee_by_id_; | 449 ControlleeByIDMap controllee_by_id_; |
430 // Will be null while shutting down. | 450 // Will be null while shutting down. |
431 base::WeakPtr<ServiceWorkerContextCore> context_; | 451 base::WeakPtr<ServiceWorkerContextCore> context_; |
432 ObserverList<Listener> listeners_; | 452 ObserverList<Listener> listeners_; |
433 ServiceWorkerScriptCacheMap script_cache_map_; | 453 ServiceWorkerScriptCacheMap script_cache_map_; |
434 base::OneShotTimer<ServiceWorkerVersion> stop_worker_timer_; | 454 base::OneShotTimer<ServiceWorkerVersion> stop_worker_timer_; |
435 base::OneShotTimer<ServiceWorkerVersion> update_timer_; | 455 base::OneShotTimer<ServiceWorkerVersion> update_timer_; |
| 456 base::OneShotTimer<ServiceWorkerVersion> ping_worker_timer_; |
| 457 bool ping_timed_out_; |
436 bool is_doomed_; | 458 bool is_doomed_; |
437 std::vector<int> pending_skip_waiting_requests_; | 459 std::vector<int> pending_skip_waiting_requests_; |
438 bool skip_waiting_; | 460 bool skip_waiting_; |
439 scoped_ptr<net::HttpResponseInfo> main_script_http_info_; | 461 scoped_ptr<net::HttpResponseInfo> main_script_http_info_; |
440 | 462 |
441 base::WeakPtrFactory<ServiceWorkerVersion> weak_factory_; | 463 base::WeakPtrFactory<ServiceWorkerVersion> weak_factory_; |
442 | 464 |
443 DISALLOW_COPY_AND_ASSIGN(ServiceWorkerVersion); | 465 DISALLOW_COPY_AND_ASSIGN(ServiceWorkerVersion); |
444 }; | 466 }; |
445 | 467 |
446 } // namespace content | 468 } // namespace content |
447 | 469 |
448 #endif // CONTENT_BROWSER_SERVICE_WORKER_SERVICE_WORKER_VERSION_H_ | 470 #endif // CONTENT_BROWSER_SERVICE_WORKER_SERVICE_WORKER_VERSION_H_ |
OLD | NEW |