Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(157)

Unified Diff: content/browser/service_worker/service_worker_version.cc

Issue 1285373002: Ensure that Service Worker clients are always returned in MRU order (1) (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Fix typos and style. Created 5 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
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 5415d33b9df232571a4495951aee5fd81e5ec295..1bdae362e87fa442584faf4c12f406ee5426c85e 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>
@@ -378,10 +379,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);
}
@@ -1271,8 +1273,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;
}
@@ -1283,22 +1286,31 @@ 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) {
+namespace {
+struct ServiceWorkerClientInfoSortMRU {
+ bool operator()(const ServiceWorkerClientInfo& a,
+ const ServiceWorkerClientInfo& b) const {
+ return a.last_active_time > b.last_active_time;
+ }
+};
+}
nhiroki 2015/08/17 06:43:22 We already have an unnamed namespace starting at l
jeremyarcher 2015/08/17 06:51:57 Ah, whoops. Added.
+
+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(
@@ -1917,7 +1929,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(

Powered by Google App Engine
This is Rietveld 408576698