| Index: services/resource_coordinator/memory/coordinator/coordinator_impl.cc
|
| diff --git a/services/resource_coordinator/memory/coordinator/coordinator_impl.cc b/services/resource_coordinator/memory/coordinator/coordinator_impl.cc
|
| index 4cc1840ba72ab45b937cd767787ea13942f9bf9a..ebd6ce513b05b0e901f61d2da96998556041d029 100644
|
| --- a/services/resource_coordinator/memory/coordinator/coordinator_impl.cc
|
| +++ b/services/resource_coordinator/memory/coordinator/coordinator_impl.cc
|
| @@ -13,9 +13,14 @@
|
| #include "base/threading/platform_thread.h"
|
| #include "base/trace_event/memory_dump_manager.h"
|
| #include "base/trace_event/memory_dump_request_args.h"
|
| +#include "content/public/common/service_manager_connection.h"
|
| #include "services/resource_coordinator/public/cpp/memory/process_local_dump_manager_impl.h"
|
| #include "services/resource_coordinator/public/interfaces/memory/constants.mojom.h"
|
| #include "services/resource_coordinator/public/interfaces/memory/memory_instrumentation.mojom.h"
|
| +#include "services/service_manager/public/cpp/connector.h"
|
| +#include "services/service_manager/public/cpp/identity.h"
|
| +#include "services/service_manager/public/interfaces/constants.mojom.h"
|
| +#include "services/service_manager/public/interfaces/service_manager.mojom.h"
|
|
|
| namespace {
|
|
|
| @@ -32,7 +37,8 @@ CoordinatorImpl* CoordinatorImpl::GetInstance() {
|
|
|
| CoordinatorImpl::CoordinatorImpl(bool initialize_memory_dump_manager)
|
| : failed_memory_dump_count_(0),
|
| - initialize_memory_dump_manager_(initialize_memory_dump_manager) {
|
| + initialize_memory_dump_manager_(initialize_memory_dump_manager),
|
| + process_map_(nullptr) {
|
| if (initialize_memory_dump_manager) {
|
| // TODO(primiano): the current state where the coordinator also creates a
|
| // client (ProcessLocalDumpManagerImpl) is contra-intuitive. BrowserMainLoop
|
| @@ -53,7 +59,7 @@ void CoordinatorImpl::BindCoordinatorRequest(
|
| const service_manager::BindSourceInfo& source_info,
|
| mojom::CoordinatorRequest request) {
|
| DCHECK(thread_checker_.CalledOnValidThread());
|
| - bindings_.AddBinding(this, std::move(request));
|
| + bindings_.AddBinding(this, std::move(request), source_info.identity);
|
| }
|
|
|
| CoordinatorImpl::QueuedMemoryDumpRequest::QueuedMemoryDumpRequest(
|
| @@ -107,10 +113,15 @@ void CoordinatorImpl::RegisterProcessLocalDumpManager(
|
| process_manager.set_connection_error_handler(
|
| base::Bind(&CoordinatorImpl::UnregisterProcessLocalDumpManager,
|
| base::Unretained(this), process_manager.get()));
|
| - auto result = process_managers_.insert(
|
| - std::make_pair<mojom::ProcessLocalDumpManager*,
|
| - mojom::ProcessLocalDumpManagerPtr>(
|
| - process_manager.get(), std::move(process_manager)));
|
| + if (!process_map_)
|
| + InitProcessMap();
|
| + DCHECK(process_map_);
|
| + service_manager::Identity identity = bindings_.dispatch_context();
|
| + auto result =
|
| + process_managers_.insert(std::make_pair<mojom::ProcessLocalDumpManager*,
|
| + ProcessLocalDumpManagerEntry>(
|
| + process_manager.get(), std::make_pair(std::move(process_manager),
|
| + bindings_.dispatch_context())));
|
| DCHECK(result.second);
|
| }
|
|
|
| @@ -135,15 +146,15 @@ void CoordinatorImpl::PerformNextQueuedGlobalMemoryDump() {
|
| queued_memory_dump_requests_.front().args;
|
|
|
| // No need to treat the service process different than other processes. The
|
| - // service process will register itself as a ProcessLocalDumpManager and will
|
| - // be treated like other process-local managers.
|
| + // service process will register itself as a ProcessLocalDumpManager and
|
| + // will be treated like other process-local managers.
|
| pending_process_managers_.clear();
|
| failed_memory_dump_count_ = 0;
|
| for (const auto& key_value : process_managers_) {
|
| pending_process_managers_.insert(key_value.first);
|
| auto callback = base::Bind(&CoordinatorImpl::OnProcessMemoryDumpResponse,
|
| base::Unretained(this), key_value.first);
|
| - key_value.second->RequestProcessMemoryDump(args, callback);
|
| + key_value.second.first->RequestProcessMemoryDump(args, callback);
|
| }
|
| // Run the callback in case there are no process-local managers.
|
| FinalizeGlobalMemoryDumpIfAllManagersReplied();
|
| @@ -163,6 +174,14 @@ void CoordinatorImpl::OnProcessMemoryDumpResponse(
|
| return;
|
| }
|
| if (process_memory_dump) {
|
| + // TODO(fmeawad): Debugging code only, the pid should be stored with the
|
| + // process memory dump
|
| + auto it = process_managers_.find(process_manager);
|
| + if (it != process_managers_.end()) {
|
| + base::ProcessId pid = process_map_->GetProcessId(it->second.second);
|
| + fprintf(stderr, "PID: %d\n", pid);
|
| + }
|
| +
|
| queued_memory_dump_requests_.front().process_memory_dumps.push_back(
|
| std::move(process_memory_dump));
|
| }
|
| @@ -207,4 +226,18 @@ void CoordinatorImpl::FinalizeGlobalMemoryDumpIfAllManagersReplied() {
|
| }
|
| }
|
|
|
| +void CoordinatorImpl::InitProcessMap() {
|
| + content::ServiceManagerConnection* service_manager_connection =
|
| + content::ServiceManagerConnection::GetForProcess();
|
| + DCHECK(service_manager_connection);
|
| + service_manager::mojom::ServiceManagerPtr service_manager;
|
| + content::ServiceManagerConnection::GetForProcess()
|
| + ->GetConnector()
|
| + ->BindInterface(service_manager::mojom::kServiceName, &service_manager);
|
| + service_manager::mojom::ServiceManagerListenerPtr listener;
|
| + service_manager::mojom::ServiceManagerListenerRequest request(&listener);
|
| + service_manager->AddListener(std::move(listener));
|
| + process_map_.reset(new ProcessMap(std::move(request)));
|
| +}
|
| +
|
| } // namespace memory_instrumentation
|
|
|