| 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 #include "content/renderer/service_worker/service_worker_script_context.h" | 5 #include "content/renderer/service_worker/service_worker_script_context.h" |
| 6 | 6 |
| 7 #include <map> | |
| 8 | |
| 9 #include "base/debug/trace_event.h" | 7 #include "base/debug/trace_event.h" |
| 10 #include "base/logging.h" | 8 #include "base/logging.h" |
| 9 #include "base/metrics/histogram.h" |
| 11 #include "content/child/thread_safe_sender.h" | 10 #include "content/child/thread_safe_sender.h" |
| 12 #include "content/child/webmessageportchannel_impl.h" | 11 #include "content/child/webmessageportchannel_impl.h" |
| 13 #include "content/common/service_worker/service_worker_messages.h" | 12 #include "content/common/service_worker/service_worker_messages.h" |
| 14 #include "content/renderer/service_worker/embedded_worker_context_client.h" | 13 #include "content/renderer/service_worker/embedded_worker_context_client.h" |
| 15 #include "ipc/ipc_message.h" | 14 #include "ipc/ipc_message.h" |
| 16 #include "third_party/WebKit/public/platform/WebReferrerPolicy.h" | 15 #include "third_party/WebKit/public/platform/WebReferrerPolicy.h" |
| 17 #include "third_party/WebKit/public/platform/WebServiceWorkerRequest.h" | 16 #include "third_party/WebKit/public/platform/WebServiceWorkerRequest.h" |
| 18 #include "third_party/WebKit/public/platform/WebString.h" | 17 #include "third_party/WebKit/public/platform/WebString.h" |
| 19 #include "third_party/WebKit/public/platform/WebURL.h" | 18 #include "third_party/WebKit/public/platform/WebURL.h" |
| 20 #include "third_party/WebKit/public/web/WebServiceWorkerContextClient.h" | 19 #include "third_party/WebKit/public/web/WebServiceWorkerContextClient.h" |
| (...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 66 // EmbeddedWorkerContextClient? | 65 // EmbeddedWorkerContextClient? |
| 67 if (!handled) | 66 if (!handled) |
| 68 handled = cache_storage_dispatcher_->OnMessageReceived(message); | 67 handled = cache_storage_dispatcher_->OnMessageReceived(message); |
| 69 | 68 |
| 70 DCHECK(handled); | 69 DCHECK(handled); |
| 71 } | 70 } |
| 72 | 71 |
| 73 void ServiceWorkerScriptContext::DidHandleActivateEvent( | 72 void ServiceWorkerScriptContext::DidHandleActivateEvent( |
| 74 int request_id, | 73 int request_id, |
| 75 blink::WebServiceWorkerEventResult result) { | 74 blink::WebServiceWorkerEventResult result) { |
| 75 UMA_HISTOGRAM_TIMES( |
| 76 "ServiceWorker.ActivateEventExecutionTime", |
| 77 base::TimeTicks::Now() - activate_start_timings_[request_id]); |
| 78 activate_start_timings_.erase(request_id); |
| 79 |
| 76 Send(new ServiceWorkerHostMsg_ActivateEventFinished( | 80 Send(new ServiceWorkerHostMsg_ActivateEventFinished( |
| 77 GetRoutingID(), request_id, result)); | 81 GetRoutingID(), request_id, result)); |
| 78 } | 82 } |
| 79 | 83 |
| 80 void ServiceWorkerScriptContext::DidHandleInstallEvent( | 84 void ServiceWorkerScriptContext::DidHandleInstallEvent( |
| 81 int request_id, | 85 int request_id, |
| 82 blink::WebServiceWorkerEventResult result) { | 86 blink::WebServiceWorkerEventResult result) { |
| 87 UMA_HISTOGRAM_TIMES( |
| 88 "ServiceWorker.InstallEventExecutionTime", |
| 89 base::TimeTicks::Now() - install_start_timings_[request_id]); |
| 90 install_start_timings_.erase(request_id); |
| 91 |
| 83 Send(new ServiceWorkerHostMsg_InstallEventFinished( | 92 Send(new ServiceWorkerHostMsg_InstallEventFinished( |
| 84 GetRoutingID(), request_id, result)); | 93 GetRoutingID(), request_id, result)); |
| 85 } | 94 } |
| 86 | 95 |
| 87 void ServiceWorkerScriptContext::DidHandleFetchEvent( | 96 void ServiceWorkerScriptContext::DidHandleFetchEvent( |
| 88 int request_id, | 97 int request_id, |
| 89 ServiceWorkerFetchEventResult result, | 98 ServiceWorkerFetchEventResult result, |
| 90 const ServiceWorkerResponse& response) { | 99 const ServiceWorkerResponse& response) { |
| 100 UMA_HISTOGRAM_TIMES( |
| 101 "ServiceWorker.FetchEventExecutionTime", |
| 102 base::TimeTicks::Now() - fetch_start_timings_[request_id]); |
| 103 fetch_start_timings_.erase(request_id); |
| 104 |
| 91 Send(new ServiceWorkerHostMsg_FetchEventFinished( | 105 Send(new ServiceWorkerHostMsg_FetchEventFinished( |
| 92 GetRoutingID(), request_id, result, response)); | 106 GetRoutingID(), request_id, result, response)); |
| 93 } | 107 } |
| 94 | 108 |
| 95 void ServiceWorkerScriptContext::DidHandleSyncEvent(int request_id) { | 109 void ServiceWorkerScriptContext::DidHandleSyncEvent(int request_id) { |
| 96 Send(new ServiceWorkerHostMsg_SyncEventFinished( | 110 Send(new ServiceWorkerHostMsg_SyncEventFinished( |
| 97 GetRoutingID(), request_id)); | 111 GetRoutingID(), request_id)); |
| 98 } | 112 } |
| 99 | 113 |
| 100 void ServiceWorkerScriptContext::GetClientDocuments( | 114 void ServiceWorkerScriptContext::GetClientDocuments( |
| (...skipping 23 matching lines...) Expand all Loading... |
| 124 embedded_context_->Send(message); | 138 embedded_context_->Send(message); |
| 125 } | 139 } |
| 126 | 140 |
| 127 int ServiceWorkerScriptContext::GetRoutingID() const { | 141 int ServiceWorkerScriptContext::GetRoutingID() const { |
| 128 return embedded_context_->embedded_worker_id(); | 142 return embedded_context_->embedded_worker_id(); |
| 129 } | 143 } |
| 130 | 144 |
| 131 void ServiceWorkerScriptContext::OnActivateEvent(int request_id) { | 145 void ServiceWorkerScriptContext::OnActivateEvent(int request_id) { |
| 132 TRACE_EVENT0("ServiceWorker", | 146 TRACE_EVENT0("ServiceWorker", |
| 133 "ServiceWorkerScriptContext::OnActivateEvent"); | 147 "ServiceWorkerScriptContext::OnActivateEvent"); |
| 148 activate_start_timings_[request_id] = base::TimeTicks::Now(); |
| 134 proxy_->dispatchActivateEvent(request_id); | 149 proxy_->dispatchActivateEvent(request_id); |
| 135 } | 150 } |
| 136 | 151 |
| 137 void ServiceWorkerScriptContext::OnInstallEvent(int request_id, | 152 void ServiceWorkerScriptContext::OnInstallEvent(int request_id, |
| 138 int active_version_id) { | 153 int active_version_id) { |
| 139 TRACE_EVENT0("ServiceWorker", | 154 TRACE_EVENT0("ServiceWorker", |
| 140 "ServiceWorkerScriptContext::OnInstallEvent"); | 155 "ServiceWorkerScriptContext::OnInstallEvent"); |
| 156 install_start_timings_[request_id] = base::TimeTicks::Now(); |
| 141 proxy_->dispatchInstallEvent(request_id); | 157 proxy_->dispatchInstallEvent(request_id); |
| 142 } | 158 } |
| 143 | 159 |
| 144 void ServiceWorkerScriptContext::OnFetchEvent( | 160 void ServiceWorkerScriptContext::OnFetchEvent( |
| 145 int request_id, | 161 int request_id, |
| 146 const ServiceWorkerFetchRequest& request) { | 162 const ServiceWorkerFetchRequest& request) { |
| 147 blink::WebServiceWorkerRequest webRequest; | 163 blink::WebServiceWorkerRequest webRequest; |
| 148 TRACE_EVENT0("ServiceWorker", | 164 TRACE_EVENT0("ServiceWorker", |
| 149 "ServiceWorkerScriptContext::OnFetchEvent"); | 165 "ServiceWorkerScriptContext::OnFetchEvent"); |
| 150 webRequest.setURL(blink::WebURL(request.url)); | 166 webRequest.setURL(blink::WebURL(request.url)); |
| 151 webRequest.setMethod(blink::WebString::fromUTF8(request.method)); | 167 webRequest.setMethod(blink::WebString::fromUTF8(request.method)); |
| 152 for (ServiceWorkerHeaderMap::const_iterator it = request.headers.begin(); | 168 for (ServiceWorkerHeaderMap::const_iterator it = request.headers.begin(); |
| 153 it != request.headers.end(); | 169 it != request.headers.end(); |
| 154 ++it) { | 170 ++it) { |
| 155 webRequest.setHeader(blink::WebString::fromUTF8(it->first), | 171 webRequest.setHeader(blink::WebString::fromUTF8(it->first), |
| 156 blink::WebString::fromUTF8(it->second)); | 172 blink::WebString::fromUTF8(it->second)); |
| 157 } | 173 } |
| 158 if (!request.blob_uuid.empty()) { | 174 if (!request.blob_uuid.empty()) { |
| 159 webRequest.setBlob(blink::WebString::fromUTF8(request.blob_uuid), | 175 webRequest.setBlob(blink::WebString::fromUTF8(request.blob_uuid), |
| 160 request.blob_size); | 176 request.blob_size); |
| 161 } | 177 } |
| 162 webRequest.setReferrer(blink::WebString::fromUTF8(request.referrer.spec()), | 178 webRequest.setReferrer(blink::WebString::fromUTF8(request.referrer.spec()), |
| 163 blink::WebReferrerPolicyDefault); | 179 blink::WebReferrerPolicyDefault); |
| 164 webRequest.setIsReload(request.is_reload); | 180 webRequest.setIsReload(request.is_reload); |
| 181 fetch_start_timings_[request_id] = base::TimeTicks::Now(); |
| 165 proxy_->dispatchFetchEvent(request_id, webRequest); | 182 proxy_->dispatchFetchEvent(request_id, webRequest); |
| 166 } | 183 } |
| 167 | 184 |
| 168 void ServiceWorkerScriptContext::OnSyncEvent(int request_id) { | 185 void ServiceWorkerScriptContext::OnSyncEvent(int request_id) { |
| 169 TRACE_EVENT0("ServiceWorker", | 186 TRACE_EVENT0("ServiceWorker", |
| 170 "ServiceWorkerScriptContext::OnSyncEvent"); | 187 "ServiceWorkerScriptContext::OnSyncEvent"); |
| 171 proxy_->dispatchSyncEvent(request_id); | 188 proxy_->dispatchSyncEvent(request_id); |
| 172 } | 189 } |
| 173 | 190 |
| 174 void ServiceWorkerScriptContext::OnPushEvent(int request_id, | 191 void ServiceWorkerScriptContext::OnPushEvent(int request_id, |
| (...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 210 return; | 227 return; |
| 211 } | 228 } |
| 212 scoped_ptr<blink::WebServiceWorkerClientsInfo> info( | 229 scoped_ptr<blink::WebServiceWorkerClientsInfo> info( |
| 213 new blink::WebServiceWorkerClientsInfo); | 230 new blink::WebServiceWorkerClientsInfo); |
| 214 info->clientIDs = client_ids; | 231 info->clientIDs = client_ids; |
| 215 callbacks->onSuccess(info.release()); | 232 callbacks->onSuccess(info.release()); |
| 216 pending_clients_callbacks_.Remove(request_id); | 233 pending_clients_callbacks_.Remove(request_id); |
| 217 } | 234 } |
| 218 | 235 |
| 219 } // namespace content | 236 } // namespace content |
| OLD | NEW |