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