Commit 8668849b authored by Renjie Liu's avatar Renjie Liu Committed by Commit Bot

PublicIpAddressGeolocationProvider interface and implementation

original owner: amoylan@chromium.org
original cl: https://chromium-review.googlesource.com/c/chromium/src/+/754255

This CL is part of the implementation of public-IP-only geolocation
as described in the design doc:
https://docs.google.com/document/d/1oSQM3GEMTL1raWLYv8S6_Yyt93FF2zQbANI4bKJ6LDs

This part is a new Mojo interface PublicIpAddressGeolocationProvider
that provides mojom::Geolocation implementations using the
PublicIpAddressGeolocator (from the upstream dependent CL).

In a subsequent CL, DeviceService will provide this implementation
of PublicIpAddressGeolocationProvider via ServiceManager.

Change-Id: I2458c816b5a861a409ab2b3a5defa8d80444c59e
Reviewed-on: https://chromium-review.googlesource.com/784533Reviewed-by: default avatarSam McNally <sammc@chromium.org>
Reviewed-by: default avatarMike West <mkwst@chromium.org>
Reviewed-by: default avatarColin Blundell <blundell@chromium.org>
Commit-Queue: Renjie Liu <renjieliu@chromium.org>
Cr-Commit-Position: refs/heads/master@{#521521}
parent 9dcdf4d8
......@@ -10,11 +10,21 @@ import "device/geolocation/public/interfaces/geoposition.mojom";
// provides updates with low accuracy, but |SetHighAccuracy()| may be called
// to change this.
interface Geolocation {
// Select between high and low accuracy, if supported by the implementation.
// Ignored if unsupported.
SetHighAccuracy(bool high_accuracy);
// Position is reported once it changes or immediately (to report the initial
// position) if this is the first call to QueryNextPosition on this instance.
// Position updates may be throttled by the service. Overlapping calls to
// this method are prohibited and will be treated as a connection error.
// Use this method to get notified of future position updates, by calling
// QueryNextPosition once, and then calling it again when/if it returns.
//
// When first called:
// Returns the latest known Geoposition.
// When subsequently called:
// Issues a request for a single position update, which the implementation
// may fulfill at its discretion (e.g. when the next geoposition change is
// detected).
//
// Overlapping calls to this method are prohibited and will be treated as a
// connection error. Position updates may be throttled by the service.
QueryNextPosition() => (Geoposition geoposition);
};
......@@ -8,6 +8,8 @@ source_set("geolocation") {
visibility = [ "//services/device:*" ]
sources = [
"public_ip_address_geolocation_provider.cc",
"public_ip_address_geolocation_provider.h",
"public_ip_address_geolocator.cc",
"public_ip_address_geolocator.h",
"public_ip_address_location_notifier.cc",
......@@ -19,5 +21,6 @@ source_set("geolocation") {
"//device/geolocation",
"//mojo/public/cpp/bindings",
"//net",
"//services/device/public/interfaces",
]
}
// Copyright 2017 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include "services/device/geolocation/public_ip_address_geolocation_provider.h"
#include "services/device/geolocation/public_ip_address_geolocator.h"
namespace device {
PublicIpAddressGeolocationProvider::PublicIpAddressGeolocationProvider() {
DETACH_FROM_SEQUENCE(sequence_checker_);
}
PublicIpAddressGeolocationProvider::~PublicIpAddressGeolocationProvider() {}
void PublicIpAddressGeolocationProvider::Initialize(
GeolocationProvider::RequestContextProducer request_context_producer,
const std::string& api_key) {
// Bind sequence_checker_ to the initialization sequence.
DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_);
public_ip_address_location_notifier_ =
std::make_unique<PublicIpAddressLocationNotifier>(
request_context_producer, api_key);
}
void PublicIpAddressGeolocationProvider::Bind(
mojom::PublicIpAddressGeolocationProviderRequest request) {
DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_);
DCHECK(public_ip_address_location_notifier_);
provider_binding_set_.AddBinding(this, std::move(request));
}
void PublicIpAddressGeolocationProvider::CreateGeolocation(
const net::MutablePartialNetworkTrafficAnnotationTag& tag,
mojom::GeolocationRequest request) {
DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_);
DCHECK(public_ip_address_location_notifier_);
geolocation_binding_set_.AddBinding(
std::make_unique<PublicIpAddressGeolocator>(
static_cast<net::PartialNetworkTrafficAnnotationTag>(tag),
public_ip_address_location_notifier_.get(),
base::Bind(
&mojo::StrongBindingSet<mojom::Geolocation>::ReportBadMessage,
base::Unretained(&geolocation_binding_set_))),
std::move(request));
}
} // namespace device
// Copyright 2017 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#ifndef SERVICES_DEVICE_GEOLOCATION_PUBLIC_IP_ADDRESS_GEOLOCATION_PROVIDER_H_
#define SERVICES_DEVICE_GEOLOCATION_PUBLIC_IP_ADDRESS_GEOLOCATION_PROVIDER_H_
#include <string>
#include "base/macros.h"
#include "device/geolocation/public/interfaces/geolocation.mojom.h"
#include "mojo/public/cpp/bindings/binding_set.h"
#include "mojo/public/cpp/bindings/strong_binding_set.h"
#include "net/traffic_annotation/network_traffic_annotation.h"
#include "services/device/geolocation/public_ip_address_geolocator.h"
#include "services/device/geolocation/public_ip_address_location_notifier.h"
#include "services/device/public/interfaces/public_ip_address_geolocation_provider.mojom.h"
namespace device {
// Implementation of PublicIpAddressGeolocationProvider Mojo interface that will
// provide mojom::Geolocation implementations that use IP-only geolocation.
// Binds multiple PublicIpAddressGeolocationProvider requests.
//
// Sequencing:
// * Must be used and destroyed on the same sequence.
// * Provides mojom::Geolocation instances that are bound on the same sequence.
// * Requires two-step construction: Construct on any sequence, then invoke
// Initialize() on the sequence on which this object will run.
class PublicIpAddressGeolocationProvider
: public mojom::PublicIpAddressGeolocationProvider {
public:
// After construction, invoke Initialize() (on the appropriate sequence) to
// finish initialization.
PublicIpAddressGeolocationProvider();
~PublicIpAddressGeolocationProvider() override;
// Finishes initialization, using the specified Google |api_key| and a URL
// request context produced by |request_context_producer| for network location
// requests.
// After this call is made, this object must be used only on the sequence on
// which this call was made.
void Initialize(
GeolocationProvider::RequestContextProducer request_context_producer,
const std::string& api_key);
// Binds a PublicIpAddressGeolocationProvider request to this instance.
void Bind(mojom::PublicIpAddressGeolocationProviderRequest request);
private:
SEQUENCE_CHECKER(sequence_checker_);
// mojom::PublicIpAddressGeolocationProvider implementation:
// Provides a Geolocation instance that performs IP-geolocation only.
void CreateGeolocation(
const net::MutablePartialNetworkTrafficAnnotationTag& tag,
mojom::GeolocationRequest request) override;
// Central PublicIpAddressLocationNotifier for use by all implementations of
// mojom::Geolocation provided by the CreateGeolocation method.
// Note that this must be before the StrongBindingSet<mojom::Geolocation> as
// it must outlive the Geolocation implementations.
std::unique_ptr<PublicIpAddressLocationNotifier>
public_ip_address_location_notifier_;
mojo::BindingSet<mojom::PublicIpAddressGeolocationProvider>
provider_binding_set_;
mojo::StrongBindingSet<mojom::Geolocation> geolocation_binding_set_;
DISALLOW_COPY_AND_ASSIGN(PublicIpAddressGeolocationProvider);
};
} // namespace device
#endif // SERVICES_DEVICE_GEOLOCATION_PUBLIC_IP_ADDRESS_GEOLOCATION_PROVIDER_H_
......@@ -14,6 +14,7 @@ mojom("interfaces") {
"nfc.mojom",
"nfc_provider.mojom",
"power_monitor.mojom",
"public_ip_address_geolocation_provider.mojom",
"serial.mojom",
"time_zone_monitor.mojom",
"vibration_manager.mojom",
......@@ -22,9 +23,17 @@ mojom("interfaces") {
"wake_lock_provider.mojom",
]
deps = [
"//device/geolocation/public/interfaces",
"//services/network/public/interfaces:interfaces",
]
public_deps = [
":constants",
]
overridden_deps_blink = [ "//services/network/public/interfaces:interfaces" ]
component_deps_blink = [ "//third_party/WebKit/Source/platform" ]
}
mojom("generic_sensor") {
......
// Copyright 2017 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
module device.mojom;
import "device/geolocation/public/interfaces/geolocation.mojom";
import "services/network/public/interfaces/mutable_partial_network_traffic_annotation_tag.mojom";
// Provides a coarse-grained device.mojom.Geolocation which, subject to
// case-by-case privacy review, may be able to operate without explicit user
// consent.
//
// WARNING: DO NOT USE WITHOUT PRIVACY REVIEW.
interface PublicIpAddressGeolocationProvider {
CreateGeolocation(network.mojom.MutablePartialNetworkTrafficAnnotationTag tag,
Geolocation& request);
};
......@@ -223,6 +223,7 @@ jumbo_component("platform") {
visibility = [] # Allow re-assignment of list.
visibility = [
"//components/pdf/common:interfaces_blink",
"//services/device/public/interfaces:interfaces_blink",
"//third_party/WebKit/*",
"//url/mojo:url_mojom_origin_blink",
"//url/mojo:url_mojom_gurl_blink",
......
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