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 1048 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1059 embedded_worker_->SendMessage(ServiceWorkerMsg_ActivateEvent(request_id)); | 1059 embedded_worker_->SendMessage(ServiceWorkerMsg_ActivateEvent(request_id)); |
1060 if (status != SERVICE_WORKER_OK) { | 1060 if (status != SERVICE_WORKER_OK) { |
1061 activate_callbacks_.Remove(request_id); | 1061 activate_callbacks_.Remove(request_id); |
1062 RunSoon(base::Bind(callback, status)); | 1062 RunSoon(base::Bind(callback, status)); |
1063 } | 1063 } |
1064 } | 1064 } |
1065 | 1065 |
1066 void ServiceWorkerVersion::OnGetClients( | 1066 void ServiceWorkerVersion::OnGetClients( |
1067 int request_id, | 1067 int request_id, |
1068 const ServiceWorkerClientQueryOptions& options) { | 1068 const ServiceWorkerClientQueryOptions& options) { |
| 1069 TRACE_EVENT_ASYNC_BEGIN2( |
| 1070 "ServiceWorker", "ServiceWorkerVersion::OnGetClients", request_id, |
| 1071 "client_type", options.client_type, "include_uncontrolled", |
| 1072 options.include_uncontrolled); |
| 1073 |
1069 if (controllee_map_.empty() && !options.include_uncontrolled) { | 1074 if (controllee_map_.empty() && !options.include_uncontrolled) { |
1070 if (running_status() == RUNNING) { | 1075 OnGetClientsFinished(request_id, std::vector<ServiceWorkerClientInfo>()); |
1071 embedded_worker_->SendMessage( | |
1072 ServiceWorkerMsg_DidGetClients(request_id, | |
1073 std::vector<ServiceWorkerClientInfo>())); | |
1074 } | |
1075 return; | 1076 return; |
1076 } | 1077 } |
1077 | 1078 |
1078 // For Window clients we want to query the info on the UI thread first. | 1079 // For Window clients we want to query the info on the UI thread first. |
1079 if (options.client_type == blink::WebServiceWorkerClientTypeWindow || | 1080 if (options.client_type == blink::WebServiceWorkerClientTypeWindow || |
1080 options.client_type == blink::WebServiceWorkerClientTypeAll) { | 1081 options.client_type == blink::WebServiceWorkerClientTypeAll) { |
1081 GetWindowClients(request_id, options); | 1082 GetWindowClients(request_id, options); |
1082 return; | 1083 return; |
1083 } | 1084 } |
1084 | 1085 |
1085 ServiceWorkerClients clients; | 1086 ServiceWorkerClients clients; |
1086 GetNonWindowClients(request_id, options, &clients); | 1087 GetNonWindowClients(request_id, options, &clients); |
| 1088 OnGetClientsFinished(request_id, clients); |
| 1089 } |
| 1090 |
| 1091 void ServiceWorkerVersion::OnGetClientsFinished( |
| 1092 int request_id, |
| 1093 const ServiceWorkerClients& clients) { |
| 1094 DCHECK_CURRENTLY_ON(BrowserThread::IO); |
| 1095 TRACE_EVENT_ASYNC_END1("ServiceWorker", "ServiceWorkerVersion::OnGetClients", |
| 1096 request_id, "The number of clients", clients.size()); |
| 1097 |
| 1098 if (running_status() != RUNNING) |
| 1099 return; |
1087 embedded_worker_->SendMessage( | 1100 embedded_worker_->SendMessage( |
1088 ServiceWorkerMsg_DidGetClients(request_id, clients)); | 1101 ServiceWorkerMsg_DidGetClients(request_id, clients)); |
1089 } | 1102 } |
1090 | 1103 |
1091 void ServiceWorkerVersion::OnActivateEventFinished( | 1104 void ServiceWorkerVersion::OnActivateEventFinished( |
1092 int request_id, | 1105 int request_id, |
1093 blink::WebServiceWorkerEventResult result) { | 1106 blink::WebServiceWorkerEventResult result) { |
1094 DCHECK(ACTIVATING == status() || | 1107 DCHECK(ACTIVATING == status() || |
1095 REDUNDANT == status()) << status(); | 1108 REDUNDANT == status()) << status(); |
1096 TRACE_EVENT0("ServiceWorker", | 1109 TRACE_EVENT0("ServiceWorker", |
(...skipping 318 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1415 // possibly due to timing issue or bad message. | 1428 // possibly due to timing issue or bad message. |
1416 return; | 1429 return; |
1417 } | 1430 } |
1418 provider_host->Focus(base::Bind(&ServiceWorkerVersion::OnFocusClientFinished, | 1431 provider_host->Focus(base::Bind(&ServiceWorkerVersion::OnFocusClientFinished, |
1419 weak_factory_.GetWeakPtr(), request_id, | 1432 weak_factory_.GetWeakPtr(), request_id, |
1420 client_uuid)); | 1433 client_uuid)); |
1421 } | 1434 } |
1422 | 1435 |
1423 void ServiceWorkerVersion::OnFocusClientFinished( | 1436 void ServiceWorkerVersion::OnFocusClientFinished( |
1424 int request_id, | 1437 int request_id, |
1425 const std::string& cliend_uuid, | 1438 const std::string& client_uuid, |
1426 const ServiceWorkerClientInfo& client) { | 1439 const ServiceWorkerClientInfo& client) { |
1427 DCHECK_CURRENTLY_ON(BrowserThread::IO); | 1440 DCHECK_CURRENTLY_ON(BrowserThread::IO); |
1428 | 1441 |
1429 if (running_status() != RUNNING) | 1442 if (running_status() != RUNNING) |
1430 return; | 1443 return; |
1431 | 1444 |
1432 ServiceWorkerClientInfo client_info(client); | 1445 ServiceWorkerClientInfo client_info(client); |
1433 client_info.client_uuid = cliend_uuid; | 1446 client_info.client_uuid = client_uuid; |
1434 | 1447 |
1435 embedded_worker_->SendMessage(ServiceWorkerMsg_FocusClientResponse( | 1448 embedded_worker_->SendMessage(ServiceWorkerMsg_FocusClientResponse( |
1436 request_id, client_info)); | 1449 request_id, client_info)); |
1437 } | 1450 } |
1438 | 1451 |
1439 void ServiceWorkerVersion::OnSkipWaiting(int request_id) { | 1452 void ServiceWorkerVersion::OnSkipWaiting(int request_id) { |
1440 skip_waiting_ = true; | 1453 skip_waiting_ = true; |
1441 if (status_ != INSTALLED) | 1454 if (status_ != INSTALLED) |
1442 return DidSkipWaiting(request_id); | 1455 return DidSkipWaiting(request_id); |
1443 | 1456 |
(...skipping 79 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1523 base::Bind(&ServiceWorkerVersion::OnStartSentAndScriptEvaluated, | 1536 base::Bind(&ServiceWorkerVersion::OnStartSentAndScriptEvaluated, |
1524 weak_factory_.GetWeakPtr())); | 1537 weak_factory_.GetWeakPtr())); |
1525 } | 1538 } |
1526 } | 1539 } |
1527 | 1540 |
1528 void ServiceWorkerVersion::GetWindowClients( | 1541 void ServiceWorkerVersion::GetWindowClients( |
1529 int request_id, | 1542 int request_id, |
1530 const ServiceWorkerClientQueryOptions& options) { | 1543 const ServiceWorkerClientQueryOptions& options) { |
1531 DCHECK(options.client_type == blink::WebServiceWorkerClientTypeWindow || | 1544 DCHECK(options.client_type == blink::WebServiceWorkerClientTypeWindow || |
1532 options.client_type == blink::WebServiceWorkerClientTypeAll); | 1545 options.client_type == blink::WebServiceWorkerClientTypeAll); |
1533 TRACE_EVENT0("ServiceWorker", "ServiceWorkerVersion::GetWindowClients"); | |
1534 | |
1535 // 4.3.1 matchAll(options) | |
1536 std::vector<Tuple<int, int, std::string>> clients_info; | 1546 std::vector<Tuple<int, int, std::string>> clients_info; |
1537 if (!options.include_uncontrolled) { | 1547 if (!options.include_uncontrolled) { |
1538 for (auto& controllee : controllee_map_) | 1548 for (auto& controllee : controllee_map_) |
1539 AddWindowClient(controllee.second, &clients_info); | 1549 AddWindowClient(controllee.second, &clients_info); |
1540 } else { | 1550 } else { |
1541 for (auto it = | 1551 for (auto it = |
1542 context_->GetClientProviderHostIterator(script_url_.GetOrigin()); | 1552 context_->GetClientProviderHostIterator(script_url_.GetOrigin()); |
1543 !it->IsAtEnd(); it->Advance()) { | 1553 !it->IsAtEnd(); it->Advance()) { |
1544 AddWindowClient(it->GetProviderHost(), &clients_info); | 1554 AddWindowClient(it->GetProviderHost(), &clients_info); |
1545 } | 1555 } |
(...skipping 10 matching lines...) Expand all Loading... |
1556 base::Bind(&OnGetWindowClientsFromUI, clients_info, script_url_, | 1566 base::Bind(&OnGetWindowClientsFromUI, clients_info, script_url_, |
1557 base::Bind(&ServiceWorkerVersion::DidGetWindowClients, | 1567 base::Bind(&ServiceWorkerVersion::DidGetWindowClients, |
1558 weak_factory_.GetWeakPtr(), request_id, options))); | 1568 weak_factory_.GetWeakPtr(), request_id, options))); |
1559 } | 1569 } |
1560 | 1570 |
1561 void ServiceWorkerVersion::DidGetWindowClients( | 1571 void ServiceWorkerVersion::DidGetWindowClients( |
1562 int request_id, | 1572 int request_id, |
1563 const ServiceWorkerClientQueryOptions& options, | 1573 const ServiceWorkerClientQueryOptions& options, |
1564 scoped_ptr<ServiceWorkerClients> clients) { | 1574 scoped_ptr<ServiceWorkerClients> clients) { |
1565 DCHECK_CURRENTLY_ON(BrowserThread::IO); | 1575 DCHECK_CURRENTLY_ON(BrowserThread::IO); |
1566 if (running_status() != RUNNING) | |
1567 return; | |
1568 | |
1569 if (options.client_type == blink::WebServiceWorkerClientTypeAll) | 1576 if (options.client_type == blink::WebServiceWorkerClientTypeAll) |
1570 GetNonWindowClients(request_id, options, clients.get()); | 1577 GetNonWindowClients(request_id, options, clients.get()); |
1571 | 1578 OnGetClientsFinished(request_id, *clients); |
1572 embedded_worker_->SendMessage( | |
1573 ServiceWorkerMsg_DidGetClients(request_id, *clients)); | |
1574 } | 1579 } |
1575 | 1580 |
1576 void ServiceWorkerVersion::GetNonWindowClients( | 1581 void ServiceWorkerVersion::GetNonWindowClients( |
1577 int request_id, | 1582 int request_id, |
1578 const ServiceWorkerClientQueryOptions& options, | 1583 const ServiceWorkerClientQueryOptions& options, |
1579 ServiceWorkerClients* clients) { | 1584 ServiceWorkerClients* clients) { |
1580 if (!options.include_uncontrolled) { | 1585 if (!options.include_uncontrolled) { |
1581 for (auto& controllee : controllee_map_) { | 1586 for (auto& controllee : controllee_map_) { |
1582 AddNonWindowClient(controllee.second, options, clients); | 1587 AddNonWindowClient(controllee.second, options, clients); |
1583 } | 1588 } |
(...skipping 251 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1835 while (!requests_.empty()) { | 1840 while (!requests_.empty()) { |
1836 RequestInfo info = requests_.front(); | 1841 RequestInfo info = requests_.front(); |
1837 info.time = ticks; | 1842 info.time = ticks; |
1838 new_requests.push(info); | 1843 new_requests.push(info); |
1839 requests_.pop(); | 1844 requests_.pop(); |
1840 } | 1845 } |
1841 requests_ = new_requests; | 1846 requests_ = new_requests; |
1842 } | 1847 } |
1843 | 1848 |
1844 } // namespace content | 1849 } // namespace content |
OLD | NEW |