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

Side by Side Diff: content/browser/shared_worker/shared_worker_service_impl.cc

Issue 1545243002: Convert Pass()→std::move() in //content/browser (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 4 years, 12 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 2014 The Chromium Authors. All rights reserved. 1 // Copyright 2014 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/shared_worker/shared_worker_service_impl.h" 5 #include "content/browser/shared_worker/shared_worker_service_impl.h"
6 6
7 #include <stddef.h> 7 #include <stddef.h>
8
9 #include <algorithm> 8 #include <algorithm>
10 #include <iterator> 9 #include <iterator>
11 #include <set> 10 #include <set>
11 #include <utility>
12 #include <vector> 12 #include <vector>
13 13
14 #include "base/callback.h" 14 #include "base/callback.h"
15 #include "base/macros.h" 15 #include "base/macros.h"
16 #include "base/memory/ref_counted.h" 16 #include "base/memory/ref_counted.h"
17 #include "content/browser/devtools/shared_worker_devtools_manager.h" 17 #include "content/browser/devtools/shared_worker_devtools_manager.h"
18 #include "content/browser/renderer_host/render_process_host_impl.h" 18 #include "content/browser/renderer_host/render_process_host_impl.h"
19 #include "content/browser/shared_worker/shared_worker_host.h" 19 #include "content/browser/shared_worker/shared_worker_host.h"
20 #include "content/browser/shared_worker/shared_worker_instance.h" 20 #include "content/browser/shared_worker/shared_worker_instance.h"
21 #include "content/browser/shared_worker/shared_worker_message_filter.h" 21 #include "content/browser/shared_worker/shared_worker_message_filter.h"
(...skipping 101 matching lines...) Expand 10 before | Expand all | Expand 10 after
123 const int route_id; 123 const int route_id;
124 const unsigned long long document_id; 124 const unsigned long long document_id;
125 const int render_process_id; 125 const int render_process_id;
126 const int render_frame_route_id; 126 const int render_frame_route_id;
127 }; 127 };
128 128
129 typedef ScopedVector<SharedWorkerPendingRequest> SharedWorkerPendingRequests; 129 typedef ScopedVector<SharedWorkerPendingRequest> SharedWorkerPendingRequests;
130 130
131 explicit SharedWorkerPendingInstance( 131 explicit SharedWorkerPendingInstance(
132 scoped_ptr<SharedWorkerInstance> instance) 132 scoped_ptr<SharedWorkerInstance> instance)
133 : instance_(instance.Pass()) {} 133 : instance_(std::move(instance)) {}
134 ~SharedWorkerPendingInstance() {} 134 ~SharedWorkerPendingInstance() {}
135 SharedWorkerInstance* instance() { return instance_.get(); } 135 SharedWorkerInstance* instance() { return instance_.get(); }
136 SharedWorkerInstance* release_instance() { return instance_.release(); } 136 SharedWorkerInstance* release_instance() { return instance_.release(); }
137 SharedWorkerPendingRequests* requests() { return &requests_; } 137 SharedWorkerPendingRequests* requests() { return &requests_; }
138 SharedWorkerMessageFilter* FindFilter(int process_id) { 138 SharedWorkerMessageFilter* FindFilter(int process_id) {
139 for (size_t i = 0; i < requests_.size(); ++i) { 139 for (size_t i = 0; i < requests_.size(); ++i) {
140 if (requests_[i]->render_process_id == process_id) 140 if (requests_[i]->render_process_id == process_id)
141 return requests_[i]->filter; 141 return requests_[i]->filter;
142 } 142 }
143 return NULL; 143 return NULL;
(...skipping 160 matching lines...) Expand 10 before | Expand all | Expand 10 after
304 if (SharedWorkerPendingInstance* pending = FindPendingInstance(*instance)) { 304 if (SharedWorkerPendingInstance* pending = FindPendingInstance(*instance)) {
305 if (params.url != pending->instance()->url()) { 305 if (params.url != pending->instance()->url()) {
306 *creation_error = blink::WebWorkerCreationErrorURLMismatch; 306 *creation_error = blink::WebWorkerCreationErrorURLMismatch;
307 return; 307 return;
308 } 308 }
309 if (params.creation_context_type != 309 if (params.creation_context_type !=
310 pending->instance()->creation_context_type()) { 310 pending->instance()->creation_context_type()) {
311 *creation_error = blink::WebWorkerCreationErrorSecureContextMismatch; 311 *creation_error = blink::WebWorkerCreationErrorSecureContextMismatch;
312 return; 312 return;
313 } 313 }
314 pending->AddRequest(request.Pass()); 314 pending->AddRequest(std::move(request));
315 return; 315 return;
316 } 316 }
317 scoped_ptr<SharedWorkerPendingInstance> pending_instance( 317 scoped_ptr<SharedWorkerPendingInstance> pending_instance(
318 new SharedWorkerPendingInstance(instance.Pass())); 318 new SharedWorkerPendingInstance(std::move(instance)));
319 pending_instance->AddRequest(request.Pass()); 319 pending_instance->AddRequest(std::move(request));
320 ReserveRenderProcessToCreateWorker(pending_instance.Pass(), creation_error); 320 ReserveRenderProcessToCreateWorker(std::move(pending_instance),
321 creation_error);
321 } 322 }
322 323
323 void SharedWorkerServiceImpl::ForwardToWorker( 324 void SharedWorkerServiceImpl::ForwardToWorker(
324 const IPC::Message& message, 325 const IPC::Message& message,
325 SharedWorkerMessageFilter* filter) { 326 SharedWorkerMessageFilter* filter) {
326 for (WorkerHostMap::const_iterator iter = worker_hosts_.begin(); 327 for (WorkerHostMap::const_iterator iter = worker_hosts_.begin();
327 iter != worker_hosts_.end(); 328 iter != worker_hosts_.end();
328 ++iter) { 329 ++iter) {
329 if (iter->second->FilterMessage(message, filter)) 330 if (iter->second->FilterMessage(message, filter))
330 return; 331 return;
(...skipping 192 matching lines...) Expand 10 before | Expand all | Expand 10 after
523 worker_route_id, 524 worker_route_id,
524 is_new_worker), 525 is_new_worker),
525 base::Bind( 526 base::Bind(
526 &SharedWorkerServiceImpl::RenderProcessReserveFailedCallback, 527 &SharedWorkerServiceImpl::RenderProcessReserveFailedCallback,
527 base::Unretained(this), 528 base::Unretained(this),
528 pending_instance_id, 529 pending_instance_id,
529 worker_process_id, 530 worker_process_id,
530 worker_route_id, 531 worker_route_id,
531 is_new_worker), 532 is_new_worker),
532 s_try_increment_worker_ref_count_)); 533 s_try_increment_worker_ref_count_));
533 pending_instances_.set(pending_instance_id, pending_instance.Pass()); 534 pending_instances_.set(pending_instance_id, std::move(pending_instance));
534 } 535 }
535 536
536 void SharedWorkerServiceImpl::RenderProcessReservedCallback( 537 void SharedWorkerServiceImpl::RenderProcessReservedCallback(
537 int pending_instance_id, 538 int pending_instance_id,
538 int worker_process_id, 539 int worker_process_id,
539 int worker_route_id, 540 int worker_route_id,
540 bool is_new_worker, 541 bool is_new_worker,
541 bool pause_on_start) { 542 bool pause_on_start) {
542 DCHECK_CURRENTLY_ON(BrowserThread::IO); 543 DCHECK_CURRENTLY_ON(BrowserThread::IO);
543 // To offset the TryIncrementWorkerRefCount called for the reservation, 544 // To offset the TryIncrementWorkerRefCount called for the reservation,
544 // calls DecrementWorkerRefCount after CheckWorkerDependency in 545 // calls DecrementWorkerRefCount after CheckWorkerDependency in
545 // ScopeWorkerDependencyChecker's destructor. 546 // ScopeWorkerDependencyChecker's destructor.
546 ScopedWorkerDependencyChecker checker( 547 ScopedWorkerDependencyChecker checker(
547 this, base::Bind(&DecrementWorkerRefCount, worker_process_id)); 548 this, base::Bind(&DecrementWorkerRefCount, worker_process_id));
548 scoped_ptr<SharedWorkerPendingInstance> pending_instance = 549 scoped_ptr<SharedWorkerPendingInstance> pending_instance =
549 pending_instances_.take_and_erase(pending_instance_id); 550 pending_instances_.take_and_erase(pending_instance_id);
550 if (!pending_instance) 551 if (!pending_instance)
551 return; 552 return;
552 if (!is_new_worker) { 553 if (!is_new_worker) {
553 SharedWorkerHost* existing_host = 554 SharedWorkerHost* existing_host =
554 worker_hosts_.get(std::make_pair(worker_process_id, worker_route_id)); 555 worker_hosts_.get(std::make_pair(worker_process_id, worker_route_id));
555 if (!existing_host) { 556 if (!existing_host) {
556 // Retry reserving a renderer process if the existed Shared Worker was 557 // Retry reserving a renderer process if the existed Shared Worker was
557 // destroyed on IO thread while reserving the renderer process on UI 558 // destroyed on IO thread while reserving the renderer process on UI
558 // thread. 559 // thread.
559 ReserveRenderProcessToCreateWorker(pending_instance.Pass(), NULL); 560 ReserveRenderProcessToCreateWorker(std::move(pending_instance), NULL);
560 return; 561 return;
561 } 562 }
562 pending_instance->RegisterToSharedWorkerHost(existing_host); 563 pending_instance->RegisterToSharedWorkerHost(existing_host);
563 pending_instance->SendWorkerCreatedMessages(); 564 pending_instance->SendWorkerCreatedMessages();
564 return; 565 return;
565 } 566 }
566 SharedWorkerMessageFilter* filter = 567 SharedWorkerMessageFilter* filter =
567 pending_instance->FindFilter(worker_process_id); 568 pending_instance->FindFilter(worker_process_id);
568 if (!filter) { 569 if (!filter) {
569 pending_instance->RemoveRequest(worker_process_id); 570 pending_instance->RemoveRequest(worker_process_id);
570 // Retry reserving a renderer process if the requested renderer process was 571 // Retry reserving a renderer process if the requested renderer process was
571 // destroyed on IO thread while reserving the renderer process on UI thread. 572 // destroyed on IO thread while reserving the renderer process on UI thread.
572 ReserveRenderProcessToCreateWorker(pending_instance.Pass(), NULL); 573 ReserveRenderProcessToCreateWorker(std::move(pending_instance), NULL);
573 return; 574 return;
574 } 575 }
575 scoped_ptr<SharedWorkerHost> host(new SharedWorkerHost( 576 scoped_ptr<SharedWorkerHost> host(new SharedWorkerHost(
576 pending_instance->release_instance(), filter, worker_route_id)); 577 pending_instance->release_instance(), filter, worker_route_id));
577 pending_instance->RegisterToSharedWorkerHost(host.get()); 578 pending_instance->RegisterToSharedWorkerHost(host.get());
578 const GURL url = host->instance()->url(); 579 const GURL url = host->instance()->url();
579 const base::string16 name = host->instance()->name(); 580 const base::string16 name = host->instance()->name();
580 host->Start(pause_on_start); 581 host->Start(pause_on_start);
581 worker_hosts_.set(std::make_pair(worker_process_id, worker_route_id), 582 worker_hosts_.set(std::make_pair(worker_process_id, worker_route_id),
582 host.Pass()); 583 std::move(host));
583 FOR_EACH_OBSERVER( 584 FOR_EACH_OBSERVER(
584 WorkerServiceObserver, 585 WorkerServiceObserver,
585 observers_, 586 observers_,
586 WorkerCreated(url, name, worker_process_id, worker_route_id)); 587 WorkerCreated(url, name, worker_process_id, worker_route_id));
587 } 588 }
588 589
589 void SharedWorkerServiceImpl::RenderProcessReserveFailedCallback( 590 void SharedWorkerServiceImpl::RenderProcessReserveFailedCallback(
590 int pending_instance_id, 591 int pending_instance_id,
591 int worker_process_id, 592 int worker_process_id,
592 int worker_route_id, 593 int worker_route_id,
593 bool is_new_worker) { 594 bool is_new_worker) {
594 worker_hosts_.take_and_erase( 595 worker_hosts_.take_and_erase(
595 std::make_pair(worker_process_id, worker_route_id)); 596 std::make_pair(worker_process_id, worker_route_id));
596 scoped_ptr<SharedWorkerPendingInstance> pending_instance = 597 scoped_ptr<SharedWorkerPendingInstance> pending_instance =
597 pending_instances_.take_and_erase(pending_instance_id); 598 pending_instances_.take_and_erase(pending_instance_id);
598 if (!pending_instance) 599 if (!pending_instance)
599 return; 600 return;
600 pending_instance->RemoveRequest(worker_process_id); 601 pending_instance->RemoveRequest(worker_process_id);
601 // Retry reserving a renderer process. 602 // Retry reserving a renderer process.
602 ReserveRenderProcessToCreateWorker(pending_instance.Pass(), NULL); 603 ReserveRenderProcessToCreateWorker(std::move(pending_instance), NULL);
603 } 604 }
604 605
605 SharedWorkerHost* SharedWorkerServiceImpl::FindSharedWorkerHost( 606 SharedWorkerHost* SharedWorkerServiceImpl::FindSharedWorkerHost(
606 SharedWorkerMessageFilter* filter, 607 SharedWorkerMessageFilter* filter,
607 int worker_route_id) { 608 int worker_route_id) {
608 return worker_hosts_.get(std::make_pair(filter->render_process_id(), 609 return worker_hosts_.get(std::make_pair(filter->render_process_id(),
609 worker_route_id)); 610 worker_route_id));
610 } 611 }
611 612
612 SharedWorkerHost* SharedWorkerServiceImpl::FindSharedWorkerHost( 613 SharedWorkerHost* SharedWorkerServiceImpl::FindSharedWorkerHost(
(...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after
667 UpdateWorkerDependencyFunc new_func) { 668 UpdateWorkerDependencyFunc new_func) {
668 update_worker_dependency_ = new_func; 669 update_worker_dependency_ = new_func;
669 } 670 }
670 671
671 void SharedWorkerServiceImpl::ChangeTryIncrementWorkerRefCountFuncForTesting( 672 void SharedWorkerServiceImpl::ChangeTryIncrementWorkerRefCountFuncForTesting(
672 bool (*new_func)(int)) { 673 bool (*new_func)(int)) {
673 s_try_increment_worker_ref_count_ = new_func; 674 s_try_increment_worker_ref_count_ = new_func;
674 } 675 }
675 676
676 } // namespace content 677 } // namespace content
OLDNEW
« no previous file with comments | « content/browser/session_history_browsertest.cc ('k') | content/browser/shared_worker/shared_worker_service_impl_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698