| Index: content/browser/geolocation/geolocation_service_impl.cc
|
| diff --git a/content/browser/geolocation/geolocation_service_impl.cc b/content/browser/geolocation/geolocation_service_impl.cc
|
| index aae95ac01b6bf465564048bee3e7b197d2cc70b8..e5d97f191ad0d2fccb0d93e1c87d6c4592b05941 100644
|
| --- a/content/browser/geolocation/geolocation_service_impl.cc
|
| +++ b/content/browser/geolocation/geolocation_service_impl.cc
|
| @@ -7,10 +7,15 @@
|
| #include "base/bind.h"
|
| #include "base/metrics/histogram.h"
|
| #include "content/browser/geolocation/geolocation_service_context.h"
|
| -#include "content/public/common/mojo_geoposition.mojom.h"
|
| +#include "content/public/browser/browser_context.h"
|
| +#include "content/public/browser/geolocation_provider.h"
|
| +#include "content/public/browser/permission_manager.h"
|
| +#include "content/public/browser/permission_type.h"
|
| +#include "content/public/browser/render_frame_host.h"
|
| +#include "content/public/browser/render_process_host.h"
|
| +#include "content/public/common/geoposition.h"
|
|
|
| namespace content {
|
| -
|
| namespace {
|
|
|
| // Geoposition error codes for reporting in UMA.
|
| @@ -51,47 +56,31 @@ void RecordGeopositionErrorCode(Geoposition::ErrorCode error_code) {
|
| code = GEOPOSITION_ERROR_CODE_TIMEOUT;
|
| break;
|
| }
|
| - UMA_HISTOGRAM_ENUMERATION("Geolocation.LocationUpdate.ErrorCode",
|
| - code,
|
| + UMA_HISTOGRAM_ENUMERATION("Geolocation.LocationUpdate.ErrorCode", code,
|
| GEOPOSITION_ERROR_CODE_COUNT);
|
| }
|
|
|
| } // namespace
|
|
|
| GeolocationServiceImpl::GeolocationServiceImpl(
|
| - mojo::InterfaceRequest<GeolocationService> request,
|
| GeolocationServiceContext* context,
|
| - const base::Closure& update_callback)
|
| - : binding_(this, request.Pass()),
|
| - context_(context),
|
| - update_callback_(update_callback),
|
| - high_accuracy_(false),
|
| - has_position_to_report_(false) {
|
| + RenderFrameHost* render_frame_host)
|
| + : context_(context),
|
| + render_frame_host_(render_frame_host),
|
| + high_accuracy_(false) {
|
| DCHECK(context_);
|
| - binding_.set_connection_error_handler(
|
| - base::Bind(&GeolocationServiceImpl::OnConnectionError,
|
| - base::Unretained(this)));
|
| }
|
|
|
| -GeolocationServiceImpl::~GeolocationServiceImpl() {
|
| - // Make sure to respond to any pending callback even without a valid position.
|
| - if (!position_callback_.is_null()) {
|
| - if (!current_position_.valid) {
|
| - current_position_.error_code = MojoGeoposition::ErrorCode(
|
| - GEOPOSITION_ERROR_CODE_POSITION_UNAVAILABLE);
|
| - current_position_.error_message = mojo::String("");
|
| - }
|
| - ReportCurrentPosition();
|
| - }
|
| -}
|
| +GeolocationServiceImpl::~GeolocationServiceImpl() = default;
|
|
|
| void GeolocationServiceImpl::PauseUpdates() {
|
| geolocation_subscription_.reset();
|
| }
|
|
|
| void GeolocationServiceImpl::ResumeUpdates() {
|
| - if (position_override_.Validate()) {
|
| - OnLocationUpdate(position_override_);
|
| + if (context_->geoposition_override_ &&
|
| + context_->geoposition_override_->Validate()) {
|
| + OnLocationUpdate(*context_->geoposition_override_);
|
| return;
|
| }
|
|
|
| @@ -112,8 +101,9 @@ void GeolocationServiceImpl::SetHighAccuracy(bool high_accuracy) {
|
| high_accuracy);
|
| high_accuracy_ = high_accuracy;
|
|
|
| - if (position_override_.Validate()) {
|
| - OnLocationUpdate(position_override_);
|
| + if (context_->geoposition_override_ &&
|
| + context_->geoposition_override_->Validate()) {
|
| + OnLocationUpdate(*context_->geoposition_override_);
|
| return;
|
| }
|
|
|
| @@ -124,39 +114,30 @@ void GeolocationServiceImpl::QueryNextPosition(
|
| const PositionCallback& callback) {
|
| if (!position_callback_.is_null()) {
|
| DVLOG(1) << "Overlapped call to QueryNextPosition!";
|
| - OnConnectionError(); // Simulate a connection error.
|
| + context_->services_.EraseService(this);
|
| return;
|
| }
|
|
|
| position_callback_ = callback;
|
|
|
| - if (has_position_to_report_)
|
| + if (current_position_)
|
| ReportCurrentPosition();
|
| }
|
|
|
| -void GeolocationServiceImpl::SetOverride(const Geoposition& position) {
|
| - position_override_ = position;
|
| - if (!position_override_.Validate()) {
|
| +void GeolocationServiceImpl::OnOverrideSet() {
|
| + if (!context_->geoposition_override_->Validate()) {
|
| ResumeUpdates();
|
| }
|
|
|
| geolocation_subscription_.reset();
|
|
|
| - OnLocationUpdate(position_override_);
|
| + OnLocationUpdate(*context_->geoposition_override_);
|
| }
|
|
|
| void GeolocationServiceImpl::ClearOverride() {
|
| - position_override_ = Geoposition();
|
| StartListeningForUpdates();
|
| }
|
|
|
| -void GeolocationServiceImpl::OnConnectionError() {
|
| - context_->ServiceHadConnectionError(this);
|
| -
|
| - // The above call deleted this instance, so the only safe thing to do is
|
| - // return.
|
| -}
|
| -
|
| void GeolocationServiceImpl::OnLocationUpdate(const Geoposition& position) {
|
| RecordGeopositionErrorCode(position.error_code);
|
| DCHECK(context_);
|
| @@ -164,31 +145,41 @@ void GeolocationServiceImpl::OnLocationUpdate(const Geoposition& position) {
|
| if (context_->paused())
|
| return;
|
|
|
| - update_callback_.Run();
|
| -
|
| - current_position_.valid = position.Validate();
|
| - current_position_.latitude = position.latitude;
|
| - current_position_.longitude = position.longitude;
|
| - current_position_.altitude = position.altitude;
|
| - current_position_.accuracy = position.accuracy;
|
| - current_position_.altitude_accuracy = position.altitude_accuracy;
|
| - current_position_.heading = position.heading;
|
| - current_position_.speed = position.speed;
|
| - current_position_.timestamp = position.timestamp.ToDoubleT();
|
| - current_position_.error_code =
|
| - MojoGeoposition::ErrorCode(position.error_code);
|
| - current_position_.error_message = position.error_message;
|
| + PermissionManager* permission_manager = render_frame_host_->GetProcess()
|
| + ->GetBrowserContext()
|
| + ->GetPermissionManager();
|
| + if (permission_manager) {
|
| + permission_manager->RegisterPermissionUsage(
|
| + PermissionType::GEOLOCATION,
|
| + render_frame_host_->GetLastCommittedURL().GetOrigin(),
|
| + WebContents::FromRenderFrameHost(render_frame_host_)
|
| + ->GetMainFrame()
|
| + ->GetLastCommittedURL()
|
| + .GetOrigin());
|
| + }
|
|
|
| - has_position_to_report_ = true;
|
| + if (!current_position_)
|
| + current_position_ = MojoGeoposition::New();
|
| + current_position_->valid = position.Validate();
|
| + current_position_->latitude = position.latitude;
|
| + current_position_->longitude = position.longitude;
|
| + current_position_->altitude = position.altitude;
|
| + current_position_->accuracy = position.accuracy;
|
| + current_position_->altitude_accuracy = position.altitude_accuracy;
|
| + current_position_->heading = position.heading;
|
| + current_position_->speed = position.speed;
|
| + current_position_->timestamp = position.timestamp.ToDoubleT();
|
| + current_position_->error_code =
|
| + MojoGeoposition::ErrorCode(position.error_code);
|
| + current_position_->error_message = position.error_message;
|
|
|
| if (!position_callback_.is_null())
|
| ReportCurrentPosition();
|
| }
|
|
|
| void GeolocationServiceImpl::ReportCurrentPosition() {
|
| - position_callback_.Run(current_position_.Clone());
|
| + position_callback_.Run(current_position_.Pass());
|
| position_callback_.reset();
|
| - has_position_to_report_ = false;
|
| }
|
|
|
| } // namespace content
|
|
|