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

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: Address shimazu's comments #16 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..98eae7910511494f10ced4b424bdd7716604f168 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,21 +314,22 @@ 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);
+ host->create_time(), host_client_type);
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);
- std::unique_ptr<ServiceWorkerClients> clients(new ServiceWorkerClients);
+ auto clients = base::MakeUnique<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
@@ -345,21 +351,26 @@ void OnGetWindowClientsOnUI(
base::Bind(callback, base::Passed(&clients)));
}
-struct ServiceWorkerClientInfoSortMRU {
+struct ServiceWorkerClientInfoSort {
bool operator()(const ServiceWorkerClientInfo& a,
const ServiceWorkerClientInfo& b) const {
- return a.last_focus_time > b.last_focus_time;
+ if (a.last_focus_time != b.last_focus_time)
leonhsl(Using Gerrit) 2017/05/26 05:48:38 I suggest we keep the comparison algorithm strictl
xiaofengzhang 2017/05/26 13:57:48 Acknowledged. I am working on the test cases failu
xiaofengzhang 2017/05/27 05:27:42 Done. It seems the test cases' failure is because
+ return a.last_focus_time > b.last_focus_time;
+ else if (a.client_type == blink::kWebServiceWorkerClientTypeWindow &&
+ b.client_type != blink::kWebServiceWorkerClientTypeWindow)
+ return true;
+ else
+ return a.create_time < b.create_time;
}
};
void DidGetClients(const ClientsCallback& callback,
- ServiceWorkerClients* clients) {
+ std::unique_ptr<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());
+ std::sort(clients->begin(), clients->end(), ServiceWorkerClientInfoSort());
- callback.Run(clients);
+ callback.Run(clients.get());
shimazu 2017/05/26 08:10:07 Could you change the argument to use std::unique_p
xiaofengzhang 2017/05/26 13:57:48 Acknowledged.
xiaofengzhang 2017/05/27 05:27:42 Done.
}
void GetNonWindowClients(const base::WeakPtr<ServiceWorkerVersion>& controller,
@@ -385,7 +396,7 @@ void DidGetWindowClients(const base::WeakPtr<ServiceWorkerVersion>& controller,
DCHECK_CURRENTLY_ON(BrowserThread::IO);
if (options.client_type == blink::kWebServiceWorkerClientTypeAll)
GetNonWindowClients(controller, options, clients.get());
shimazu 2017/05/26 08:10:07 Please move clients to GetNonWindowClients and add
xiaofengzhang 2017/05/26 13:57:48 I am thinking if we move DidGetClients into GetNon
xiaofengzhang 2017/05/27 05:27:42 Done.
- DidGetClients(callback, clients.get());
+ DidGetClients(callback, std::move(clients));
}
void GetWindowClients(const base::WeakPtr<ServiceWorkerVersion>& controller,
@@ -395,10 +406,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);
@@ -409,7 +421,7 @@ void GetWindowClients(const base::WeakPtr<ServiceWorkerVersion>& controller,
if (clients_info.empty()) {
DidGetWindowClients(controller, options, callback,
- base::WrapUnique(new ServiceWorkerClients));
+ base::MakeUnique<ServiceWorkerClients>());
shimazu 2017/05/26 08:10:07 Pass |clients| to DidGetWindowClients
xiaofengzhang 2017/05/27 05:27:42 Done.
return;
}
@@ -430,7 +442,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 +489,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 +499,8 @@ 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(), provider_host->create_time(),
+ provider_host->client_type());
BrowserThread::PostTask(BrowserThread::IO, FROM_HERE,
base::Bind(callback, client_info));
}
@@ -495,9 +510,9 @@ void GetClients(const base::WeakPtr<ServiceWorkerVersion>& controller,
const ClientsCallback& callback) {
DCHECK_CURRENTLY_ON(BrowserThread::IO);
- ServiceWorkerClients clients;
+ std::unique_ptr<ServiceWorkerClients> clients;
shimazu 2017/05/26 08:10:07 How about creating the instance of clients here an
xiaofengzhang 2017/05/26 13:57:48 Acknowledged.
xiaofengzhang 2017/05/27 05:27:42 Done.
if (!controller->HasControllee() && !options.include_uncontrolled) {
- DidGetClients(callback, &clients);
+ DidGetClients(callback, std::move(clients));
return;
}
@@ -508,8 +523,8 @@ void GetClients(const base::WeakPtr<ServiceWorkerVersion>& controller,
return;
}
- GetNonWindowClients(controller, options, &clients);
- DidGetClients(callback, &clients);
+ GetNonWindowClients(controller, options, clients.get());
shimazu 2017/05/26 08:10:07 Passing clients and calling DidGetClients at the e
xiaofengzhang 2017/05/27 05:27:42 Done.
+ DidGetClients(callback, std::move(clients));
}
} // namespace service_worker_client_utils
« 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