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