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

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

Issue 962543005: Service Worker: Add metrics and timeout for starting a Service Worker. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: sync again Created 5 years, 9 months 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_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
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 221 matching lines...) Expand 10 before | Expand all | Expand 10 after
302 private: 300 private:
303 class GetClientDocumentsCallback; 301 class GetClientDocumentsCallback;
304 302
305 friend class base::RefCounted<ServiceWorkerVersion>; 303 friend class base::RefCounted<ServiceWorkerVersion>;
306 friend class ServiceWorkerURLRequestJobTest; 304 friend class ServiceWorkerURLRequestJobTest;
307 FRIEND_TEST_ALL_PREFIXES(ServiceWorkerControlleeRequestHandlerTest, 305 FRIEND_TEST_ALL_PREFIXES(ServiceWorkerControlleeRequestHandlerTest,
308 ActivateWaitingVersion); 306 ActivateWaitingVersion);
309 FRIEND_TEST_ALL_PREFIXES(ServiceWorkerVersionTest, ScheduleStopWorker); 307 FRIEND_TEST_ALL_PREFIXES(ServiceWorkerVersionTest, ScheduleStopWorker);
310 FRIEND_TEST_ALL_PREFIXES(ServiceWorkerVersionTest, KeepAlive); 308 FRIEND_TEST_ALL_PREFIXES(ServiceWorkerVersionTest, KeepAlive);
311 FRIEND_TEST_ALL_PREFIXES(ServiceWorkerVersionTest, ListenerAvailability); 309 FRIEND_TEST_ALL_PREFIXES(ServiceWorkerVersionTest, ListenerAvailability);
310 FRIEND_TEST_ALL_PREFIXES(ServiceWorkerFailToStartTest, Timeout);
312 FRIEND_TEST_ALL_PREFIXES(ServiceWorkerVersionBrowserTest, 311 FRIEND_TEST_ALL_PREFIXES(ServiceWorkerVersionBrowserTest,
313 TimeoutStartingWorker); 312 TimeoutStartingWorker);
314 FRIEND_TEST_ALL_PREFIXES(ServiceWorkerVersionBrowserTest, 313 FRIEND_TEST_ALL_PREFIXES(ServiceWorkerVersionBrowserTest,
315 TimeoutWorkerInEvent); 314 TimeoutWorkerInEvent);
316 friend class ServiceWorkerVersionBrowserTest; 315 friend class ServiceWorkerVersionBrowserTest;
317 316
318 typedef ServiceWorkerVersion self; 317 typedef ServiceWorkerVersion self;
319 typedef std::map<ServiceWorkerProviderHost*, int> ControlleeMap; 318 typedef std::map<ServiceWorkerProviderHost*, int> ControlleeMap;
320 typedef IDMap<ServiceWorkerProviderHost> ControlleeByIDMap; 319 typedef IDMap<ServiceWorkerProviderHost> ControlleeByIDMap;
321 320
322 ~ServiceWorkerVersion() override; 321 ~ServiceWorkerVersion() override;
323 322
324 // EmbeddedWorkerInstance::Listener overrides: 323 // EmbeddedWorkerInstance::Listener overrides:
325 void OnScriptLoaded() override; 324 void OnScriptLoaded() override;
326 void OnStarted() override; 325 void OnStarted() override;
327 void OnStopped(EmbeddedWorkerInstance::Status old_status) override; 326 void OnStopped(EmbeddedWorkerInstance::Status old_status) override;
328 void OnReportException(const base::string16& error_message, 327 void OnReportException(const base::string16& error_message,
329 int line_number, 328 int line_number,
330 int column_number, 329 int column_number,
331 const GURL& source_url) override; 330 const GURL& source_url) override;
332 void OnReportConsoleMessage(int source_identifier, 331 void OnReportConsoleMessage(int source_identifier,
333 int message_level, 332 int message_level,
334 const base::string16& message, 333 const base::string16& message,
335 int line_number, 334 int line_number,
336 const GURL& source_url) override; 335 const GURL& source_url) override;
337 bool OnMessageReceived(const IPC::Message& message) override; 336 bool OnMessageReceived(const IPC::Message& message) override;
338 337
339 void OnStartMessageSent(ServiceWorkerStatusCode status); 338 void OnStartSentAndScriptEvaluated(ServiceWorkerStatusCode status);
340 339
341 void DispatchInstallEventAfterStartWorker(const StatusCallback& callback); 340 void DispatchInstallEventAfterStartWorker(const StatusCallback& callback);
342 void DispatchActivateEventAfterStartWorker(const StatusCallback& callback); 341 void DispatchActivateEventAfterStartWorker(const StatusCallback& callback);
343 342
344 void DispatchMessageEventInternal( 343 void DispatchMessageEventInternal(
345 const base::string16& message, 344 const base::string16& message,
346 const std::vector<TransferredMessagePort>& sent_message_ports, 345 const std::vector<TransferredMessagePort>& sent_message_ports,
347 const StatusCallback& callback); 346 const StatusCallback& callback);
348 347
349 // Message handlers. 348 // Message handlers.
(...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after
403 void SchedulePingWorker(); 402 void SchedulePingWorker();
404 void OnPingTimeout(); 403 void OnPingTimeout();
405 404
406 // ScheduleStopWorker is for terminating idle workers. It schedules an attempt 405 // ScheduleStopWorker is for terminating idle workers. It schedules an attempt
407 // to stop: if the worker has no inflight requests when the attempt runs, the 406 // to stop: if the worker has no inflight requests when the attempt runs, the
408 // worker is terminated, otherwise the attempt is rescheduled. 407 // worker is terminated, otherwise the attempt is rescheduled.
409 void ScheduleStopWorker(); 408 void ScheduleStopWorker();
410 void StopWorkerIfIdle(); 409 void StopWorkerIfIdle();
411 bool HasInflightRequests() const; 410 bool HasInflightRequests() const;
412 411
412 // ScheduleStartWorkerTimeout is called when attempting to the start the
413 // embedded worker. It sets a timer for calling OnStartWorkerTimeout, which
414 // invokes start callbacks with ERROR_TIMEOUT. It also adds its own start
415 // callback RecordStartWorkerResult which cancels the timer and records
416 // metrics about startup.
417 void ScheduleStartWorkerTimeout();
418 void RecordStartWorkerResult(ServiceWorkerStatusCode status);
419 void OnStartWorkerTimeout();
420
413 void DoomInternal(); 421 void DoomInternal();
414 422
415 template <typename IDMAP> 423 template <typename IDMAP>
416 void RemoveCallbackAndStopIfDoomed(IDMAP* callbacks, int request_id); 424 void RemoveCallbackAndStopIfDoomed(IDMAP* callbacks, int request_id);
417 425
418 const int64 version_id_; 426 const int64 version_id_;
419 int64 registration_id_; 427 int64 registration_id_;
420 GURL script_url_; 428 GURL script_url_;
421 GURL scope_; 429 GURL scope_;
422 Status status_; 430 Status status_;
(...skipping 19 matching lines...) Expand all
442 450
443 ControlleeMap controllee_map_; 451 ControlleeMap controllee_map_;
444 ControlleeByIDMap controllee_by_id_; 452 ControlleeByIDMap controllee_by_id_;
445 // Will be null while shutting down. 453 // Will be null while shutting down.
446 base::WeakPtr<ServiceWorkerContextCore> context_; 454 base::WeakPtr<ServiceWorkerContextCore> context_;
447 ObserverList<Listener> listeners_; 455 ObserverList<Listener> listeners_;
448 ServiceWorkerScriptCacheMap script_cache_map_; 456 ServiceWorkerScriptCacheMap script_cache_map_;
449 base::OneShotTimer<ServiceWorkerVersion> stop_worker_timer_; 457 base::OneShotTimer<ServiceWorkerVersion> stop_worker_timer_;
450 base::OneShotTimer<ServiceWorkerVersion> update_timer_; 458 base::OneShotTimer<ServiceWorkerVersion> update_timer_;
451 base::OneShotTimer<ServiceWorkerVersion> ping_worker_timer_; 459 base::OneShotTimer<ServiceWorkerVersion> ping_worker_timer_;
460 base::OneShotTimer<ServiceWorkerVersion> start_worker_timeout_timer_;
461 base::TimeTicks start_timing_;
452 bool ping_timed_out_; 462 bool ping_timed_out_;
453 bool is_doomed_; 463 bool is_doomed_;
454 std::vector<int> pending_skip_waiting_requests_; 464 std::vector<int> pending_skip_waiting_requests_;
455 bool skip_waiting_; 465 bool skip_waiting_;
456 scoped_ptr<net::HttpResponseInfo> main_script_http_info_; 466 scoped_ptr<net::HttpResponseInfo> main_script_http_info_;
457 467
458 base::WeakPtrFactory<ServiceWorkerVersion> weak_factory_; 468 base::WeakPtrFactory<ServiceWorkerVersion> weak_factory_;
459 469
460 DISALLOW_COPY_AND_ASSIGN(ServiceWorkerVersion); 470 DISALLOW_COPY_AND_ASSIGN(ServiceWorkerVersion);
461 }; 471 };
462 472
463 } // namespace content 473 } // namespace content
464 474
465 #endif // CONTENT_BROWSER_SERVICE_WORKER_SERVICE_WORKER_VERSION_H_ 475 #endif // CONTENT_BROWSER_SERVICE_WORKER_SERVICE_WORKER_VERSION_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698