Commit 0cd3cf9a authored by Henrique Ferreiro's avatar Henrique Ferreiro Committed by Commit Bot

Migrate discards.mojom to the new Mojo types

Convert the implementation and all users of the
discards::mojom::DetailsProvider, GraphChangeStream and GraphDump
interfaces.

Bug: 955171
Change-Id: I907a35b6175b6c0b8bf45fab141d58fa2ae6baeb
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1805666
Commit-Queue: Henrique Ferreiro <hferreiro@igalia.com>
Reviewed-by: default avatarOksana Zhuravlova <oksamyt@chromium.org>
Reviewed-by: default avatarSigurður Ásgeirsson <siggi@chromium.org>
Reviewed-by: default avatarEmily Stark <estark@chromium.org>
Cr-Commit-Position: refs/heads/master@{#698457}
parent b8078a49
...@@ -246,5 +246,5 @@ interface GraphChangeStream { ...@@ -246,5 +246,5 @@ interface GraphChangeStream {
// of the performance manager graph. // of the performance manager graph.
interface GraphDump { interface GraphDump {
// Subscribes |change_subscriber| to a graph change stream. // Subscribes |change_subscriber| to a graph change stream.
SubscribeToChanges(GraphChangeStream change_subscriber); SubscribeToChanges(pending_remote<GraphChangeStream> change_subscriber);
}; };
...@@ -38,7 +38,8 @@ ...@@ -38,7 +38,8 @@
#include "content/public/browser/web_ui.h" #include "content/public/browser/web_ui.h"
#include "content/public/browser/web_ui_data_source.h" #include "content/public/browser/web_ui_data_source.h"
#include "content/public/browser/web_ui_message_handler.h" #include "content/public/browser/web_ui_message_handler.h"
#include "mojo/public/cpp/bindings/binding.h" #include "mojo/public/cpp/bindings/pending_receiver.h"
#include "mojo/public/cpp/bindings/receiver.h"
#include "ui/resources/grit/ui_resources.h" #include "ui/resources/grit/ui_resources.h"
#include "url/gurl.h" #include "url/gurl.h"
#include "url/origin.h" #include "url/origin.h"
...@@ -167,9 +168,9 @@ class DiscardsDetailsProviderImpl : public discards::mojom::DetailsProvider { ...@@ -167,9 +168,9 @@ class DiscardsDetailsProviderImpl : public discards::mojom::DetailsProvider {
DiscardsDetailsProviderImpl( DiscardsDetailsProviderImpl(
resource_coordinator::LocalSiteCharacteristicsDataStoreInspector* resource_coordinator::LocalSiteCharacteristicsDataStoreInspector*
data_store_inspector, data_store_inspector,
mojo::InterfaceRequest<discards::mojom::DetailsProvider> request) mojo::PendingReceiver<discards::mojom::DetailsProvider> receiver)
: data_store_inspector_(data_store_inspector), : data_store_inspector_(data_store_inspector),
binding_(this, std::move(request)) {} receiver_(this, std::move(receiver)) {}
~DiscardsDetailsProviderImpl() override {} ~DiscardsDetailsProviderImpl() override {}
...@@ -309,7 +310,7 @@ class DiscardsDetailsProviderImpl : public discards::mojom::DetailsProvider { ...@@ -309,7 +310,7 @@ class DiscardsDetailsProviderImpl : public discards::mojom::DetailsProvider {
OriginToReaderMap requested_origins_; OriginToReaderMap requested_origins_;
LocalSiteCharacteristicsDataStoreInspector* data_store_inspector_; LocalSiteCharacteristicsDataStoreInspector* data_store_inspector_;
mojo::Binding<discards::mojom::DetailsProvider> binding_; mojo::Receiver<discards::mojom::DetailsProvider> receiver_;
DISALLOW_COPY_AND_ASSIGN(DiscardsDetailsProviderImpl); DISALLOW_COPY_AND_ASSIGN(DiscardsDetailsProviderImpl);
}; };
...@@ -453,17 +454,17 @@ DiscardsUI::DiscardsUI(content::WebUI* web_ui) ...@@ -453,17 +454,17 @@ DiscardsUI::DiscardsUI(content::WebUI* web_ui)
DiscardsUI::~DiscardsUI() {} DiscardsUI::~DiscardsUI() {}
void DiscardsUI::BindDiscardsDetailsProvider( void DiscardsUI::BindDiscardsDetailsProvider(
discards::mojom::DetailsProviderRequest request) { mojo::PendingReceiver<discards::mojom::DetailsProvider> receiver) {
ui_handler_ = std::make_unique<DiscardsDetailsProviderImpl>( ui_handler_ = std::make_unique<DiscardsDetailsProviderImpl>(
data_store_inspector_, std::move(request)); data_store_inspector_, std::move(receiver));
} }
void DiscardsUI::BindDiscardsGraphDumpProvider( void DiscardsUI::BindDiscardsGraphDumpProvider(
discards::mojom::GraphDumpRequest request) { mojo::PendingReceiver<discards::mojom::GraphDump> receiver) {
if (performance_manager::PerformanceManager::IsAvailable()) { if (performance_manager::PerformanceManager::IsAvailable()) {
// Forward the interface request directly to the service. // Forward the interface receiver directly to the service.
performance_manager::PerformanceManager::CallOnGraph( performance_manager::PerformanceManager::CallOnGraph(
FROM_HERE, base::BindOnce(&DiscardsGraphDumpImpl::CreateAndBind, FROM_HERE, base::BindOnce(&DiscardsGraphDumpImpl::CreateAndBind,
std::move(request))); std::move(receiver)));
} }
} }
...@@ -9,6 +9,7 @@ ...@@ -9,6 +9,7 @@
#include "base/macros.h" #include "base/macros.h"
#include "chrome/browser/ui/webui/discards/discards.mojom.h" #include "chrome/browser/ui/webui/discards/discards.mojom.h"
#include "mojo/public/cpp/bindings/pending_receiver.h"
#include "ui/webui/mojo_web_ui_controller.h" #include "ui/webui/mojo_web_ui_controller.h"
namespace resource_coordinator { namespace resource_coordinator {
...@@ -24,8 +25,9 @@ class DiscardsUI : public ui::MojoWebUIController { ...@@ -24,8 +25,9 @@ class DiscardsUI : public ui::MojoWebUIController {
private: private:
void BindDiscardsDetailsProvider( void BindDiscardsDetailsProvider(
discards::mojom::DetailsProviderRequest request); mojo::PendingReceiver<discards::mojom::DetailsProvider> receiver);
void BindDiscardsGraphDumpProvider(discards::mojom::GraphDumpRequest request); void BindDiscardsGraphDumpProvider(
mojo::PendingReceiver<discards::mojom::GraphDump> receiver);
std::unique_ptr<discards::mojom::DetailsProvider> ui_handler_; std::unique_ptr<discards::mojom::DetailsProvider> ui_handler_;
resource_coordinator::LocalSiteCharacteristicsDataStoreInspector* resource_coordinator::LocalSiteCharacteristicsDataStoreInspector*
......
...@@ -18,11 +18,16 @@ ...@@ -18,11 +18,16 @@
#include "chrome/browser/performance_manager/public/performance_manager.h" #include "chrome/browser/performance_manager/public/performance_manager.h"
#include "chrome/browser/performance_manager/public/web_contents_proxy.h" #include "chrome/browser/performance_manager/public/web_contents_proxy.h"
#include "chrome/browser/profiles/profile.h" #include "chrome/browser/profiles/profile.h"
#include "chrome/browser/ui/webui/discards/discards.mojom.h"
#include "components/favicon/core/favicon_service.h" #include "components/favicon/core/favicon_service.h"
#include "components/favicon_base/favicon_callback.h" #include "components/favicon_base/favicon_callback.h"
#include "content/public/browser/browser_task_traits.h" #include "content/public/browser/browser_task_traits.h"
#include "content/public/browser/browser_thread.h" #include "content/public/browser/browser_thread.h"
#include "content/public/browser/web_contents.h" #include "content/public/browser/web_contents.h"
#include "mojo/public/cpp/bindings/pending_receiver.h"
#include "mojo/public/cpp/bindings/pending_remote.h"
#include "mojo/public/cpp/bindings/receiver.h"
#include "mojo/public/cpp/bindings/remote.h"
namespace { namespace {
...@@ -108,7 +113,7 @@ void DiscardsGraphDumpImpl::FaviconRequestHelper::FaviconDataAvailable( ...@@ -108,7 +113,7 @@ void DiscardsGraphDumpImpl::FaviconRequestHelper::FaviconDataAvailable(
graph_dump_, serialization_id, result.bitmap_data)); graph_dump_, serialization_id, result.bitmap_data));
} }
DiscardsGraphDumpImpl::DiscardsGraphDumpImpl() : binding_(this) {} DiscardsGraphDumpImpl::DiscardsGraphDumpImpl() {}
DiscardsGraphDumpImpl::~DiscardsGraphDumpImpl() { DiscardsGraphDumpImpl::~DiscardsGraphDumpImpl() {
DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_); DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_);
...@@ -119,20 +124,20 @@ DiscardsGraphDumpImpl::~DiscardsGraphDumpImpl() { ...@@ -119,20 +124,20 @@ DiscardsGraphDumpImpl::~DiscardsGraphDumpImpl() {
// static // static
void DiscardsGraphDumpImpl::CreateAndBind( void DiscardsGraphDumpImpl::CreateAndBind(
discards::mojom::GraphDumpRequest request, mojo::PendingReceiver<discards::mojom::GraphDump> receiver,
performance_manager::Graph* graph) { performance_manager::Graph* graph) {
std::unique_ptr<DiscardsGraphDumpImpl> dump = std::unique_ptr<DiscardsGraphDumpImpl> dump =
std::make_unique<DiscardsGraphDumpImpl>(); std::make_unique<DiscardsGraphDumpImpl>();
dump->BindWithGraph(graph, std::move(request)); dump->BindWithGraph(graph, std::move(receiver));
graph->PassToGraph(std::move(dump)); graph->PassToGraph(std::move(dump));
} }
void DiscardsGraphDumpImpl::BindWithGraph( void DiscardsGraphDumpImpl::BindWithGraph(
performance_manager::Graph* graph, performance_manager::Graph* graph,
discards::mojom::GraphDumpRequest request) { mojo::PendingReceiver<discards::mojom::GraphDump> receiver) {
binding_.Bind(std::move(request)); receiver_.Bind(std::move(receiver));
binding_.set_connection_error_handler(base::BindOnce( receiver_.set_disconnect_handler(base::BindOnce(
&DiscardsGraphDumpImpl::OnConnectionError, base::Unretained(this))); &DiscardsGraphDumpImpl::OnConnectionError, base::Unretained(this)));
} }
...@@ -151,9 +156,9 @@ void ForFrameAndOffspring(const performance_manager::FrameNode* parent_frame, ...@@ -151,9 +156,9 @@ void ForFrameAndOffspring(const performance_manager::FrameNode* parent_frame,
} // namespace } // namespace
void DiscardsGraphDumpImpl::SubscribeToChanges( void DiscardsGraphDumpImpl::SubscribeToChanges(
discards::mojom::GraphChangeStreamPtr change_subscriber) { mojo::PendingRemote<discards::mojom::GraphChangeStream> change_subscriber) {
DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_); DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_);
change_subscriber_ = std::move(change_subscriber); change_subscriber_.Bind(std::move(change_subscriber));
// Send creation notifications for all existing nodes. // Send creation notifications for all existing nodes.
for (const performance_manager::ProcessNode* process_node : for (const performance_manager::ProcessNode* process_node :
......
...@@ -15,7 +15,10 @@ ...@@ -15,7 +15,10 @@
#include "chrome/browser/performance_manager/public/graph/page_node.h" #include "chrome/browser/performance_manager/public/graph/page_node.h"
#include "chrome/browser/performance_manager/public/graph/process_node.h" #include "chrome/browser/performance_manager/public/graph/process_node.h"
#include "chrome/browser/ui/webui/discards/discards.mojom.h" #include "chrome/browser/ui/webui/discards/discards.mojom.h"
#include "mojo/public/cpp/bindings/binding.h" #include "mojo/public/cpp/bindings/pending_receiver.h"
#include "mojo/public/cpp/bindings/pending_remote.h"
#include "mojo/public/cpp/bindings/receiver.h"
#include "mojo/public/cpp/bindings/remote.h"
// TODO(siggi): Add workers to the WebUI graph. // TODO(siggi): Add workers to the WebUI graph.
class DiscardsGraphDumpImpl : public discards::mojom::GraphDump, class DiscardsGraphDumpImpl : public discards::mojom::GraphDump,
...@@ -27,19 +30,22 @@ class DiscardsGraphDumpImpl : public discards::mojom::GraphDump, ...@@ -27,19 +30,22 @@ class DiscardsGraphDumpImpl : public discards::mojom::GraphDump,
DiscardsGraphDumpImpl(); DiscardsGraphDumpImpl();
~DiscardsGraphDumpImpl() override; ~DiscardsGraphDumpImpl() override;
// Creates a new DiscardsGraphDumpImpl to service |request| and passes its // Creates a new DiscardsGraphDumpImpl to service |receiver| and passes its
// ownership to |graph|. // ownership to |graph|.
static void CreateAndBind(discards::mojom::GraphDumpRequest request, static void CreateAndBind(
mojo::PendingReceiver<discards::mojom::GraphDump> receiver,
performance_manager::Graph* graph); performance_manager::Graph* graph);
// Exposed for testing. // Exposed for testing.
void BindWithGraph(performance_manager::Graph* graph, void BindWithGraph(
discards::mojom::GraphDumpRequest request); performance_manager::Graph* graph,
mojo::PendingReceiver<discards::mojom::GraphDump> receiver);
protected: protected:
// WebUIGraphDump implementation. // WebUIGraphDump implementation.
void SubscribeToChanges( void SubscribeToChanges(
discards::mojom::GraphChangeStreamPtr change_subscriber) override; mojo::PendingRemote<discards::mojom::GraphChangeStream> change_subscriber)
override;
// GraphOwned implementation. // GraphOwned implementation.
void OnPassedToGraph(performance_manager::Graph* graph) override; void OnPassedToGraph(performance_manager::Graph* graph) override;
...@@ -141,7 +147,8 @@ class DiscardsGraphDumpImpl : public discards::mojom::GraphDump, ...@@ -141,7 +147,8 @@ class DiscardsGraphDumpImpl : public discards::mojom::GraphDump,
int64_t serialization_id, int64_t serialization_id,
scoped_refptr<base::RefCountedMemory> bitmap_data); scoped_refptr<base::RefCountedMemory> bitmap_data);
static void BindOnPMSequence(discards::mojom::GraphDumpRequest request, static void BindOnPMSequence(
mojo::PendingReceiver<discards::mojom::GraphDump> receiver,
performance_manager::Graph* graph); performance_manager::Graph* graph);
static void OnConnectionError(DiscardsGraphDumpImpl* impl); static void OnConnectionError(DiscardsGraphDumpImpl* impl);
...@@ -152,8 +159,8 @@ class DiscardsGraphDumpImpl : public discards::mojom::GraphDump, ...@@ -152,8 +159,8 @@ class DiscardsGraphDumpImpl : public discards::mojom::GraphDump,
// The current change subscriber to this dumper. This instance is subscribed // The current change subscriber to this dumper. This instance is subscribed
// to every node in |graph_| save for the system node, so long as there is a // to every node in |graph_| save for the system node, so long as there is a
// subscriber. // subscriber.
discards::mojom::GraphChangeStreamPtr change_subscriber_; mojo::Remote<discards::mojom::GraphChangeStream> change_subscriber_;
mojo::Binding<discards::mojom::GraphDump> binding_; mojo::Receiver<discards::mojom::GraphDump> receiver_{this};
SEQUENCE_CHECKER(sequence_checker_); SEQUENCE_CHECKER(sequence_checker_);
......
...@@ -6,6 +6,7 @@ ...@@ -6,6 +6,7 @@
#include <map> #include <map>
#include <set> #include <set>
#include <utility>
#include "base/run_loop.h" #include "base/run_loop.h"
#include "base/stl_util.h" #include "base/stl_util.h"
...@@ -13,8 +14,12 @@ ...@@ -13,8 +14,12 @@
#include "base/time/time.h" #include "base/time/time.h"
#include "chrome/browser/performance_manager/test_support/graph_impl.h" #include "chrome/browser/performance_manager/test_support/graph_impl.h"
#include "chrome/browser/performance_manager/test_support/mock_graphs.h" #include "chrome/browser/performance_manager/test_support/mock_graphs.h"
#include "chrome/browser/ui/webui/discards/discards.mojom.h"
#include "content/public/test/browser_task_environment.h" #include "content/public/test/browser_task_environment.h"
#include "mojo/public/cpp/bindings/interface_request.h" #include "mojo/public/cpp/bindings/interface_request.h"
#include "mojo/public/cpp/bindings/pending_remote.h"
#include "mojo/public/cpp/bindings/receiver.h"
#include "mojo/public/cpp/bindings/remote.h"
#include "testing/gtest/include/gtest/gtest.h" #include "testing/gtest/include/gtest/gtest.h"
namespace { namespace {
...@@ -28,14 +33,14 @@ class TestChangeStream : public discards::mojom::GraphChangeStream { ...@@ -28,14 +33,14 @@ class TestChangeStream : public discards::mojom::GraphChangeStream {
using ProcessMap = std::map<int64_t, discards::mojom::ProcessInfoPtr>; using ProcessMap = std::map<int64_t, discards::mojom::ProcessInfoPtr>;
using IdSet = std::set<int64_t>; using IdSet = std::set<int64_t>;
TestChangeStream() : binding_(this) {} TestChangeStream() {}
discards::mojom::GraphChangeStreamPtr GetProxy() { mojo::PendingRemote<discards::mojom::GraphChangeStream> GetRemote() {
discards::mojom::GraphChangeStreamPtr proxy; mojo::PendingRemote<discards::mojom::GraphChangeStream> remote;
binding_.Bind(mojo::MakeRequest(&proxy)); receiver_.Bind(remote.InitWithNewPipeAndPassReceiver());
return proxy; return remote;
} }
// discards::mojom::GraphChangeStream implementation // discards::mojom::GraphChangeStream implementation
...@@ -106,7 +111,7 @@ class TestChangeStream : public discards::mojom::GraphChangeStream { ...@@ -106,7 +111,7 @@ class TestChangeStream : public discards::mojom::GraphChangeStream {
IdSet id_set_; IdSet id_set_;
size_t num_changes_ = 0; size_t num_changes_ = 0;
mojo::Binding<discards::mojom::GraphChangeStream> binding_; mojo::Receiver<discards::mojom::GraphChangeStream> receiver_{this};
}; };
class DiscardsGraphDumpImplTest : public testing::Test { class DiscardsGraphDumpImplTest : public testing::Test {
...@@ -137,13 +142,13 @@ TEST_F(DiscardsGraphDumpImplTest, ChangeStream) { ...@@ -137,13 +142,13 @@ TEST_F(DiscardsGraphDumpImplTest, ChangeStream) {
std::unique_ptr<DiscardsGraphDumpImpl> impl = std::unique_ptr<DiscardsGraphDumpImpl> impl =
std::make_unique<DiscardsGraphDumpImpl>(); std::make_unique<DiscardsGraphDumpImpl>();
DiscardsGraphDumpImpl* impl_raw = impl.get(); DiscardsGraphDumpImpl* impl_raw = impl.get();
// Create a mojo proxy to the impl. // Create a mojo remote to the impl.
discards::mojom::GraphDumpPtr impl_proxy; mojo::Remote<discards::mojom::GraphDump> graph_dump_remote;
impl->BindWithGraph(&graph_, mojo::MakeRequest(&impl_proxy)); impl->BindWithGraph(&graph_, graph_dump_remote.BindNewPipeAndPassReceiver());
graph_.PassToGraph(std::move(impl)); graph_.PassToGraph(std::move(impl));
TestChangeStream change_stream; TestChangeStream change_stream;
impl_proxy->SubscribeToChanges(change_stream.GetProxy()); graph_dump_remote->SubscribeToChanges(change_stream.GetRemote());
task_environment.RunUntilIdle(); task_environment.RunUntilIdle();
...@@ -207,7 +212,7 @@ TEST_F(DiscardsGraphDumpImplTest, ChangeStream) { ...@@ -207,7 +212,7 @@ TEST_F(DiscardsGraphDumpImplTest, ChangeStream) {
task_environment.RunUntilIdle(); task_environment.RunUntilIdle();
// Make sure the Dump impl is torn down when the proxy closes. // Make sure the Dump impl is torn down when the proxy closes.
impl_proxy.reset(); graph_dump_remote.reset();
task_environment.RunUntilIdle(); task_environment.RunUntilIdle();
EXPECT_EQ(nullptr, graph_.TakeFromGraph(impl_raw)); EXPECT_EQ(nullptr, graph_.TakeFromGraph(impl_raw));
......
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