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 <queue> | 9 #include <queue> |
10 #include <set> | 10 #include <set> |
11 #include <string> | 11 #include <string> |
12 #include <vector> | 12 #include <vector> |
13 | 13 |
14 #include "base/basictypes.h" | 14 #include "base/basictypes.h" |
15 #include "base/callback.h" | 15 #include "base/callback.h" |
16 #include "base/gtest_prod_util.h" | 16 #include "base/gtest_prod_util.h" |
17 #include "base/id_map.h" | 17 #include "base/id_map.h" |
18 #include "base/memory/ref_counted.h" | 18 #include "base/memory/ref_counted.h" |
19 #include "base/memory/scoped_ptr.h" | 19 #include "base/memory/scoped_ptr.h" |
20 #include "base/observer_list.h" | 20 #include "base/observer_list.h" |
21 #include "base/timer/timer.h" | 21 #include "base/timer/timer.h" |
22 #include "content/browser/service_worker/embedded_worker_instance.h" | 22 #include "content/browser/service_worker/embedded_worker_instance.h" |
23 #include "content/browser/service_worker/service_worker_script_cache_map.h" | 23 #include "content/browser/service_worker/service_worker_script_cache_map.h" |
24 #include "content/common/background_sync_service.mojom.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/common/service_worker/service_worker_types.h" | 27 #include "content/common/service_worker/service_worker_types.h" |
27 #include "third_party/WebKit/public/platform/WebGeofencingEventType.h" | 28 #include "third_party/WebKit/public/platform/WebGeofencingEventType.h" |
28 #include "third_party/WebKit/public/platform/WebServiceWorkerEventResult.h" | 29 #include "third_party/WebKit/public/platform/WebServiceWorkerEventResult.h" |
29 | 30 |
30 // Windows headers will redefine SendMessage. | 31 // Windows headers will redefine SendMessage. |
31 #ifdef SendMessage | 32 #ifdef SendMessage |
32 #undef SendMessage | 33 #undef SendMessage |
33 #endif | 34 #endif |
34 | 35 |
35 class GURL; | 36 class GURL; |
36 | 37 |
37 namespace blink { | 38 namespace blink { |
38 struct WebCircularGeofencingRegion; | 39 struct WebCircularGeofencingRegion; |
39 } | 40 } |
40 | 41 |
41 namespace net { | 42 namespace net { |
42 class HttpResponseInfo; | 43 class HttpResponseInfo; |
43 } | 44 } |
44 | 45 |
45 namespace content { | 46 namespace content { |
46 | 47 |
47 class EmbeddedWorkerRegistry; | 48 class EmbeddedWorkerRegistry; |
48 class ServiceWorkerContextCore; | 49 class ServiceWorkerContextCore; |
50 class ServiceWorkerMojoEventDispatcher; | |
49 class ServiceWorkerProviderHost; | 51 class ServiceWorkerProviderHost; |
50 class ServiceWorkerRegistration; | 52 class ServiceWorkerRegistration; |
51 class ServiceWorkerURLRequestJob; | 53 class ServiceWorkerURLRequestJob; |
52 struct NavigatorConnectClient; | 54 struct NavigatorConnectClient; |
53 struct PlatformNotificationData; | 55 struct PlatformNotificationData; |
54 struct ServiceWorkerClientInfo; | 56 struct ServiceWorkerClientInfo; |
55 struct ServiceWorkerVersionInfo; | 57 struct ServiceWorkerVersionInfo; |
56 struct TransferredMessagePort; | 58 struct TransferredMessagePort; |
57 | 59 |
58 // This class corresponds to a specific version of a ServiceWorker | 60 // This class corresponds to a specific version of a ServiceWorker |
(...skipping 288 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
347 class Metrics; | 349 class Metrics; |
348 class PingController; | 350 class PingController; |
349 | 351 |
350 typedef ServiceWorkerVersion self; | 352 typedef ServiceWorkerVersion self; |
351 using ServiceWorkerClients = std::vector<ServiceWorkerClientInfo>; | 353 using ServiceWorkerClients = std::vector<ServiceWorkerClientInfo>; |
352 | 354 |
353 enum RequestType { | 355 enum RequestType { |
354 REQUEST_ACTIVATE, | 356 REQUEST_ACTIVATE, |
355 REQUEST_INSTALL, | 357 REQUEST_INSTALL, |
356 REQUEST_FETCH, | 358 REQUEST_FETCH, |
357 REQUEST_SYNC, | |
358 REQUEST_NOTIFICATION_CLICK, | 359 REQUEST_NOTIFICATION_CLICK, |
359 REQUEST_PUSH, | 360 REQUEST_PUSH, |
360 REQUEST_GEOFENCING, | 361 REQUEST_GEOFENCING, |
361 REQUEST_CROSS_ORIGIN_CONNECT | 362 REQUEST_CROSS_ORIGIN_CONNECT |
362 }; | 363 }; |
363 | 364 |
364 struct RequestInfo { | 365 struct RequestInfo { |
365 RequestInfo(int id, RequestType type); | 366 RequestInfo(int id, RequestType type); |
366 ~RequestInfo(); | 367 ~RequestInfo(); |
367 int id; | 368 int id; |
(...skipping 18 matching lines...) Expand all Loading... | |
386 int line_number, | 387 int line_number, |
387 int column_number, | 388 int column_number, |
388 const GURL& source_url) override; | 389 const GURL& source_url) override; |
389 void OnReportConsoleMessage(int source_identifier, | 390 void OnReportConsoleMessage(int source_identifier, |
390 int message_level, | 391 int message_level, |
391 const base::string16& message, | 392 const base::string16& message, |
392 int line_number, | 393 int line_number, |
393 const GURL& source_url) override; | 394 const GURL& source_url) override; |
394 bool OnMessageReceived(const IPC::Message& message) override; | 395 bool OnMessageReceived(const IPC::Message& message) override; |
395 | 396 |
397 // Handle callbacks from background sync events | |
398 void OnSyncEventFinished(const StatusCallback& callback, | |
399 ServiceWorkerStatusCode status); | |
400 | |
396 void OnStartSentAndScriptEvaluated(ServiceWorkerStatusCode status); | 401 void OnStartSentAndScriptEvaluated(ServiceWorkerStatusCode status); |
397 | 402 |
398 void DispatchInstallEventAfterStartWorker(const StatusCallback& callback); | 403 void DispatchInstallEventAfterStartWorker(const StatusCallback& callback); |
399 void DispatchActivateEventAfterStartWorker(const StatusCallback& callback); | 404 void DispatchActivateEventAfterStartWorker(const StatusCallback& callback); |
400 | 405 |
401 void DispatchMessageEventInternal( | 406 void DispatchMessageEventInternal( |
402 const base::string16& message, | 407 const base::string16& message, |
403 const std::vector<TransferredMessagePort>& sent_message_ports, | 408 const std::vector<TransferredMessagePort>& sent_message_ports, |
404 const StatusCallback& callback); | 409 const StatusCallback& callback); |
405 | 410 |
406 // Message handlers. | 411 // Message handlers. |
407 | 412 |
408 // This corresponds to the spec's matchAll(options) steps. | 413 // This corresponds to the spec's matchAll(options) steps. |
409 void OnGetClients(int request_id, | 414 void OnGetClients(int request_id, |
410 const ServiceWorkerClientQueryOptions& options); | 415 const ServiceWorkerClientQueryOptions& options); |
411 | 416 |
412 void OnActivateEventFinished(int request_id, | 417 void OnActivateEventFinished(int request_id, |
413 blink::WebServiceWorkerEventResult result); | 418 blink::WebServiceWorkerEventResult result); |
414 void OnInstallEventFinished(int request_id, | 419 void OnInstallEventFinished(int request_id, |
415 blink::WebServiceWorkerEventResult result); | 420 blink::WebServiceWorkerEventResult result); |
416 void OnFetchEventFinished(int request_id, | 421 void OnFetchEventFinished(int request_id, |
417 ServiceWorkerFetchEventResult result, | 422 ServiceWorkerFetchEventResult result, |
418 const ServiceWorkerResponse& response); | 423 const ServiceWorkerResponse& response); |
419 void OnSyncEventFinished(int request_id, | |
420 blink::WebServiceWorkerEventResult result); | |
421 void OnNotificationClickEventFinished(int request_id); | 424 void OnNotificationClickEventFinished(int request_id); |
422 void OnPushEventFinished(int request_id, | 425 void OnPushEventFinished(int request_id, |
423 blink::WebServiceWorkerEventResult result); | 426 blink::WebServiceWorkerEventResult result); |
424 void OnGeofencingEventFinished(int request_id); | 427 void OnGeofencingEventFinished(int request_id); |
425 void OnCrossOriginConnectEventFinished(int request_id, | 428 void OnCrossOriginConnectEventFinished(int request_id, |
426 bool accept_connection); | 429 bool accept_connection); |
427 void OnOpenWindow(int request_id, GURL url); | 430 void OnOpenWindow(int request_id, GURL url); |
428 void DidOpenWindow(int request_id, | 431 void DidOpenWindow(int request_id, |
429 int render_process_id, | 432 int render_process_id, |
430 int render_frame_id); | 433 int render_frame_id); |
(...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
483 | 486 |
484 // Stops the worker if it is idle (has no in-flight requests) or timed out | 487 // Stops the worker if it is idle (has no in-flight requests) or timed out |
485 // ping. | 488 // ping. |
486 void StopWorkerIfIdle(); | 489 void StopWorkerIfIdle(); |
487 bool HasInflightRequests() const; | 490 bool HasInflightRequests() const; |
488 | 491 |
489 // RecordStartWorkerResult is added as a start callback by StartTimeoutTimer | 492 // RecordStartWorkerResult is added as a start callback by StartTimeoutTimer |
490 // and records metrics about startup. | 493 // and records metrics about startup. |
491 void RecordStartWorkerResult(ServiceWorkerStatusCode status); | 494 void RecordStartWorkerResult(ServiceWorkerStatusCode status); |
492 | 495 |
496 void StopIfRedundant(); | |
497 | |
493 template <typename IDMAP> | 498 template <typename IDMAP> |
494 void RemoveCallbackAndStopIfRedundant(IDMAP* callbacks, int request_id); | 499 void RemoveCallbackAndStopIfRedundant(IDMAP* callbacks, int request_id); |
495 | 500 |
496 template <typename CallbackType> | 501 template <typename CallbackType> |
497 int AddRequest(const CallbackType& callback, | 502 int AddRequest(const CallbackType& callback, |
498 IDMap<CallbackType, IDMapOwnPointer>* callback_map, | 503 IDMap<CallbackType, IDMapOwnPointer>* callback_map, |
499 RequestType request_type); | 504 RequestType request_type); |
500 | 505 |
501 bool OnRequestTimeout(const RequestInfo& info); | 506 bool OnRequestTimeout(const RequestInfo& info); |
502 void SetAllRequestTimes(const base::TimeTicks& ticks); | 507 void SetAllRequestTimes(const base::TimeTicks& ticks); |
(...skipping 13 matching lines...) Expand all Loading... | |
516 scoped_ptr<EmbeddedWorkerInstance> embedded_worker_; | 521 scoped_ptr<EmbeddedWorkerInstance> embedded_worker_; |
517 std::vector<StatusCallback> start_callbacks_; | 522 std::vector<StatusCallback> start_callbacks_; |
518 std::vector<StatusCallback> stop_callbacks_; | 523 std::vector<StatusCallback> stop_callbacks_; |
519 std::vector<base::Closure> status_change_callbacks_; | 524 std::vector<base::Closure> status_change_callbacks_; |
520 | 525 |
521 // Message callbacks. (Update HasInflightRequests() too when you update this | 526 // Message callbacks. (Update HasInflightRequests() too when you update this |
522 // list.) | 527 // list.) |
523 IDMap<StatusCallback, IDMapOwnPointer> activate_callbacks_; | 528 IDMap<StatusCallback, IDMapOwnPointer> activate_callbacks_; |
524 IDMap<StatusCallback, IDMapOwnPointer> install_callbacks_; | 529 IDMap<StatusCallback, IDMapOwnPointer> install_callbacks_; |
525 IDMap<FetchCallback, IDMapOwnPointer> fetch_callbacks_; | 530 IDMap<FetchCallback, IDMapOwnPointer> fetch_callbacks_; |
526 IDMap<StatusCallback, IDMapOwnPointer> sync_callbacks_; | |
jkarlin
2015/06/17 15:17:29
You're going to need to keep this, for the reasons
iclelland
2015/06/18 16:01:14
As we discussed, I've reinstated all of the callba
| |
527 IDMap<StatusCallback, IDMapOwnPointer> notification_click_callbacks_; | 531 IDMap<StatusCallback, IDMapOwnPointer> notification_click_callbacks_; |
528 IDMap<StatusCallback, IDMapOwnPointer> push_callbacks_; | 532 IDMap<StatusCallback, IDMapOwnPointer> push_callbacks_; |
529 IDMap<StatusCallback, IDMapOwnPointer> geofencing_callbacks_; | 533 IDMap<StatusCallback, IDMapOwnPointer> geofencing_callbacks_; |
530 IDMap<CrossOriginConnectCallback, IDMapOwnPointer> | 534 IDMap<CrossOriginConnectCallback, IDMapOwnPointer> |
531 cross_origin_connect_callbacks_; | 535 cross_origin_connect_callbacks_; |
532 | 536 |
533 std::set<const ServiceWorkerURLRequestJob*> streaming_url_request_jobs_; | 537 std::set<const ServiceWorkerURLRequestJob*> streaming_url_request_jobs_; |
534 | 538 |
535 std::map<std::string, ServiceWorkerProviderHost*> controllee_map_; | 539 std::map<std::string, ServiceWorkerProviderHost*> controllee_map_; |
536 // Will be null while shutting down. | 540 // Will be null while shutting down. |
(...skipping 24 matching lines...) Expand all Loading... | |
561 | 565 |
562 // The status when StartWorker was invoked. Used for UMA. | 566 // The status when StartWorker was invoked. Used for UMA. |
563 Status prestart_status_ = NEW; | 567 Status prestart_status_ = NEW; |
564 // If not OK, the reason that StartWorker failed. Used for | 568 // If not OK, the reason that StartWorker failed. Used for |
565 // running |start_callbacks_|. | 569 // running |start_callbacks_|. |
566 ServiceWorkerStatusCode start_worker_status_ = SERVICE_WORKER_OK; | 570 ServiceWorkerStatusCode start_worker_status_ = SERVICE_WORKER_OK; |
567 | 571 |
568 scoped_ptr<PingController> ping_controller_; | 572 scoped_ptr<PingController> ping_controller_; |
569 scoped_ptr<Metrics> metrics_; | 573 scoped_ptr<Metrics> metrics_; |
570 | 574 |
575 scoped_ptr<ServiceWorkerMojoEventDispatcher> mojo_event_dispatcher_; | |
jkarlin
2015/06/17 15:17:29
Why a scoped_ptr? This could just be a member.
iclelland
2015/06/18 16:01:14
No good reason, I suppose; I've untangled the #inc
| |
576 | |
571 base::WeakPtrFactory<ServiceWorkerVersion> weak_factory_; | 577 base::WeakPtrFactory<ServiceWorkerVersion> weak_factory_; |
572 | 578 |
573 DISALLOW_COPY_AND_ASSIGN(ServiceWorkerVersion); | 579 DISALLOW_COPY_AND_ASSIGN(ServiceWorkerVersion); |
574 }; | 580 }; |
575 | 581 |
576 } // namespace content | 582 } // namespace content |
577 | 583 |
578 #endif // CONTENT_BROWSER_SERVICE_WORKER_SERVICE_WORKER_VERSION_H_ | 584 #endif // CONTENT_BROWSER_SERVICE_WORKER_SERVICE_WORKER_VERSION_H_ |
OLD | NEW |