| 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 <functional> | 10 #include <functional> |
| (...skipping 209 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 220 // associated with the |request_id| is called. Any messages sent back in | 220 // associated with the |request_id| is called. Any messages sent back in |
| 221 // response to this event are passed on to the response |callback|. | 221 // response to this event are passed on to the response |callback|. |
| 222 // ResponseMessage is the type of the IPC message that is used for the | 222 // ResponseMessage is the type of the IPC message that is used for the |
| 223 // response, and its first argument MUST be the request_id. | 223 // response, and its first argument MUST be the request_id. |
| 224 // This must be called when the worker is running. | 224 // This must be called when the worker is running. |
| 225 template <typename ResponseMessage, typename ResponseCallbackType> | 225 template <typename ResponseMessage, typename ResponseCallbackType> |
| 226 void DispatchEvent(int request_id, | 226 void DispatchEvent(int request_id, |
| 227 const IPC::Message& message, | 227 const IPC::Message& message, |
| 228 const ResponseCallbackType& callback); | 228 const ResponseCallbackType& callback); |
| 229 | 229 |
| 230 // For simple events where the full functionality of DispatchEvent is not |
| 231 // needed, this method can be used instead. The ResponseMessage must consist |
| 232 // of just a request_id and a blink::WebServiceWorkerEventResult field. The |
| 233 // result is converted to a ServiceWorkerStatusCode and passed to the error |
| 234 // handler associated with the request. Additionally this methods calls |
| 235 // FinishRequest before passing the reply to the callback. |
| 236 template <typename ResponseMessage> |
| 237 void DispatchSimpleEvent(int request_id, const IPC::Message& message); |
| 238 |
| 230 // Sends a message event to the associated embedded worker. | 239 // Sends a message event to the associated embedded worker. |
| 231 void DispatchMessageEvent( | 240 void DispatchMessageEvent( |
| 232 const base::string16& message, | 241 const base::string16& message, |
| 233 const std::vector<TransferredMessagePort>& sent_message_ports, | 242 const std::vector<TransferredMessagePort>& sent_message_ports, |
| 234 const StatusCallback& callback); | 243 const StatusCallback& callback); |
| 235 | 244 |
| 236 // Sends install event to the associated embedded worker and asynchronously | 245 // Sends install event to the associated embedded worker and asynchronously |
| 237 // calls |callback| when it errors out or it gets a response from the worker | 246 // calls |callback| when it errors out or it gets a response from the worker |
| 238 // to notify install completion. | 247 // to notify install completion. |
| 239 // | 248 // |
| (...skipping 26 matching lines...) Expand all Loading... |
| 266 // asynchronously calls |callback| when it errors out or it gets a response | 275 // asynchronously calls |callback| when it errors out or it gets a response |
| 267 // from the worker to notify completion. | 276 // from the worker to notify completion. |
| 268 // | 277 // |
| 269 // This must be called when the status() is ACTIVATED. | 278 // This must be called when the status() is ACTIVATED. |
| 270 void DispatchNotificationClickEvent( | 279 void DispatchNotificationClickEvent( |
| 271 const StatusCallback& callback, | 280 const StatusCallback& callback, |
| 272 int64_t persistent_notification_id, | 281 int64_t persistent_notification_id, |
| 273 const PlatformNotificationData& notification_data, | 282 const PlatformNotificationData& notification_data, |
| 274 int action_index); | 283 int action_index); |
| 275 | 284 |
| 276 // Sends push event to the associated embedded worker and asynchronously calls | |
| 277 // |callback| when it errors out or it gets a response from the worker to | |
| 278 // notify completion. | |
| 279 // | |
| 280 // This must be called when the status() is ACTIVATED. | |
| 281 void DispatchPushEvent(const StatusCallback& callback, | |
| 282 const std::string& data); | |
| 283 | |
| 284 // Sends a cross origin message event to the associated embedded worker and | 285 // Sends a cross origin message event to the associated embedded worker and |
| 285 // asynchronously calls |callback| when the message was sent (or failed to | 286 // asynchronously calls |callback| when the message was sent (or failed to |
| 286 // sent). | 287 // sent). |
| 287 // It is the responsibility of the code calling this method to make sure that | 288 // It is the responsibility of the code calling this method to make sure that |
| 288 // any transferred message ports are put on hold while potentially a process | 289 // any transferred message ports are put on hold while potentially a process |
| 289 // for the service worker is spun up. | 290 // for the service worker is spun up. |
| 290 // | 291 // |
| 291 // This must be called when the status() is ACTIVATED. | 292 // This must be called when the status() is ACTIVATED. |
| 292 void DispatchCrossOriginMessageEvent( | 293 void DispatchCrossOriginMessageEvent( |
| 293 const NavigatorConnectClient& client, | 294 const NavigatorConnectClient& client, |
| (...skipping 108 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 402 MixedRequestTimeouts); | 403 MixedRequestTimeouts); |
| 403 | 404 |
| 404 class Metrics; | 405 class Metrics; |
| 405 class PingController; | 406 class PingController; |
| 406 | 407 |
| 407 enum RequestType { | 408 enum RequestType { |
| 408 REQUEST_ACTIVATE, | 409 REQUEST_ACTIVATE, |
| 409 REQUEST_INSTALL, | 410 REQUEST_INSTALL, |
| 410 REQUEST_FETCH, | 411 REQUEST_FETCH, |
| 411 REQUEST_NOTIFICATION_CLICK, | 412 REQUEST_NOTIFICATION_CLICK, |
| 412 REQUEST_PUSH, | |
| 413 REQUEST_CUSTOM, | 413 REQUEST_CUSTOM, |
| 414 NUM_REQUEST_TYPES | 414 NUM_REQUEST_TYPES |
| 415 }; | 415 }; |
| 416 | 416 |
| 417 struct RequestInfo { | 417 struct RequestInfo { |
| 418 RequestInfo(int id, | 418 RequestInfo(int id, |
| 419 RequestType type, | 419 RequestType type, |
| 420 ServiceWorkerMetrics::EventType event_type, | 420 ServiceWorkerMetrics::EventType event_type, |
| 421 const base::TimeTicks& expiration, | 421 const base::TimeTicks& expiration, |
| 422 TimeoutBehavior timeout_behavior); | 422 TimeoutBehavior timeout_behavior); |
| (...skipping 141 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 564 const ServiceWorkerClientQueryOptions& options); | 564 const ServiceWorkerClientQueryOptions& options); |
| 565 | 565 |
| 566 void OnActivateEventFinished(int request_id, | 566 void OnActivateEventFinished(int request_id, |
| 567 blink::WebServiceWorkerEventResult result); | 567 blink::WebServiceWorkerEventResult result); |
| 568 void OnInstallEventFinished(int request_id, | 568 void OnInstallEventFinished(int request_id, |
| 569 blink::WebServiceWorkerEventResult result); | 569 blink::WebServiceWorkerEventResult result); |
| 570 void OnFetchEventFinished(int request_id, | 570 void OnFetchEventFinished(int request_id, |
| 571 ServiceWorkerFetchEventResult result, | 571 ServiceWorkerFetchEventResult result, |
| 572 const ServiceWorkerResponse& response); | 572 const ServiceWorkerResponse& response); |
| 573 void OnNotificationClickEventFinished(int request_id); | 573 void OnNotificationClickEventFinished(int request_id); |
| 574 void OnPushEventFinished(int request_id, | 574 void OnSimpleEventResponse(int request_id, |
| 575 blink::WebServiceWorkerEventResult result); | 575 blink::WebServiceWorkerEventResult result); |
| 576 void OnOpenWindow(int request_id, GURL url); | 576 void OnOpenWindow(int request_id, GURL url); |
| 577 void OnOpenWindowFinished(int request_id, | 577 void OnOpenWindowFinished(int request_id, |
| 578 ServiceWorkerStatusCode status, | 578 ServiceWorkerStatusCode status, |
| 579 const std::string& client_uuid, | 579 const std::string& client_uuid, |
| 580 const ServiceWorkerClientInfo& client_info); | 580 const ServiceWorkerClientInfo& client_info); |
| 581 | 581 |
| 582 void OnSetCachedMetadata(const GURL& url, const std::vector<char>& data); | 582 void OnSetCachedMetadata(const GURL& url, const std::vector<char>& data); |
| 583 void OnSetCachedMetadataFinished(int64_t callback_id, int result); | 583 void OnSetCachedMetadataFinished(int64_t callback_id, int result); |
| 584 void OnClearCachedMetadata(const GURL& url); | 584 void OnClearCachedMetadata(const GURL& url); |
| 585 void OnClearCachedMetadataFinished(int64_t callback_id, int result); | 585 void OnClearCachedMetadataFinished(int64_t callback_id, int result); |
| (...skipping 108 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 694 std::vector<StatusCallback> stop_callbacks_; | 694 std::vector<StatusCallback> stop_callbacks_; |
| 695 std::vector<base::Closure> status_change_callbacks_; | 695 std::vector<base::Closure> status_change_callbacks_; |
| 696 | 696 |
| 697 // Message callbacks. (Update HasInflightRequests() too when you update this | 697 // Message callbacks. (Update HasInflightRequests() too when you update this |
| 698 // list.) | 698 // list.) |
| 699 IDMap<PendingRequest<StatusCallback>, IDMapOwnPointer> activate_requests_; | 699 IDMap<PendingRequest<StatusCallback>, IDMapOwnPointer> activate_requests_; |
| 700 IDMap<PendingRequest<StatusCallback>, IDMapOwnPointer> install_requests_; | 700 IDMap<PendingRequest<StatusCallback>, IDMapOwnPointer> install_requests_; |
| 701 IDMap<PendingRequest<FetchCallback>, IDMapOwnPointer> fetch_requests_; | 701 IDMap<PendingRequest<FetchCallback>, IDMapOwnPointer> fetch_requests_; |
| 702 IDMap<PendingRequest<StatusCallback>, IDMapOwnPointer> | 702 IDMap<PendingRequest<StatusCallback>, IDMapOwnPointer> |
| 703 notification_click_requests_; | 703 notification_click_requests_; |
| 704 IDMap<PendingRequest<StatusCallback>, IDMapOwnPointer> push_requests_; | |
| 705 IDMap<PendingRequest<StatusCallback>, IDMapOwnPointer> custom_requests_; | 704 IDMap<PendingRequest<StatusCallback>, IDMapOwnPointer> custom_requests_; |
| 706 | 705 |
| 707 // Stores all open connections to mojo services. Maps the service name to | 706 // Stores all open connections to mojo services. Maps the service name to |
| 708 // the actual interface pointer. When a connection is closed it is removed | 707 // the actual interface pointer. When a connection is closed it is removed |
| 709 // from this map. | 708 // from this map. |
| 710 // mojo_services_[Interface::Name_] is assumed to always contain a | 709 // mojo_services_[Interface::Name_] is assumed to always contain a |
| 711 // MojoServiceWrapper<Interface> instance. | 710 // MojoServiceWrapper<Interface> instance. |
| 712 base::ScopedPtrHashMap<const char*, scoped_ptr<BaseMojoServiceWrapper>> | 711 base::ScopedPtrHashMap<const char*, scoped_ptr<BaseMojoServiceWrapper>> |
| 713 mojo_services_; | 712 mojo_services_; |
| 714 | 713 |
| (...skipping 91 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 806 base::ThreadTaskRunnerHandle::Get()->PostTask( | 805 base::ThreadTaskRunnerHandle::Get()->PostTask( |
| 807 FROM_HERE, base::Bind(request->callback, status)); | 806 FROM_HERE, base::Bind(request->callback, status)); |
| 808 custom_requests_.Remove(request_id); | 807 custom_requests_.Remove(request_id); |
| 809 } else { | 808 } else { |
| 810 request->listener.reset( | 809 request->listener.reset( |
| 811 new EventResponseHandler<ResponseMessage, ResponseCallbackType>( | 810 new EventResponseHandler<ResponseMessage, ResponseCallbackType>( |
| 812 embedded_worker(), request_id, callback)); | 811 embedded_worker(), request_id, callback)); |
| 813 } | 812 } |
| 814 } | 813 } |
| 815 | 814 |
| 815 template <typename ResponseMessage> |
| 816 void ServiceWorkerVersion::DispatchSimpleEvent(int request_id, |
| 817 const IPC::Message& message) { |
| 818 DispatchEvent<ResponseMessage>( |
| 819 request_id, message, |
| 820 base::Bind(&ServiceWorkerVersion::OnSimpleEventResponse, this)); |
| 821 } |
| 822 |
| 816 template <typename ResponseMessage, typename CallbackType> | 823 template <typename ResponseMessage, typename CallbackType> |
| 817 bool ServiceWorkerVersion::EventResponseHandler<ResponseMessage, CallbackType>:: | 824 bool ServiceWorkerVersion::EventResponseHandler<ResponseMessage, CallbackType>:: |
| 818 OnMessageReceived(const IPC::Message& message) { | 825 OnMessageReceived(const IPC::Message& message) { |
| 819 if (message.type() != ResponseMessage::ID) | 826 if (message.type() != ResponseMessage::ID) |
| 820 return false; | 827 return false; |
| 821 int received_request_id; | 828 int received_request_id; |
| 822 bool result = base::PickleIterator(message).ReadInt(&received_request_id); | 829 bool result = base::PickleIterator(message).ReadInt(&received_request_id); |
| 823 if (!result || received_request_id != request_id_) | 830 if (!result || received_request_id != request_id_) |
| 824 return false; | 831 return false; |
| 825 | 832 |
| 833 CallbackType protect(callback_); |
| 826 // Essentially same code as what IPC_MESSAGE_FORWARD expands to. | 834 // Essentially same code as what IPC_MESSAGE_FORWARD expands to. |
| 827 void* param = nullptr; | 835 void* param = nullptr; |
| 828 if (!ResponseMessage::Dispatch(&message, &callback_, this, param, | 836 if (!ResponseMessage::Dispatch(&message, &callback_, this, param, |
| 829 &CallbackType::Run)) | 837 &CallbackType::Run)) |
| 830 message.set_dispatch_error(); | 838 message.set_dispatch_error(); |
| 831 | 839 |
| 832 return true; | 840 return true; |
| 833 } | 841 } |
| 834 | 842 |
| 835 } // namespace content | 843 } // namespace content |
| 836 | 844 |
| 837 #endif // CONTENT_BROWSER_SERVICE_WORKER_SERVICE_WORKER_VERSION_H_ | 845 #endif // CONTENT_BROWSER_SERVICE_WORKER_SERVICE_WORKER_VERSION_H_ |
| OLD | NEW |