Chromium Code Reviews| 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/containers/scoped_ptr_hash_map.h" | |
| 16 #include "base/gtest_prod_util.h" | 17 #include "base/gtest_prod_util.h" |
| 17 #include "base/id_map.h" | 18 #include "base/id_map.h" |
| 18 #include "base/memory/ref_counted.h" | 19 #include "base/memory/ref_counted.h" |
| 19 #include "base/memory/scoped_ptr.h" | 20 #include "base/memory/scoped_ptr.h" |
| 20 #include "base/observer_list.h" | 21 #include "base/observer_list.h" |
| 21 #include "base/timer/timer.h" | 22 #include "base/timer/timer.h" |
| 22 #include "content/browser/background_sync/background_sync_registration_handle.h" | 23 #include "content/browser/background_sync/background_sync_registration_handle.h" |
| 23 #include "content/browser/service_worker/embedded_worker_instance.h" | 24 #include "content/browser/service_worker/embedded_worker_instance.h" |
| 24 #include "content/browser/service_worker/service_worker_script_cache_map.h" | 25 #include "content/browser/service_worker/service_worker_script_cache_map.h" |
| 25 #include "content/common/background_sync_service.mojom.h" | 26 #include "content/common/background_sync_service.mojom.h" |
| 26 #include "content/common/content_export.h" | 27 #include "content/common/content_export.h" |
| 27 #include "content/common/service_port_service.mojom.h" | |
| 28 #include "content/common/service_worker/service_worker_status_code.h" | 28 #include "content/common/service_worker/service_worker_status_code.h" |
| 29 #include "content/common/service_worker/service_worker_types.h" | 29 #include "content/common/service_worker/service_worker_types.h" |
| 30 #include "content/public/common/service_registry.h" | 30 #include "content/public/common/service_registry.h" |
| 31 #include "third_party/WebKit/public/platform/WebGeofencingEventType.h" | 31 #include "third_party/WebKit/public/platform/WebGeofencingEventType.h" |
| 32 #include "third_party/WebKit/public/platform/modules/serviceworker/WebServiceWor kerEventResult.h" | 32 #include "third_party/WebKit/public/platform/modules/serviceworker/WebServiceWor kerEventResult.h" |
| 33 | 33 |
| 34 // Windows headers will redefine SendMessage. | 34 // Windows headers will redefine SendMessage. |
| 35 #ifdef SendMessage | 35 #ifdef SendMessage |
| 36 #undef SendMessage | 36 #undef SendMessage |
| 37 #endif | 37 #endif |
| (...skipping 27 matching lines...) Expand all Loading... | |
| 65 // one of them is activated. This class connects the actual script with a | 65 // one of them is activated. This class connects the actual script with a |
| 66 // running worker. | 66 // running worker. |
| 67 class CONTENT_EXPORT ServiceWorkerVersion | 67 class CONTENT_EXPORT ServiceWorkerVersion |
| 68 : NON_EXPORTED_BASE(public base::RefCounted<ServiceWorkerVersion>), | 68 : NON_EXPORTED_BASE(public base::RefCounted<ServiceWorkerVersion>), |
| 69 public EmbeddedWorkerInstance::Listener { | 69 public EmbeddedWorkerInstance::Listener { |
| 70 public: | 70 public: |
| 71 typedef base::Callback<void(ServiceWorkerStatusCode)> StatusCallback; | 71 typedef base::Callback<void(ServiceWorkerStatusCode)> StatusCallback; |
| 72 typedef base::Callback<void(ServiceWorkerStatusCode, | 72 typedef base::Callback<void(ServiceWorkerStatusCode, |
| 73 ServiceWorkerFetchEventResult, | 73 ServiceWorkerFetchEventResult, |
| 74 const ServiceWorkerResponse&)> FetchCallback; | 74 const ServiceWorkerResponse&)> FetchCallback; |
| 75 typedef base::Callback<void(ServiceWorkerStatusCode, | |
| 76 bool /* accept_connction */, | |
| 77 const base::string16& /* name */, | |
| 78 const base::string16& /* data */)> | |
| 79 ServicePortConnectCallback; | |
| 80 | 75 |
| 81 enum RunningStatus { | 76 enum RunningStatus { |
| 82 STOPPED = EmbeddedWorkerInstance::STOPPED, | 77 STOPPED = EmbeddedWorkerInstance::STOPPED, |
| 83 STARTING = EmbeddedWorkerInstance::STARTING, | 78 STARTING = EmbeddedWorkerInstance::STARTING, |
| 84 RUNNING = EmbeddedWorkerInstance::RUNNING, | 79 RUNNING = EmbeddedWorkerInstance::RUNNING, |
| 85 STOPPING = EmbeddedWorkerInstance::STOPPING, | 80 STOPPING = EmbeddedWorkerInstance::STOPPING, |
| 86 }; | 81 }; |
| 87 | 82 |
| 88 // Current version status; some of the status (e.g. INSTALLED and ACTIVATED) | 83 // Current version status; some of the status (e.g. INSTALLED and ACTIVATED) |
| 89 // should be persisted unlike running status. | 84 // should be persisted unlike running status. |
| (...skipping 80 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 170 // Schedules an update to be run 'soon'. | 165 // Schedules an update to be run 'soon'. |
| 171 void ScheduleUpdate(); | 166 void ScheduleUpdate(); |
| 172 | 167 |
| 173 // If an update is scheduled but not yet started, this resets the timer | 168 // If an update is scheduled but not yet started, this resets the timer |
| 174 // delaying the start time by a 'small' amount. | 169 // delaying the start time by a 'small' amount. |
| 175 void DeferScheduledUpdate(); | 170 void DeferScheduledUpdate(); |
| 176 | 171 |
| 177 // Starts an update now. | 172 // Starts an update now. |
| 178 void StartUpdate(); | 173 void StartUpdate(); |
| 179 | 174 |
| 175 // Starts the worker if it isn't already running, and calls |task| when the | |
| 176 // worker is running, or |error_callback| if starting the worker failed. | |
| 177 void RunAfterStartWorker(const StatusCallback& error_callback, | |
| 178 const base::Closure& task); | |
| 179 | |
| 180 // Call this while the worker is running before dispatching an event to the | |
| 181 // worker. This informs ServiceWorkerVersion about the event in progress. | |
| 182 // Returns a request id, which should later be passed to FinishRequest when | |
| 183 // the event finished. | |
| 184 // The |error_callback| is called if either ServiceWorkerVersion decides the | |
| 185 // event is taking too long, or if for some reason the worker stops or is | |
| 186 // killed before the request finishes. | |
| 187 int StartRequest(const StatusCallback& error_callback); | |
| 188 | |
| 189 // Informs ServiceWorkerVersion that an event has finished being dispatched. | |
| 190 // Returns false if no pending requests with the provided id exist, for | |
| 191 // example if the request has already timed out. | |
| 192 bool FinishRequest(int request_id); | |
| 193 | |
| 194 // Connects to a specific mojo service exposed by the (running) service | |
| 195 // worker. If a connection to a service for the same Interface already exists | |
| 196 // this will return that existing connection. The |request_id| must be a value | |
| 197 // previously returned by StartRequest. If the connection to the service | |
| 198 // fails or closes before the request finished, the error callback associated | |
| 199 // with |request_id| is called. | |
| 200 // Only call GetMojoServiceForRequest once for a specific |request_id|. | |
| 201 template <typename Interface> | |
| 202 base::WeakPtr<Interface> GetMojoServiceForRequest(int request_id); | |
| 203 | |
| 180 // Sends a message event to the associated embedded worker. | 204 // Sends a message event to the associated embedded worker. |
| 181 void DispatchMessageEvent( | 205 void DispatchMessageEvent( |
| 182 const base::string16& message, | 206 const base::string16& message, |
| 183 const std::vector<TransferredMessagePort>& sent_message_ports, | 207 const std::vector<TransferredMessagePort>& sent_message_ports, |
| 184 const StatusCallback& callback); | 208 const StatusCallback& callback); |
| 185 | 209 |
| 186 // Sends install event to the associated embedded worker and asynchronously | 210 // Sends install event to the associated embedded worker and asynchronously |
| 187 // calls |callback| when it errors out or it gets a response from the worker | 211 // calls |callback| when it errors out or it gets a response from the worker |
| 188 // to notify install completion. | 212 // to notify install completion. |
| 189 // | 213 // |
| (...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 246 // calls |callback| when it errors out or it gets a response from the worker | 270 // calls |callback| when it errors out or it gets a response from the worker |
| 247 // to notify completion. | 271 // to notify completion. |
| 248 // | 272 // |
| 249 // This must be called when the status() is ACTIVATED. | 273 // This must be called when the status() is ACTIVATED. |
| 250 void DispatchGeofencingEvent( | 274 void DispatchGeofencingEvent( |
| 251 const StatusCallback& callback, | 275 const StatusCallback& callback, |
| 252 blink::WebGeofencingEventType event_type, | 276 blink::WebGeofencingEventType event_type, |
| 253 const std::string& region_id, | 277 const std::string& region_id, |
| 254 const blink::WebCircularGeofencingRegion& region); | 278 const blink::WebCircularGeofencingRegion& region); |
| 255 | 279 |
| 256 // Sends a ServicePort connect event to the associated embedded worker and | |
| 257 // asynchronously calls |callback| with the response from the worker. | |
| 258 // | |
| 259 // This must be called when the status() is ACTIVATED. | |
| 260 void DispatchServicePortConnectEvent( | |
| 261 const ServicePortConnectCallback& callback, | |
| 262 const GURL& target_url, | |
| 263 const GURL& origin, | |
| 264 int port_id); | |
| 265 | |
| 266 // Sends a cross origin message event to the associated embedded worker and | 280 // Sends a cross origin message event to the associated embedded worker and |
| 267 // asynchronously calls |callback| when the message was sent (or failed to | 281 // asynchronously calls |callback| when the message was sent (or failed to |
| 268 // sent). | 282 // sent). |
| 269 // It is the responsibility of the code calling this method to make sure that | 283 // It is the responsibility of the code calling this method to make sure that |
| 270 // any transferred message ports are put on hold while potentially a process | 284 // any transferred message ports are put on hold while potentially a process |
| 271 // for the service worker is spun up. | 285 // for the service worker is spun up. |
| 272 // | 286 // |
| 273 // This must be called when the status() is ACTIVATED. | 287 // This must be called when the status() is ACTIVATED. |
| 274 void DispatchCrossOriginMessageEvent( | 288 void DispatchCrossOriginMessageEvent( |
| 275 const NavigatorConnectClient& client, | 289 const NavigatorConnectClient& client, |
| (...skipping 77 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 353 FRIEND_TEST_ALL_PREFIXES(ServiceWorkerVersionTest, IdleTimeout); | 367 FRIEND_TEST_ALL_PREFIXES(ServiceWorkerVersionTest, IdleTimeout); |
| 354 FRIEND_TEST_ALL_PREFIXES(ServiceWorkerVersionTest, SetDevToolsAttached); | 368 FRIEND_TEST_ALL_PREFIXES(ServiceWorkerVersionTest, SetDevToolsAttached); |
| 355 FRIEND_TEST_ALL_PREFIXES(ServiceWorkerVersionTest, StaleUpdate_FreshWorker); | 369 FRIEND_TEST_ALL_PREFIXES(ServiceWorkerVersionTest, StaleUpdate_FreshWorker); |
| 356 FRIEND_TEST_ALL_PREFIXES(ServiceWorkerVersionTest, | 370 FRIEND_TEST_ALL_PREFIXES(ServiceWorkerVersionTest, |
| 357 StaleUpdate_NonActiveWorker); | 371 StaleUpdate_NonActiveWorker); |
| 358 FRIEND_TEST_ALL_PREFIXES(ServiceWorkerVersionTest, StaleUpdate_StartWorker); | 372 FRIEND_TEST_ALL_PREFIXES(ServiceWorkerVersionTest, StaleUpdate_StartWorker); |
| 359 FRIEND_TEST_ALL_PREFIXES(ServiceWorkerVersionTest, StaleUpdate_RunningWorker); | 373 FRIEND_TEST_ALL_PREFIXES(ServiceWorkerVersionTest, StaleUpdate_RunningWorker); |
| 360 FRIEND_TEST_ALL_PREFIXES(ServiceWorkerVersionTest, | 374 FRIEND_TEST_ALL_PREFIXES(ServiceWorkerVersionTest, |
| 361 StaleUpdate_DoNotDeferTimer); | 375 StaleUpdate_DoNotDeferTimer); |
| 362 FRIEND_TEST_ALL_PREFIXES(ServiceWorkerWaitForeverInFetchTest, RequestTimeout); | 376 FRIEND_TEST_ALL_PREFIXES(ServiceWorkerWaitForeverInFetchTest, RequestTimeout); |
| 377 FRIEND_TEST_ALL_PREFIXES(ServiceWorkerVersionTest, RequestTimeout); | |
| 363 FRIEND_TEST_ALL_PREFIXES(ServiceWorkerFailToStartTest, Timeout); | 378 FRIEND_TEST_ALL_PREFIXES(ServiceWorkerFailToStartTest, Timeout); |
| 364 FRIEND_TEST_ALL_PREFIXES(ServiceWorkerVersionBrowserTest, | 379 FRIEND_TEST_ALL_PREFIXES(ServiceWorkerVersionBrowserTest, |
| 365 TimeoutStartingWorker); | 380 TimeoutStartingWorker); |
| 366 FRIEND_TEST_ALL_PREFIXES(ServiceWorkerVersionBrowserTest, | 381 FRIEND_TEST_ALL_PREFIXES(ServiceWorkerVersionBrowserTest, |
| 367 TimeoutWorkerInEvent); | 382 TimeoutWorkerInEvent); |
| 368 FRIEND_TEST_ALL_PREFIXES(ServiceWorkerStallInStoppingTest, DetachThenStart); | 383 FRIEND_TEST_ALL_PREFIXES(ServiceWorkerStallInStoppingTest, DetachThenStart); |
| 369 FRIEND_TEST_ALL_PREFIXES(ServiceWorkerStallInStoppingTest, DetachThenRestart); | 384 FRIEND_TEST_ALL_PREFIXES(ServiceWorkerStallInStoppingTest, DetachThenRestart); |
| 370 FRIEND_TEST_ALL_PREFIXES(ServiceWorkerVersionTest, | 385 FRIEND_TEST_ALL_PREFIXES(ServiceWorkerVersionTest, |
| 371 RegisterForeignFetchScopes); | 386 RegisterForeignFetchScopes); |
| 372 FRIEND_TEST_ALL_PREFIXES(ServiceWorkerVersionTest, RequestCustomizedTimeout); | 387 FRIEND_TEST_ALL_PREFIXES(ServiceWorkerVersionTest, RequestCustomizedTimeout); |
| 373 FRIEND_TEST_ALL_PREFIXES(ServiceWorkerWaitForeverInFetchTest, | 388 FRIEND_TEST_ALL_PREFIXES(ServiceWorkerWaitForeverInFetchTest, |
| 374 MixedRequestTimeouts); | 389 MixedRequestTimeouts); |
| 375 | 390 |
| 376 class Metrics; | 391 class Metrics; |
| 377 class PingController; | 392 class PingController; |
| 378 | 393 |
| 379 // Used for UMA; add new entries to the end, before NUM_REQUEST_TYPES. | 394 // Used for UMA; add new entries to the end, before NUM_REQUEST_TYPES. |
| 380 enum RequestType { | 395 enum RequestType { |
| 381 REQUEST_ACTIVATE, | 396 REQUEST_ACTIVATE, |
| 382 REQUEST_INSTALL, | 397 REQUEST_INSTALL, |
| 383 REQUEST_FETCH, | 398 REQUEST_FETCH, |
| 384 REQUEST_SYNC, | 399 REQUEST_SYNC, |
| 385 REQUEST_NOTIFICATION_CLICK, | 400 REQUEST_NOTIFICATION_CLICK, |
| 386 REQUEST_PUSH, | 401 REQUEST_PUSH, |
| 387 REQUEST_GEOFENCING, | 402 REQUEST_GEOFENCING, |
| 388 REQUEST_SERVICE_PORT_CONNECT, | 403 REQUEST_CUSTOM, |
|
nhiroki
2016/01/05 09:33:24
I think it'd be better that each event has a uniqu
Marijn Kruisselbrink
2016/01/05 23:23:16
Currently my approach was to add necessary functio
nhiroki
2016/01/06 10:13:57
Thank you for the explanation.
On 2016/01/05 23:2
Marijn Kruisselbrink
2016/01/07 00:59:08
Ah yes, not sure how I missed the "Used for UMA" c
| |
| 389 NUM_REQUEST_TYPES | 404 NUM_REQUEST_TYPES |
| 390 }; | 405 }; |
| 391 | 406 |
| 392 struct RequestInfo { | 407 struct RequestInfo { |
| 393 RequestInfo(int id, RequestType type, const base::TimeTicks& expiration); | 408 RequestInfo(int id, RequestType type, const base::TimeTicks& expiration); |
| 394 ~RequestInfo(); | 409 ~RequestInfo(); |
| 395 bool operator>(const RequestInfo& other) const; | 410 bool operator>(const RequestInfo& other) const; |
| 396 int id; | 411 int id; |
| 397 RequestType type; | 412 RequestType type; |
| 398 base::TimeTicks expiration; | 413 base::TimeTicks expiration; |
| 399 }; | 414 }; |
| 400 | 415 |
| 401 template <typename CallbackType> | 416 template <typename CallbackType> |
| 402 struct PendingRequest { | 417 struct PendingRequest { |
| 403 PendingRequest(const CallbackType& callback, const base::TimeTicks& time); | 418 PendingRequest(const CallbackType& callback, const base::TimeTicks& time); |
| 404 ~PendingRequest(); | 419 ~PendingRequest(); |
| 405 | 420 |
| 406 CallbackType callback; | 421 CallbackType callback; |
| 407 base::TimeTicks start_time; | 422 base::TimeTicks start_time; |
| 423 // Name of the mojo service this request is associated with. Used to call | |
| 424 // the callback when a connection closes with outstanding requests. | |
| 425 // Compared as pointer, so should only contain static strings. Typically | |
| 426 // this would be Interface::Name_ for some mojo interface. | |
| 427 const char* mojo_service = nullptr; | |
| 428 }; | |
| 429 | |
| 430 // Base class to enable storing a list of mojo interface pointers for | |
| 431 // arbitrary interfaces. The destructor is also responsible for calling the | |
| 432 // error callbacks for any outstanding requests using this service. | |
| 433 class CONTENT_EXPORT BaseMojoService { | |
| 434 public: | |
| 435 BaseMojoService(ServiceWorkerVersion* worker, const char* service_name); | |
| 436 virtual ~BaseMojoService(); | |
| 437 | |
| 438 private: | |
| 439 ServiceWorkerVersion* worker_; | |
| 440 const char* service_name_; | |
| 441 }; | |
| 442 | |
| 443 // Wrapper around a mojo::InterfacePtr, which passes out WeakPtr's to the | |
| 444 // interface. | |
| 445 template <typename Interface> | |
| 446 class MojoService : public BaseMojoService { | |
| 447 public: | |
| 448 MojoService(ServiceWorkerVersion* worker, | |
| 449 mojo::InterfacePtr<Interface> interface) | |
| 450 : BaseMojoService(worker, Interface::Name_), | |
| 451 interface_(std::move(interface)), | |
| 452 weak_ptr_factory_(interface_.get()) {} | |
| 453 | |
| 454 base::WeakPtr<Interface> GetWeakPtr() { | |
| 455 return weak_ptr_factory_.GetWeakPtr(); | |
| 456 } | |
| 457 | |
| 458 private: | |
| 459 mojo::InterfacePtr<Interface> interface_; | |
| 460 base::WeakPtrFactory<Interface> weak_ptr_factory_; | |
| 408 }; | 461 }; |
| 409 | 462 |
| 410 typedef ServiceWorkerVersion self; | 463 typedef ServiceWorkerVersion self; |
| 411 using ServiceWorkerClients = std::vector<ServiceWorkerClientInfo>; | 464 using ServiceWorkerClients = std::vector<ServiceWorkerClientInfo>; |
| 412 using RequestInfoPriorityQueue = | 465 using RequestInfoPriorityQueue = |
| 413 std::priority_queue<RequestInfo, | 466 std::priority_queue<RequestInfo, |
| 414 std::vector<RequestInfo>, | 467 std::vector<RequestInfo>, |
| 415 std::greater<RequestInfo>>; | 468 std::greater<RequestInfo>>; |
| 416 | 469 |
| 417 // The timeout timer interval. | 470 // The timeout timer interval. |
| (...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 468 void OnInstallEventFinished(int request_id, | 521 void OnInstallEventFinished(int request_id, |
| 469 blink::WebServiceWorkerEventResult result); | 522 blink::WebServiceWorkerEventResult result); |
| 470 void OnFetchEventFinished(int request_id, | 523 void OnFetchEventFinished(int request_id, |
| 471 ServiceWorkerFetchEventResult result, | 524 ServiceWorkerFetchEventResult result, |
| 472 const ServiceWorkerResponse& response); | 525 const ServiceWorkerResponse& response); |
| 473 void OnSyncEventFinished(int request_id, ServiceWorkerEventStatus status); | 526 void OnSyncEventFinished(int request_id, ServiceWorkerEventStatus status); |
| 474 void OnNotificationClickEventFinished(int request_id); | 527 void OnNotificationClickEventFinished(int request_id); |
| 475 void OnPushEventFinished(int request_id, | 528 void OnPushEventFinished(int request_id, |
| 476 blink::WebServiceWorkerEventResult result); | 529 blink::WebServiceWorkerEventResult result); |
| 477 void OnGeofencingEventFinished(int request_id); | 530 void OnGeofencingEventFinished(int request_id); |
| 478 void OnServicePortConnectEventFinished(int request_id, | |
| 479 ServicePortConnectResult result, | |
| 480 const mojo::String& name, | |
| 481 const mojo::String& data); | |
| 482 void OnOpenWindow(int request_id, GURL url); | 531 void OnOpenWindow(int request_id, GURL url); |
| 483 void OnOpenWindowFinished(int request_id, | 532 void OnOpenWindowFinished(int request_id, |
| 484 ServiceWorkerStatusCode status, | 533 ServiceWorkerStatusCode status, |
| 485 const std::string& client_uuid, | 534 const std::string& client_uuid, |
| 486 const ServiceWorkerClientInfo& client_info); | 535 const ServiceWorkerClientInfo& client_info); |
| 487 | 536 |
| 488 void OnSetCachedMetadata(const GURL& url, const std::vector<char>& data); | 537 void OnSetCachedMetadata(const GURL& url, const std::vector<char>& data); |
| 489 void OnSetCachedMetadataFinished(int64 callback_id, int result); | 538 void OnSetCachedMetadataFinished(int64 callback_id, int result); |
| 490 void OnClearCachedMetadata(const GURL& url); | 539 void OnClearCachedMetadata(const GURL& url); |
| 491 void OnClearCachedMetadataFinished(int64 callback_id, int result); | 540 void OnClearCachedMetadataFinished(int64 callback_id, int result); |
| (...skipping 90 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 582 | 631 |
| 583 void FoundRegistrationForUpdate( | 632 void FoundRegistrationForUpdate( |
| 584 ServiceWorkerStatusCode status, | 633 ServiceWorkerStatusCode status, |
| 585 const scoped_refptr<ServiceWorkerRegistration>& registration); | 634 const scoped_refptr<ServiceWorkerRegistration>& registration); |
| 586 | 635 |
| 587 void OnStoppedInternal(EmbeddedWorkerInstance::Status old_status); | 636 void OnStoppedInternal(EmbeddedWorkerInstance::Status old_status); |
| 588 | 637 |
| 589 // Called when a connection to a mojo event Dispatcher drops or fails. | 638 // Called when a connection to a mojo event Dispatcher drops or fails. |
| 590 // Calls callbacks for any outstanding requests to the dispatcher as well | 639 // Calls callbacks for any outstanding requests to the dispatcher as well |
| 591 // as cleans up the dispatcher. | 640 // as cleans up the dispatcher. |
| 592 void OnServicePortDispatcherConnectionError(); | |
| 593 void OnBackgroundSyncDispatcherConnectionError(); | 641 void OnBackgroundSyncDispatcherConnectionError(); |
| 594 | 642 |
| 643 // Called when the remote side of a connection to a mojo service is lost. | |
| 644 void OnMojoConnectionError(const char* service_name); | |
| 645 | |
| 595 // Called at the beginning of each Dispatch*Event function: records | 646 // Called at the beginning of each Dispatch*Event function: records |
| 596 // the time elapsed since idle (generally the time since the previous | 647 // the time elapsed since idle (generally the time since the previous |
| 597 // event ended). | 648 // event ended). |
| 598 void OnBeginEvent(); | 649 void OnBeginEvent(); |
| 599 | 650 |
| 600 const int64 version_id_; | 651 const int64 version_id_; |
| 601 const int64 registration_id_; | 652 const int64 registration_id_; |
| 602 const GURL script_url_; | 653 const GURL script_url_; |
| 603 const GURL scope_; | 654 const GURL scope_; |
| 604 std::vector<GURL> foreign_fetch_scopes_; | 655 std::vector<GURL> foreign_fetch_scopes_; |
| 605 | 656 |
| 606 Status status_ = NEW; | 657 Status status_ = NEW; |
| 607 scoped_ptr<EmbeddedWorkerInstance> embedded_worker_; | 658 scoped_ptr<EmbeddedWorkerInstance> embedded_worker_; |
| 608 std::vector<StatusCallback> start_callbacks_; | 659 std::vector<StatusCallback> start_callbacks_; |
| 609 std::vector<StatusCallback> stop_callbacks_; | 660 std::vector<StatusCallback> stop_callbacks_; |
| 610 std::vector<base::Closure> status_change_callbacks_; | 661 std::vector<base::Closure> status_change_callbacks_; |
| 611 | 662 |
| 612 // Message callbacks. (Update HasInflightRequests() too when you update this | 663 // Message callbacks. (Update HasInflightRequests() too when you update this |
| 613 // list.) | 664 // list.) |
| 614 IDMap<PendingRequest<StatusCallback>, IDMapOwnPointer> activate_requests_; | 665 IDMap<PendingRequest<StatusCallback>, IDMapOwnPointer> activate_requests_; |
| 615 IDMap<PendingRequest<StatusCallback>, IDMapOwnPointer> install_requests_; | 666 IDMap<PendingRequest<StatusCallback>, IDMapOwnPointer> install_requests_; |
| 616 IDMap<PendingRequest<FetchCallback>, IDMapOwnPointer> fetch_requests_; | 667 IDMap<PendingRequest<FetchCallback>, IDMapOwnPointer> fetch_requests_; |
| 617 IDMap<PendingRequest<StatusCallback>, IDMapOwnPointer> sync_requests_; | 668 IDMap<PendingRequest<StatusCallback>, IDMapOwnPointer> sync_requests_; |
| 618 IDMap<PendingRequest<StatusCallback>, IDMapOwnPointer> | 669 IDMap<PendingRequest<StatusCallback>, IDMapOwnPointer> |
| 619 notification_click_requests_; | 670 notification_click_requests_; |
| 620 IDMap<PendingRequest<StatusCallback>, IDMapOwnPointer> push_requests_; | 671 IDMap<PendingRequest<StatusCallback>, IDMapOwnPointer> push_requests_; |
| 621 IDMap<PendingRequest<StatusCallback>, IDMapOwnPointer> geofencing_requests_; | 672 IDMap<PendingRequest<StatusCallback>, IDMapOwnPointer> geofencing_requests_; |
| 622 IDMap<PendingRequest<ServicePortConnectCallback>, IDMapOwnPointer> | 673 IDMap<PendingRequest<StatusCallback>, IDMapOwnPointer> custom_requests_; |
| 623 service_port_connect_requests_; | |
| 624 | 674 |
| 625 ServicePortDispatcherPtr service_port_dispatcher_; | |
| 626 BackgroundSyncServiceClientPtr background_sync_dispatcher_; | 675 BackgroundSyncServiceClientPtr background_sync_dispatcher_; |
| 627 | 676 |
| 677 // Stores all open connections to mojo services. Maps the service name to | |
| 678 // the actual interface pointer. When a connection is closed it is removed | |
| 679 // from this map. | |
| 680 // mojo_services_[Interface::Name_] is assumed to always contain a | |
| 681 // MojoService<Interface> instance. | |
| 682 base::ScopedPtrHashMap<const char*, scoped_ptr<BaseMojoService>> | |
| 683 mojo_services_; | |
| 684 | |
| 628 std::set<const ServiceWorkerURLRequestJob*> streaming_url_request_jobs_; | 685 std::set<const ServiceWorkerURLRequestJob*> streaming_url_request_jobs_; |
| 629 | 686 |
| 630 std::map<std::string, ServiceWorkerProviderHost*> controllee_map_; | 687 std::map<std::string, ServiceWorkerProviderHost*> controllee_map_; |
| 631 // Will be null while shutting down. | 688 // Will be null while shutting down. |
| 632 base::WeakPtr<ServiceWorkerContextCore> context_; | 689 base::WeakPtr<ServiceWorkerContextCore> context_; |
| 633 base::ObserverList<Listener> listeners_; | 690 base::ObserverList<Listener> listeners_; |
| 634 ServiceWorkerScriptCacheMap script_cache_map_; | 691 ServiceWorkerScriptCacheMap script_cache_map_; |
| 635 base::OneShotTimer update_timer_; | 692 base::OneShotTimer update_timer_; |
| 636 | 693 |
| 637 // Starts running in StartWorker and continues until the worker is stopped. | 694 // Starts running in StartWorker and continues until the worker is stopped. |
| (...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 672 | 729 |
| 673 scoped_ptr<PingController> ping_controller_; | 730 scoped_ptr<PingController> ping_controller_; |
| 674 scoped_ptr<Metrics> metrics_; | 731 scoped_ptr<Metrics> metrics_; |
| 675 const bool should_exclude_from_uma_ = false; | 732 const bool should_exclude_from_uma_ = false; |
| 676 | 733 |
| 677 base::WeakPtrFactory<ServiceWorkerVersion> weak_factory_; | 734 base::WeakPtrFactory<ServiceWorkerVersion> weak_factory_; |
| 678 | 735 |
| 679 DISALLOW_COPY_AND_ASSIGN(ServiceWorkerVersion); | 736 DISALLOW_COPY_AND_ASSIGN(ServiceWorkerVersion); |
| 680 }; | 737 }; |
| 681 | 738 |
| 739 template <typename Interface> | |
| 740 base::WeakPtr<Interface> ServiceWorkerVersion::GetMojoServiceForRequest( | |
| 741 int request_id) { | |
| 742 DCHECK_EQ(RUNNING, running_status()); | |
| 743 PendingRequest<StatusCallback>* request = custom_requests_.Lookup(request_id); | |
| 744 DCHECK(request) << "Invalid request id"; | |
| 745 DCHECK(!request->mojo_service) | |
| 746 << "Request is already associated with a mojo service"; | |
| 747 | |
| 748 MojoService<Interface>* service = static_cast<MojoService<Interface>*>( | |
| 749 mojo_services_.get(Interface::Name_)); | |
| 750 if (!service) { | |
| 751 mojo::InterfacePtr<Interface> interface; | |
| 752 embedded_worker_->GetServiceRegistry()->ConnectToRemoteService( | |
| 753 mojo::GetProxy(&interface)); | |
| 754 interface.set_connection_error_handler( | |
| 755 base::Bind(&ServiceWorkerVersion::OnMojoConnectionError, | |
| 756 weak_factory_.GetWeakPtr(), Interface::Name_)); | |
| 757 service = new MojoService<Interface>(this, std::move(interface)); | |
| 758 mojo_services_.add(Interface::Name_, make_scoped_ptr(service)); | |
| 759 } | |
| 760 request->mojo_service = Interface::Name_; | |
| 761 return service->GetWeakPtr(); | |
| 762 } | |
| 763 | |
| 682 } // namespace content | 764 } // namespace content |
| 683 | 765 |
| 684 #endif // CONTENT_BROWSER_SERVICE_WORKER_SERVICE_WORKER_VERSION_H_ | 766 #endif // CONTENT_BROWSER_SERVICE_WORKER_SERVICE_WORKER_VERSION_H_ |
| OLD | NEW |