Commit 9d893fd8 authored by Miyoung Shin's avatar Miyoung Shin Committed by Commit Bot

Convert Geolocation to new Mojo types

This CL converts GeolocationPtr and GeolocationRequest in services,
content and components to the new Mojo type.

Bug: 955171
Change-Id: I442b1fdd699d7199a38c71331801292e9c5ac094
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1792473Reviewed-by: default avatarOksana Zhuravlova <oksamyt@chromium.org>
Reviewed-by: default avatarKinuko Yasuda <kinuko@chromium.org>
Reviewed-by: default avatarColin Blundell <blundell@chromium.org>
Commit-Queue: Miyoung Shin <myid.shin@igalia.com>
Cr-Commit-Position: refs/heads/master@{#695621}
parent 779bd069
......@@ -40,6 +40,7 @@
#include "content/public/common/webplugininfo.h"
#include "gpu/config/gpu_info.h"
#include "mojo/public/cpp/bindings/interface_request.h"
#include "mojo/public/cpp/bindings/remote.h"
#include "ppapi/buildflags/buildflags.h"
#include "services/device/public/cpp/geolocation/geoposition.h"
#include "services/device/public/mojom/constants.mojom.h"
......@@ -241,7 +242,7 @@ class FingerprintDataLoader : public content::GpuDataManagerObserver {
std::vector<content::WebPluginInfo> plugins_;
bool waiting_on_plugins_;
device::mojom::Geoposition geoposition_;
device::mojom::GeolocationPtr geolocation_;
mojo::Remote<device::mojom::Geolocation> geolocation_;
device::mojom::GeolocationContextPtr geolocation_context_;
// Timer to enforce a maximum timeout before the |callback_| is called, even
......@@ -315,7 +316,8 @@ FingerprintDataLoader::FingerprintDataLoader(
DCHECK(connector);
connector->BindInterface(device::mojom::kServiceName,
mojo::MakeRequest(&geolocation_context_));
geolocation_context_->BindGeolocation(mojo::MakeRequest(&geolocation_));
geolocation_context_->BindGeolocation(
geolocation_.BindNewPipeAndPassReceiver());
geolocation_->SetHighAccuracy(false);
geolocation_->QueryNextPosition(
base::BindOnce(&FingerprintDataLoader::OnGotGeoposition,
......
......@@ -133,7 +133,7 @@ void GeoLanguageProvider::BindIpGeolocationService() {
ip_geolocation_provider->CreateGeolocation(
static_cast<net::MutablePartialNetworkTrafficAnnotationTag>(
partial_traffic_annotation),
mojo::MakeRequest(&geolocation_provider_));
geolocation_provider_.BindNewPipeAndPassReceiver());
// No error handler required: If the connection is broken, QueryNextPosition
// will bind it again.
}
......@@ -141,7 +141,7 @@ void GeoLanguageProvider::BindIpGeolocationService() {
void GeoLanguageProvider::QueryNextPosition() {
DCHECK_CALLED_ON_VALID_SEQUENCE(background_sequence_checker_);
if (geolocation_provider_.encountered_error())
if (geolocation_provider_.is_bound() && !geolocation_provider_.is_connected())
geolocation_provider_.reset();
if (!geolocation_provider_.is_bound())
BindIpGeolocationService();
......
......@@ -12,6 +12,7 @@
#include "base/sequence_checker.h"
#include "base/sequenced_task_runner.h"
#include "components/language/content/browser/language_code_locator.h"
#include "mojo/public/cpp/bindings/remote.h"
#include "services/device/public/mojom/geolocation.mojom.h"
namespace base {
......@@ -102,7 +103,7 @@ class GeoLanguageProvider {
std::unique_ptr<service_manager::Connector> service_manager_connector_;
// Connection to the IP geolocation service.
device::mojom::GeolocationPtr geolocation_provider_;
mojo::Remote<device::mojom::Geolocation> geolocation_provider_;
// Location -> Language lookup library.
std::unique_ptr<language::LanguageCodeLocator> language_code_locator_;
......
......@@ -16,6 +16,7 @@
#include "content/public/test/test_browser_context.h"
#include "content/public/test/test_service_manager_context.h"
#include "content/test/test_render_frame_host.h"
#include "mojo/public/cpp/bindings/remote.h"
#include "services/device/public/cpp/test/scoped_geolocation_overrider.h"
#include "services/device/public/mojom/constants.mojom.h"
#include "services/device/public/mojom/geolocation.mojom.h"
......@@ -26,11 +27,11 @@
#include "testing/gtest/include/gtest/gtest.h"
#include "third_party/blink/public/mojom/feature_policy/feature_policy.mojom.h"
using blink::mojom::PermissionStatus;
using device::mojom::GeolocationPtr;
using device::mojom::GeopositionPtr;
using blink::mojom::GeolocationService;
using blink::mojom::GeolocationServicePtr;
using blink::mojom::PermissionStatus;
using device::mojom::Geolocation;
using device::mojom::GeopositionPtr;
namespace content {
namespace {
......@@ -157,15 +158,15 @@ TEST_F(GeolocationServiceTest, PermissionGrantedPolicyViolation) {
base::BindRepeating([](PermissionCallback callback) {
ADD_FAILURE() << "Permissions checked unexpectedly.";
}));
GeolocationPtr geolocation;
mojo::Remote<Geolocation> geolocation;
service()->CreateGeolocation(
mojo::MakeRequest(&geolocation), true,
geolocation.BindNewPipeAndPassReceiver(), true,
base::BindRepeating([](blink::mojom::PermissionStatus status) {
EXPECT_EQ(blink::mojom::PermissionStatus::DENIED, status);
}));
base::RunLoop loop;
geolocation.set_connection_error_handler(loop.QuitClosure());
geolocation.set_disconnect_handler(loop.QuitClosure());
geolocation->QueryNextPosition(base::BindOnce([](GeopositionPtr geoposition) {
ADD_FAILURE() << "Position updated unexpectedly";
......@@ -181,15 +182,15 @@ TEST_F(GeolocationServiceTest, PermissionGrantedNoPolicyViolation) {
base::BindRepeating([](PermissionCallback callback) {
std::move(callback).Run(PermissionStatus::GRANTED);
}));
GeolocationPtr geolocation;
mojo::Remote<Geolocation> geolocation;
service()->CreateGeolocation(
mojo::MakeRequest(&geolocation), true,
geolocation.BindNewPipeAndPassReceiver(), true,
base::BindRepeating([](blink::mojom::PermissionStatus status) {
EXPECT_EQ(blink::mojom::PermissionStatus::GRANTED, status);
}));
base::RunLoop loop;
geolocation.set_connection_error_handler(base::BindOnce(
geolocation.set_disconnect_handler(base::BindOnce(
[] { ADD_FAILURE() << "Connection error handler called unexpectedly"; }));
geolocation->QueryNextPosition(base::BindOnce(
......@@ -208,15 +209,15 @@ TEST_F(GeolocationServiceTest, PermissionGrantedSync) {
base::BindRepeating([](PermissionCallback callback) {
std::move(callback).Run(PermissionStatus::GRANTED);
}));
GeolocationPtr geolocation;
mojo::Remote<Geolocation> geolocation;
service()->CreateGeolocation(
mojo::MakeRequest(&geolocation), true,
geolocation.BindNewPipeAndPassReceiver(), true,
base::BindRepeating([](blink::mojom::PermissionStatus status) {
EXPECT_EQ(blink::mojom::PermissionStatus::GRANTED, status);
}));
base::RunLoop loop;
geolocation.set_connection_error_handler(base::BindOnce(
geolocation.set_disconnect_handler(base::BindOnce(
[] { ADD_FAILURE() << "Connection error handler called unexpectedly"; }));
geolocation->QueryNextPosition(base::BindOnce(
......@@ -235,15 +236,15 @@ TEST_F(GeolocationServiceTest, PermissionDeniedSync) {
base::BindRepeating([](PermissionCallback callback) {
std::move(callback).Run(PermissionStatus::DENIED);
}));
GeolocationPtr geolocation;
mojo::Remote<Geolocation> geolocation;
service()->CreateGeolocation(
mojo::MakeRequest(&geolocation), true,
geolocation.BindNewPipeAndPassReceiver(), true,
base::BindRepeating([](blink::mojom::PermissionStatus status) {
EXPECT_EQ(blink::mojom::PermissionStatus::DENIED, status);
}));
base::RunLoop loop;
geolocation.set_connection_error_handler(loop.QuitClosure());
geolocation.set_disconnect_handler(loop.QuitClosure());
geolocation->QueryNextPosition(base::BindOnce([](GeopositionPtr geoposition) {
ADD_FAILURE() << "Position updated unexpectedly";
......@@ -260,15 +261,15 @@ TEST_F(GeolocationServiceTest, PermissionGrantedAsync) {
FROM_HERE, base::BindOnce(std::move(permission_callback),
PermissionStatus::GRANTED));
}));
GeolocationPtr geolocation;
mojo::Remote<Geolocation> geolocation;
service()->CreateGeolocation(
mojo::MakeRequest(&geolocation), true,
geolocation.BindNewPipeAndPassReceiver(), true,
base::BindRepeating([](blink::mojom::PermissionStatus status) {
EXPECT_EQ(blink::mojom::PermissionStatus::GRANTED, status);
}));
base::RunLoop loop;
geolocation.set_connection_error_handler(base::BindOnce(
geolocation.set_disconnect_handler(base::BindOnce(
[] { ADD_FAILURE() << "Connection error handler called unexpectedly"; }));
geolocation->QueryNextPosition(base::BindOnce(
......@@ -290,15 +291,15 @@ TEST_F(GeolocationServiceTest, PermissionDeniedAsync) {
FROM_HERE, base::BindOnce(std::move(permission_callback),
PermissionStatus::DENIED));
}));
GeolocationPtr geolocation;
mojo::Remote<Geolocation> geolocation;
service()->CreateGeolocation(
mojo::MakeRequest(&geolocation), true,
geolocation.BindNewPipeAndPassReceiver(), true,
base::BindRepeating([](blink::mojom::PermissionStatus status) {
EXPECT_EQ(blink::mojom::PermissionStatus::DENIED, status);
}));
base::RunLoop loop;
geolocation.set_connection_error_handler(loop.QuitClosure());
geolocation.set_disconnect_handler(loop.QuitClosure());
geolocation->QueryNextPosition(base::BindOnce([](GeopositionPtr geoposition) {
ADD_FAILURE() << "Position updated unexpectedly";
......@@ -309,9 +310,9 @@ TEST_F(GeolocationServiceTest, PermissionDeniedAsync) {
TEST_F(GeolocationServiceTest, ServiceClosedBeforePermissionResponse) {
CreateEmbeddedFrameAndGeolocationService(/*allow_via_feature_policy=*/true);
permission_manager()->SetRequestId(42);
GeolocationPtr geolocation;
mojo::Remote<Geolocation> geolocation;
service()->CreateGeolocation(
mojo::MakeRequest(&geolocation), true,
geolocation.BindNewPipeAndPassReceiver(), true,
base::BindRepeating([](blink::mojom::PermissionStatus) {
ADD_FAILURE() << "PositionStatus received unexpectedly.";
}));
......
......@@ -11,6 +11,7 @@
#include "chromeos/network/geolocation_handler.h"
#endif
#include "mojo/public/cpp/bindings/interface_ptr.h"
#include "mojo/public/cpp/bindings/remote.h"
#include "net/base/network_change_notifier.h"
#include "services/device/device_service_test_base.h"
#include "services/device/geolocation/geolocation_provider_impl.h"
......@@ -52,7 +53,8 @@ class GeolocationServiceUnitTest : public DeviceServiceTestBase {
geolocation_control_->UserDidOptIntoLocationServices();
connector()->BindInterface(mojom::kServiceName, &geolocation_context_);
geolocation_context_->BindGeolocation(MakeRequest(&geolocation_));
geolocation_context_->BindGeolocation(
geolocation_.BindNewPipeAndPassReceiver());
}
void TearDown() override {
......@@ -79,7 +81,7 @@ class GeolocationServiceUnitTest : public DeviceServiceTestBase {
std::unique_ptr<net::NetworkChangeNotifier> network_change_notifier_;
mojom::GeolocationControlPtr geolocation_control_;
mojom::GeolocationContextPtr geolocation_context_;
mojom::GeolocationPtr geolocation_;
mojo::Remote<mojom::Geolocation> geolocation_;
mojom::GeolocationConfigPtr geolocation_config_;
DISALLOW_COPY_AND_ASSIGN(GeolocationServiceUnitTest);
......
......@@ -9,7 +9,8 @@
#include "base/strings/string_util.h"
#include "base/test/task_environment.h"
#include "mojo/core/embedder/embedder.h"
#include "mojo/public/cpp/bindings/strong_binding_set.h"
#include "mojo/public/cpp/bindings/remote.h"
#include "mojo/public/cpp/bindings/unique_receiver_set.h"
#include "net/traffic_annotation/network_traffic_annotation_test_helper.h"
#include "services/network/public/cpp/weak_wrapper_shared_url_loader_factory.h"
#include "services/network/test/test_network_connection_tracker.h"
......@@ -44,12 +45,12 @@ class PublicIpAddressGeolocatorTest : public testing::Test {
base::Bind(&PublicIpAddressGeolocatorTest::OnMojoBadMessage,
base::Unretained(this)));
binding_set_.AddBinding(
receiver_set_.Add(
std::make_unique<PublicIpAddressGeolocator>(
PARTIAL_TRAFFIC_ANNOTATION_FOR_TESTS, notifier_.get(),
base::Bind(&PublicIpAddressGeolocatorTest::OnGeolocatorBadMessage,
base::Unretained(this))),
mojo::MakeRequest(&public_ip_address_geolocator_));
public_ip_address_geolocator_.BindNewPipeAndPassReceiver());
}
void TearDown() override {
......@@ -65,7 +66,7 @@ class PublicIpAddressGeolocatorTest : public testing::Test {
// Deal with PublicIpAddressGeolocator bad message.
void OnGeolocatorBadMessage(const std::string& message) {
binding_set_.ReportBadMessage(message);
receiver_set_.ReportBadMessage(message);
}
// Invokes QueryNextPosition on |public_ip_address_geolocator_|, and runs
......@@ -87,8 +88,8 @@ class PublicIpAddressGeolocatorTest : public testing::Test {
// Result of the latest completed call to QueryNextPosition.
mojom::GeopositionPtr position_;
// StrongBindingSet to mojom::Geolocation.
mojo::StrongBindingSet<mojom::Geolocation> binding_set_;
// UniqueReceiverSet to mojom::Geolocation.
mojo::UniqueReceiverSet<mojom::Geolocation> receiver_set_;
// Test task runner.
base::test::TaskEnvironment task_environment_;
......@@ -104,7 +105,7 @@ class PublicIpAddressGeolocatorTest : public testing::Test {
std::unique_ptr<PublicIpAddressLocationNotifier> notifier_;
// The object under test.
mojom::GeolocationPtr public_ip_address_geolocator_;
mojo::Remote<mojom::Geolocation> public_ip_address_geolocator_;
// Test URLLoaderFactory for handling requests to the geolocation API.
network::TestURLLoaderFactory test_url_loader_factory_;
......@@ -147,8 +148,7 @@ TEST_F(PublicIpAddressGeolocatorTest, BindAndQuery) {
// connection error and reports a bad message.
TEST_F(PublicIpAddressGeolocatorTest, ProhibitedOverlappingCalls) {
base::RunLoop loop;
public_ip_address_geolocator_.set_connection_error_handler(
loop.QuitClosure());
public_ip_address_geolocator_.set_disconnect_handler(loop.QuitClosure());
// Issue two overlapping calls to QueryNextPosition.
QueryNextPosition(base::Closure());
......
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