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

Side by Side 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 #31 and fix the test failure Created 3 years, 6 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 unified diff | Download patch
OLDNEW
1 // Copyright 2015 The Chromium Authors. All rights reserved. 1 // Copyright 2015 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_client_utils.h" 5 #include "content/browser/service_worker/service_worker_client_utils.h"
6 6
7 #include <algorithm> 7 #include <algorithm>
8 #include <tuple> 8 #include <tuple>
9 9
10 #include "base/location.h" 10 #include "base/location.h"
(...skipping 84 matching lines...) Expand 10 before | Expand all | Expand 10 after
95 95
96 int frame_tree_node_id_; 96 int frame_tree_node_id_;
97 const OpenURLCallback callback_; 97 const OpenURLCallback callback_;
98 98
99 DISALLOW_COPY_AND_ASSIGN(OpenURLObserver); 99 DISALLOW_COPY_AND_ASSIGN(OpenURLObserver);
100 }; 100 };
101 101
102 ServiceWorkerClientInfo GetWindowClientInfoOnUI( 102 ServiceWorkerClientInfo GetWindowClientInfoOnUI(
103 int render_process_id, 103 int render_process_id,
104 int render_frame_id, 104 int render_frame_id,
105 base::TimeTicks create_time,
105 const std::string& client_uuid) { 106 const std::string& client_uuid) {
106 DCHECK_CURRENTLY_ON(BrowserThread::UI); 107 DCHECK_CURRENTLY_ON(BrowserThread::UI);
107 RenderFrameHostImpl* render_frame_host = 108 RenderFrameHostImpl* render_frame_host =
108 RenderFrameHostImpl::FromID(render_process_id, render_frame_id); 109 RenderFrameHostImpl::FromID(render_process_id, render_frame_id);
109 if (!render_frame_host) 110 if (!render_frame_host)
110 return ServiceWorkerClientInfo(); 111 return ServiceWorkerClientInfo();
111 112
112 // TODO(mlamouri,michaeln): it is possible to end up collecting information 113 // TODO(mlamouri,michaeln): it is possible to end up collecting information
113 // for a frame that is actually being navigated and isn't exactly what we are 114 // for a frame that is actually being navigated and isn't exactly what we are
114 // expecting. 115 // expecting.
115 return ServiceWorkerClientInfo( 116 return ServiceWorkerClientInfo(
116 client_uuid, render_frame_host->GetVisibilityState(), 117 client_uuid, render_frame_host->GetVisibilityState(),
117 render_frame_host->IsFocused(), render_frame_host->GetLastCommittedURL(), 118 render_frame_host->IsFocused(), render_frame_host->GetLastCommittedURL(),
118 render_frame_host->GetParent() ? REQUEST_CONTEXT_FRAME_TYPE_NESTED 119 render_frame_host->GetParent() ? REQUEST_CONTEXT_FRAME_TYPE_NESTED
119 : REQUEST_CONTEXT_FRAME_TYPE_TOP_LEVEL, 120 : REQUEST_CONTEXT_FRAME_TYPE_TOP_LEVEL,
120 render_frame_host->frame_tree_node()->last_focus_time(), 121 render_frame_host->frame_tree_node()->last_focus_time(), create_time,
121 blink::kWebServiceWorkerClientTypeWindow); 122 blink::kWebServiceWorkerClientTypeWindow);
122 } 123 }
123 124
124 ServiceWorkerClientInfo FocusOnUI(int render_process_id, 125 ServiceWorkerClientInfo FocusOnUI(int render_process_id,
125 int render_frame_id, 126 int render_frame_id,
127 base::TimeTicks create_time,
126 const std::string& client_uuid) { 128 const std::string& client_uuid) {
127 DCHECK_CURRENTLY_ON(BrowserThread::UI); 129 DCHECK_CURRENTLY_ON(BrowserThread::UI);
128 RenderFrameHostImpl* render_frame_host = 130 RenderFrameHostImpl* render_frame_host =
129 RenderFrameHostImpl::FromID(render_process_id, render_frame_id); 131 RenderFrameHostImpl::FromID(render_process_id, render_frame_id);
130 WebContentsImpl* web_contents = static_cast<WebContentsImpl*>( 132 WebContentsImpl* web_contents = static_cast<WebContentsImpl*>(
131 WebContents::FromRenderFrameHost(render_frame_host)); 133 WebContents::FromRenderFrameHost(render_frame_host));
132 134
133 if (!render_frame_host || !web_contents) 135 if (!render_frame_host || !web_contents)
134 return ServiceWorkerClientInfo(); 136 return ServiceWorkerClientInfo();
135 137
136 FrameTreeNode* frame_tree_node = render_frame_host->frame_tree_node(); 138 FrameTreeNode* frame_tree_node = render_frame_host->frame_tree_node();
137 139
138 // Focus the frame in the frame tree node, in case it has changed. 140 // Focus the frame in the frame tree node, in case it has changed.
139 frame_tree_node->frame_tree()->SetFocusedFrame( 141 frame_tree_node->frame_tree()->SetFocusedFrame(
140 frame_tree_node, render_frame_host->GetSiteInstance()); 142 frame_tree_node, render_frame_host->GetSiteInstance());
141 143
142 // Focus the frame's view to make sure the frame is now considered as focused. 144 // Focus the frame's view to make sure the frame is now considered as focused.
143 render_frame_host->GetView()->Focus(); 145 render_frame_host->GetView()->Focus();
144 146
145 // Move the web contents to the foreground. 147 // Move the web contents to the foreground.
146 web_contents->Activate(); 148 web_contents->Activate();
147 149
148 return GetWindowClientInfoOnUI(render_process_id, render_frame_id, 150 return GetWindowClientInfoOnUI(render_process_id, render_frame_id,
149 client_uuid); 151 create_time, client_uuid);
150 } 152 }
151 153
152 // This is only called for main frame navigations in OpenWindowOnUI(). 154 // This is only called for main frame navigations in OpenWindowOnUI().
153 void DidOpenURLOnUI(const OpenURLCallback& callback, 155 void DidOpenURLOnUI(const OpenURLCallback& callback,
154 WebContents* web_contents) { 156 WebContents* web_contents) {
155 DCHECK_CURRENTLY_ON(BrowserThread::UI); 157 DCHECK_CURRENTLY_ON(BrowserThread::UI);
156 158
157 if (!web_contents) { 159 if (!web_contents) {
158 BrowserThread::PostTask( 160 BrowserThread::PostTask(
159 BrowserThread::IO, FROM_HERE, 161 BrowserThread::IO, FROM_HERE,
(...skipping 107 matching lines...) Expand 10 before | Expand all | Expand 10 after
267 context->GetClientProviderHostIterator(origin); 269 context->GetClientProviderHostIterator(origin);
268 !it->IsAtEnd(); it->Advance()) { 270 !it->IsAtEnd(); it->Advance()) {
269 ServiceWorkerProviderHost* provider_host = it->GetProviderHost(); 271 ServiceWorkerProviderHost* provider_host = it->GetProviderHost();
270 if (provider_host->process_id() != render_process_id || 272 if (provider_host->process_id() != render_process_id ||
271 provider_host->frame_id() != render_frame_id) { 273 provider_host->frame_id() != render_frame_id) {
272 continue; 274 continue;
273 } 275 }
274 BrowserThread::PostTaskAndReplyWithResult( 276 BrowserThread::PostTaskAndReplyWithResult(
275 BrowserThread::UI, FROM_HERE, 277 BrowserThread::UI, FROM_HERE,
276 base::Bind(&GetWindowClientInfoOnUI, provider_host->process_id(), 278 base::Bind(&GetWindowClientInfoOnUI, provider_host->process_id(),
277 provider_host->route_id(), provider_host->client_uuid()), 279 provider_host->route_id(), provider_host->create_time(),
280 provider_host->client_uuid()),
278 base::Bind(callback, SERVICE_WORKER_OK)); 281 base::Bind(callback, SERVICE_WORKER_OK));
279 return; 282 return;
280 } 283 }
281 284
282 // If here, it means that no provider_host was found, in which case, the 285 // If here, it means that no provider_host was found, in which case, the
283 // renderer should still be informed that the window was opened. 286 // renderer should still be informed that the window was opened.
284 callback.Run(SERVICE_WORKER_OK, ServiceWorkerClientInfo()); 287 callback.Run(SERVICE_WORKER_OK, ServiceWorkerClientInfo());
285 } 288 }
286 289
287 void AddWindowClient( 290 void AddWindowClient(
288 ServiceWorkerProviderHost* host, 291 ServiceWorkerProviderHost* host,
289 std::vector<std::tuple<int, int, std::string>>* client_info) { 292 std::vector<std::tuple<int, int, base::TimeTicks, std::string>>*
293 client_info) {
290 DCHECK_CURRENTLY_ON(BrowserThread::IO); 294 DCHECK_CURRENTLY_ON(BrowserThread::IO);
291 if (host->client_type() != blink::kWebServiceWorkerClientTypeWindow) 295 if (host->client_type() != blink::kWebServiceWorkerClientTypeWindow)
292 return; 296 return;
293 client_info->push_back(std::make_tuple(host->process_id(), host->frame_id(), 297 client_info->push_back(std::make_tuple(host->process_id(), host->frame_id(),
298 host->create_time(),
294 host->client_uuid())); 299 host->client_uuid()));
295 } 300 }
296 301
297 void AddNonWindowClient(ServiceWorkerProviderHost* host, 302 void AddNonWindowClient(ServiceWorkerProviderHost* host,
298 const ServiceWorkerClientQueryOptions& options, 303 const ServiceWorkerClientQueryOptions& options,
299 ServiceWorkerClients* clients) { 304 ServiceWorkerClients* clients) {
300 DCHECK_CURRENTLY_ON(BrowserThread::IO); 305 DCHECK_CURRENTLY_ON(BrowserThread::IO);
301 blink::WebServiceWorkerClientType host_client_type = host->client_type(); 306 blink::WebServiceWorkerClientType host_client_type = host->client_type();
302 if (host_client_type == blink::kWebServiceWorkerClientTypeWindow) 307 if (host_client_type == blink::kWebServiceWorkerClientTypeWindow)
303 return; 308 return;
304 if (options.client_type != blink::kWebServiceWorkerClientTypeAll && 309 if (options.client_type != blink::kWebServiceWorkerClientTypeAll &&
305 options.client_type != host_client_type) 310 options.client_type != host_client_type)
306 return; 311 return;
307 312
308 ServiceWorkerClientInfo client_info( 313 ServiceWorkerClientInfo client_info(
309 host->client_uuid(), blink::kWebPageVisibilityStateHidden, 314 host->client_uuid(), blink::kWebPageVisibilityStateHidden,
310 false, // is_focused 315 false, // is_focused
311 host->document_url(), REQUEST_CONTEXT_FRAME_TYPE_NONE, base::TimeTicks(), 316 host->document_url(), REQUEST_CONTEXT_FRAME_TYPE_NONE, base::TimeTicks(),
312 host_client_type); 317 host->create_time(), host_client_type);
313 clients->push_back(client_info); 318 clients->push_back(client_info);
314 } 319 }
315 320
316 void OnGetWindowClientsOnUI( 321 void OnGetWindowClientsOnUI(
317 // The tuple contains process_id, frame_id, client_uuid. 322 // The tuple contains process_id, frame_id, create_time, client_uuid.
318 const std::vector<std::tuple<int, int, std::string>>& clients_info, 323 const std::vector<std::tuple<int, int, base::TimeTicks, std::string>>&
324 clients_info,
319 const GURL& script_url, 325 const GURL& script_url,
320 const GetWindowClientsCallback& callback) { 326 const GetWindowClientsCallback& callback,
327 std::unique_ptr<ServiceWorkerClients> clients) {
321 DCHECK_CURRENTLY_ON(BrowserThread::UI); 328 DCHECK_CURRENTLY_ON(BrowserThread::UI);
322 329
323 std::unique_ptr<ServiceWorkerClients> clients(new ServiceWorkerClients);
324 for (const auto& it : clients_info) { 330 for (const auto& it : clients_info) {
325 ServiceWorkerClientInfo info = GetWindowClientInfoOnUI( 331 ServiceWorkerClientInfo info = GetWindowClientInfoOnUI(
326 std::get<0>(it), std::get<1>(it), std::get<2>(it)); 332 std::get<0>(it), std::get<1>(it), std::get<2>(it), std::get<3>(it));
327 333
328 // If the request to the provider_host returned an empty 334 // If the request to the provider_host returned an empty
329 // ServiceWorkerClientInfo, that means that it wasn't possible to associate 335 // ServiceWorkerClientInfo, that means that it wasn't possible to associate
330 // it with a valid RenderFrameHost. It might be because the frame was killed 336 // it with a valid RenderFrameHost. It might be because the frame was killed
331 // or navigated in between. 337 // or navigated in between.
332 if (info.IsEmpty()) 338 if (info.IsEmpty())
333 continue; 339 continue;
334 340
335 // We can get info for a frame that was navigating end ended up with a 341 // We can get info for a frame that was navigating end ended up with a
336 // different URL than expected. In such case, we should make sure to not 342 // different URL than expected. In such case, we should make sure to not
337 // expose cross-origin WindowClient. 343 // expose cross-origin WindowClient.
338 if (info.url.GetOrigin() != script_url.GetOrigin()) 344 if (info.url.GetOrigin() != script_url.GetOrigin())
339 continue; 345 continue;
340 346
341 clients->push_back(info); 347 clients->push_back(info);
342 } 348 }
343 349
344 BrowserThread::PostTask(BrowserThread::IO, FROM_HERE, 350 BrowserThread::PostTask(BrowserThread::IO, FROM_HERE,
345 base::Bind(callback, base::Passed(&clients))); 351 base::Bind(callback, base::Passed(&clients)));
346 } 352 }
347 353
348 struct ServiceWorkerClientInfoSortMRU { 354 struct ServiceWorkerClientInfoSort {
349 bool operator()(const ServiceWorkerClientInfo& a, 355 bool operator()(const ServiceWorkerClientInfo& a,
350 const ServiceWorkerClientInfo& b) const { 356 const ServiceWorkerClientInfo& b) const {
351 return a.last_focus_time > b.last_focus_time; 357 // Clients for windows should be appeared earlier.
358 if (a.client_type == blink::kWebServiceWorkerClientTypeWindow &&
359 b.client_type != blink::kWebServiceWorkerClientTypeWindow) {
360 return true;
361 }
362 if (a.client_type != blink::kWebServiceWorkerClientTypeWindow &&
363 b.client_type == blink::kWebServiceWorkerClientTypeWindow) {
364 return false;
365 }
366
367 // Clients focused recently should be appeared earlier.
368 if (a.last_focus_time != b.last_focus_time)
369 return a.last_focus_time > b.last_focus_time;
370
371 // Clients created before should be appeared earlier.
372 return a.create_time < b.create_time;
352 } 373 }
353 }; 374 };
354 375
355 void DidGetClients(const ClientsCallback& callback, 376 void DidGetClients(const ClientsCallback& callback,
356 ServiceWorkerClients* clients) { 377 std::unique_ptr<ServiceWorkerClients> clients) {
357 DCHECK_CURRENTLY_ON(BrowserThread::IO); 378 DCHECK_CURRENTLY_ON(BrowserThread::IO);
358 379
359 // Sort clients so that the most recently active tab is in the front. 380 std::sort(clients->begin(), clients->end(), ServiceWorkerClientInfoSort());
360 std::sort(clients->begin(), clients->end(), ServiceWorkerClientInfoSortMRU());
361 381
362 callback.Run(clients); 382 callback.Run(std::move(clients));
363 } 383 }
364 384
365 void GetNonWindowClients(const base::WeakPtr<ServiceWorkerVersion>& controller, 385 void GetNonWindowClients(const base::WeakPtr<ServiceWorkerVersion>& controller,
366 const ServiceWorkerClientQueryOptions& options, 386 const ServiceWorkerClientQueryOptions& options,
367 ServiceWorkerClients* clients) { 387 const ClientsCallback& callback,
388 std::unique_ptr<ServiceWorkerClients> clients) {
368 DCHECK_CURRENTLY_ON(BrowserThread::IO); 389 DCHECK_CURRENTLY_ON(BrowserThread::IO);
369 if (!options.include_uncontrolled) { 390 if (!options.include_uncontrolled) {
370 for (auto& controllee : controller->controllee_map()) 391 for (auto& controllee : controller->controllee_map())
371 AddNonWindowClient(controllee.second, options, clients); 392 AddNonWindowClient(controllee.second, options, clients.get());
372 } else if (controller->context()) { 393 } else if (controller->context()) {
373 GURL origin = controller->script_url().GetOrigin(); 394 GURL origin = controller->script_url().GetOrigin();
374 for (auto it = controller->context()->GetClientProviderHostIterator(origin); 395 for (auto it = controller->context()->GetClientProviderHostIterator(origin);
375 !it->IsAtEnd(); it->Advance()) { 396 !it->IsAtEnd(); it->Advance()) {
376 AddNonWindowClient(it->GetProviderHost(), options, clients); 397 AddNonWindowClient(it->GetProviderHost(), options, clients.get());
377 } 398 }
378 } 399 }
400 DidGetClients(callback, std::move(clients));
379 } 401 }
380 402
381 void DidGetWindowClients(const base::WeakPtr<ServiceWorkerVersion>& controller, 403 void DidGetWindowClients(const base::WeakPtr<ServiceWorkerVersion>& controller,
382 const ServiceWorkerClientQueryOptions& options, 404 const ServiceWorkerClientQueryOptions& options,
383 const ClientsCallback& callback, 405 const ClientsCallback& callback,
384 std::unique_ptr<ServiceWorkerClients> clients) { 406 std::unique_ptr<ServiceWorkerClients> clients) {
385 DCHECK_CURRENTLY_ON(BrowserThread::IO); 407 DCHECK_CURRENTLY_ON(BrowserThread::IO);
386 if (options.client_type == blink::kWebServiceWorkerClientTypeAll) 408 if (options.client_type == blink::kWebServiceWorkerClientTypeAll) {
387 GetNonWindowClients(controller, options, clients.get()); 409 GetNonWindowClients(controller, options, callback, std::move(clients));
388 DidGetClients(callback, clients.get()); 410 return;
411 }
412 DidGetClients(callback, std::move(clients));
389 } 413 }
390 414
391 void GetWindowClients(const base::WeakPtr<ServiceWorkerVersion>& controller, 415 void GetWindowClients(const base::WeakPtr<ServiceWorkerVersion>& controller,
392 const ServiceWorkerClientQueryOptions& options, 416 const ServiceWorkerClientQueryOptions& options,
393 const ClientsCallback& callback) { 417 const ClientsCallback& callback,
418 std::unique_ptr<ServiceWorkerClients> clients) {
394 DCHECK_CURRENTLY_ON(BrowserThread::IO); 419 DCHECK_CURRENTLY_ON(BrowserThread::IO);
395 DCHECK(options.client_type == blink::kWebServiceWorkerClientTypeWindow || 420 DCHECK(options.client_type == blink::kWebServiceWorkerClientTypeWindow ||
396 options.client_type == blink::kWebServiceWorkerClientTypeAll); 421 options.client_type == blink::kWebServiceWorkerClientTypeAll);
397 422
398 std::vector<std::tuple<int, int, std::string>> clients_info; 423 std::vector<std::tuple<int, int, base::TimeTicks, std::string>> clients_info;
399 if (!options.include_uncontrolled) { 424 if (!options.include_uncontrolled) {
400 for (auto& controllee : controller->controllee_map()) 425 for (auto& controllee : controller->controllee_map())
401 AddWindowClient(controllee.second, &clients_info); 426 AddWindowClient(controllee.second, &clients_info);
402 } else if (controller->context()) { 427 } else if (controller->context()) {
403 GURL origin = controller->script_url().GetOrigin(); 428 GURL origin = controller->script_url().GetOrigin();
404 for (auto it = controller->context()->GetClientProviderHostIterator(origin); 429 for (auto it = controller->context()->GetClientProviderHostIterator(origin);
405 !it->IsAtEnd(); it->Advance()) { 430 !it->IsAtEnd(); it->Advance()) {
406 AddWindowClient(it->GetProviderHost(), &clients_info); 431 AddWindowClient(it->GetProviderHost(), &clients_info);
407 } 432 }
408 } 433 }
409 434
410 if (clients_info.empty()) { 435 if (clients_info.empty()) {
411 DidGetWindowClients(controller, options, callback, 436 DidGetWindowClients(controller, options, callback, std::move(clients));
412 base::WrapUnique(new ServiceWorkerClients));
413 return; 437 return;
414 } 438 }
415 439
416 BrowserThread::PostTask( 440 BrowserThread::PostTask(
417 BrowserThread::UI, FROM_HERE, 441 BrowserThread::UI, FROM_HERE,
418 base::Bind( 442 base::Bind(
419 &OnGetWindowClientsOnUI, clients_info, controller->script_url(), 443 &OnGetWindowClientsOnUI, clients_info, controller->script_url(),
420 base::Bind(&DidGetWindowClients, controller, options, callback))); 444 base::Bind(&DidGetWindowClients, controller, options, callback),
445 base::Passed(&clients)));
421 } 446 }
422 447
423 } // namespace 448 } // namespace
424 449
425 void FocusWindowClient(ServiceWorkerProviderHost* provider_host, 450 void FocusWindowClient(ServiceWorkerProviderHost* provider_host,
426 const ClientCallback& callback) { 451 const ClientCallback& callback) {
427 DCHECK_CURRENTLY_ON(BrowserThread::IO); 452 DCHECK_CURRENTLY_ON(BrowserThread::IO);
428 DCHECK_EQ(blink::kWebServiceWorkerClientTypeWindow, 453 DCHECK_EQ(blink::kWebServiceWorkerClientTypeWindow,
429 provider_host->client_type()); 454 provider_host->client_type());
430 BrowserThread::PostTaskAndReplyWithResult( 455 BrowserThread::PostTaskAndReplyWithResult(
431 BrowserThread::UI, FROM_HERE, 456 BrowserThread::UI, FROM_HERE,
432 base::Bind(&FocusOnUI, provider_host->process_id(), 457 base::Bind(&FocusOnUI, provider_host->process_id(),
433 provider_host->frame_id(), provider_host->client_uuid()), 458 provider_host->frame_id(), provider_host->create_time(),
459 provider_host->client_uuid()),
434 callback); 460 callback);
435 } 461 }
436 462
437 void OpenWindow(const GURL& url, 463 void OpenWindow(const GURL& url,
438 const GURL& script_url, 464 const GURL& script_url,
439 int worker_process_id, 465 int worker_process_id,
440 const base::WeakPtr<ServiceWorkerContextCore>& context, 466 const base::WeakPtr<ServiceWorkerContextCore>& context,
441 const NavigationCallback& callback) { 467 const NavigationCallback& callback) {
442 DCHECK_CURRENTLY_ON(BrowserThread::IO); 468 DCHECK_CURRENTLY_ON(BrowserThread::IO);
443 BrowserThread::PostTask( 469 BrowserThread::PostTask(
(...skipping 25 matching lines...) Expand all
469 blink::WebServiceWorkerClientType client_type = provider_host->client_type(); 495 blink::WebServiceWorkerClientType client_type = provider_host->client_type();
470 DCHECK(client_type == blink::kWebServiceWorkerClientTypeWindow || 496 DCHECK(client_type == blink::kWebServiceWorkerClientTypeWindow ||
471 client_type == blink::kWebServiceWorkerClientTypeWorker || 497 client_type == blink::kWebServiceWorkerClientTypeWorker ||
472 client_type == blink::kWebServiceWorkerClientTypeSharedWorker) 498 client_type == blink::kWebServiceWorkerClientTypeSharedWorker)
473 << client_type; 499 << client_type;
474 500
475 if (client_type == blink::kWebServiceWorkerClientTypeWindow) { 501 if (client_type == blink::kWebServiceWorkerClientTypeWindow) {
476 BrowserThread::PostTaskAndReplyWithResult( 502 BrowserThread::PostTaskAndReplyWithResult(
477 BrowserThread::UI, FROM_HERE, 503 BrowserThread::UI, FROM_HERE,
478 base::Bind(&GetWindowClientInfoOnUI, provider_host->process_id(), 504 base::Bind(&GetWindowClientInfoOnUI, provider_host->process_id(),
479 provider_host->route_id(), provider_host->client_uuid()), 505 provider_host->route_id(), provider_host->create_time(),
506 provider_host->client_uuid()),
480 callback); 507 callback);
481 return; 508 return;
482 } 509 }
483 510
484 ServiceWorkerClientInfo client_info( 511 ServiceWorkerClientInfo client_info(
485 provider_host->client_uuid(), blink::kWebPageVisibilityStateHidden, 512 provider_host->client_uuid(), blink::kWebPageVisibilityStateHidden,
486 false, // is_focused 513 false, // is_focused
487 provider_host->document_url(), REQUEST_CONTEXT_FRAME_TYPE_NONE, 514 provider_host->document_url(), REQUEST_CONTEXT_FRAME_TYPE_NONE,
488 base::TimeTicks(), provider_host->client_type()); 515 base::TimeTicks(), provider_host->create_time(),
516 provider_host->client_type());
489 BrowserThread::PostTask(BrowserThread::IO, FROM_HERE, 517 BrowserThread::PostTask(BrowserThread::IO, FROM_HERE,
490 base::Bind(callback, client_info)); 518 base::Bind(callback, client_info));
491 } 519 }
492 520
493 void GetClients(const base::WeakPtr<ServiceWorkerVersion>& controller, 521 void GetClients(const base::WeakPtr<ServiceWorkerVersion>& controller,
494 const ServiceWorkerClientQueryOptions& options, 522 const ServiceWorkerClientQueryOptions& options,
495 const ClientsCallback& callback) { 523 const ClientsCallback& callback) {
496 DCHECK_CURRENTLY_ON(BrowserThread::IO); 524 DCHECK_CURRENTLY_ON(BrowserThread::IO);
497 525
498 ServiceWorkerClients clients; 526 auto clients = base::MakeUnique<ServiceWorkerClients>();
499 if (!controller->HasControllee() && !options.include_uncontrolled) { 527 if (!controller->HasControllee() && !options.include_uncontrolled) {
500 DidGetClients(callback, &clients); 528 DidGetClients(callback, std::move(clients));
501 return; 529 return;
502 } 530 }
503 531
504 // For Window clients we want to query the info on the UI thread first. 532 // For Window clients we want to query the info on the UI thread first.
505 if (options.client_type == blink::kWebServiceWorkerClientTypeWindow || 533 if (options.client_type == blink::kWebServiceWorkerClientTypeWindow ||
506 options.client_type == blink::kWebServiceWorkerClientTypeAll) { 534 options.client_type == blink::kWebServiceWorkerClientTypeAll) {
507 GetWindowClients(controller, options, callback); 535 GetWindowClients(controller, options, callback, std::move(clients));
508 return; 536 return;
509 } 537 }
510 538
511 GetNonWindowClients(controller, options, &clients); 539 GetNonWindowClients(controller, options, callback, std::move(clients));
512 DidGetClients(callback, &clients);
513 } 540 }
514 541
515 } // namespace service_worker_client_utils 542 } // namespace service_worker_client_utils
516 } // namespace content 543 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698