Index: content/browser/service_worker/service_worker_version.cc |
diff --git a/content/browser/service_worker/service_worker_version.cc b/content/browser/service_worker/service_worker_version.cc |
index d4cee3793c4088f47a675bba31d73332c1452296..b15fb6e314c948c24655bca0c87c6fe80e1b343d 100644 |
--- a/content/browser/service_worker/service_worker_version.cc |
+++ b/content/browser/service_worker/service_worker_version.cc |
@@ -4,6 +4,7 @@ |
#include "content/browser/service_worker/service_worker_version.h" |
+#include <algorithm> |
#include <map> |
#include <string> |
@@ -336,7 +337,6 @@ void OnGetWindowClientsFromUI( |
ServiceWorkerClientInfo info = |
ServiceWorkerProviderHost::GetWindowClientInfoOnUI(base::get<0>(it), |
base::get<1>(it)); |
- |
nhiroki
2015/08/19 07:42:33
Please keep this blank line for readability.
jeremyarcher
2015/08/19 07:50:57
Done.
|
// If the request to the provider_host returned an empty |
// ServiceWorkerClientInfo, that means that it wasn't possible to associate |
// it with a valid RenderFrameHost. It might be because the frame was killed |
@@ -377,10 +377,11 @@ void AddNonWindowClient(ServiceWorkerProviderHost* host, |
options.client_type != host_client_type) |
return; |
- ServiceWorkerClientInfo client_info( |
- blink::WebPageVisibilityStateHidden, |
- false, // is_focused |
- host->document_url(), REQUEST_CONTEXT_FRAME_TYPE_NONE, host_client_type); |
+ ServiceWorkerClientInfo client_info(blink::WebPageVisibilityStateHidden, |
+ false, // is_focused |
+ host->document_url(), |
+ REQUEST_CONTEXT_FRAME_TYPE_NONE, |
+ base::TimeTicks(), host_client_type); |
client_info.client_uuid = host->client_uuid(); |
clients->push_back(client_info); |
} |
@@ -400,6 +401,13 @@ bool IsInstalled(ServiceWorkerVersion::Status status) { |
return false; |
} |
+struct ServiceWorkerClientInfoSortMRU { |
+ bool operator()(const ServiceWorkerClientInfo& a, |
+ const ServiceWorkerClientInfo& b) const { |
+ return a.last_active_time > b.last_active_time; |
+ } |
+}; |
+ |
} // namespace |
const int ServiceWorkerVersion::kStartWorkerTimeoutMinutes = 5; |
@@ -1273,8 +1281,9 @@ void ServiceWorkerVersion::OnGetClients( |
"client_type", options.client_type, "include_uncontrolled", |
options.include_uncontrolled); |
+ ServiceWorkerClients clients; |
if (controllee_map_.empty() && !options.include_uncontrolled) { |
- OnGetClientsFinished(request_id, std::vector<ServiceWorkerClientInfo>()); |
+ OnGetClientsFinished(request_id, &clients); |
return; |
} |
@@ -1285,22 +1294,22 @@ void ServiceWorkerVersion::OnGetClients( |
return; |
} |
- ServiceWorkerClients clients; |
GetNonWindowClients(request_id, options, &clients); |
- OnGetClientsFinished(request_id, clients); |
+ OnGetClientsFinished(request_id, &clients); |
} |
-void ServiceWorkerVersion::OnGetClientsFinished( |
- int request_id, |
- const ServiceWorkerClients& clients) { |
+void ServiceWorkerVersion::OnGetClientsFinished(int request_id, |
+ ServiceWorkerClients* clients) { |
DCHECK_CURRENTLY_ON(BrowserThread::IO); |
TRACE_EVENT_ASYNC_END1("ServiceWorker", "ServiceWorkerVersion::OnGetClients", |
- request_id, "The number of clients", clients.size()); |
+ request_id, "The number of clients", clients->size()); |
if (running_status() != RUNNING) |
return; |
+ // Sort clients so that the most recently active tab is in the front. |
+ std::sort(clients->begin(), clients->end(), ServiceWorkerClientInfoSortMRU()); |
embedded_worker_->SendMessage( |
- ServiceWorkerMsg_DidGetClients(request_id, clients)); |
+ ServiceWorkerMsg_DidGetClients(request_id, *clients)); |
} |
void ServiceWorkerVersion::OnActivateEventFinished( |
@@ -1919,7 +1928,7 @@ void ServiceWorkerVersion::DidGetWindowClients( |
DCHECK_CURRENTLY_ON(BrowserThread::IO); |
if (options.client_type == blink::WebServiceWorkerClientTypeAll) |
GetNonWindowClients(request_id, options, clients.get()); |
- OnGetClientsFinished(request_id, *clients); |
+ OnGetClientsFinished(request_id, clients.get()); |
} |
void ServiceWorkerVersion::GetNonWindowClients( |