Commit 924acc8f authored by Julie Jeongeun Kim's avatar Julie Jeongeun Kim Committed by Commit Bot

Convert NetBenchmarking to new Mojo types

This CL converts NetBenchmarking to new mojo types using
Remote and PendingReceiver.

Bug: 955171
Change-Id: Ic7bb297bfd5ade05e33d93d527f2ccb3ffff90eb
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1828718Reviewed-by: default avatarAvi Drissman <avi@chromium.org>
Reviewed-by: default avatarOksana Zhuravlova <oksamyt@chromium.org>
Commit-Queue: Julie Kim <jkim@igalia.com>
Cr-Commit-Position: refs/heads/master@{#700933}
parent 64505414
...@@ -18,7 +18,7 @@ ...@@ -18,7 +18,7 @@
#include "content/public/browser/browser_thread.h" #include "content/public/browser/browser_thread.h"
#include "content/public/browser/render_process_host.h" #include "content/public/browser/render_process_host.h"
#include "content/public/browser/storage_partition.h" #include "content/public/browser/storage_partition.h"
#include "mojo/public/cpp/bindings/strong_binding.h" #include "mojo/public/cpp/bindings/self_owned_receiver.h"
#include "services/network/public/mojom/network_context.mojom.h" #include "services/network/public/mojom/network_context.mojom.h"
using content::BrowserThread; using content::BrowserThread;
...@@ -51,11 +51,12 @@ NetBenchmarking::~NetBenchmarking() { ...@@ -51,11 +51,12 @@ NetBenchmarking::~NetBenchmarking() {
void NetBenchmarking::Create( void NetBenchmarking::Create(
base::WeakPtr<predictors::LoadingPredictor> loading_predictor, base::WeakPtr<predictors::LoadingPredictor> loading_predictor,
int render_process_id, int render_process_id,
chrome::mojom::NetBenchmarkingRequest request) { mojo::PendingReceiver<chrome::mojom::NetBenchmarking> receiver) {
DCHECK_CURRENTLY_ON(BrowserThread::UI); DCHECK_CURRENTLY_ON(BrowserThread::UI);
mojo::MakeStrongBinding(std::make_unique<NetBenchmarking>( mojo::MakeSelfOwnedReceiver(
std::move(loading_predictor), render_process_id), std::make_unique<NetBenchmarking>(std::move(loading_predictor),
std::move(request)); render_process_id),
std::move(receiver));
} }
// static // static
......
...@@ -8,6 +8,7 @@ ...@@ -8,6 +8,7 @@
#include "base/macros.h" #include "base/macros.h"
#include "base/memory/weak_ptr.h" #include "base/memory/weak_ptr.h"
#include "chrome/common/net_benchmarking.mojom.h" #include "chrome/common/net_benchmarking.mojom.h"
#include "mojo/public/cpp/bindings/pending_receiver.h"
namespace predictors { namespace predictors {
class LoadingPredictor; class LoadingPredictor;
...@@ -28,7 +29,7 @@ class NetBenchmarking : public chrome::mojom::NetBenchmarking { ...@@ -28,7 +29,7 @@ class NetBenchmarking : public chrome::mojom::NetBenchmarking {
static void Create( static void Create(
base::WeakPtr<predictors::LoadingPredictor> loading_predictor, base::WeakPtr<predictors::LoadingPredictor> loading_predictor,
int render_process_id, int render_process_id,
chrome::mojom::NetBenchmarkingRequest request); mojo::PendingReceiver<chrome::mojom::NetBenchmarking> receiver);
// This method is thread-safe. // This method is thread-safe.
static bool CheckBenchmarkingEnabled(); static bool CheckBenchmarkingEnabled();
......
...@@ -8,6 +8,7 @@ ...@@ -8,6 +8,7 @@
#include "chrome/common/net_benchmarking.mojom.h" #include "chrome/common/net_benchmarking.mojom.h"
#include "content/public/common/service_names.mojom.h" #include "content/public/common/service_names.mojom.h"
#include "content/public/renderer/render_thread.h" #include "content/public/renderer/render_thread.h"
#include "mojo/public/cpp/bindings/remote.h"
#include "third_party/blink/public/platform/web_cache.h" #include "third_party/blink/public/platform/web_cache.h"
#include "v8/include/v8.h" #include "v8/include/v8.h"
...@@ -74,15 +75,15 @@ class NetBenchmarkingWrapper : public v8::Extension { ...@@ -74,15 +75,15 @@ class NetBenchmarkingWrapper : public v8::Extension {
} }
static chrome::mojom::NetBenchmarking& GetNetBenchmarking() { static chrome::mojom::NetBenchmarking& GetNetBenchmarking() {
static base::NoDestructor<chrome::mojom::NetBenchmarkingPtr> static base::NoDestructor<mojo::Remote<chrome::mojom::NetBenchmarking>>
net_benchmarking(ConnectToBrowser()); net_benchmarking(ConnectToBrowser());
return **net_benchmarking; return **net_benchmarking;
} }
static chrome::mojom::NetBenchmarkingPtr ConnectToBrowser() { static mojo::Remote<chrome::mojom::NetBenchmarking> ConnectToBrowser() {
chrome::mojom::NetBenchmarkingPtr net_benchmarking; mojo::Remote<chrome::mojom::NetBenchmarking> net_benchmarking;
content::RenderThread::Get()->BindHostReceiver( content::RenderThread::Get()->BindHostReceiver(
mojo::MakeRequest(&net_benchmarking)); net_benchmarking.BindNewPipeAndPassReceiver());
return net_benchmarking; return net_benchmarking;
} }
......
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