Commit 7fc6e8fd authored by tzik's avatar tzik Committed by Commit Bot

Use OnceCallback on Mojo interfaces in //device/geolocation

This CL flips `use_once_calback` flag on the Mojo code generator, and
fixes all compile errors after it. After this CL, Mojo interfaces in
//device/geolocation starts using base::OnceCallback instead of
base::Callback on its return value handling.

The migration recipe was:
 - Convert pass-by-ref callback objects to pass-by-value.
 - Use std::move() to forward it to other consumer, or to invoke it
   with Callback::Run().
 - Handle wherever copies are required manually.
 - Check if the conversion doesn't change the semantics. As the transfer
   and invocation clobber the callback object, care about use-after-move.
   It's considered safe to consume almost scoped-out callback.

BUG=714018

Review-Url: https://codereview.chromium.org/2866003002
Cr-Commit-Position: refs/heads/master@{#475807}
parent 9570c41a
...@@ -118,14 +118,14 @@ void GeolocationServiceImpl::SetHighAccuracy(bool high_accuracy) { ...@@ -118,14 +118,14 @@ void GeolocationServiceImpl::SetHighAccuracy(bool high_accuracy) {
} }
void GeolocationServiceImpl::QueryNextPosition( void GeolocationServiceImpl::QueryNextPosition(
const QueryNextPositionCallback& callback) { QueryNextPositionCallback callback) {
if (!position_callback_.is_null()) { if (!position_callback_.is_null()) {
DVLOG(1) << "Overlapped call to QueryNextPosition!"; DVLOG(1) << "Overlapped call to QueryNextPosition!";
OnConnectionError(); // Simulate a connection error. OnConnectionError(); // Simulate a connection error.
return; return;
} }
position_callback_ = callback; position_callback_ = std::move(callback);
if (has_position_to_report_) if (has_position_to_report_)
ReportCurrentPosition(); ReportCurrentPosition();
...@@ -178,8 +178,7 @@ void GeolocationServiceImpl::OnLocationUpdate(const Geoposition& position) { ...@@ -178,8 +178,7 @@ void GeolocationServiceImpl::OnLocationUpdate(const Geoposition& position) {
} }
void GeolocationServiceImpl::ReportCurrentPosition() { void GeolocationServiceImpl::ReportCurrentPosition() {
position_callback_.Run(current_position_.Clone()); std::move(position_callback_).Run(current_position_.Clone());
position_callback_.Reset();
has_position_to_report_ = false; has_position_to_report_ = false;
} }
......
...@@ -42,7 +42,7 @@ class GeolocationServiceImpl : public mojom::GeolocationService { ...@@ -42,7 +42,7 @@ class GeolocationServiceImpl : public mojom::GeolocationService {
private: private:
// mojom::GeolocationService: // mojom::GeolocationService:
void SetHighAccuracy(bool high_accuracy) override; void SetHighAccuracy(bool high_accuracy) override;
void QueryNextPosition(const QueryNextPositionCallback& callback) override; void QueryNextPosition(QueryNextPositionCallback callback) override;
void OnConnectionError(); void OnConnectionError();
......
...@@ -9,9 +9,6 @@ mojom("interfaces") { ...@@ -9,9 +9,6 @@ mojom("interfaces") {
"geolocation.mojom", "geolocation.mojom",
] ]
# TODO(crbug.com/714018): Convert the implementation to use OnceCallback.
use_once_callback = false
# TODO(crbug.com/699569): Convert to use the new JS bindings. # TODO(crbug.com/699569): Convert to use the new JS bindings.
use_new_js_bindings = false use_new_js_bindings = false
} }
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