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

Side by Side Diff: device/geolocation/geolocation_service_impl.cc

Issue 2866003002: Use OnceCallback on Mojo interfaces in //device/geolocation (Closed)
Patch Set: rebase Created 3 years, 6 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 unified diff | Download patch
OLDNEW
1 // Copyright 2014 The Chromium Authors. All rights reserved. 1 // Copyright 2014 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "device/geolocation/geolocation_service_impl.h" 5 #include "device/geolocation/geolocation_service_impl.h"
6 6
7 #include <utility> 7 #include <utility>
8 8
9 #include "base/bind.h" 9 #include "base/bind.h"
10 #include "base/metrics/histogram_macros.h" 10 #include "base/metrics/histogram_macros.h"
(...skipping 100 matching lines...) Expand 10 before | Expand all | Expand 10 after
111 111
112 if (position_override_.Validate()) { 112 if (position_override_.Validate()) {
113 OnLocationUpdate(position_override_); 113 OnLocationUpdate(position_override_);
114 return; 114 return;
115 } 115 }
116 116
117 StartListeningForUpdates(); 117 StartListeningForUpdates();
118 } 118 }
119 119
120 void GeolocationServiceImpl::QueryNextPosition( 120 void GeolocationServiceImpl::QueryNextPosition(
121 const QueryNextPositionCallback& callback) { 121 QueryNextPositionCallback callback) {
122 if (!position_callback_.is_null()) { 122 if (!position_callback_.is_null()) {
123 DVLOG(1) << "Overlapped call to QueryNextPosition!"; 123 DVLOG(1) << "Overlapped call to QueryNextPosition!";
124 OnConnectionError(); // Simulate a connection error. 124 OnConnectionError(); // Simulate a connection error.
125 return; 125 return;
126 } 126 }
127 127
128 position_callback_ = callback; 128 position_callback_ = std::move(callback);
129 129
130 if (has_position_to_report_) 130 if (has_position_to_report_)
131 ReportCurrentPosition(); 131 ReportCurrentPosition();
132 } 132 }
133 133
134 void GeolocationServiceImpl::SetOverride(const Geoposition& position) { 134 void GeolocationServiceImpl::SetOverride(const Geoposition& position) {
135 position_override_ = position; 135 position_override_ = position;
136 if (!position_override_.Validate()) { 136 if (!position_override_.Validate()) {
137 ResumeUpdates(); 137 ResumeUpdates();
138 } 138 }
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after
171 mojom::Geoposition::ErrorCode(position.error_code); 171 mojom::Geoposition::ErrorCode(position.error_code);
172 current_position_.error_message = position.error_message; 172 current_position_.error_message = position.error_message;
173 173
174 has_position_to_report_ = true; 174 has_position_to_report_ = true;
175 175
176 if (!position_callback_.is_null()) 176 if (!position_callback_.is_null())
177 ReportCurrentPosition(); 177 ReportCurrentPosition();
178 } 178 }
179 179
180 void GeolocationServiceImpl::ReportCurrentPosition() { 180 void GeolocationServiceImpl::ReportCurrentPosition() {
181 position_callback_.Run(current_position_.Clone()); 181 std::move(position_callback_).Run(current_position_.Clone());
182 position_callback_.Reset();
183 has_position_to_report_ = false; 182 has_position_to_report_ = false;
184 } 183 }
185 184
186 } // namespace device 185 } // namespace device
OLDNEW
« no previous file with comments | « device/geolocation/geolocation_service_impl.h ('k') | device/geolocation/public/interfaces/BUILD.gn » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698