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/content_export.h" | 24 #include "content/common/content_export.h" |
| 25 #include "content/common/service_port_service.mojom.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" |
| 28 #include "content/public/common/service_registry.h" |
27 #include "third_party/WebKit/public/platform/WebGeofencingEventType.h" | 29 #include "third_party/WebKit/public/platform/WebGeofencingEventType.h" |
28 #include "third_party/WebKit/public/platform/WebServiceWorkerEventResult.h" | 30 #include "third_party/WebKit/public/platform/WebServiceWorkerEventResult.h" |
29 | 31 |
30 // Windows headers will redefine SendMessage. | 32 // Windows headers will redefine SendMessage. |
31 #ifdef SendMessage | 33 #ifdef SendMessage |
32 #undef SendMessage | 34 #undef SendMessage |
33 #endif | 35 #endif |
34 | 36 |
35 class GURL; | 37 class GURL; |
36 | 38 |
(...skipping 25 matching lines...) Expand all Loading... |
62 // running worker. | 64 // running worker. |
63 class CONTENT_EXPORT ServiceWorkerVersion | 65 class CONTENT_EXPORT ServiceWorkerVersion |
64 : NON_EXPORTED_BASE(public base::RefCounted<ServiceWorkerVersion>), | 66 : NON_EXPORTED_BASE(public base::RefCounted<ServiceWorkerVersion>), |
65 public EmbeddedWorkerInstance::Listener { | 67 public EmbeddedWorkerInstance::Listener { |
66 public: | 68 public: |
67 typedef base::Callback<void(ServiceWorkerStatusCode)> StatusCallback; | 69 typedef base::Callback<void(ServiceWorkerStatusCode)> StatusCallback; |
68 typedef base::Callback<void(ServiceWorkerStatusCode, | 70 typedef base::Callback<void(ServiceWorkerStatusCode, |
69 ServiceWorkerFetchEventResult, | 71 ServiceWorkerFetchEventResult, |
70 const ServiceWorkerResponse&)> FetchCallback; | 72 const ServiceWorkerResponse&)> FetchCallback; |
71 typedef base::Callback<void(ServiceWorkerStatusCode, | 73 typedef base::Callback<void(ServiceWorkerStatusCode, |
72 bool /* accept_connction */)> | 74 bool /* accept_connction */, |
73 CrossOriginConnectCallback; | 75 const base::string16& /* name */, |
| 76 const base::string16& /* data */)> |
| 77 ServicePortConnectCallback; |
74 typedef base::Callback<void(ServiceWorkerStatusCode, const std::vector<int>&)> | 78 typedef base::Callback<void(ServiceWorkerStatusCode, const std::vector<int>&)> |
75 SendStashedPortsCallback; | 79 SendStashedPortsCallback; |
76 | 80 |
77 enum RunningStatus { | 81 enum RunningStatus { |
78 STOPPED = EmbeddedWorkerInstance::STOPPED, | 82 STOPPED = EmbeddedWorkerInstance::STOPPED, |
79 STARTING = EmbeddedWorkerInstance::STARTING, | 83 STARTING = EmbeddedWorkerInstance::STARTING, |
80 RUNNING = EmbeddedWorkerInstance::RUNNING, | 84 RUNNING = EmbeddedWorkerInstance::RUNNING, |
81 STOPPING = EmbeddedWorkerInstance::STOPPING, | 85 STOPPING = EmbeddedWorkerInstance::STOPPING, |
82 }; | 86 }; |
83 | 87 |
(...skipping 146 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
230 // calls |callback| when it errors out or it gets a response from the worker | 234 // calls |callback| when it errors out or it gets a response from the worker |
231 // to notify completion. | 235 // to notify completion. |
232 // | 236 // |
233 // This must be called when the status() is ACTIVATED. | 237 // This must be called when the status() is ACTIVATED. |
234 void DispatchGeofencingEvent( | 238 void DispatchGeofencingEvent( |
235 const StatusCallback& callback, | 239 const StatusCallback& callback, |
236 blink::WebGeofencingEventType event_type, | 240 blink::WebGeofencingEventType event_type, |
237 const std::string& region_id, | 241 const std::string& region_id, |
238 const blink::WebCircularGeofencingRegion& region); | 242 const blink::WebCircularGeofencingRegion& region); |
239 | 243 |
240 // Sends a cross origin connect event to the associated embedded worker and | 244 // Sends a ServicePort connect event to the associated embedded worker and |
241 // asynchronously calls |callback| with the response from the worker. | 245 // asynchronously calls |callback| with the response from the worker. |
242 // | 246 // |
243 // This must be called when the status() is ACTIVATED. | 247 // This must be called when the status() is ACTIVATED. |
244 void DispatchCrossOriginConnectEvent( | 248 void DispatchServicePortConnectEvent( |
245 const CrossOriginConnectCallback& callback, | 249 const ServicePortConnectCallback& callback, |
246 const NavigatorConnectClient& client); | 250 const GURL& target_url, |
| 251 const GURL& origin, |
| 252 int port_id); |
247 | 253 |
248 // Sends a cross origin message event to the associated embedded worker and | 254 // Sends a cross origin message event to the associated embedded worker and |
249 // asynchronously calls |callback| when the message was sent (or failed to | 255 // asynchronously calls |callback| when the message was sent (or failed to |
250 // sent). | 256 // sent). |
251 // It is the responsibility of the code calling this method to make sure that | 257 // It is the responsibility of the code calling this method to make sure that |
252 // any transferred message ports are put on hold while potentially a process | 258 // any transferred message ports are put on hold while potentially a process |
253 // for the service worker is spun up. | 259 // for the service worker is spun up. |
254 // | 260 // |
255 // This must be called when the status() is ACTIVATED. | 261 // This must be called when the status() is ACTIVATED. |
256 void DispatchCrossOriginMessageEvent( | 262 void DispatchCrossOriginMessageEvent( |
(...skipping 100 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
357 using ServiceWorkerClients = std::vector<ServiceWorkerClientInfo>; | 363 using ServiceWorkerClients = std::vector<ServiceWorkerClientInfo>; |
358 | 364 |
359 enum RequestType { | 365 enum RequestType { |
360 REQUEST_ACTIVATE, | 366 REQUEST_ACTIVATE, |
361 REQUEST_INSTALL, | 367 REQUEST_INSTALL, |
362 REQUEST_FETCH, | 368 REQUEST_FETCH, |
363 REQUEST_SYNC, | 369 REQUEST_SYNC, |
364 REQUEST_NOTIFICATION_CLICK, | 370 REQUEST_NOTIFICATION_CLICK, |
365 REQUEST_PUSH, | 371 REQUEST_PUSH, |
366 REQUEST_GEOFENCING, | 372 REQUEST_GEOFENCING, |
367 REQUEST_CROSS_ORIGIN_CONNECT | 373 REQUEST_SERVICE_PORT_CONNECT |
368 }; | 374 }; |
369 | 375 |
370 struct RequestInfo { | 376 struct RequestInfo { |
371 RequestInfo(int id, RequestType type, const base::TimeTicks& time); | 377 RequestInfo(int id, RequestType type, const base::TimeTicks& time); |
372 ~RequestInfo(); | 378 ~RequestInfo(); |
373 int id; | 379 int id; |
374 RequestType type; | 380 RequestType type; |
375 base::TimeTicks time; | 381 base::TimeTicks time; |
376 }; | 382 }; |
377 | 383 |
(...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
431 blink::WebServiceWorkerEventResult result); | 437 blink::WebServiceWorkerEventResult result); |
432 void OnFetchEventFinished(int request_id, | 438 void OnFetchEventFinished(int request_id, |
433 ServiceWorkerFetchEventResult result, | 439 ServiceWorkerFetchEventResult result, |
434 const ServiceWorkerResponse& response); | 440 const ServiceWorkerResponse& response); |
435 void OnSyncEventFinished(int request_id, | 441 void OnSyncEventFinished(int request_id, |
436 blink::WebServiceWorkerEventResult result); | 442 blink::WebServiceWorkerEventResult result); |
437 void OnNotificationClickEventFinished(int request_id); | 443 void OnNotificationClickEventFinished(int request_id); |
438 void OnPushEventFinished(int request_id, | 444 void OnPushEventFinished(int request_id, |
439 blink::WebServiceWorkerEventResult result); | 445 blink::WebServiceWorkerEventResult result); |
440 void OnGeofencingEventFinished(int request_id); | 446 void OnGeofencingEventFinished(int request_id); |
441 void OnCrossOriginConnectEventFinished(int request_id, | 447 void OnServicePortConnectEventFinished(int request_id, |
442 bool accept_connection); | 448 ServicePortConnectResult result, |
| 449 const mojo::String& name, |
| 450 const mojo::String& data); |
443 void OnOpenWindow(int request_id, GURL url); | 451 void OnOpenWindow(int request_id, GURL url); |
444 void DidOpenWindow(int request_id, | 452 void DidOpenWindow(int request_id, |
445 int render_process_id, | 453 int render_process_id, |
446 int render_frame_id); | 454 int render_frame_id); |
447 void OnOpenWindowFinished(int request_id, | 455 void OnOpenWindowFinished(int request_id, |
448 const std::string& client_uuid, | 456 const std::string& client_uuid, |
449 const ServiceWorkerClientInfo& client_info); | 457 const ServiceWorkerClientInfo& client_info); |
450 | 458 |
451 void OnSetCachedMetadata(const GURL& url, const std::vector<char>& data); | 459 void OnSetCachedMetadata(const GURL& url, const std::vector<char>& data); |
452 void OnSetCachedMetadataFinished(int64 callback_id, int result); | 460 void OnSetCachedMetadataFinished(int64 callback_id, int result); |
(...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
526 // Sets |stale_time_| if this worker is stale, causing an update to eventually | 534 // Sets |stale_time_| if this worker is stale, causing an update to eventually |
527 // occur once the worker stops or is running too long. | 535 // occur once the worker stops or is running too long. |
528 void MarkIfStale(); | 536 void MarkIfStale(); |
529 | 537 |
530 void FoundRegistrationForUpdate( | 538 void FoundRegistrationForUpdate( |
531 ServiceWorkerStatusCode status, | 539 ServiceWorkerStatusCode status, |
532 const scoped_refptr<ServiceWorkerRegistration>& registration); | 540 const scoped_refptr<ServiceWorkerRegistration>& registration); |
533 | 541 |
534 void OnStoppedInternal(EmbeddedWorkerInstance::Status old_status); | 542 void OnStoppedInternal(EmbeddedWorkerInstance::Status old_status); |
535 | 543 |
| 544 // Called when the connection to a ServicePortDispatcher drops or fails. |
| 545 // Calls callbacks for any outstanding requests to the dispatcher as well |
| 546 // as cleans up the dispatcher. |
| 547 void OnServicePortDispatcherConnectionError(); |
| 548 |
536 const int64 version_id_; | 549 const int64 version_id_; |
537 const int64 registration_id_; | 550 const int64 registration_id_; |
538 const GURL script_url_; | 551 const GURL script_url_; |
539 const GURL scope_; | 552 const GURL scope_; |
540 | 553 |
541 Status status_ = NEW; | 554 Status status_ = NEW; |
542 scoped_ptr<EmbeddedWorkerInstance> embedded_worker_; | 555 scoped_ptr<EmbeddedWorkerInstance> embedded_worker_; |
543 std::vector<StatusCallback> start_callbacks_; | 556 std::vector<StatusCallback> start_callbacks_; |
544 std::vector<StatusCallback> stop_callbacks_; | 557 std::vector<StatusCallback> stop_callbacks_; |
545 std::vector<base::Closure> status_change_callbacks_; | 558 std::vector<base::Closure> status_change_callbacks_; |
546 | 559 |
547 // Message callbacks. (Update HasInflightRequests() too when you update this | 560 // Message callbacks. (Update HasInflightRequests() too when you update this |
548 // list.) | 561 // list.) |
549 IDMap<PendingRequest<StatusCallback>, IDMapOwnPointer> activate_requests_; | 562 IDMap<PendingRequest<StatusCallback>, IDMapOwnPointer> activate_requests_; |
550 IDMap<PendingRequest<StatusCallback>, IDMapOwnPointer> install_requests_; | 563 IDMap<PendingRequest<StatusCallback>, IDMapOwnPointer> install_requests_; |
551 IDMap<PendingRequest<FetchCallback>, IDMapOwnPointer> fetch_requests_; | 564 IDMap<PendingRequest<FetchCallback>, IDMapOwnPointer> fetch_requests_; |
552 IDMap<PendingRequest<StatusCallback>, IDMapOwnPointer> sync_requests_; | 565 IDMap<PendingRequest<StatusCallback>, IDMapOwnPointer> sync_requests_; |
553 IDMap<PendingRequest<StatusCallback>, IDMapOwnPointer> | 566 IDMap<PendingRequest<StatusCallback>, IDMapOwnPointer> |
554 notification_click_requests_; | 567 notification_click_requests_; |
555 IDMap<PendingRequest<StatusCallback>, IDMapOwnPointer> push_requests_; | 568 IDMap<PendingRequest<StatusCallback>, IDMapOwnPointer> push_requests_; |
556 IDMap<PendingRequest<StatusCallback>, IDMapOwnPointer> geofencing_requests_; | 569 IDMap<PendingRequest<StatusCallback>, IDMapOwnPointer> geofencing_requests_; |
557 IDMap<PendingRequest<CrossOriginConnectCallback>, IDMapOwnPointer> | 570 IDMap<PendingRequest<ServicePortConnectCallback>, IDMapOwnPointer> |
558 cross_origin_connect_requests_; | 571 service_port_connect_requests_; |
| 572 |
| 573 ServicePortDispatcherPtr service_port_dispatcher_; |
559 | 574 |
560 std::set<const ServiceWorkerURLRequestJob*> streaming_url_request_jobs_; | 575 std::set<const ServiceWorkerURLRequestJob*> streaming_url_request_jobs_; |
561 | 576 |
562 std::map<std::string, ServiceWorkerProviderHost*> controllee_map_; | 577 std::map<std::string, ServiceWorkerProviderHost*> controllee_map_; |
563 // Will be null while shutting down. | 578 // Will be null while shutting down. |
564 base::WeakPtr<ServiceWorkerContextCore> context_; | 579 base::WeakPtr<ServiceWorkerContextCore> context_; |
565 base::ObserverList<Listener> listeners_; | 580 base::ObserverList<Listener> listeners_; |
566 ServiceWorkerScriptCacheMap script_cache_map_; | 581 ServiceWorkerScriptCacheMap script_cache_map_; |
567 base::OneShotTimer<ServiceWorkerVersion> update_timer_; | 582 base::OneShotTimer<ServiceWorkerVersion> update_timer_; |
568 | 583 |
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
603 scoped_ptr<Metrics> metrics_; | 618 scoped_ptr<Metrics> metrics_; |
604 | 619 |
605 base::WeakPtrFactory<ServiceWorkerVersion> weak_factory_; | 620 base::WeakPtrFactory<ServiceWorkerVersion> weak_factory_; |
606 | 621 |
607 DISALLOW_COPY_AND_ASSIGN(ServiceWorkerVersion); | 622 DISALLOW_COPY_AND_ASSIGN(ServiceWorkerVersion); |
608 }; | 623 }; |
609 | 624 |
610 } // namespace content | 625 } // namespace content |
611 | 626 |
612 #endif // CONTENT_BROWSER_SERVICE_WORKER_SERVICE_WORKER_VERSION_H_ | 627 #endif // CONTENT_BROWSER_SERVICE_WORKER_SERVICE_WORKER_VERSION_H_ |
OLD | NEW |