| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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 "content/browser/geolocation/gps_location_provider_linux.h" | 5 #include "content/browser/geolocation/gps_location_provider_linux.h" |
| 6 | 6 |
| 7 #include <dlfcn.h> | 7 #include <dlfcn.h> |
| 8 #include <errno.h> | 8 #include <errno.h> |
| 9 | 9 |
| 10 #include <algorithm> | 10 #include <algorithm> |
| (...skipping 126 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 137 is_open_ = true; | 137 is_open_ = true; |
| 138 return true; | 138 return true; |
| 139 } | 139 } |
| 140 | 140 |
| 141 void LibGps::Stop() { | 141 void LibGps::Stop() { |
| 142 if (is_open_) | 142 if (is_open_) |
| 143 gps_close_(gps_data_.get()); | 143 gps_close_(gps_data_.get()); |
| 144 is_open_ = false; | 144 is_open_ = false; |
| 145 } | 145 } |
| 146 | 146 |
| 147 bool LibGps::Read(content::Geoposition* position) { | 147 bool LibGps::Read(Geoposition* position) { |
| 148 DCHECK(position); | 148 DCHECK(position); |
| 149 position->error_code = content::Geoposition::ERROR_CODE_POSITION_UNAVAILABLE; | 149 position->error_code = Geoposition::ERROR_CODE_POSITION_UNAVAILABLE; |
| 150 if (!is_open_) { | 150 if (!is_open_) { |
| 151 DLOG(WARNING) << "No gpsd connection"; | 151 DLOG(WARNING) << "No gpsd connection"; |
| 152 position->error_message = "No gpsd connection"; | 152 position->error_message = "No gpsd connection"; |
| 153 return false; | 153 return false; |
| 154 } | 154 } |
| 155 | 155 |
| 156 if (gps_read_(gps_data_.get()) < 0) { | 156 if (gps_read_(gps_data_.get()) < 0) { |
| 157 DLOG(WARNING) << "gps_read() fails"; | 157 DLOG(WARNING) << "gps_read() fails"; |
| 158 position->error_message = "gps_read() fails"; | 158 position->error_message = "gps_read() fails"; |
| 159 return false; | 159 return false; |
| 160 } | 160 } |
| 161 | 161 |
| 162 if (!GetPositionIfFixed(position)) { | 162 if (!GetPositionIfFixed(position)) { |
| 163 DLOG(WARNING) << "No fixed position"; | 163 DLOG(WARNING) << "No fixed position"; |
| 164 position->error_message = "No fixed position"; | 164 position->error_message = "No fixed position"; |
| 165 return false; | 165 return false; |
| 166 } | 166 } |
| 167 | 167 |
| 168 position->error_code = content::Geoposition::ERROR_CODE_NONE; | 168 position->error_code = Geoposition::ERROR_CODE_NONE; |
| 169 position->timestamp = base::Time::Now(); | 169 position->timestamp = base::Time::Now(); |
| 170 if (!position->Validate()) { | 170 if (!position->Validate()) { |
| 171 // GetPositionIfFixed returned true, yet we've not got a valid fix. | 171 // GetPositionIfFixed returned true, yet we've not got a valid fix. |
| 172 // This shouldn't happen; something went wrong in the conversion. | 172 // This shouldn't happen; something went wrong in the conversion. |
| 173 NOTREACHED() << "Invalid position from GetPositionIfFixed: lat,long " | 173 NOTREACHED() << "Invalid position from GetPositionIfFixed: lat,long " |
| 174 << position->latitude << "," << position->longitude | 174 << position->latitude << "," << position->longitude |
| 175 << " accuracy " << position->accuracy << " time " | 175 << " accuracy " << position->accuracy << " time " |
| 176 << position->timestamp.ToDoubleT(); | 176 << position->timestamp.ToDoubleT(); |
| 177 position->error_code = | 177 position->error_code = Geoposition::ERROR_CODE_POSITION_UNAVAILABLE; |
| 178 content::Geoposition::ERROR_CODE_POSITION_UNAVAILABLE; | |
| 179 position->error_message = "Bad fix from gps"; | 178 position->error_message = "Bad fix from gps"; |
| 180 return false; | 179 return false; |
| 181 } | 180 } |
| 182 return true; | 181 return true; |
| 183 } | 182 } |
| 184 | 183 |
| 185 bool LibGps::GetPositionIfFixed(content::Geoposition* position) { | 184 bool LibGps::GetPositionIfFixed(Geoposition* position) { |
| 186 DCHECK(position); | 185 DCHECK(position); |
| 187 if (gps_data_->status == STATUS_NO_FIX) { | 186 if (gps_data_->status == STATUS_NO_FIX) { |
| 188 DVLOG(2) << "Status_NO_FIX"; | 187 DVLOG(2) << "Status_NO_FIX"; |
| 189 return false; | 188 return false; |
| 190 } | 189 } |
| 191 | 190 |
| 192 if (isnan(gps_data_->fix.latitude) || isnan(gps_data_->fix.longitude)) { | 191 if (isnan(gps_data_->fix.latitude) || isnan(gps_data_->fix.longitude)) { |
| 193 DVLOG(2) << "No valid lat/lon value"; | 192 DVLOG(2) << "No valid lat/lon value"; |
| 194 return false; | 193 return false; |
| 195 } | 194 } |
| (...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 238 return NULL; | 237 return NULL; |
| 239 } | 238 } |
| 240 | 239 |
| 241 bool LibGps::Start() { | 240 bool LibGps::Start() { |
| 242 return false; | 241 return false; |
| 243 } | 242 } |
| 244 | 243 |
| 245 void LibGps::Stop() { | 244 void LibGps::Stop() { |
| 246 } | 245 } |
| 247 | 246 |
| 248 bool LibGps::Read(content::Geoposition* position) { | 247 bool LibGps::Read(Geoposition* position) { |
| 249 return false; | 248 return false; |
| 250 } | 249 } |
| 251 | 250 |
| 252 bool LibGps::GetPositionIfFixed(content::Geoposition* position) { | 251 bool LibGps::GetPositionIfFixed(Geoposition* position) { |
| 253 return false; | 252 return false; |
| 254 } | 253 } |
| 255 | 254 |
| 256 #endif // !defined(USE_LIBGPS) | 255 #endif // !defined(USE_LIBGPS) |
| 257 | 256 |
| 258 GpsLocationProviderLinux::GpsLocationProviderLinux(LibGpsFactory libgps_factory) | 257 GpsLocationProviderLinux::GpsLocationProviderLinux(LibGpsFactory libgps_factory) |
| 259 : gpsd_reconnect_interval_millis_(kGpsdReconnectRetryIntervalMillis), | 258 : gpsd_reconnect_interval_millis_(kGpsdReconnectRetryIntervalMillis), |
| 260 poll_period_moving_millis_(kPollPeriodMovingMillis), | 259 poll_period_moving_millis_(kPollPeriodMovingMillis), |
| 261 poll_period_stationary_millis_(kPollPeriodStationaryMillis), | 260 poll_period_stationary_millis_(kPollPeriodStationaryMillis), |
| 262 libgps_factory_(libgps_factory), | 261 libgps_factory_(libgps_factory), |
| (...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 334 base::Bind(&GpsLocationProviderLinux::DoGpsPollTask, | 333 base::Bind(&GpsLocationProviderLinux::DoGpsPollTask, |
| 335 weak_factory_.GetWeakPtr()), | 334 weak_factory_.GetWeakPtr()), |
| 336 base::TimeDelta::FromMilliseconds(interval)); | 335 base::TimeDelta::FromMilliseconds(interval)); |
| 337 } | 336 } |
| 338 | 337 |
| 339 LocationProviderBase* NewSystemLocationProvider() { | 338 LocationProviderBase* NewSystemLocationProvider() { |
| 340 return new GpsLocationProviderLinux(LibGps::New); | 339 return new GpsLocationProviderLinux(LibGps::New); |
| 341 } | 340 } |
| 342 | 341 |
| 343 } // namespace content | 342 } // namespace content |
| OLD | NEW |