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 #include "content/browser/service_worker/service_worker_version.h" | 5 #include "content/browser/service_worker/service_worker_version.h" |
6 | 6 |
7 #include "base/command_line.h" | 7 #include "base/command_line.h" |
8 #include "base/memory/ref_counted.h" | 8 #include "base/memory/ref_counted.h" |
9 #include "base/metrics/histogram_macros.h" | 9 #include "base/metrics/histogram_macros.h" |
10 #include "base/stl_util.h" | 10 #include "base/stl_util.h" |
(...skipping 19 matching lines...) Expand all Loading... |
30 #include "content/public/browser/web_contents_observer.h" | 30 #include "content/public/browser/web_contents_observer.h" |
31 #include "content/public/common/child_process_host.h" | 31 #include "content/public/common/child_process_host.h" |
32 #include "content/public/common/content_client.h" | 32 #include "content/public/common/content_client.h" |
33 #include "content/public/common/content_switches.h" | 33 #include "content/public/common/content_switches.h" |
34 #include "content/public/common/result_codes.h" | 34 #include "content/public/common/result_codes.h" |
35 #include "net/http/http_response_info.h" | 35 #include "net/http/http_response_info.h" |
36 | 36 |
37 namespace content { | 37 namespace content { |
38 | 38 |
39 using StatusCallback = ServiceWorkerVersion::StatusCallback; | 39 using StatusCallback = ServiceWorkerVersion::StatusCallback; |
40 using GetClientDocumentsCallback = | 40 using GetClientsCallback = |
41 base::Callback<void(const std::vector<ServiceWorkerClientInfo>&)>; | 41 base::Callback<void(const std::vector<ServiceWorkerClientInfo>&)>; |
42 | 42 |
43 namespace { | 43 namespace { |
44 | 44 |
45 // Delay between the timeout timer firing. | 45 // Delay between the timeout timer firing. |
46 const int kTimeoutTimerDelaySeconds = 30; | 46 const int kTimeoutTimerDelaySeconds = 30; |
47 | 47 |
48 // Time to wait until stopping an idle worker. | 48 // Time to wait until stopping an idle worker. |
49 const int kIdleWorkerTimeoutSeconds = 30; | 49 const int kIdleWorkerTimeoutSeconds = 30; |
50 | 50 |
(...skipping 204 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
255 void RestartTick(base::TimeTicks* time) { | 255 void RestartTick(base::TimeTicks* time) { |
256 *time = base::TimeTicks().Now(); | 256 *time = base::TimeTicks().Now(); |
257 } | 257 } |
258 | 258 |
259 base::TimeDelta GetTickDuration(const base::TimeTicks& time) { | 259 base::TimeDelta GetTickDuration(const base::TimeTicks& time) { |
260 if (time.is_null()) | 260 if (time.is_null()) |
261 return base::TimeDelta(); | 261 return base::TimeDelta(); |
262 return base::TimeTicks().Now() - time; | 262 return base::TimeTicks().Now() - time; |
263 } | 263 } |
264 | 264 |
265 void OnGetClientDocumentsFromUI( | 265 void OnGetClientsFromUI( |
266 // The tuple contains process_id, frame_id, client_id. | 266 // The tuple contains process_id, frame_id, client_id. |
267 const std::vector<Tuple<int,int,int>>& clients_info, | 267 const std::vector<Tuple<int,int,int>>& clients_info, |
268 const GURL& script_url, | 268 const GURL& script_url, |
269 const GetClientDocumentsCallback& callback) { | 269 const GetClientsCallback& callback) { |
270 std::vector<ServiceWorkerClientInfo> clients; | 270 std::vector<ServiceWorkerClientInfo> clients; |
271 | 271 |
272 for (const auto& it : clients_info) { | 272 for (const auto& it : clients_info) { |
273 ServiceWorkerClientInfo info = | 273 ServiceWorkerClientInfo info = |
274 ServiceWorkerProviderHost::GetClientInfoOnUI(get<0>(it), get<1>(it)); | 274 ServiceWorkerProviderHost::GetClientInfoOnUI(get<0>(it), get<1>(it)); |
275 | 275 |
276 // If the request to the provider_host returned an empty | 276 // If the request to the provider_host returned an empty |
277 // ServiceWorkerClientInfo, that means that it wasn't possible to associate | 277 // ServiceWorkerClientInfo, that means that it wasn't possible to associate |
278 // it with a valid RenderFrameHost. It might be because the frame was killed | 278 // it with a valid RenderFrameHost. It might be because the frame was killed |
279 // or navigated in between. | 279 // or navigated in between. |
(...skipping 633 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
913 source_identifier, | 913 source_identifier, |
914 message_level, | 914 message_level, |
915 message, | 915 message, |
916 line_number, | 916 line_number, |
917 source_url)); | 917 source_url)); |
918 } | 918 } |
919 | 919 |
920 bool ServiceWorkerVersion::OnMessageReceived(const IPC::Message& message) { | 920 bool ServiceWorkerVersion::OnMessageReceived(const IPC::Message& message) { |
921 bool handled = true; | 921 bool handled = true; |
922 IPC_BEGIN_MESSAGE_MAP(ServiceWorkerVersion, message) | 922 IPC_BEGIN_MESSAGE_MAP(ServiceWorkerVersion, message) |
923 IPC_MESSAGE_HANDLER(ServiceWorkerHostMsg_GetClientDocuments, | 923 IPC_MESSAGE_HANDLER(ServiceWorkerHostMsg_GetClients, |
924 OnGetClientDocuments) | 924 OnGetClients) |
925 IPC_MESSAGE_HANDLER(ServiceWorkerHostMsg_ActivateEventFinished, | 925 IPC_MESSAGE_HANDLER(ServiceWorkerHostMsg_ActivateEventFinished, |
926 OnActivateEventFinished) | 926 OnActivateEventFinished) |
927 IPC_MESSAGE_HANDLER(ServiceWorkerHostMsg_InstallEventFinished, | 927 IPC_MESSAGE_HANDLER(ServiceWorkerHostMsg_InstallEventFinished, |
928 OnInstallEventFinished) | 928 OnInstallEventFinished) |
929 IPC_MESSAGE_HANDLER(ServiceWorkerHostMsg_FetchEventFinished, | 929 IPC_MESSAGE_HANDLER(ServiceWorkerHostMsg_FetchEventFinished, |
930 OnFetchEventFinished) | 930 OnFetchEventFinished) |
931 IPC_MESSAGE_HANDLER(ServiceWorkerHostMsg_SyncEventFinished, | 931 IPC_MESSAGE_HANDLER(ServiceWorkerHostMsg_SyncEventFinished, |
932 OnSyncEventFinished) | 932 OnSyncEventFinished) |
933 IPC_MESSAGE_HANDLER(ServiceWorkerHostMsg_NotificationClickEventFinished, | 933 IPC_MESSAGE_HANDLER(ServiceWorkerHostMsg_NotificationClickEventFinished, |
934 OnNotificationClickEventFinished) | 934 OnNotificationClickEventFinished) |
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
985 | 985 |
986 int request_id = activate_callbacks_.Add(new StatusCallback(callback)); | 986 int request_id = activate_callbacks_.Add(new StatusCallback(callback)); |
987 ServiceWorkerStatusCode status = | 987 ServiceWorkerStatusCode status = |
988 embedded_worker_->SendMessage(ServiceWorkerMsg_ActivateEvent(request_id)); | 988 embedded_worker_->SendMessage(ServiceWorkerMsg_ActivateEvent(request_id)); |
989 if (status != SERVICE_WORKER_OK) { | 989 if (status != SERVICE_WORKER_OK) { |
990 activate_callbacks_.Remove(request_id); | 990 activate_callbacks_.Remove(request_id); |
991 RunSoon(base::Bind(callback, status)); | 991 RunSoon(base::Bind(callback, status)); |
992 } | 992 } |
993 } | 993 } |
994 | 994 |
995 void ServiceWorkerVersion::OnGetClientDocuments(int request_id) { | 995 void ServiceWorkerVersion::OnGetClients( |
| 996 int request_id, |
| 997 const ServiceWorkerClientQueryOptions& /* options */) { |
| 998 // TODO(kinuko): Handle ClientQueryOptions. (crbug.com/455241, 460415 etc) |
996 if (controllee_by_id_.IsEmpty()) { | 999 if (controllee_by_id_.IsEmpty()) { |
997 if (running_status() == RUNNING) { | 1000 if (running_status() == RUNNING) { |
998 embedded_worker_->SendMessage( | 1001 embedded_worker_->SendMessage( |
999 ServiceWorkerMsg_DidGetClientDocuments(request_id, | 1002 ServiceWorkerMsg_DidGetClients(request_id, |
1000 std::vector<ServiceWorkerClientInfo>())); | 1003 std::vector<ServiceWorkerClientInfo>())); |
1001 } | 1004 } |
1002 return; | 1005 return; |
1003 } | 1006 } |
1004 | 1007 |
1005 TRACE_EVENT0("ServiceWorker", | 1008 TRACE_EVENT0("ServiceWorker", |
1006 "ServiceWorkerVersion::OnGetClientDocuments"); | 1009 "ServiceWorkerVersion::OnGetClients"); |
1007 | 1010 |
1008 std::vector<Tuple<int,int,int>> clients_info; | 1011 std::vector<Tuple<int,int,int>> clients_info; |
1009 for (ControlleeByIDMap::iterator it(&controllee_by_id_); !it.IsAtEnd(); | 1012 for (ControlleeByIDMap::iterator it(&controllee_by_id_); !it.IsAtEnd(); |
1010 it.Advance()) { | 1013 it.Advance()) { |
1011 int process_id = it.GetCurrentValue()->process_id(); | 1014 int process_id = it.GetCurrentValue()->process_id(); |
1012 int frame_id = it.GetCurrentValue()->frame_id(); | 1015 int frame_id = it.GetCurrentValue()->frame_id(); |
1013 int client_id = it.GetCurrentKey(); | 1016 int client_id = it.GetCurrentKey(); |
1014 | 1017 |
1015 clients_info.push_back(MakeTuple(process_id, frame_id, client_id)); | 1018 clients_info.push_back(MakeTuple(process_id, frame_id, client_id)); |
1016 } | 1019 } |
1017 | 1020 |
1018 BrowserThread::PostTask( | 1021 BrowserThread::PostTask( |
1019 BrowserThread::UI, FROM_HERE, | 1022 BrowserThread::UI, FROM_HERE, |
1020 base::Bind(&OnGetClientDocumentsFromUI, clients_info, script_url_, | 1023 base::Bind(&OnGetClientsFromUI, clients_info, script_url_, |
1021 base::Bind(&ServiceWorkerVersion::DidGetClientDocuments, | 1024 base::Bind(&ServiceWorkerVersion::DidGetClients, |
1022 weak_factory_.GetWeakPtr(), | 1025 weak_factory_.GetWeakPtr(), |
1023 request_id))); | 1026 request_id))); |
1024 | 1027 |
1025 } | 1028 } |
1026 | 1029 |
1027 void ServiceWorkerVersion::OnActivateEventFinished( | 1030 void ServiceWorkerVersion::OnActivateEventFinished( |
1028 int request_id, | 1031 int request_id, |
1029 blink::WebServiceWorkerEventResult result) { | 1032 blink::WebServiceWorkerEventResult result) { |
1030 DCHECK(ACTIVATING == status() || | 1033 DCHECK(ACTIVATING == status() || |
1031 REDUNDANT == status()) << status(); | 1034 REDUNDANT == status()) << status(); |
(...skipping 371 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1403 if (status == SERVICE_WORKER_ERROR_ABORT) { | 1406 if (status == SERVICE_WORKER_ERROR_ABORT) { |
1404 embedded_worker_->SendMessage(ServiceWorkerMsg_ClaimClientsError( | 1407 embedded_worker_->SendMessage(ServiceWorkerMsg_ClaimClientsError( |
1405 request_id, blink::WebServiceWorkerError::ErrorTypeAbort, | 1408 request_id, blink::WebServiceWorkerError::ErrorTypeAbort, |
1406 base::ASCIIToUTF16(kClaimClientsShutdownErrorMesage))); | 1409 base::ASCIIToUTF16(kClaimClientsShutdownErrorMesage))); |
1407 return; | 1410 return; |
1408 } | 1411 } |
1409 DCHECK(status == SERVICE_WORKER_OK); | 1412 DCHECK(status == SERVICE_WORKER_OK); |
1410 embedded_worker_->SendMessage(ServiceWorkerMsg_DidClaimClients(request_id)); | 1413 embedded_worker_->SendMessage(ServiceWorkerMsg_DidClaimClients(request_id)); |
1411 } | 1414 } |
1412 | 1415 |
1413 void ServiceWorkerVersion::DidGetClientDocuments( | 1416 void ServiceWorkerVersion::DidGetClients( |
1414 int request_id, | 1417 int request_id, |
1415 const std::vector<ServiceWorkerClientInfo>& clients) { | 1418 const std::vector<ServiceWorkerClientInfo>& clients) { |
1416 DCHECK_CURRENTLY_ON(BrowserThread::IO); | 1419 DCHECK_CURRENTLY_ON(BrowserThread::IO); |
1417 if (running_status() != RUNNING) | 1420 if (running_status() != RUNNING) |
1418 return; | 1421 return; |
1419 | 1422 |
1420 embedded_worker_->SendMessage( | 1423 embedded_worker_->SendMessage( |
1421 ServiceWorkerMsg_DidGetClientDocuments(request_id, clients)); | 1424 ServiceWorkerMsg_DidGetClients(request_id, clients)); |
1422 } | 1425 } |
1423 | 1426 |
1424 void ServiceWorkerVersion::StartTimeoutTimer() { | 1427 void ServiceWorkerVersion::StartTimeoutTimer() { |
1425 DCHECK(!timeout_timer_.IsRunning()); | 1428 DCHECK(!timeout_timer_.IsRunning()); |
1426 ClearTick(&idle_time_); | 1429 ClearTick(&idle_time_); |
1427 ClearTick(&ping_time_); | 1430 ClearTick(&ping_time_); |
1428 ping_timed_out_ = false; | 1431 ping_timed_out_ = false; |
1429 timeout_timer_.Start(FROM_HERE, | 1432 timeout_timer_.Start(FROM_HERE, |
1430 base::TimeDelta::FromSeconds(kTimeoutTimerDelaySeconds), | 1433 base::TimeDelta::FromSeconds(kTimeoutTimerDelaySeconds), |
1431 this, &ServiceWorkerVersion::OnTimeoutTimer); | 1434 this, &ServiceWorkerVersion::OnTimeoutTimer); |
(...skipping 155 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1587 int request_id) { | 1590 int request_id) { |
1588 callbacks->Remove(request_id); | 1591 callbacks->Remove(request_id); |
1589 if (is_doomed_) { | 1592 if (is_doomed_) { |
1590 // The stop should be already scheduled, but try to stop immediately, in | 1593 // The stop should be already scheduled, but try to stop immediately, in |
1591 // order to release worker resources soon. | 1594 // order to release worker resources soon. |
1592 StopWorkerIfIdle(); | 1595 StopWorkerIfIdle(); |
1593 } | 1596 } |
1594 } | 1597 } |
1595 | 1598 |
1596 } // namespace content | 1599 } // namespace content |
OLD | NEW |