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

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

Issue 2905593002: Clients.matchAll() should return ordered clients by type/focus time/creation time (Closed)
Patch Set: Created 3 years, 7 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
« no previous file with comments | « no previous file | content/browser/service_worker/service_worker_provider_host.h » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: content/browser/service_worker/service_worker_client_utils.cc
diff --git a/content/browser/service_worker/service_worker_client_utils.cc b/content/browser/service_worker/service_worker_client_utils.cc
index 2888bd48de6fa6f1f0374f70b58940686f576798..6a9a2f0ff50a7b70f7affc4359b51dc4a2c2ff42 100644
--- a/content/browser/service_worker/service_worker_client_utils.cc
+++ b/content/browser/service_worker/service_worker_client_utils.cc
@@ -102,6 +102,7 @@ class OpenURLObserver : public WebContentsObserver {
ServiceWorkerClientInfo GetWindowClientInfoOnUI(
int render_process_id,
int render_frame_id,
+ base::TimeTicks create_time,
const std::string& client_uuid) {
DCHECK_CURRENTLY_ON(BrowserThread::UI);
RenderFrameHostImpl* render_frame_host =
@@ -117,12 +118,13 @@ ServiceWorkerClientInfo GetWindowClientInfoOnUI(
render_frame_host->IsFocused(), render_frame_host->GetLastCommittedURL(),
render_frame_host->GetParent() ? REQUEST_CONTEXT_FRAME_TYPE_NESTED
: REQUEST_CONTEXT_FRAME_TYPE_TOP_LEVEL,
- render_frame_host->frame_tree_node()->last_focus_time(),
+ render_frame_host->frame_tree_node()->last_focus_time(), create_time,
blink::kWebServiceWorkerClientTypeWindow);
}
ServiceWorkerClientInfo FocusOnUI(int render_process_id,
int render_frame_id,
+ base::TimeTicks create_time,
const std::string& client_uuid) {
DCHECK_CURRENTLY_ON(BrowserThread::UI);
RenderFrameHostImpl* render_frame_host =
@@ -146,7 +148,7 @@ ServiceWorkerClientInfo FocusOnUI(int render_process_id,
web_contents->Activate();
return GetWindowClientInfoOnUI(render_process_id, render_frame_id,
- client_uuid);
+ create_time, client_uuid);
}
// This is only called for main frame navigations in OpenWindowOnUI().
@@ -274,7 +276,8 @@ void DidNavigate(const base::WeakPtr<ServiceWorkerContextCore>& context,
BrowserThread::PostTaskAndReplyWithResult(
BrowserThread::UI, FROM_HERE,
base::Bind(&GetWindowClientInfoOnUI, provider_host->process_id(),
- provider_host->route_id(), provider_host->client_uuid()),
+ provider_host->route_id(), provider_host->create_time(),
+ provider_host->client_uuid()),
base::Bind(callback, SERVICE_WORKER_OK));
return;
}
@@ -286,11 +289,13 @@ void DidNavigate(const base::WeakPtr<ServiceWorkerContextCore>& context,
void AddWindowClient(
ServiceWorkerProviderHost* host,
- std::vector<std::tuple<int, int, std::string>>* client_info) {
+ std::vector<std::tuple<int, int, base::TimeTicks, std::string>>*
+ client_info) {
DCHECK_CURRENTLY_ON(BrowserThread::IO);
if (host->client_type() != blink::kWebServiceWorkerClientTypeWindow)
return;
client_info->push_back(std::make_tuple(host->process_id(), host->frame_id(),
+ host->create_time(),
host->client_uuid()));
}
@@ -309,13 +314,14 @@ void AddNonWindowClient(ServiceWorkerProviderHost* host,
host->client_uuid(), blink::kWebPageVisibilityStateHidden,
false, // is_focused
host->document_url(), REQUEST_CONTEXT_FRAME_TYPE_NONE, base::TimeTicks(),
- host_client_type);
+ base::TimeTicks(), host_client_type);
leonhsl(Using Gerrit) 2017/05/24 07:26:31 Use host->create_time() ?
clients->push_back(client_info);
}
void OnGetWindowClientsOnUI(
// The tuple contains process_id, frame_id, client_uuid.
- const std::vector<std::tuple<int, int, std::string>>& clients_info,
+ const std::vector<std::tuple<int, int, base::TimeTicks, std::string>>&
+ clients_info,
const GURL& script_url,
const GetWindowClientsCallback& callback) {
DCHECK_CURRENTLY_ON(BrowserThread::UI);
@@ -323,7 +329,7 @@ void OnGetWindowClientsOnUI(
std::unique_ptr<ServiceWorkerClients> clients(new ServiceWorkerClients);
for (const auto& it : clients_info) {
ServiceWorkerClientInfo info = GetWindowClientInfoOnUI(
- std::get<0>(it), std::get<1>(it), std::get<2>(it));
+ std::get<0>(it), std::get<1>(it), std::get<2>(it), std::get<3>(it));
// If the request to the provider_host returned an empty
// ServiceWorkerClientInfo, that means that it wasn't possible to associate
@@ -352,12 +358,28 @@ struct ServiceWorkerClientInfoSortMRU {
}
};
+struct ServiceWorkerClientInfoSortCreateTime {
+ bool operator()(const ServiceWorkerClientInfo& a,
+ const ServiceWorkerClientInfo& b) const {
+ return a.create_time < b.create_time;
+ }
+};
+
void DidGetClients(const ClientsCallback& callback,
ServiceWorkerClients* clients) {
DCHECK_CURRENTLY_ON(BrowserThread::IO);
- // Sort clients so that the most recently active tab is in the front.
- std::sort(clients->begin(), clients->end(), ServiceWorkerClientInfoSortMRU());
+ // Find the subgroud that ever been focused
xiaofengzhang 2017/05/24 06:07:33 subgroud --> subgroup Find the subgroud that ever
+ auto bound = std::stable_partition(
+ clients->begin(), clients->end(), [](ServiceWorkerClientInfo info) {
+ return info.last_focus_time > base::TimeTicks();
+ });
+
+ // Sort focused clients so that the most recently active tab is in the front.
+ std::sort(clients->begin(), bound, ServiceWorkerClientInfoSortMRU());
+
+ // Sort non-focused clients so that the earliest created tab is in the front.
+ std::sort(bound, clients->end(), ServiceWorkerClientInfoSortCreateTime());
callback.Run(clients);
}
@@ -395,10 +417,11 @@ void GetWindowClients(const base::WeakPtr<ServiceWorkerVersion>& controller,
DCHECK(options.client_type == blink::kWebServiceWorkerClientTypeWindow ||
options.client_type == blink::kWebServiceWorkerClientTypeAll);
- std::vector<std::tuple<int, int, std::string>> clients_info;
+ std::vector<std::tuple<int, int, base::TimeTicks, std::string>> clients_info;
if (!options.include_uncontrolled) {
- for (auto& controllee : controller->controllee_map())
+ for (auto& controllee : controller->controllee_map()) {
AddWindowClient(controllee.second, &clients_info);
+ }
} else if (controller->context()) {
GURL origin = controller->script_url().GetOrigin();
for (auto it = controller->context()->GetClientProviderHostIterator(origin);
@@ -430,7 +453,8 @@ void FocusWindowClient(ServiceWorkerProviderHost* provider_host,
BrowserThread::PostTaskAndReplyWithResult(
BrowserThread::UI, FROM_HERE,
base::Bind(&FocusOnUI, provider_host->process_id(),
- provider_host->frame_id(), provider_host->client_uuid()),
+ provider_host->frame_id(), provider_host->create_time(),
+ provider_host->client_uuid()),
callback);
}
@@ -476,7 +500,8 @@ void GetClient(ServiceWorkerProviderHost* provider_host,
BrowserThread::PostTaskAndReplyWithResult(
BrowserThread::UI, FROM_HERE,
base::Bind(&GetWindowClientInfoOnUI, provider_host->process_id(),
- provider_host->route_id(), provider_host->client_uuid()),
+ provider_host->route_id(), provider_host->create_time(),
+ provider_host->client_uuid()),
callback);
return;
}
@@ -485,7 +510,7 @@ void GetClient(ServiceWorkerProviderHost* provider_host,
provider_host->client_uuid(), blink::kWebPageVisibilityStateHidden,
false, // is_focused
provider_host->document_url(), REQUEST_CONTEXT_FRAME_TYPE_NONE,
- base::TimeTicks(), provider_host->client_type());
+ base::TimeTicks(), base::TimeTicks(), provider_host->client_type());
leonhsl(Using Gerrit) 2017/05/24 07:26:31 Use provider_host->create_time() ?
BrowserThread::PostTask(BrowserThread::IO, FROM_HERE,
base::Bind(callback, client_info));
}
« no previous file with comments | « no previous file | content/browser/service_worker/service_worker_provider_host.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698