| OLD | NEW |
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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_RENDERER_SERVICE_WORKER_SERVICE_WORKER_SCRIPT_CONTEXT_H_ | 5 #ifndef CONTENT_RENDERER_SERVICE_WORKER_SERVICE_WORKER_SCRIPT_CONTEXT_H_ |
| 6 #define CONTENT_RENDERER_SERVICE_WORKER_SERVICE_WORKER_SCRIPT_CONTEXT_H_ | 6 #define CONTENT_RENDERER_SERVICE_WORKER_SERVICE_WORKER_SCRIPT_CONTEXT_H_ |
| 7 | 7 |
| 8 #include <map> | 8 #include <map> |
| 9 #include <string> | 9 #include <string> |
| 10 #include <vector> | 10 #include <vector> |
| 11 | 11 |
| 12 #include "base/basictypes.h" | 12 #include "base/basictypes.h" |
| 13 #include "base/id_map.h" | 13 #include "base/id_map.h" |
| 14 #include "base/memory/scoped_ptr.h" | 14 #include "base/memory/scoped_ptr.h" |
| 15 #include "base/strings/string16.h" | 15 #include "base/strings/string16.h" |
| 16 #include "base/time/time.h" | 16 #include "base/time/time.h" |
| 17 #include "content/child/webmessageportchannel_impl.h" | 17 #include "content/child/webmessageportchannel_impl.h" |
| 18 #include "content/common/background_sync_service.mojom.h" |
| 18 #include "content/common/service_worker/service_worker_types.h" | 19 #include "content/common/service_worker/service_worker_types.h" |
| 19 #include "third_party/WebKit/public/platform/WebGeofencingEventType.h" | 20 #include "third_party/WebKit/public/platform/WebGeofencingEventType.h" |
| 20 #include "third_party/WebKit/public/platform/WebMessagePortChannel.h" | 21 #include "third_party/WebKit/public/platform/WebMessagePortChannel.h" |
| 21 #include "third_party/WebKit/public/platform/WebServiceWorkerClientsClaimCallbac
ks.h" | 22 #include "third_party/WebKit/public/platform/WebServiceWorkerClientsClaimCallbac
ks.h" |
| 22 #include "third_party/WebKit/public/platform/WebServiceWorkerClientsInfo.h" | 23 #include "third_party/WebKit/public/platform/WebServiceWorkerClientsInfo.h" |
| 23 #include "third_party/WebKit/public/platform/WebServiceWorkerError.h" | 24 #include "third_party/WebKit/public/platform/WebServiceWorkerError.h" |
| 24 #include "third_party/WebKit/public/platform/WebServiceWorkerEventResult.h" | 25 #include "third_party/WebKit/public/platform/WebServiceWorkerEventResult.h" |
| 25 #include "third_party/WebKit/public/platform/WebServiceWorkerSkipWaitingCallback
s.h" | 26 #include "third_party/WebKit/public/platform/WebServiceWorkerSkipWaitingCallback
s.h" |
| 26 | 27 |
| 27 namespace blink { | 28 namespace blink { |
| 28 struct WebCircularGeofencingRegion; | 29 struct WebCircularGeofencingRegion; |
| 29 struct WebCrossOriginServiceWorkerClient; | 30 struct WebCrossOriginServiceWorkerClient; |
| 30 struct WebServiceWorkerClientQueryOptions; | 31 struct WebServiceWorkerClientQueryOptions; |
| 31 class WebServiceWorkerContextProxy; | 32 class WebServiceWorkerContextProxy; |
| 32 } | 33 } |
| 33 | 34 |
| 34 namespace IPC { | 35 namespace IPC { |
| 35 class Message; | 36 class Message; |
| 36 } | 37 } |
| 37 | 38 |
| 38 namespace content { | 39 namespace content { |
| 39 | 40 |
| 40 class EmbeddedWorkerContextClient; | 41 class EmbeddedWorkerContextClient; |
| 41 class WebServiceWorkerRegistrationImpl; | 42 class WebServiceWorkerRegistrationImpl; |
| 42 struct NavigatorConnectClient; | 43 struct NavigatorConnectClient; |
| 43 struct PlatformNotificationData; | 44 struct PlatformNotificationData; |
| 44 struct ServiceWorkerClientInfo; | 45 struct ServiceWorkerClientInfo; |
| 45 | 46 |
| 47 using SyncCallback = mojo::Callback<void(BackgroundSyncEventStatus)>; |
| 48 |
| 46 // TODO(kinuko): This should implement WebServiceWorkerContextClient | 49 // TODO(kinuko): This should implement WebServiceWorkerContextClient |
| 47 // rather than having EmbeddedWorkerContextClient implement it. | 50 // rather than having EmbeddedWorkerContextClient implement it. |
| 48 // See the header comment in embedded_worker_context_client.h for the | 51 // See the header comment in embedded_worker_context_client.h for the |
| 49 // potential EW/SW layering concerns. | 52 // potential EW/SW layering concerns. |
| 50 class ServiceWorkerScriptContext { | 53 class ServiceWorkerScriptContext { |
| 51 public: | 54 public: |
| 52 ServiceWorkerScriptContext( | 55 ServiceWorkerScriptContext( |
| 53 EmbeddedWorkerContextClient* embedded_context, | 56 EmbeddedWorkerContextClient* embedded_context, |
| 54 blink::WebServiceWorkerContextProxy* proxy); | 57 blink::WebServiceWorkerContextProxy* proxy); |
| 55 ~ServiceWorkerScriptContext(); | 58 ~ServiceWorkerScriptContext(); |
| (...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 95 void StashMessagePort(blink::WebMessagePortChannel* channel, | 98 void StashMessagePort(blink::WebMessagePortChannel* channel, |
| 96 const base::string16& name); | 99 const base::string16& name); |
| 97 | 100 |
| 98 // Send a message to the browser. Takes ownership of |message|. | 101 // Send a message to the browser. Takes ownership of |message|. |
| 99 void Send(IPC::Message* message); | 102 void Send(IPC::Message* message); |
| 100 | 103 |
| 101 // Get routing_id for sending message to the ServiceWorkerVersion | 104 // Get routing_id for sending message to the ServiceWorkerVersion |
| 102 // in the browser process. | 105 // in the browser process. |
| 103 int GetRoutingID() const; | 106 int GetRoutingID() const; |
| 104 | 107 |
| 108 void DispatchSyncEvent(const SyncCallback& callbacks); |
| 109 |
| 105 private: | 110 private: |
| 106 typedef IDMap<blink::WebServiceWorkerClientsCallbacks, IDMapOwnPointer> | 111 typedef IDMap<blink::WebServiceWorkerClientsCallbacks, IDMapOwnPointer> |
| 107 ClientsCallbacksMap; | 112 ClientsCallbacksMap; |
| 108 typedef IDMap<blink::WebServiceWorkerClientsClaimCallbacks, IDMapOwnPointer> | 113 typedef IDMap<blink::WebServiceWorkerClientsClaimCallbacks, IDMapOwnPointer> |
| 109 ClaimClientsCallbacksMap; | 114 ClaimClientsCallbacksMap; |
| 110 typedef IDMap<blink::WebServiceWorkerClientCallbacks, IDMapOwnPointer> | 115 typedef IDMap<blink::WebServiceWorkerClientCallbacks, IDMapOwnPointer> |
| 111 ClientCallbacksMap; | 116 ClientCallbacksMap; |
| 112 typedef IDMap<blink::WebServiceWorkerSkipWaitingCallbacks, IDMapOwnPointer> | 117 typedef IDMap<blink::WebServiceWorkerSkipWaitingCallbacks, IDMapOwnPointer> |
| 113 SkipWaitingCallbacksMap; | 118 SkipWaitingCallbacksMap; |
| 119 typedef IDMap<const mojo::Callback<void(BackgroundSyncEventStatus)>, |
| 120 IDMapExternalPointer> SyncEventCallbacksMap; |
| 114 | 121 |
| 115 void OnActivateEvent(int request_id); | 122 void OnActivateEvent(int request_id); |
| 116 void OnInstallEvent(int request_id); | 123 void OnInstallEvent(int request_id); |
| 117 void OnFetchEvent(int request_id, const ServiceWorkerFetchRequest& request); | 124 void OnFetchEvent(int request_id, const ServiceWorkerFetchRequest& request); |
| 118 void OnSyncEvent(int request_id); | |
| 119 void OnNotificationClickEvent( | 125 void OnNotificationClickEvent( |
| 120 int request_id, | 126 int request_id, |
| 121 int64_t persistent_notification_id, | 127 int64_t persistent_notification_id, |
| 122 const PlatformNotificationData& notification_data); | 128 const PlatformNotificationData& notification_data); |
| 123 void OnPushEvent(int request_id, const std::string& data); | 129 void OnPushEvent(int request_id, const std::string& data); |
| 124 void OnGeofencingEvent(int request_id, | 130 void OnGeofencingEvent(int request_id, |
| 125 blink::WebGeofencingEventType event_type, | 131 blink::WebGeofencingEventType event_type, |
| 126 const std::string& region_id, | 132 const std::string& region_id, |
| 127 const blink::WebCircularGeofencingRegion& region); | 133 const blink::WebCircularGeofencingRegion& region); |
| 128 void OnCrossOriginConnectEvent(int request_id, | 134 void OnCrossOriginConnectEvent(int request_id, |
| (...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 170 | 176 |
| 171 // Pending callbacks for OpenWindow() and FocusClient(). | 177 // Pending callbacks for OpenWindow() and FocusClient(). |
| 172 ClientCallbacksMap pending_client_callbacks_; | 178 ClientCallbacksMap pending_client_callbacks_; |
| 173 | 179 |
| 174 // Pending callbacks for SkipWaiting(). | 180 // Pending callbacks for SkipWaiting(). |
| 175 SkipWaitingCallbacksMap pending_skip_waiting_callbacks_; | 181 SkipWaitingCallbacksMap pending_skip_waiting_callbacks_; |
| 176 | 182 |
| 177 // Pending callbacks for ClaimClients(). | 183 // Pending callbacks for ClaimClients(). |
| 178 ClaimClientsCallbacksMap pending_claim_clients_callbacks_; | 184 ClaimClientsCallbacksMap pending_claim_clients_callbacks_; |
| 179 | 185 |
| 186 // Pending callbacks for Background Sync Events |
| 187 SyncEventCallbacksMap sync_event_callbacks_; |
| 188 |
| 180 // Capture timestamps for UMA | 189 // Capture timestamps for UMA |
| 181 std::map<int, base::TimeTicks> activate_start_timings_; | 190 std::map<int, base::TimeTicks> activate_start_timings_; |
| 182 std::map<int, base::TimeTicks> fetch_start_timings_; | 191 std::map<int, base::TimeTicks> fetch_start_timings_; |
| 183 std::map<int, base::TimeTicks> install_start_timings_; | 192 std::map<int, base::TimeTicks> install_start_timings_; |
| 184 std::map<int, base::TimeTicks> notification_click_start_timings_; | 193 std::map<int, base::TimeTicks> notification_click_start_timings_; |
| 185 std::map<int, base::TimeTicks> push_start_timings_; | 194 std::map<int, base::TimeTicks> push_start_timings_; |
| 186 | 195 |
| 187 DISALLOW_COPY_AND_ASSIGN(ServiceWorkerScriptContext); | 196 DISALLOW_COPY_AND_ASSIGN(ServiceWorkerScriptContext); |
| 188 }; | 197 }; |
| 189 | 198 |
| 190 } // namespace content | 199 } // namespace content |
| 191 | 200 |
| 192 #endif // CONTENT_RENDERER_SERVICE_WORKER_SERVICE_WORKER_SCRIPT_CONTEXT_H_ | 201 #endif // CONTENT_RENDERER_SERVICE_WORKER_SERVICE_WORKER_SCRIPT_CONTEXT_H_ |
| OLD | NEW |