Commit e91fd9b9 authored by Julie Jeongeun Kim's avatar Julie Jeongeun Kim Committed by Commit Bot

Convert CallStackProfileCollector to new Mojo types

This CL converts CallStackProfileCollectorPtr and
CallStackProfileCollectorRequest to new Mojo types.

It uses Remote, PendingReceiver, and Receiver instead of
CallStackProfileCollectorPtr, CallStackProfileCollectorRequest,
and binding.

Bug: 955171
Change-Id: Iafc17945a133946713e11359ee806e0bfb184ec8
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1810174Reviewed-by: default avatarOksana Zhuravlova <oksamyt@chromium.org>
Reviewed-by: default avatarDavid Roger <droger@chromium.org>
Reviewed-by: default avatarSteven Holte <holte@chromium.org>
Commit-Queue: Julie Kim <jkim@igalia.com>
Cr-Commit-Position: refs/heads/master@{#699168}
parent 2d051b8e
......@@ -205,7 +205,7 @@ void ThreadProfiler::SetCollectorForChildProcess(
DCHECK_NE(CallStackProfileParams::BROWSER_PROCESS, GetProcess());
CallStackProfileBuilder::SetParentProfileCollectorForChildProcess(
metrics::mojom::CallStackProfileCollectorPtr(std::move(collector)));
std::move(collector));
}
// ThreadProfiler implementation synopsis:
......
......@@ -242,7 +242,8 @@ void CallStackProfileBuilder::SetBrowserProcessReceiverCallback(
// static
void CallStackProfileBuilder::SetParentProfileCollectorForChildProcess(
metrics::mojom::CallStackProfileCollectorPtr browser_interface) {
mojo::PendingRemote<metrics::mojom::CallStackProfileCollector>
browser_interface) {
g_child_call_stack_profile_collector.Get().SetParentProfileCollector(
std::move(browser_interface));
}
......
......@@ -19,6 +19,7 @@
#include "base/time/time.h"
#include "components/metrics/call_stack_profile_params.h"
#include "components/metrics/child_call_stack_profile_collector.h"
#include "mojo/public/cpp/bindings/pending_remote.h"
#include "third_party/metrics_proto/sampled_profile.pb.h"
namespace metrics {
......@@ -84,7 +85,8 @@ class CallStackProfileBuilder : public base::ProfileBuilder {
// Sets the CallStackProfileCollector interface from |browser_interface|.
// This function must be called within child processes.
static void SetParentProfileCollectorForChildProcess(
metrics::mojom::CallStackProfileCollectorPtr browser_interface);
mojo::PendingRemote<metrics::mojom::CallStackProfileCollector>
browser_interface);
protected:
// Test seam.
......
......@@ -9,7 +9,7 @@
#include "components/metrics/call_stack_profile_encoding.h"
#include "components/metrics/call_stack_profile_metrics_provider.h"
#include "mojo/public/cpp/bindings/strong_binding.h"
#include "mojo/public/cpp/bindings/self_owned_receiver.h"
namespace metrics {
......@@ -19,9 +19,9 @@ CallStackProfileCollector::~CallStackProfileCollector() = default;
// static
void CallStackProfileCollector::Create(
mojom::CallStackProfileCollectorRequest request) {
mojo::MakeStrongBinding(std::make_unique<CallStackProfileCollector>(),
std::move(request));
mojo::PendingReceiver<mojom::CallStackProfileCollector> receiver) {
mojo::MakeSelfOwnedReceiver(std::make_unique<CallStackProfileCollector>(),
std::move(receiver));
}
void CallStackProfileCollector::Collect(base::TimeTicks start_timestamp,
......
......@@ -7,6 +7,7 @@
#include "base/macros.h"
#include "components/metrics/public/mojom/call_stack_profile_collector.mojom.h"
#include "mojo/public/cpp/bindings/pending_receiver.h"
namespace metrics {
......@@ -16,7 +17,8 @@ class CallStackProfileCollector : public mojom::CallStackProfileCollector {
~CallStackProfileCollector() override;
// Create a collector to receive profiles from |expected_process|.
static void Create(mojom::CallStackProfileCollectorRequest request);
static void Create(
mojo::PendingReceiver<mojom::CallStackProfileCollector> receiver);
// mojom::CallStackProfileCollector:
void Collect(base::TimeTicks start_timestamp,
......
......@@ -36,7 +36,8 @@ ChildCallStackProfileCollector::ChildCallStackProfileCollector() {}
ChildCallStackProfileCollector::~ChildCallStackProfileCollector() {}
void ChildCallStackProfileCollector::SetParentProfileCollector(
metrics::mojom::CallStackProfileCollectorPtr parent_collector) {
mojo::PendingRemote<metrics::mojom::CallStackProfileCollector>
parent_collector) {
base::AutoLock alock(lock_);
// This function should only invoked once, during the mode of operation when
// retaining profiles after construction.
......@@ -45,13 +46,17 @@ void ChildCallStackProfileCollector::SetParentProfileCollector(
task_runner_ = base::ThreadTaskRunnerHandle::Get();
// This should only be set one time per child process.
DCHECK(!parent_collector_);
parent_collector_ = std::move(parent_collector);
if (parent_collector_) {
for (ProfileState& state : profiles_) {
mojom::SampledProfilePtr mojo_profile = mojom::SampledProfile::New();
mojo_profile->contents = std::move(state.profile);
parent_collector_->Collect(state.start_timestamp,
std::move(mojo_profile));
// If |parent_collector| is mojo::NullRemote(), it skips Bind since
// mojo::Remote doesn't allow Bind with mojo::NullRemote().
if (parent_collector) {
parent_collector_.Bind(std::move(parent_collector));
if (parent_collector_) {
for (ProfileState& state : profiles_) {
mojom::SampledProfilePtr mojo_profile = mojom::SampledProfile::New();
mojo_profile->contents = std::move(state.profile);
parent_collector_->Collect(state.start_timestamp,
std::move(mojo_profile));
}
}
}
profiles_.clear();
......
......@@ -13,6 +13,8 @@
#include "base/single_thread_task_runner.h"
#include "base/synchronization/lock.h"
#include "components/metrics/public/mojom/call_stack_profile_collector.mojom.h"
#include "mojo/public/cpp/bindings/pending_remote.h"
#include "mojo/public/cpp/bindings/remote.h"
namespace service_manager {
class InterfaceProvider;
......@@ -55,9 +57,11 @@ class ChildCallStackProfileCollector {
// Sets the CallStackProfileCollector interface from |parent_collector|. This
// function MUST be invoked exactly once, regardless of whether
// |parent_collector| is null, as it flushes pending data in either case.
// |parent_collector| is mojo::NullRemote(), as it flushes pending data in
// either case.
void SetParentProfileCollector(
metrics::mojom::CallStackProfileCollectorPtr parent_collector);
mojo::PendingRemote<metrics::mojom::CallStackProfileCollector>
parent_collector);
// Collects |profile| whose collection start time is |start_timestamp|.
void Collect(base::TimeTicks start_timestamp, SampledProfile profile);
......@@ -101,10 +105,11 @@ class ChildCallStackProfileCollector {
scoped_refptr<base::SingleThreadTaskRunner> task_runner_;
// The interface to use to collect the stack profiles provided to this
// object. Initially null until SetParentProfileCollector() is invoked, at
// which point it may either become set or remain null. If set, stacks are
// collected via the interface, otherwise they are ignored.
mojom::CallStackProfileCollectorPtr parent_collector_;
// object. Initially mojo::NullRemote() until SetParentProfileCollector() is
// invoked, at which point it may either become set or remain
// mojo::NullRemote(). If set, stacks are collected via the interface,
// otherwise they are ignored.
mojo::Remote<mojom::CallStackProfileCollector> parent_collector_;
// Profiles being cached by this object, pending a parent interface to be
// supplied.
......
......@@ -11,7 +11,8 @@
#include "base/bind.h"
#include "base/run_loop.h"
#include "base/test/task_environment.h"
#include "mojo/public/cpp/bindings/binding.h"
#include "mojo/public/cpp/bindings/pending_receiver.h"
#include "mojo/public/cpp/bindings/receiver.h"
#include "testing/gtest/include/gtest/gtest.h"
#include "third_party/metrics_proto/sampled_profile.pb.h"
......@@ -21,8 +22,9 @@ class ChildCallStackProfileCollectorTest : public testing::Test {
protected:
class Receiver : public mojom::CallStackProfileCollector {
public:
explicit Receiver(mojom::CallStackProfileCollectorRequest request)
: binding_(this, std::move(request)) {}
explicit Receiver(
mojo::PendingReceiver<mojom::CallStackProfileCollector> receiver)
: receiver_(this, std::move(receiver)) {}
~Receiver() override {}
void Collect(base::TimeTicks start_timestamp,
......@@ -33,13 +35,14 @@ class ChildCallStackProfileCollectorTest : public testing::Test {
std::vector<base::TimeTicks> profile_start_times;
private:
mojo::Binding<mojom::CallStackProfileCollector> binding_;
mojo::Receiver<mojom::CallStackProfileCollector> receiver_;
DISALLOW_COPY_AND_ASSIGN(Receiver);
};
ChildCallStackProfileCollectorTest()
: receiver_impl_(new Receiver(MakeRequest(&receiver_))) {}
: receiver_impl_(
new Receiver(collector_remote_.InitWithNewPipeAndPassReceiver())) {}
void CollectEmptyProfile() {
child_collector_.Collect(base::TimeTicks::Now(), SampledProfile());
......@@ -51,7 +54,7 @@ class ChildCallStackProfileCollectorTest : public testing::Test {
}
base::test::SingleThreadTaskEnvironment task_environment_;
mojom::CallStackProfileCollectorPtr receiver_;
mojo::PendingRemote<mojom::CallStackProfileCollector> collector_remote_;
std::unique_ptr<Receiver> receiver_impl_;
ChildCallStackProfileCollector child_collector_;
......@@ -71,7 +74,7 @@ TEST_F(ChildCallStackProfileCollectorTest, InterfaceProvided) {
base::TimeTicks::Now() - start_timestamp);
// Set the interface. The profiles should be passed to it.
child_collector_.SetParentProfileCollector(std::move(receiver_));
child_collector_.SetParentProfileCollector(std::move(collector_remote_));
base::RunLoop().RunUntilIdle();
EXPECT_EQ(0u, profiles().size());
ASSERT_EQ(1u, receiver_impl_->profile_start_times.size());
......@@ -97,8 +100,7 @@ TEST_F(ChildCallStackProfileCollectorTest, InterfaceNotProvided) {
base::TimeTicks::Now() - profiles()[0].start_timestamp);
// Set the null interface. The profile should be flushed.
child_collector_.SetParentProfileCollector(
mojom::CallStackProfileCollectorPtr());
child_collector_.SetParentProfileCollector(mojo::NullRemote());
base::RunLoop().RunUntilIdle();
EXPECT_EQ(0u, profiles().size());
......
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