Include all dupe types (event when value is zero) in scan stats.
[chromium-blink-merge.git] / content / renderer / service_worker / service_worker_script_context.h
blob7203140e71dd4d90f49f62583efb1662550de456
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
3 // found in the LICENSE file.
5 #ifndef CONTENT_RENDERER_SERVICE_WORKER_SERVICE_WORKER_SCRIPT_CONTEXT_H_
6 #define CONTENT_RENDERER_SERVICE_WORKER_SERVICE_WORKER_SCRIPT_CONTEXT_H_
8 #include <map>
9 #include <string>
10 #include <vector>
12 #include "base/basictypes.h"
13 #include "base/id_map.h"
14 #include "base/memory/scoped_ptr.h"
15 #include "base/strings/string16.h"
16 #include "base/time/time.h"
17 #include "content/child/webmessageportchannel_impl.h"
18 #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/WebMessagePortChannel.h"
21 #include "third_party/WebKit/public/platform/WebServiceWorkerClientsClaimCallbacks.h"
22 #include "third_party/WebKit/public/platform/WebServiceWorkerClientsInfo.h"
23 #include "third_party/WebKit/public/platform/WebServiceWorkerError.h"
24 #include "third_party/WebKit/public/platform/WebServiceWorkerEventResult.h"
25 #include "third_party/WebKit/public/platform/WebServiceWorkerSkipWaitingCallbacks.h"
27 namespace blink {
28 struct WebCircularGeofencingRegion;
29 struct WebCrossOriginServiceWorkerClient;
30 struct WebServiceWorkerClientQueryOptions;
31 class WebServiceWorkerContextProxy;
34 namespace IPC {
35 class Message;
38 namespace content {
40 class EmbeddedWorkerContextClient;
41 class WebServiceWorkerRegistrationImpl;
42 struct NavigatorConnectClient;
43 struct PlatformNotificationData;
44 struct ServiceWorkerClientInfo;
46 // TODO(kinuko): This should implement WebServiceWorkerContextClient
47 // rather than having EmbeddedWorkerContextClient implement it.
48 // See the header comment in embedded_worker_context_client.h for the
49 // potential EW/SW layering concerns.
50 class ServiceWorkerScriptContext {
51 public:
52 ServiceWorkerScriptContext(
53 EmbeddedWorkerContextClient* embedded_context,
54 blink::WebServiceWorkerContextProxy* proxy);
55 ~ServiceWorkerScriptContext();
57 void OnMessageReceived(const IPC::Message& message);
59 void SetRegistrationInServiceWorkerGlobalScope(
60 scoped_ptr<WebServiceWorkerRegistrationImpl> registration);
61 void DidHandleActivateEvent(int request_id,
62 blink::WebServiceWorkerEventResult);
63 void DidHandleInstallEvent(int request_id,
64 blink::WebServiceWorkerEventResult result);
65 void DidHandleFetchEvent(int request_id,
66 ServiceWorkerFetchEventResult result,
67 const ServiceWorkerResponse& response);
68 void DidHandleNotificationClickEvent(
69 int request_id,
70 blink::WebServiceWorkerEventResult result);
71 void DidHandlePushEvent(int request_id,
72 blink::WebServiceWorkerEventResult result);
73 void DidHandleSyncEvent(int request_id);
74 void DidHandleCrossOriginConnectEvent(int request_id, bool accept_connection);
75 void GetClients(
76 const blink::WebServiceWorkerClientQueryOptions& options,
77 blink::WebServiceWorkerClientsCallbacks* callbacks);
78 void OpenWindow(const GURL& url,
79 blink::WebServiceWorkerClientCallbacks* callbacks);
80 void SetCachedMetadata(const GURL& url, const char* data, size_t size);
81 void ClearCachedMetadata(const GURL& url);
82 void PostMessageToClient(
83 const base::string16& uuid,
84 const base::string16& message,
85 scoped_ptr<blink::WebMessagePortChannelArray> channels);
86 void PostCrossOriginMessageToClient(
87 const blink::WebCrossOriginServiceWorkerClient& client,
88 const base::string16& message,
89 scoped_ptr<blink::WebMessagePortChannelArray> channels);
90 void FocusClient(const base::string16& uuid,
91 blink::WebServiceWorkerClientCallbacks* callback);
92 void SkipWaiting(blink::WebServiceWorkerSkipWaitingCallbacks* callbacks);
93 void ClaimClients(blink::WebServiceWorkerClientsClaimCallbacks* callbacks);
94 void StashMessagePort(blink::WebMessagePortChannel* channel,
95 const base::string16& name);
97 // Send a message to the browser. Takes ownership of |message|.
98 void Send(IPC::Message* message);
100 // Get routing_id for sending message to the ServiceWorkerVersion
101 // in the browser process.
102 int GetRoutingID() const;
104 private:
105 typedef IDMap<blink::WebServiceWorkerClientsCallbacks, IDMapOwnPointer>
106 ClientsCallbacksMap;
107 typedef IDMap<blink::WebServiceWorkerClientsClaimCallbacks, IDMapOwnPointer>
108 ClaimClientsCallbacksMap;
109 typedef IDMap<blink::WebServiceWorkerClientCallbacks, IDMapOwnPointer>
110 ClientCallbacksMap;
111 typedef IDMap<blink::WebServiceWorkerSkipWaitingCallbacks, IDMapOwnPointer>
112 SkipWaitingCallbacksMap;
114 void OnActivateEvent(int request_id);
115 void OnInstallEvent(int request_id);
116 void OnFetchEvent(int request_id, const ServiceWorkerFetchRequest& request);
117 void OnSyncEvent(int request_id);
118 void OnNotificationClickEvent(
119 int request_id,
120 int64_t persistent_notification_id,
121 const PlatformNotificationData& notification_data);
122 void OnPushEvent(int request_id, const std::string& data);
123 void OnGeofencingEvent(int request_id,
124 blink::WebGeofencingEventType event_type,
125 const std::string& region_id,
126 const blink::WebCircularGeofencingRegion& region);
127 void OnCrossOriginConnectEvent(int request_id,
128 const NavigatorConnectClient& client);
129 void OnPostMessage(
130 const base::string16& message,
131 const std::vector<TransferredMessagePort>& sent_message_ports,
132 const std::vector<int>& new_routing_ids);
133 void OnCrossOriginMessageToWorker(
134 const NavigatorConnectClient& client,
135 const base::string16& message,
136 const std::vector<TransferredMessagePort>& sent_message_ports,
137 const std::vector<int>& new_routing_ids);
138 void OnSendStashedMessagePorts(
139 const std::vector<TransferredMessagePort>& stashed_message_ports,
140 const std::vector<int>& new_routing_ids,
141 const std::vector<base::string16>& port_names);
142 void OnDidGetClients(
143 int request_id, const std::vector<ServiceWorkerClientInfo>& clients);
144 void OnOpenWindowResponse(int request_id,
145 const ServiceWorkerClientInfo& client);
146 void OnOpenWindowError(int request_id, const std::string& message);
147 void OnFocusClientResponse(int request_id,
148 const ServiceWorkerClientInfo& client);
149 void OnDidSkipWaiting(int request_id);
150 void OnDidClaimClients(int request_id);
151 void OnClaimClientsError(int request_id,
152 blink::WebServiceWorkerError::ErrorType error_type,
153 const base::string16& message);
154 void OnPing();
156 // Not owned; embedded_context_ owns this.
157 EmbeddedWorkerContextClient* embedded_context_;
159 // Not owned; this object is destroyed when proxy_ becomes invalid.
160 blink::WebServiceWorkerContextProxy* proxy_;
162 // Used for incoming messages from the browser for which an outgoing response
163 // back to the browser is expected, the id must be sent back with the
164 // response.
165 int current_request_id_;
167 // Pending callbacks for GetClientDocuments().
168 ClientsCallbacksMap pending_clients_callbacks_;
170 // Pending callbacks for OpenWindow() and FocusClient().
171 ClientCallbacksMap pending_client_callbacks_;
173 // Pending callbacks for SkipWaiting().
174 SkipWaitingCallbacksMap pending_skip_waiting_callbacks_;
176 // Pending callbacks for ClaimClients().
177 ClaimClientsCallbacksMap pending_claim_clients_callbacks_;
179 // Capture timestamps for UMA
180 std::map<int, base::TimeTicks> activate_start_timings_;
181 std::map<int, base::TimeTicks> fetch_start_timings_;
182 std::map<int, base::TimeTicks> install_start_timings_;
183 std::map<int, base::TimeTicks> notification_click_start_timings_;
184 std::map<int, base::TimeTicks> push_start_timings_;
186 DISALLOW_COPY_AND_ASSIGN(ServiceWorkerScriptContext);
189 } // namespace content
191 #endif // CONTENT_RENDERER_SERVICE_WORKER_SERVICE_WORKER_SCRIPT_CONTEXT_H_