Commit 3e23ece1 authored by Dmitry Gozman's avatar Dmitry Gozman Committed by Commit Bot

Remove unneeded WorkerId from SharedWorkerServiceImpl

Bug: none
Change-Id: Id6123227f6532343b70a57fea7394be91d8cffac
Reviewed-on: https://chromium-review.googlesource.com/786372Reviewed-by: default avatarTsuyoshi Horo <horo@chromium.org>
Commit-Queue: Dmitry Gozman <dgozman@chromium.org>
Cr-Commit-Position: refs/heads/master@{#523631}
parent 7f037176
......@@ -249,7 +249,7 @@ void SharedWorkerHost::OnWorkerConnectionLost() {
// This will destroy |this| resulting in client's observing their mojo
// connection being dropped.
static_cast<SharedWorkerServiceImpl*>(SharedWorkerService::GetInstance())
->DestroyHost(process_id_, route_id_);
->DestroyHost(this);
}
void SharedWorkerHost::GetInterface(
......
......@@ -75,8 +75,7 @@ bool SharedWorkerServiceImpl::TerminateWorker(
storage_partition_impl->GetIndexedDBContext(),
storage_partition_impl->GetServiceWorkerContext()));
for (const auto& iter : worker_hosts_) {
SharedWorkerHost* host = iter.second.get();
for (auto& host : worker_hosts_) {
if (host->IsAvailable() &&
host->instance()->Matches(url, name, constructor_origin, partition_id,
resource_context)) {
......@@ -97,8 +96,8 @@ void SharedWorkerServiceImpl::TerminateAllWorkersForTesting(
std::move(callback));
} else {
terminate_all_workers_callback_ = std::move(callback);
for (auto& iter : worker_hosts_)
iter.second->TerminateWorker();
for (auto& host : worker_hosts_)
host->TerminateWorker();
// Monitor for actual termination in DestroyHost.
}
}
......@@ -160,21 +159,22 @@ void SharedWorkerServiceImpl::ConnectToWorker(
// instances. This host would likely be observing the destruction of the
// child process shortly, but we can clean this up now to avoid some
// complexity.
DestroyHost(host->process_id(), host->route_id());
DestroyHost(host);
}
CreateWorker(std::move(instance), std::move(client), process_id, frame_id,
message_port);
}
void SharedWorkerServiceImpl::DestroyHost(int process_id, int route_id) {
worker_hosts_.erase(WorkerID(process_id, route_id));
void SharedWorkerServiceImpl::DestroyHost(SharedWorkerHost* host) {
RenderProcessHost* process_host =
RenderProcessHost::FromID(host->process_id());
worker_hosts_.erase(worker_hosts_.find(host));
// Complete the call to TerminateAllWorkersForTesting if no more workers.
if (worker_hosts_.empty() && terminate_all_workers_callback_)
std::move(terminate_all_workers_callback_).Run();
RenderProcessHost* process_host = RenderProcessHost::FromID(process_id);
if (!IsShuttingDown(process_host))
process_host->DecrementKeepAliveRefCount();
}
......@@ -218,23 +218,14 @@ void SharedWorkerServiceImpl::CreateWorker(
const GURL url = host->instance()->url();
const std::string name = host->instance()->name();
worker_hosts_[WorkerID(worker_process_id, worker_route_id)] = std::move(host);
}
SharedWorkerHost* SharedWorkerServiceImpl::FindSharedWorkerHost(int process_id,
int route_id) {
auto iter = worker_hosts_.find(WorkerID(process_id, route_id));
if (iter == worker_hosts_.end())
return nullptr;
return iter->second.get();
worker_hosts_.insert(std::move(host));
}
SharedWorkerHost* SharedWorkerServiceImpl::FindAvailableSharedWorkerHost(
const SharedWorkerInstance& instance) {
for (const auto& iter : worker_hosts_) {
SharedWorkerHost* host = iter.second.get();
for (auto& host : worker_hosts_) {
if (host->IsAvailable() && host->instance()->Matches(instance))
return host;
return host.get();
}
return nullptr;
}
......
......@@ -5,13 +5,13 @@
#ifndef CONTENT_BROWSER_SHARED_WORKER_SHARED_WORKER_SERVICE_IMPL_H_
#define CONTENT_BROWSER_SHARED_WORKER_SHARED_WORKER_SERVICE_IMPL_H_
#include <map>
#include <memory>
#include <set>
#include <utility>
#include <vector>
#include "base/compiler_specific.h"
#include "base/containers/unique_ptr_comparator.h"
#include "base/macros.h"
#include "base/memory/singleton.h"
#include "content/browser/shared_worker/shared_worker_host.h"
......@@ -53,16 +53,13 @@ class CONTENT_EXPORT SharedWorkerServiceImpl : public SharedWorkerService {
ResourceContext* resource_context,
const WorkerStoragePartitionId& partition_id);
void DestroyHost(int process_id, int route_id);
void DestroyHost(SharedWorkerHost* host);
private:
friend struct base::DefaultSingletonTraits<SharedWorkerServiceImpl>;
friend class SharedWorkerServiceImplTest;
friend class SharedWorkerService;
using WorkerID = std::pair<int /* process_id */, int /* route_id */>;
using WorkerHostMap = std::map<WorkerID, std::unique_ptr<SharedWorkerHost>>;
SharedWorkerServiceImpl();
~SharedWorkerServiceImpl() override;
......@@ -79,7 +76,8 @@ class CONTENT_EXPORT SharedWorkerServiceImpl : public SharedWorkerService {
SharedWorkerHost* FindAvailableSharedWorkerHost(
const SharedWorkerInstance& instance);
WorkerHostMap worker_hosts_;
std::set<std::unique_ptr<SharedWorkerHost>, base::UniquePtrComparator>
worker_hosts_;
base::OnceClosure terminate_all_workers_callback_;
DISALLOW_COPY_AND_ASSIGN(SharedWorkerServiceImpl);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment