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