| 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 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 59 // script for a given pattern. When a script is upgraded, there may be | 59 // script for a given pattern. When a script is upgraded, there may be |
| 60 // more than one ServiceWorkerVersion "running" at a time, but only | 60 // more than one ServiceWorkerVersion "running" at a time, but only |
| 61 // one of them is activated. This class connects the actual script with a | 61 // one of them is activated. This class connects the actual script with a |
| 62 // running worker. | 62 // running worker. |
| 63 class CONTENT_EXPORT ServiceWorkerVersion | 63 class CONTENT_EXPORT ServiceWorkerVersion |
| 64 : NON_EXPORTED_BASE(public base::RefCounted<ServiceWorkerVersion>), | 64 : NON_EXPORTED_BASE(public base::RefCounted<ServiceWorkerVersion>), |
| 65 public EmbeddedWorkerInstance::Listener { | 65 public EmbeddedWorkerInstance::Listener { |
| 66 public: | 66 public: |
| 67 typedef base::Callback<void(ServiceWorkerStatusCode)> StatusCallback; | 67 typedef base::Callback<void(ServiceWorkerStatusCode)> StatusCallback; |
| 68 typedef base::Callback<void(ServiceWorkerStatusCode, | 68 typedef base::Callback<void(ServiceWorkerStatusCode, |
| 69 const IPC::Message& message)> MessageCallback; | |
| 70 typedef base::Callback<void(ServiceWorkerStatusCode, | |
| 71 ServiceWorkerFetchEventResult, | 69 ServiceWorkerFetchEventResult, |
| 72 const ServiceWorkerResponse&)> FetchCallback; | 70 const ServiceWorkerResponse&)> FetchCallback; |
| 73 typedef base::Callback<void(ServiceWorkerStatusCode, bool)> | 71 typedef base::Callback<void(ServiceWorkerStatusCode, bool)> |
| 74 CrossOriginConnectCallback; | 72 CrossOriginConnectCallback; |
| 75 | 73 |
| 76 enum RunningStatus { | 74 enum RunningStatus { |
| 77 STOPPED = EmbeddedWorkerInstance::STOPPED, | 75 STOPPED = EmbeddedWorkerInstance::STOPPED, |
| 78 STARTING = EmbeddedWorkerInstance::STARTING, | 76 STARTING = EmbeddedWorkerInstance::STARTING, |
| 79 RUNNING = EmbeddedWorkerInstance::RUNNING, | 77 RUNNING = EmbeddedWorkerInstance::RUNNING, |
| 80 STOPPING = EmbeddedWorkerInstance::STOPPING, | 78 STOPPING = EmbeddedWorkerInstance::STOPPING, |
| (...skipping 231 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 312 private: | 310 private: |
| 313 class GetClientDocumentsCallback; | 311 class GetClientDocumentsCallback; |
| 314 | 312 |
| 315 friend class base::RefCounted<ServiceWorkerVersion>; | 313 friend class base::RefCounted<ServiceWorkerVersion>; |
| 316 friend class ServiceWorkerURLRequestJobTest; | 314 friend class ServiceWorkerURLRequestJobTest; |
| 317 FRIEND_TEST_ALL_PREFIXES(ServiceWorkerControlleeRequestHandlerTest, | 315 FRIEND_TEST_ALL_PREFIXES(ServiceWorkerControlleeRequestHandlerTest, |
| 318 ActivateWaitingVersion); | 316 ActivateWaitingVersion); |
| 319 FRIEND_TEST_ALL_PREFIXES(ServiceWorkerVersionTest, ScheduleStopWorker); | 317 FRIEND_TEST_ALL_PREFIXES(ServiceWorkerVersionTest, ScheduleStopWorker); |
| 320 FRIEND_TEST_ALL_PREFIXES(ServiceWorkerVersionTest, KeepAlive); | 318 FRIEND_TEST_ALL_PREFIXES(ServiceWorkerVersionTest, KeepAlive); |
| 321 FRIEND_TEST_ALL_PREFIXES(ServiceWorkerVersionTest, ListenerAvailability); | 319 FRIEND_TEST_ALL_PREFIXES(ServiceWorkerVersionTest, ListenerAvailability); |
| 320 FRIEND_TEST_ALL_PREFIXES(ServiceWorkerFailToStartTest, Timeout); |
| 322 FRIEND_TEST_ALL_PREFIXES(ServiceWorkerVersionBrowserTest, | 321 FRIEND_TEST_ALL_PREFIXES(ServiceWorkerVersionBrowserTest, |
| 323 TimeoutStartingWorker); | 322 TimeoutStartingWorker); |
| 324 FRIEND_TEST_ALL_PREFIXES(ServiceWorkerVersionBrowserTest, | 323 FRIEND_TEST_ALL_PREFIXES(ServiceWorkerVersionBrowserTest, |
| 325 TimeoutWorkerInEvent); | 324 TimeoutWorkerInEvent); |
| 326 friend class ServiceWorkerVersionBrowserTest; | 325 friend class ServiceWorkerVersionBrowserTest; |
| 327 | 326 |
| 328 typedef ServiceWorkerVersion self; | 327 typedef ServiceWorkerVersion self; |
| 329 typedef std::map<ServiceWorkerProviderHost*, int> ControlleeMap; | 328 typedef std::map<ServiceWorkerProviderHost*, int> ControlleeMap; |
| 330 typedef IDMap<ServiceWorkerProviderHost> ControlleeByIDMap; | 329 typedef IDMap<ServiceWorkerProviderHost> ControlleeByIDMap; |
| 331 | 330 |
| 332 ~ServiceWorkerVersion() override; | 331 ~ServiceWorkerVersion() override; |
| 333 | 332 |
| 334 // EmbeddedWorkerInstance::Listener overrides: | 333 // EmbeddedWorkerInstance::Listener overrides: |
| 335 void OnScriptLoaded() override; | 334 void OnScriptLoaded() override; |
| 336 void OnStarted() override; | 335 void OnStarted() override; |
| 337 void OnStopped(EmbeddedWorkerInstance::Status old_status) override; | 336 void OnStopped(EmbeddedWorkerInstance::Status old_status) override; |
| 338 void OnReportException(const base::string16& error_message, | 337 void OnReportException(const base::string16& error_message, |
| 339 int line_number, | 338 int line_number, |
| 340 int column_number, | 339 int column_number, |
| 341 const GURL& source_url) override; | 340 const GURL& source_url) override; |
| 342 void OnReportConsoleMessage(int source_identifier, | 341 void OnReportConsoleMessage(int source_identifier, |
| 343 int message_level, | 342 int message_level, |
| 344 const base::string16& message, | 343 const base::string16& message, |
| 345 int line_number, | 344 int line_number, |
| 346 const GURL& source_url) override; | 345 const GURL& source_url) override; |
| 347 bool OnMessageReceived(const IPC::Message& message) override; | 346 bool OnMessageReceived(const IPC::Message& message) override; |
| 348 | 347 |
| 349 void OnStartMessageSent(ServiceWorkerStatusCode status); | 348 void OnStartSentAndScriptEvaluated(ServiceWorkerStatusCode status); |
| 350 | 349 |
| 351 void DispatchInstallEventAfterStartWorker(int active_version_id, | 350 void DispatchInstallEventAfterStartWorker(int active_version_id, |
| 352 const StatusCallback& callback); | 351 const StatusCallback& callback); |
| 353 void DispatchActivateEventAfterStartWorker(const StatusCallback& callback); | 352 void DispatchActivateEventAfterStartWorker(const StatusCallback& callback); |
| 354 | 353 |
| 355 void DispatchMessageEventInternal( | 354 void DispatchMessageEventInternal( |
| 356 const base::string16& message, | 355 const base::string16& message, |
| 357 const std::vector<TransferredMessagePort>& sent_message_ports, | 356 const std::vector<TransferredMessagePort>& sent_message_ports, |
| 358 const StatusCallback& callback); | 357 const StatusCallback& callback); |
| 359 | 358 |
| (...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 414 void SchedulePingWorker(); | 413 void SchedulePingWorker(); |
| 415 void OnPingTimeout(); | 414 void OnPingTimeout(); |
| 416 | 415 |
| 417 // ScheduleStopWorker is for terminating idle workers. It schedules an attempt | 416 // ScheduleStopWorker is for terminating idle workers. It schedules an attempt |
| 418 // to stop: if the worker has no inflight requests when the attempt runs, the | 417 // to stop: if the worker has no inflight requests when the attempt runs, the |
| 419 // worker is terminated, otherwise the attempt is rescheduled. | 418 // worker is terminated, otherwise the attempt is rescheduled. |
| 420 void ScheduleStopWorker(); | 419 void ScheduleStopWorker(); |
| 421 void StopWorkerIfIdle(); | 420 void StopWorkerIfIdle(); |
| 422 bool HasInflightRequests() const; | 421 bool HasInflightRequests() const; |
| 423 | 422 |
| 423 // ScheduleStartWorkerTimeout is called when attempting to the start the |
| 424 // embedded worker. It sets a timer for calling OnStartWorkerTimeout, which |
| 425 // invokes start callbacks with ERROR_TIMEOUT. It also adds its own start |
| 426 // callback RecordStartWorkerResult which cancels the timer and records |
| 427 // metrics about startup. |
| 428 void ScheduleStartWorkerTimeout(); |
| 429 void RecordStartWorkerResult(ServiceWorkerStatusCode status); |
| 430 void OnStartWorkerTimeout(); |
| 431 |
| 424 void DoomInternal(); | 432 void DoomInternal(); |
| 425 | 433 |
| 426 template <typename IDMAP> | 434 template <typename IDMAP> |
| 427 void RemoveCallbackAndStopIfDoomed(IDMAP* callbacks, int request_id); | 435 void RemoveCallbackAndStopIfDoomed(IDMAP* callbacks, int request_id); |
| 428 | 436 |
| 429 const int64 version_id_; | 437 const int64 version_id_; |
| 430 int64 registration_id_; | 438 int64 registration_id_; |
| 431 GURL script_url_; | 439 GURL script_url_; |
| 432 GURL scope_; | 440 GURL scope_; |
| 433 Status status_; | 441 Status status_; |
| (...skipping 19 matching lines...) Expand all Loading... |
| 453 | 461 |
| 454 ControlleeMap controllee_map_; | 462 ControlleeMap controllee_map_; |
| 455 ControlleeByIDMap controllee_by_id_; | 463 ControlleeByIDMap controllee_by_id_; |
| 456 // Will be null while shutting down. | 464 // Will be null while shutting down. |
| 457 base::WeakPtr<ServiceWorkerContextCore> context_; | 465 base::WeakPtr<ServiceWorkerContextCore> context_; |
| 458 ObserverList<Listener> listeners_; | 466 ObserverList<Listener> listeners_; |
| 459 ServiceWorkerScriptCacheMap script_cache_map_; | 467 ServiceWorkerScriptCacheMap script_cache_map_; |
| 460 base::OneShotTimer<ServiceWorkerVersion> stop_worker_timer_; | 468 base::OneShotTimer<ServiceWorkerVersion> stop_worker_timer_; |
| 461 base::OneShotTimer<ServiceWorkerVersion> update_timer_; | 469 base::OneShotTimer<ServiceWorkerVersion> update_timer_; |
| 462 base::OneShotTimer<ServiceWorkerVersion> ping_worker_timer_; | 470 base::OneShotTimer<ServiceWorkerVersion> ping_worker_timer_; |
| 471 base::OneShotTimer<ServiceWorkerVersion> start_worker_timeout_timer_; |
| 472 base::TimeTicks start_timing_; |
| 463 bool ping_timed_out_; | 473 bool ping_timed_out_; |
| 464 bool is_doomed_; | 474 bool is_doomed_; |
| 465 std::vector<int> pending_skip_waiting_requests_; | 475 std::vector<int> pending_skip_waiting_requests_; |
| 466 bool skip_waiting_; | 476 bool skip_waiting_; |
| 467 scoped_ptr<net::HttpResponseInfo> main_script_http_info_; | 477 scoped_ptr<net::HttpResponseInfo> main_script_http_info_; |
| 468 | 478 |
| 469 base::WeakPtrFactory<ServiceWorkerVersion> weak_factory_; | 479 base::WeakPtrFactory<ServiceWorkerVersion> weak_factory_; |
| 470 | 480 |
| 471 DISALLOW_COPY_AND_ASSIGN(ServiceWorkerVersion); | 481 DISALLOW_COPY_AND_ASSIGN(ServiceWorkerVersion); |
| 472 }; | 482 }; |
| 473 | 483 |
| 474 } // namespace content | 484 } // namespace content |
| 475 | 485 |
| 476 #endif // CONTENT_BROWSER_SERVICE_WORKER_SERVICE_WORKER_VERSION_H_ | 486 #endif // CONTENT_BROWSER_SERVICE_WORKER_SERVICE_WORKER_VERSION_H_ |
| OLD | NEW |