blob: 6c0dacde26f1ce50b6027437b9f5f2f84c8ad22d [file] [log] [blame]
// Copyright 2017 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#ifndef CHROME_PROFILING_MEMLOG_IMPL_H_
#define CHROME_PROFILING_MEMLOG_IMPL_H_
#include "base/files/file.h"
#include "base/files/platform_file.h"
#include "base/macros.h"
#include "base/memory/weak_ptr.h"
#include "chrome/common/profiling/memlog.mojom.h"
#include "chrome/profiling/memlog_connection_manager.h"
#include "mojo/public/cpp/bindings/binding.h"
#include "services/resource_coordinator/public/interfaces/memory_instrumentation/memory_instrumentation.mojom.h"
#include "services/service_manager/public/cpp/service_context_ref.h"
namespace profiling {
// Represents the profiling process side of the profiling <-> browser
// connection.
//
// This class lives on the main thread.
//
// TODO(ajwong): Why do all these mojo things get spawned on the main thread
// instead of the IO thread?
class MemlogImpl : public mojom::Memlog {
public:
MemlogImpl();
~MemlogImpl() override;
void AddSender(base::ProcessId pid,
mojo::ScopedHandle sender_pipe,
AddSenderCallback callback) override;
void DumpProcess(base::ProcessId pid,
mojo::ScopedHandle output_file) override;
private:
// Helper for managing lifetime of MemlogConnectionManager.
struct DeleteOnRunner {
DeleteOnRunner(const tracked_objects::Location& location,
base::SequencedTaskRunner* runner)
: location(location), runner(runner) {}
void operator()(MemlogConnectionManager* ptr) {
runner->DeleteSoon(location, ptr);
}
const tracked_objects::Location& location;
base::SequencedTaskRunner* runner;
};
void OnGetVmRegionsComplete(
base::ProcessId pid,
base::File file,
bool success,
memory_instrumentation::mojom::GlobalMemoryDumpPtr dump);
scoped_refptr<base::SequencedTaskRunner> io_runner_;
std::unique_ptr<MemlogConnectionManager, DeleteOnRunner> connection_manager_;
// Must be last.
base::WeakPtrFactory<MemlogImpl> weak_factory_;
DISALLOW_COPY_AND_ASSIGN(MemlogImpl);
};
} // namespace profiling
#endif // CHROME_PROFILING_MEMLOG_IMPL_H_