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

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 #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 unified diff | 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 »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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, 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) {
321 DCHECK_CURRENTLY_ON(BrowserThread::UI); 327 DCHECK_CURRENTLY_ON(BrowserThread::UI);
322 328
323 std::unique_ptr<ServiceWorkerClients> clients(new ServiceWorkerClients); 329 auto clients = base::MakeUnique<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 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
358 return a.last_focus_time > b.last_focus_time;
359 else if (a.client_type == blink::kWebServiceWorkerClientTypeWindow &&
360 b.client_type != blink::kWebServiceWorkerClientTypeWindow)
361 return true;
362 else
363 return a.create_time < b.create_time;
352 } 364 }
353 }; 365 };
354 366
355 void DidGetClients(const ClientsCallback& callback, 367 void DidGetClients(const ClientsCallback& callback,
356 ServiceWorkerClients* clients) { 368 std::unique_ptr<ServiceWorkerClients> clients) {
357 DCHECK_CURRENTLY_ON(BrowserThread::IO); 369 DCHECK_CURRENTLY_ON(BrowserThread::IO);
358 370
359 // Sort clients so that the most recently active tab is in the front. 371 std::sort(clients->begin(), clients->end(), ServiceWorkerClientInfoSort());
360 std::sort(clients->begin(), clients->end(), ServiceWorkerClientInfoSortMRU());
361 372
362 callback.Run(clients); 373 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.
363 } 374 }
364 375
365 void GetNonWindowClients(const base::WeakPtr<ServiceWorkerVersion>& controller, 376 void GetNonWindowClients(const base::WeakPtr<ServiceWorkerVersion>& controller,
366 const ServiceWorkerClientQueryOptions& options, 377 const ServiceWorkerClientQueryOptions& options,
367 ServiceWorkerClients* clients) { 378 ServiceWorkerClients* clients) {
shimazu 2017/05/26 08:10:07 std::unique_ptr<ServiceWorkerClients>
xiaofengzhang 2017/05/26 13:57:48 Acknowledged.
xiaofengzhang 2017/05/27 05:27:42 Done.
368 DCHECK_CURRENTLY_ON(BrowserThread::IO); 379 DCHECK_CURRENTLY_ON(BrowserThread::IO);
369 if (!options.include_uncontrolled) { 380 if (!options.include_uncontrolled) {
370 for (auto& controllee : controller->controllee_map()) 381 for (auto& controllee : controller->controllee_map())
371 AddNonWindowClient(controllee.second, options, clients); 382 AddNonWindowClient(controllee.second, options, clients);
372 } else if (controller->context()) { 383 } else if (controller->context()) {
373 GURL origin = controller->script_url().GetOrigin(); 384 GURL origin = controller->script_url().GetOrigin();
374 for (auto it = controller->context()->GetClientProviderHostIterator(origin); 385 for (auto it = controller->context()->GetClientProviderHostIterator(origin);
375 !it->IsAtEnd(); it->Advance()) { 386 !it->IsAtEnd(); it->Advance()) {
376 AddNonWindowClient(it->GetProviderHost(), options, clients); 387 AddNonWindowClient(it->GetProviderHost(), options, clients);
377 } 388 }
378 } 389 }
shimazu 2017/05/26 08:10:07 DidGetClients()
xiaofengzhang 2017/05/27 05:27:42 Done.
379 } 390 }
380 391
381 void DidGetWindowClients(const base::WeakPtr<ServiceWorkerVersion>& controller, 392 void DidGetWindowClients(const base::WeakPtr<ServiceWorkerVersion>& controller,
382 const ServiceWorkerClientQueryOptions& options, 393 const ServiceWorkerClientQueryOptions& options,
383 const ClientsCallback& callback, 394 const ClientsCallback& callback,
384 std::unique_ptr<ServiceWorkerClients> clients) { 395 std::unique_ptr<ServiceWorkerClients> clients) {
385 DCHECK_CURRENTLY_ON(BrowserThread::IO); 396 DCHECK_CURRENTLY_ON(BrowserThread::IO);
386 if (options.client_type == blink::kWebServiceWorkerClientTypeAll) 397 if (options.client_type == blink::kWebServiceWorkerClientTypeAll)
387 GetNonWindowClients(controller, options, clients.get()); 398 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.
388 DidGetClients(callback, clients.get()); 399 DidGetClients(callback, std::move(clients));
389 } 400 }
390 401
391 void GetWindowClients(const base::WeakPtr<ServiceWorkerVersion>& controller, 402 void GetWindowClients(const base::WeakPtr<ServiceWorkerVersion>& controller,
392 const ServiceWorkerClientQueryOptions& options, 403 const ServiceWorkerClientQueryOptions& options,
393 const ClientsCallback& callback) { 404 const ClientsCallback& callback) {
shimazu 2017/05/26 08:10:07 Please add an argument like std::unique_ptr<Servic
xiaofengzhang 2017/05/27 05:27:42 Done.
394 DCHECK_CURRENTLY_ON(BrowserThread::IO); 405 DCHECK_CURRENTLY_ON(BrowserThread::IO);
395 DCHECK(options.client_type == blink::kWebServiceWorkerClientTypeWindow || 406 DCHECK(options.client_type == blink::kWebServiceWorkerClientTypeWindow ||
396 options.client_type == blink::kWebServiceWorkerClientTypeAll); 407 options.client_type == blink::kWebServiceWorkerClientTypeAll);
397 408
398 std::vector<std::tuple<int, int, std::string>> clients_info; 409 std::vector<std::tuple<int, int, base::TimeTicks, std::string>> clients_info;
399 if (!options.include_uncontrolled) { 410 if (!options.include_uncontrolled) {
400 for (auto& controllee : controller->controllee_map()) 411 for (auto& controllee : controller->controllee_map()) {
401 AddWindowClient(controllee.second, &clients_info); 412 AddWindowClient(controllee.second, &clients_info);
413 }
402 } else if (controller->context()) { 414 } else if (controller->context()) {
403 GURL origin = controller->script_url().GetOrigin(); 415 GURL origin = controller->script_url().GetOrigin();
404 for (auto it = controller->context()->GetClientProviderHostIterator(origin); 416 for (auto it = controller->context()->GetClientProviderHostIterator(origin);
405 !it->IsAtEnd(); it->Advance()) { 417 !it->IsAtEnd(); it->Advance()) {
406 AddWindowClient(it->GetProviderHost(), &clients_info); 418 AddWindowClient(it->GetProviderHost(), &clients_info);
407 } 419 }
408 } 420 }
409 421
410 if (clients_info.empty()) { 422 if (clients_info.empty()) {
411 DidGetWindowClients(controller, options, callback, 423 DidGetWindowClients(controller, options, callback,
412 base::WrapUnique(new ServiceWorkerClients)); 424 base::MakeUnique<ServiceWorkerClients>());
shimazu 2017/05/26 08:10:07 Pass |clients| to DidGetWindowClients
xiaofengzhang 2017/05/27 05:27:42 Done.
413 return; 425 return;
414 } 426 }
415 427
416 BrowserThread::PostTask( 428 BrowserThread::PostTask(
417 BrowserThread::UI, FROM_HERE, 429 BrowserThread::UI, FROM_HERE,
418 base::Bind( 430 base::Bind(
419 &OnGetWindowClientsOnUI, clients_info, controller->script_url(), 431 &OnGetWindowClientsOnUI, clients_info, controller->script_url(),
shimazu 2017/05/26 08:10:07 Pass |clients| to OnGetWindowClientsOnUI
xiaofengzhang 2017/05/27 05:27:42 Done.
420 base::Bind(&DidGetWindowClients, controller, options, callback))); 432 base::Bind(&DidGetWindowClients, controller, options, callback)));
421 } 433 }
422 434
423 } // namespace 435 } // namespace
424 436
425 void FocusWindowClient(ServiceWorkerProviderHost* provider_host, 437 void FocusWindowClient(ServiceWorkerProviderHost* provider_host,
426 const ClientCallback& callback) { 438 const ClientCallback& callback) {
427 DCHECK_CURRENTLY_ON(BrowserThread::IO); 439 DCHECK_CURRENTLY_ON(BrowserThread::IO);
428 DCHECK_EQ(blink::kWebServiceWorkerClientTypeWindow, 440 DCHECK_EQ(blink::kWebServiceWorkerClientTypeWindow,
429 provider_host->client_type()); 441 provider_host->client_type());
430 BrowserThread::PostTaskAndReplyWithResult( 442 BrowserThread::PostTaskAndReplyWithResult(
431 BrowserThread::UI, FROM_HERE, 443 BrowserThread::UI, FROM_HERE,
432 base::Bind(&FocusOnUI, provider_host->process_id(), 444 base::Bind(&FocusOnUI, provider_host->process_id(),
433 provider_host->frame_id(), provider_host->client_uuid()), 445 provider_host->frame_id(), provider_host->create_time(),
446 provider_host->client_uuid()),
434 callback); 447 callback);
435 } 448 }
436 449
437 void OpenWindow(const GURL& url, 450 void OpenWindow(const GURL& url,
438 const GURL& script_url, 451 const GURL& script_url,
439 int worker_process_id, 452 int worker_process_id,
440 const base::WeakPtr<ServiceWorkerContextCore>& context, 453 const base::WeakPtr<ServiceWorkerContextCore>& context,
441 const NavigationCallback& callback) { 454 const NavigationCallback& callback) {
442 DCHECK_CURRENTLY_ON(BrowserThread::IO); 455 DCHECK_CURRENTLY_ON(BrowserThread::IO);
443 BrowserThread::PostTask( 456 BrowserThread::PostTask(
(...skipping 25 matching lines...) Expand all
469 blink::WebServiceWorkerClientType client_type = provider_host->client_type(); 482 blink::WebServiceWorkerClientType client_type = provider_host->client_type();
470 DCHECK(client_type == blink::kWebServiceWorkerClientTypeWindow || 483 DCHECK(client_type == blink::kWebServiceWorkerClientTypeWindow ||
471 client_type == blink::kWebServiceWorkerClientTypeWorker || 484 client_type == blink::kWebServiceWorkerClientTypeWorker ||
472 client_type == blink::kWebServiceWorkerClientTypeSharedWorker) 485 client_type == blink::kWebServiceWorkerClientTypeSharedWorker)
473 << client_type; 486 << client_type;
474 487
475 if (client_type == blink::kWebServiceWorkerClientTypeWindow) { 488 if (client_type == blink::kWebServiceWorkerClientTypeWindow) {
476 BrowserThread::PostTaskAndReplyWithResult( 489 BrowserThread::PostTaskAndReplyWithResult(
477 BrowserThread::UI, FROM_HERE, 490 BrowserThread::UI, FROM_HERE,
478 base::Bind(&GetWindowClientInfoOnUI, provider_host->process_id(), 491 base::Bind(&GetWindowClientInfoOnUI, provider_host->process_id(),
479 provider_host->route_id(), provider_host->client_uuid()), 492 provider_host->route_id(), provider_host->create_time(),
493 provider_host->client_uuid()),
480 callback); 494 callback);
481 return; 495 return;
482 } 496 }
483 497
484 ServiceWorkerClientInfo client_info( 498 ServiceWorkerClientInfo client_info(
485 provider_host->client_uuid(), blink::kWebPageVisibilityStateHidden, 499 provider_host->client_uuid(), blink::kWebPageVisibilityStateHidden,
486 false, // is_focused 500 false, // is_focused
487 provider_host->document_url(), REQUEST_CONTEXT_FRAME_TYPE_NONE, 501 provider_host->document_url(), REQUEST_CONTEXT_FRAME_TYPE_NONE,
488 base::TimeTicks(), provider_host->client_type()); 502 base::TimeTicks(), provider_host->create_time(),
503 provider_host->client_type());
489 BrowserThread::PostTask(BrowserThread::IO, FROM_HERE, 504 BrowserThread::PostTask(BrowserThread::IO, FROM_HERE,
490 base::Bind(callback, client_info)); 505 base::Bind(callback, client_info));
491 } 506 }
492 507
493 void GetClients(const base::WeakPtr<ServiceWorkerVersion>& controller, 508 void GetClients(const base::WeakPtr<ServiceWorkerVersion>& controller,
494 const ServiceWorkerClientQueryOptions& options, 509 const ServiceWorkerClientQueryOptions& options,
495 const ClientsCallback& callback) { 510 const ClientsCallback& callback) {
496 DCHECK_CURRENTLY_ON(BrowserThread::IO); 511 DCHECK_CURRENTLY_ON(BrowserThread::IO);
497 512
498 ServiceWorkerClients clients; 513 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.
499 if (!controller->HasControllee() && !options.include_uncontrolled) { 514 if (!controller->HasControllee() && !options.include_uncontrolled) {
500 DidGetClients(callback, &clients); 515 DidGetClients(callback, std::move(clients));
501 return; 516 return;
502 } 517 }
503 518
504 // For Window clients we want to query the info on the UI thread first. 519 // For Window clients we want to query the info on the UI thread first.
505 if (options.client_type == blink::kWebServiceWorkerClientTypeWindow || 520 if (options.client_type == blink::kWebServiceWorkerClientTypeWindow ||
506 options.client_type == blink::kWebServiceWorkerClientTypeAll) { 521 options.client_type == blink::kWebServiceWorkerClientTypeAll) {
507 GetWindowClients(controller, options, callback); 522 GetWindowClients(controller, options, callback);
508 return; 523 return;
509 } 524 }
510 525
511 GetNonWindowClients(controller, options, &clients); 526 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.
512 DidGetClients(callback, &clients); 527 DidGetClients(callback, std::move(clients));
513 } 528 }
514 529
515 } // namespace service_worker_client_utils 530 } // namespace service_worker_client_utils
516 } // namespace content 531 } // namespace content
OLDNEW
« 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