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