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 <stdint.h> | 8 #include <stdint.h> |
9 | 9 |
10 #include <map> | 10 #include <map> |
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
45 } | 45 } |
46 | 46 |
47 namespace content { | 47 namespace content { |
48 | 48 |
49 class EmbeddedWorkerRegistry; | 49 class EmbeddedWorkerRegistry; |
50 class ServiceWorkerContextCore; | 50 class ServiceWorkerContextCore; |
51 class ServiceWorkerProviderHost; | 51 class ServiceWorkerProviderHost; |
52 class ServiceWorkerRegistration; | 52 class ServiceWorkerRegistration; |
53 class ServiceWorkerURLRequestJob; | 53 class ServiceWorkerURLRequestJob; |
54 struct NavigatorConnectClient; | 54 struct NavigatorConnectClient; |
55 struct PlatformNotificationData; | |
56 struct ServiceWorkerClientInfo; | 55 struct ServiceWorkerClientInfo; |
57 struct ServiceWorkerVersionInfo; | 56 struct ServiceWorkerVersionInfo; |
58 struct TransferredMessagePort; | 57 struct TransferredMessagePort; |
59 | 58 |
60 // This class corresponds to a specific version of a ServiceWorker | 59 // This class corresponds to a specific version of a ServiceWorker |
61 // script for a given pattern. When a script is upgraded, there may be | 60 // script for a given pattern. When a script is upgraded, there may be |
62 // more than one ServiceWorkerVersion "running" at a time, but only | 61 // more than one ServiceWorkerVersion "running" at a time, but only |
63 // one of them is activated. This class connects the actual script with a | 62 // one of them is activated. This class connects the actual script with a |
64 // running worker. | 63 // running worker. |
65 class CONTENT_EXPORT ServiceWorkerVersion | 64 class CONTENT_EXPORT ServiceWorkerVersion |
(...skipping 186 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
252 | 251 |
253 // Sends fetch event to the associated embedded worker and calls | 252 // Sends fetch event to the associated embedded worker and calls |
254 // |callback| with the response from the worker. | 253 // |callback| with the response from the worker. |
255 // | 254 // |
256 // This must be called when the status() is ACTIVATED. Calling this in other | 255 // This must be called when the status() is ACTIVATED. Calling this in other |
257 // statuses will result in an error SERVICE_WORKER_ERROR_FAILED. | 256 // statuses will result in an error SERVICE_WORKER_ERROR_FAILED. |
258 void DispatchFetchEvent(const ServiceWorkerFetchRequest& request, | 257 void DispatchFetchEvent(const ServiceWorkerFetchRequest& request, |
259 const base::Closure& prepare_callback, | 258 const base::Closure& prepare_callback, |
260 const FetchCallback& fetch_callback); | 259 const FetchCallback& fetch_callback); |
261 | 260 |
262 // Sends notificationclick event to the associated embedded worker and | |
263 // asynchronously calls |callback| when it errors out or it gets a response | |
264 // from the worker to notify completion. | |
265 // | |
266 // This must be called when the status() is ACTIVATED. | |
267 void DispatchNotificationClickEvent( | |
268 const StatusCallback& callback, | |
269 int64_t persistent_notification_id, | |
270 const PlatformNotificationData& notification_data, | |
271 int action_index); | |
272 | |
273 // Sends push event to the associated embedded worker and asynchronously calls | 261 // Sends push event to the associated embedded worker and asynchronously calls |
274 // |callback| when it errors out or it gets a response from the worker to | 262 // |callback| when it errors out or it gets a response from the worker to |
275 // notify completion. | 263 // notify completion. |
276 // | 264 // |
277 // This must be called when the status() is ACTIVATED. | 265 // This must be called when the status() is ACTIVATED. |
278 void DispatchPushEvent(const StatusCallback& callback, | 266 void DispatchPushEvent(const StatusCallback& callback, |
279 const std::string& data); | 267 const std::string& data); |
280 | 268 |
281 // Sends a cross origin message event to the associated embedded worker and | 269 // Sends a cross origin message event to the associated embedded worker and |
282 // asynchronously calls |callback| when the message was sent (or failed to | 270 // asynchronously calls |callback| when the message was sent (or failed to |
(...skipping 113 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
396 FRIEND_TEST_ALL_PREFIXES(ServiceWorkerWaitForeverInFetchTest, | 384 FRIEND_TEST_ALL_PREFIXES(ServiceWorkerWaitForeverInFetchTest, |
397 MixedRequestTimeouts); | 385 MixedRequestTimeouts); |
398 | 386 |
399 class Metrics; | 387 class Metrics; |
400 class PingController; | 388 class PingController; |
401 | 389 |
402 enum RequestType { | 390 enum RequestType { |
403 REQUEST_ACTIVATE, | 391 REQUEST_ACTIVATE, |
404 REQUEST_INSTALL, | 392 REQUEST_INSTALL, |
405 REQUEST_FETCH, | 393 REQUEST_FETCH, |
406 REQUEST_NOTIFICATION_CLICK, | |
407 REQUEST_PUSH, | 394 REQUEST_PUSH, |
408 REQUEST_CUSTOM, | 395 REQUEST_CUSTOM, |
409 NUM_REQUEST_TYPES | 396 NUM_REQUEST_TYPES |
410 }; | 397 }; |
411 | 398 |
412 struct RequestInfo { | 399 struct RequestInfo { |
413 RequestInfo(int id, | 400 RequestInfo(int id, |
414 RequestType type, | 401 RequestType type, |
415 ServiceWorkerMetrics::EventType event_type, | 402 ServiceWorkerMetrics::EventType event_type, |
416 const base::TimeTicks& expiration, | 403 const base::TimeTicks& expiration, |
(...skipping 141 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
558 void OnGetClients(int request_id, | 545 void OnGetClients(int request_id, |
559 const ServiceWorkerClientQueryOptions& options); | 546 const ServiceWorkerClientQueryOptions& options); |
560 | 547 |
561 void OnActivateEventFinished(int request_id, | 548 void OnActivateEventFinished(int request_id, |
562 blink::WebServiceWorkerEventResult result); | 549 blink::WebServiceWorkerEventResult result); |
563 void OnInstallEventFinished(int request_id, | 550 void OnInstallEventFinished(int request_id, |
564 blink::WebServiceWorkerEventResult result); | 551 blink::WebServiceWorkerEventResult result); |
565 void OnFetchEventFinished(int request_id, | 552 void OnFetchEventFinished(int request_id, |
566 ServiceWorkerFetchEventResult result, | 553 ServiceWorkerFetchEventResult result, |
567 const ServiceWorkerResponse& response); | 554 const ServiceWorkerResponse& response); |
568 void OnNotificationClickEventFinished(int request_id); | |
569 void OnPushEventFinished(int request_id, | 555 void OnPushEventFinished(int request_id, |
570 blink::WebServiceWorkerEventResult result); | 556 blink::WebServiceWorkerEventResult result); |
571 void OnOpenWindow(int request_id, GURL url); | 557 void OnOpenWindow(int request_id, GURL url); |
572 void OnOpenWindowFinished(int request_id, | 558 void OnOpenWindowFinished(int request_id, |
573 ServiceWorkerStatusCode status, | 559 ServiceWorkerStatusCode status, |
574 const std::string& client_uuid, | 560 const std::string& client_uuid, |
575 const ServiceWorkerClientInfo& client_info); | 561 const ServiceWorkerClientInfo& client_info); |
576 | 562 |
577 void OnSetCachedMetadata(const GURL& url, const std::vector<char>& data); | 563 void OnSetCachedMetadata(const GURL& url, const std::vector<char>& data); |
578 void OnSetCachedMetadataFinished(int64_t callback_id, int result); | 564 void OnSetCachedMetadataFinished(int64_t callback_id, int result); |
(...skipping 108 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
687 scoped_ptr<EmbeddedWorkerInstance> embedded_worker_; | 673 scoped_ptr<EmbeddedWorkerInstance> embedded_worker_; |
688 std::vector<StatusCallback> start_callbacks_; | 674 std::vector<StatusCallback> start_callbacks_; |
689 std::vector<StatusCallback> stop_callbacks_; | 675 std::vector<StatusCallback> stop_callbacks_; |
690 std::vector<base::Closure> status_change_callbacks_; | 676 std::vector<base::Closure> status_change_callbacks_; |
691 | 677 |
692 // Message callbacks. (Update HasInflightRequests() too when you update this | 678 // Message callbacks. (Update HasInflightRequests() too when you update this |
693 // list.) | 679 // list.) |
694 IDMap<PendingRequest<StatusCallback>, IDMapOwnPointer> activate_requests_; | 680 IDMap<PendingRequest<StatusCallback>, IDMapOwnPointer> activate_requests_; |
695 IDMap<PendingRequest<StatusCallback>, IDMapOwnPointer> install_requests_; | 681 IDMap<PendingRequest<StatusCallback>, IDMapOwnPointer> install_requests_; |
696 IDMap<PendingRequest<FetchCallback>, IDMapOwnPointer> fetch_requests_; | 682 IDMap<PendingRequest<FetchCallback>, IDMapOwnPointer> fetch_requests_; |
697 IDMap<PendingRequest<StatusCallback>, IDMapOwnPointer> | |
698 notification_click_requests_; | |
699 IDMap<PendingRequest<StatusCallback>, IDMapOwnPointer> push_requests_; | 683 IDMap<PendingRequest<StatusCallback>, IDMapOwnPointer> push_requests_; |
700 IDMap<PendingRequest<StatusCallback>, IDMapOwnPointer> custom_requests_; | 684 IDMap<PendingRequest<StatusCallback>, IDMapOwnPointer> custom_requests_; |
701 | 685 |
702 // Stores all open connections to mojo services. Maps the service name to | 686 // Stores all open connections to mojo services. Maps the service name to |
703 // the actual interface pointer. When a connection is closed it is removed | 687 // the actual interface pointer. When a connection is closed it is removed |
704 // from this map. | 688 // from this map. |
705 // mojo_services_[Interface::Name_] is assumed to always contain a | 689 // mojo_services_[Interface::Name_] is assumed to always contain a |
706 // MojoServiceWrapper<Interface> instance. | 690 // MojoServiceWrapper<Interface> instance. |
707 base::ScopedPtrHashMap<const char*, scoped_ptr<BaseMojoServiceWrapper>> | 691 base::ScopedPtrHashMap<const char*, scoped_ptr<BaseMojoServiceWrapper>> |
708 mojo_services_; | 692 mojo_services_; |
(...skipping 102 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
811 template <typename ResponseMessage, typename CallbackType> | 795 template <typename ResponseMessage, typename CallbackType> |
812 bool ServiceWorkerVersion::EventResponseHandler<ResponseMessage, CallbackType>:: | 796 bool ServiceWorkerVersion::EventResponseHandler<ResponseMessage, CallbackType>:: |
813 OnMessageReceived(const IPC::Message& message) { | 797 OnMessageReceived(const IPC::Message& message) { |
814 if (message.type() != ResponseMessage::ID) | 798 if (message.type() != ResponseMessage::ID) |
815 return false; | 799 return false; |
816 int received_request_id; | 800 int received_request_id; |
817 bool result = base::PickleIterator(message).ReadInt(&received_request_id); | 801 bool result = base::PickleIterator(message).ReadInt(&received_request_id); |
818 if (!result || received_request_id != request_id_) | 802 if (!result || received_request_id != request_id_) |
819 return false; | 803 return false; |
820 | 804 |
805 CallbackType protect(callback_); | |
johnme
2016/01/18 17:57:05
Why are you protecting the callback? Is that becau
Marijn Kruisselbrink
2016/01/19 23:50:17
I am protecting the callback because that's what I
johnme
2016/01/20 17:07:10
Ok, sounds reasonable. Who owns the |message|? Is
| |
821 // Essentially same code as what IPC_MESSAGE_FORWARD expands to. | 806 // Essentially same code as what IPC_MESSAGE_FORWARD expands to. |
822 void* param = nullptr; | 807 void* param = nullptr; |
823 if (!ResponseMessage::Dispatch(&message, &callback_, this, param, | 808 if (!ResponseMessage::Dispatch(&message, &callback_, this, param, |
824 &CallbackType::Run)) | 809 &CallbackType::Run)) |
825 message.set_dispatch_error(); | 810 message.set_dispatch_error(); |
826 | 811 |
812 // At this point |this| can have been deleted, so don't do anything other | |
813 // than returning. | |
814 | |
827 return true; | 815 return true; |
828 } | 816 } |
829 | 817 |
830 } // namespace content | 818 } // namespace content |
831 | 819 |
832 #endif // CONTENT_BROWSER_SERVICE_WORKER_SERVICE_WORKER_VERSION_H_ | 820 #endif // CONTENT_BROWSER_SERVICE_WORKER_SERVICE_WORKER_VERSION_H_ |
OLD | NEW |