Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1284)

Unified Diff: content/browser/geolocation/geolocation_service_impl.cc

Issue 841133002: Stop using [Client=...] feature of Mojom for GeolocationService (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: improve comments Created 5 years, 11 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « content/browser/geolocation/geolocation_service_impl.h ('k') | content/common/geolocation_service.mojom » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 4c855f27046541b5ede834728846617cbd5b07b2..662319f1582cfbdd6448d2b591640866c7f40ba3 100644
--- a/content/browser/geolocation/geolocation_service_impl.cc
+++ b/content/browser/geolocation/geolocation_service_impl.cc
@@ -63,7 +63,8 @@ GeolocationServiceImpl::GeolocationServiceImpl(
const base::Closure& update_callback)
: context_(context),
update_callback_(update_callback),
- high_accuracy_(false) {
+ high_accuracy_(false),
+ has_position_to_report_(false) {
DCHECK(context_);
}
@@ -105,6 +106,14 @@ void GeolocationServiceImpl::SetHighAccuracy(bool high_accuracy) {
StartListeningForUpdates();
}
+void GeolocationServiceImpl::QueryNextPosition(
+ const PositionCallback& callback) {
+ position_callbacks_.push_back(callback);
+
+ if (has_position_to_report_)
+ ReportCurrentPosition();
+}
+
void GeolocationServiceImpl::SetOverride(const Geoposition& position) {
position_override_ = position;
if (!position_override_.Validate()) {
@@ -135,21 +144,32 @@ void GeolocationServiceImpl::OnLocationUpdate(const Geoposition& position) {
if (context_->paused())
return;
- MojoGeopositionPtr geoposition(MojoGeoposition::New());
- geoposition->valid = position.Validate();
- geoposition->latitude = position.latitude;
- geoposition->longitude = position.longitude;
- geoposition->altitude = position.altitude;
- geoposition->accuracy = position.accuracy;
- geoposition->altitude_accuracy = position.altitude_accuracy;
- geoposition->heading = position.heading;
- geoposition->speed = position.speed;
- geoposition->timestamp = position.timestamp.ToDoubleT();
- geoposition->error_code = MojoGeoposition::ErrorCode(position.error_code);
- geoposition->error_message = position.error_message;
-
update_callback_.Run();
- client()->OnLocationUpdate(geoposition.Pass());
+
+ 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;
+
+ has_position_to_report_ = true;
+
+ if (!position_callbacks_.empty())
+ ReportCurrentPosition();
+}
+
+void GeolocationServiceImpl::ReportCurrentPosition() {
+ for (const auto& callback : position_callbacks_)
+ callback.Run(current_position_.Clone());
+ position_callbacks_.clear();
+ has_position_to_report_ = false;
}
} // namespace content
« no previous file with comments | « content/browser/geolocation/geolocation_service_impl.h ('k') | content/common/geolocation_service.mojom » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698