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 {
// of the performance manager graph.
interface GraphDump {
// Subscribes |change_subscriber| to a graph change stream.
SubscribeToChanges(GraphChangeStream change_subscriber);
SubscribeToChanges(pending_remote<GraphChangeStream> change_subscriber);
};
......@@ -38,7 +38,8 @@
#include "content/public/browser/web_ui.h"
#include "content/public/browser/web_ui_data_source.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 "url/gurl.h"
#include "url/origin.h"
......@@ -167,9 +168,9 @@ class DiscardsDetailsProviderImpl : public discards::mojom::DetailsProvider {
DiscardsDetailsProviderImpl(
resource_coordinator::LocalSiteCharacteristicsDataStoreInspector*
data_store_inspector,
mojo::InterfaceRequest<discards::mojom::DetailsProvider> request)
mojo::PendingReceiver<discards::mojom::DetailsProvider> receiver)
: data_store_inspector_(data_store_inspector),
binding_(this, std::move(request)) {}
receiver_(this, std::move(receiver)) {}
~DiscardsDetailsProviderImpl() override {}
......@@ -309,7 +310,7 @@ class DiscardsDetailsProviderImpl : public discards::mojom::DetailsProvider {
OriginToReaderMap requested_origins_;
LocalSiteCharacteristicsDataStoreInspector* data_store_inspector_;
mojo::Binding<discards::mojom::DetailsProvider> binding_;
mojo::Receiver<discards::mojom::DetailsProvider> receiver_;
DISALLOW_COPY_AND_ASSIGN(DiscardsDetailsProviderImpl);
};
......@@ -453,17 +454,17 @@ DiscardsUI::DiscardsUI(content::WebUI* web_ui)
DiscardsUI::~DiscardsUI() {}
void DiscardsUI::BindDiscardsDetailsProvider(
discards::mojom::DetailsProviderRequest request) {
mojo::PendingReceiver<discards::mojom::DetailsProvider> receiver) {
ui_handler_ = std::make_unique<DiscardsDetailsProviderImpl>(
data_store_inspector_, std::move(request));
data_store_inspector_, std::move(receiver));
}
void DiscardsUI::BindDiscardsGraphDumpProvider(
discards::mojom::GraphDumpRequest request) {
mojo::PendingReceiver<discards::mojom::GraphDump> receiver) {
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(
FROM_HERE, base::BindOnce(&DiscardsGraphDumpImpl::CreateAndBind,
std::move(request)));
std::move(receiver)));
}
}
......@@ -9,6 +9,7 @@
#include "base/macros.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"
namespace resource_coordinator {
......@@ -24,8 +25,9 @@ class DiscardsUI : public ui::MojoWebUIController {
private:
void BindDiscardsDetailsProvider(
discards::mojom::DetailsProviderRequest request);
void BindDiscardsGraphDumpProvider(discards::mojom::GraphDumpRequest request);
mojo::PendingReceiver<discards::mojom::DetailsProvider> receiver);
void BindDiscardsGraphDumpProvider(
mojo::PendingReceiver<discards::mojom::GraphDump> receiver);
std::unique_ptr<discards::mojom::DetailsProvider> ui_handler_;
resource_coordinator::LocalSiteCharacteristicsDataStoreInspector*
......
......@@ -18,11 +18,16 @@
#include "chrome/browser/performance_manager/public/performance_manager.h"
#include "chrome/browser/performance_manager/public/web_contents_proxy.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_base/favicon_callback.h"
#include "content/public/browser/browser_task_traits.h"
#include "content/public/browser/browser_thread.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 {
......@@ -108,7 +113,7 @@ void DiscardsGraphDumpImpl::FaviconRequestHelper::FaviconDataAvailable(
graph_dump_, serialization_id, result.bitmap_data));
}
DiscardsGraphDumpImpl::DiscardsGraphDumpImpl() : binding_(this) {}
DiscardsGraphDumpImpl::DiscardsGraphDumpImpl() {}
DiscardsGraphDumpImpl::~DiscardsGraphDumpImpl() {
DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_);
......@@ -119,20 +124,20 @@ DiscardsGraphDumpImpl::~DiscardsGraphDumpImpl() {
// static
void DiscardsGraphDumpImpl::CreateAndBind(
discards::mojom::GraphDumpRequest request,
mojo::PendingReceiver<discards::mojom::GraphDump> receiver,
performance_manager::Graph* graph) {
std::unique_ptr<DiscardsGraphDumpImpl> dump =
std::make_unique<DiscardsGraphDumpImpl>();
dump->BindWithGraph(graph, std::move(request));
dump->BindWithGraph(graph, std::move(receiver));
graph->PassToGraph(std::move(dump));
}
void DiscardsGraphDumpImpl::BindWithGraph(
performance_manager::Graph* graph,
discards::mojom::GraphDumpRequest request) {
binding_.Bind(std::move(request));
binding_.set_connection_error_handler(base::BindOnce(
mojo::PendingReceiver<discards::mojom::GraphDump> receiver) {
receiver_.Bind(std::move(receiver));
receiver_.set_disconnect_handler(base::BindOnce(
&DiscardsGraphDumpImpl::OnConnectionError, base::Unretained(this)));
}
......@@ -151,9 +156,9 @@ void ForFrameAndOffspring(const performance_manager::FrameNode* parent_frame,
} // namespace
void DiscardsGraphDumpImpl::SubscribeToChanges(
discards::mojom::GraphChangeStreamPtr change_subscriber) {
mojo::PendingRemote<discards::mojom::GraphChangeStream> change_subscriber) {
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.
for (const performance_manager::ProcessNode* process_node :
......
......@@ -15,7 +15,10 @@
#include "chrome/browser/performance_manager/public/graph/page_node.h"
#include "chrome/browser/performance_manager/public/graph/process_node.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.
class DiscardsGraphDumpImpl : public discards::mojom::GraphDump,
......@@ -27,19 +30,22 @@ class DiscardsGraphDumpImpl : public discards::mojom::GraphDump,
DiscardsGraphDumpImpl();
~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|.
static void CreateAndBind(discards::mojom::GraphDumpRequest request,
performance_manager::Graph* graph);
static void CreateAndBind(
mojo::PendingReceiver<discards::mojom::GraphDump> receiver,
performance_manager::Graph* graph);
// Exposed for testing.
void BindWithGraph(performance_manager::Graph* graph,
discards::mojom::GraphDumpRequest request);
void BindWithGraph(
performance_manager::Graph* graph,
mojo::PendingReceiver<discards::mojom::GraphDump> receiver);
protected:
// WebUIGraphDump implementation.
void SubscribeToChanges(
discards::mojom::GraphChangeStreamPtr change_subscriber) override;
mojo::PendingRemote<discards::mojom::GraphChangeStream> change_subscriber)
override;
// GraphOwned implementation.
void OnPassedToGraph(performance_manager::Graph* graph) override;
......@@ -141,8 +147,9 @@ class DiscardsGraphDumpImpl : public discards::mojom::GraphDump,
int64_t serialization_id,
scoped_refptr<base::RefCountedMemory> bitmap_data);
static void BindOnPMSequence(discards::mojom::GraphDumpRequest request,
performance_manager::Graph* graph);
static void BindOnPMSequence(
mojo::PendingReceiver<discards::mojom::GraphDump> receiver,
performance_manager::Graph* graph);
static void OnConnectionError(DiscardsGraphDumpImpl* impl);
performance_manager::Graph* graph_ = nullptr;
......@@ -152,8 +159,8 @@ class DiscardsGraphDumpImpl : public discards::mojom::GraphDump,
// 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
// subscriber.
discards::mojom::GraphChangeStreamPtr change_subscriber_;
mojo::Binding<discards::mojom::GraphDump> binding_;
mojo::Remote<discards::mojom::GraphChangeStream> change_subscriber_;
mojo::Receiver<discards::mojom::GraphDump> receiver_{this};
SEQUENCE_CHECKER(sequence_checker_);
......
......@@ -6,6 +6,7 @@
#include <map>
#include <set>
#include <utility>
#include "base/run_loop.h"
#include "base/stl_util.h"
......@@ -13,8 +14,12 @@
#include "base/time/time.h"
#include "chrome/browser/performance_manager/test_support/graph_impl.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 "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"
namespace {
......@@ -28,14 +33,14 @@ class TestChangeStream : public discards::mojom::GraphChangeStream {
using ProcessMap = std::map<int64_t, discards::mojom::ProcessInfoPtr>;
using IdSet = std::set<int64_t>;
TestChangeStream() : binding_(this) {}
TestChangeStream() {}
discards::mojom::GraphChangeStreamPtr GetProxy() {
discards::mojom::GraphChangeStreamPtr proxy;
mojo::PendingRemote<discards::mojom::GraphChangeStream> GetRemote() {
mojo::PendingRemote<discards::mojom::GraphChangeStream> remote;
binding_.Bind(mojo::MakeRequest(&proxy));
receiver_.Bind(remote.InitWithNewPipeAndPassReceiver());
return proxy;
return remote;
}
// discards::mojom::GraphChangeStream implementation
......@@ -106,7 +111,7 @@ class TestChangeStream : public discards::mojom::GraphChangeStream {
IdSet id_set_;
size_t num_changes_ = 0;
mojo::Binding<discards::mojom::GraphChangeStream> binding_;
mojo::Receiver<discards::mojom::GraphChangeStream> receiver_{this};
};
class DiscardsGraphDumpImplTest : public testing::Test {
......@@ -137,13 +142,13 @@ TEST_F(DiscardsGraphDumpImplTest, ChangeStream) {
std::unique_ptr<DiscardsGraphDumpImpl> impl =
std::make_unique<DiscardsGraphDumpImpl>();
DiscardsGraphDumpImpl* impl_raw = impl.get();
// Create a mojo proxy to the impl.
discards::mojom::GraphDumpPtr impl_proxy;
impl->BindWithGraph(&graph_, mojo::MakeRequest(&impl_proxy));
// Create a mojo remote to the impl.
mojo::Remote<discards::mojom::GraphDump> graph_dump_remote;
impl->BindWithGraph(&graph_, graph_dump_remote.BindNewPipeAndPassReceiver());
graph_.PassToGraph(std::move(impl));
TestChangeStream change_stream;
impl_proxy->SubscribeToChanges(change_stream.GetProxy());
graph_dump_remote->SubscribeToChanges(change_stream.GetRemote());
task_environment.RunUntilIdle();
......@@ -207,7 +212,7 @@ TEST_F(DiscardsGraphDumpImplTest, ChangeStream) {
task_environment.RunUntilIdle();
// Make sure the Dump impl is torn down when the proxy closes.
impl_proxy.reset();
graph_dump_remote.reset();
task_environment.RunUntilIdle();
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