| OLD | NEW |
| 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.h" | 10 #include "base/metrics/histogram.h" |
| (...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 45 case Geoposition::ERROR_CODE_PERMISSION_DENIED: | 45 case Geoposition::ERROR_CODE_PERMISSION_DENIED: |
| 46 code = GEOPOSITION_ERROR_CODE_PERMISSION_DENIED; | 46 code = GEOPOSITION_ERROR_CODE_PERMISSION_DENIED; |
| 47 break; | 47 break; |
| 48 case Geoposition::ERROR_CODE_POSITION_UNAVAILABLE: | 48 case Geoposition::ERROR_CODE_POSITION_UNAVAILABLE: |
| 49 code = GEOPOSITION_ERROR_CODE_POSITION_UNAVAILABLE; | 49 code = GEOPOSITION_ERROR_CODE_POSITION_UNAVAILABLE; |
| 50 break; | 50 break; |
| 51 case Geoposition::ERROR_CODE_TIMEOUT: | 51 case Geoposition::ERROR_CODE_TIMEOUT: |
| 52 code = GEOPOSITION_ERROR_CODE_TIMEOUT; | 52 code = GEOPOSITION_ERROR_CODE_TIMEOUT; |
| 53 break; | 53 break; |
| 54 } | 54 } |
| 55 UMA_HISTOGRAM_ENUMERATION("Geolocation.LocationUpdate.ErrorCode", | 55 UMA_HISTOGRAM_ENUMERATION("Geolocation.LocationUpdate.ErrorCode", code, |
| 56 code, | |
| 57 GEOPOSITION_ERROR_CODE_COUNT); | 56 GEOPOSITION_ERROR_CODE_COUNT); |
| 58 } | 57 } |
| 59 | 58 |
| 60 } // namespace | 59 } // namespace |
| 61 | 60 |
| 62 GeolocationServiceImpl::GeolocationServiceImpl( | 61 GeolocationServiceImpl::GeolocationServiceImpl( |
| 63 mojo::InterfaceRequest<GeolocationService> request, | 62 mojo::InterfaceRequest<GeolocationService> request, |
| 64 GeolocationServiceContext* context, | 63 GeolocationServiceContext* context, |
| 65 const base::Closure& update_callback) | 64 const base::Closure& update_callback) |
| 66 : binding_(this, std::move(request)), | 65 : binding_(this, std::move(request)), |
| 67 context_(context), | 66 context_(context), |
| 68 update_callback_(update_callback), | 67 update_callback_(update_callback), |
| 69 high_accuracy_(false), | 68 high_accuracy_(false), |
| 70 has_position_to_report_(false) { | 69 has_position_to_report_(false) { |
| 71 DCHECK(context_); | 70 DCHECK(context_); |
| 72 binding_.set_connection_error_handler( | 71 binding_.set_connection_error_handler(base::Bind( |
| 73 base::Bind(&GeolocationServiceImpl::OnConnectionError, | 72 &GeolocationServiceImpl::OnConnectionError, base::Unretained(this))); |
| 74 base::Unretained(this))); | |
| 75 } | 73 } |
| 76 | 74 |
| 77 GeolocationServiceImpl::~GeolocationServiceImpl() { | 75 GeolocationServiceImpl::~GeolocationServiceImpl() { |
| 78 // Make sure to respond to any pending callback even without a valid position. | 76 // Make sure to respond to any pending callback even without a valid position. |
| 79 if (!position_callback_.is_null()) { | 77 if (!position_callback_.is_null()) { |
| 80 if (!current_position_.valid) { | 78 if (!current_position_.valid) { |
| 81 current_position_.error_code = blink::mojom::Geoposition::ErrorCode( | 79 current_position_.error_code = blink::mojom::Geoposition::ErrorCode( |
| 82 GEOPOSITION_ERROR_CODE_POSITION_UNAVAILABLE); | 80 GEOPOSITION_ERROR_CODE_POSITION_UNAVAILABLE); |
| 83 current_position_.error_message = mojo::String(""); | 81 current_position_.error_message = mojo::String(""); |
| 84 } | 82 } |
| (...skipping 101 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 186 ReportCurrentPosition(); | 184 ReportCurrentPosition(); |
| 187 } | 185 } |
| 188 | 186 |
| 189 void GeolocationServiceImpl::ReportCurrentPosition() { | 187 void GeolocationServiceImpl::ReportCurrentPosition() { |
| 190 position_callback_.Run(current_position_.Clone()); | 188 position_callback_.Run(current_position_.Clone()); |
| 191 position_callback_.Reset(); | 189 position_callback_.Reset(); |
| 192 has_position_to_report_ = false; | 190 has_position_to_report_ = false; |
| 193 } | 191 } |
| 194 | 192 |
| 195 } // namespace device | 193 } // namespace device |
| OLD | NEW |