| 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 "content/browser/geolocation/geolocation_service_impl.h" | 5 #include "content/browser/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" |
| 11 #include "content/browser/geolocation/geolocation_service_context.h" | 11 #include "content/browser/geolocation/geolocation_service_context.h" |
| 12 #include "content/public/common/mojo_geoposition.mojom.h" | |
| 13 | 12 |
| 14 namespace content { | 13 namespace content { |
| 15 | 14 |
| 16 namespace { | 15 namespace { |
| 17 | 16 |
| 18 // Geoposition error codes for reporting in UMA. | 17 // Geoposition error codes for reporting in UMA. |
| 19 enum GeopositionErrorCode { | 18 enum GeopositionErrorCode { |
| 20 // NOTE: Do not renumber these as that would confuse interpretation of | 19 // NOTE: Do not renumber these as that would confuse interpretation of |
| 21 // previously logged data. When making changes, also update the enum list | 20 // previously logged data. When making changes, also update the enum list |
| 22 // in tools/metrics/histograms/histograms.xml to keep it in sync. | 21 // in tools/metrics/histograms/histograms.xml to keep it in sync. |
| (...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 72 DCHECK(context_); | 71 DCHECK(context_); |
| 73 binding_.set_connection_error_handler( | 72 binding_.set_connection_error_handler( |
| 74 base::Bind(&GeolocationServiceImpl::OnConnectionError, | 73 base::Bind(&GeolocationServiceImpl::OnConnectionError, |
| 75 base::Unretained(this))); | 74 base::Unretained(this))); |
| 76 } | 75 } |
| 77 | 76 |
| 78 GeolocationServiceImpl::~GeolocationServiceImpl() { | 77 GeolocationServiceImpl::~GeolocationServiceImpl() { |
| 79 // Make sure to respond to any pending callback even without a valid position. | 78 // Make sure to respond to any pending callback even without a valid position. |
| 80 if (!position_callback_.is_null()) { | 79 if (!position_callback_.is_null()) { |
| 81 if (!current_position_.valid) { | 80 if (!current_position_.valid) { |
| 82 current_position_.error_code = MojoGeoposition::ErrorCode( | 81 current_position_.error_code = blink::mojom::Geoposition::ErrorCode( |
| 83 GEOPOSITION_ERROR_CODE_POSITION_UNAVAILABLE); | 82 GEOPOSITION_ERROR_CODE_POSITION_UNAVAILABLE); |
| 84 current_position_.error_message = mojo::String(""); | 83 current_position_.error_message = mojo::String(""); |
| 85 } | 84 } |
| 86 ReportCurrentPosition(); | 85 ReportCurrentPosition(); |
| 87 } | 86 } |
| 88 } | 87 } |
| 89 | 88 |
| 90 void GeolocationServiceImpl::PauseUpdates() { | 89 void GeolocationServiceImpl::PauseUpdates() { |
| 91 geolocation_subscription_.reset(); | 90 geolocation_subscription_.reset(); |
| 92 } | 91 } |
| (...skipping 78 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 171 current_position_.valid = position.Validate(); | 170 current_position_.valid = position.Validate(); |
| 172 current_position_.latitude = position.latitude; | 171 current_position_.latitude = position.latitude; |
| 173 current_position_.longitude = position.longitude; | 172 current_position_.longitude = position.longitude; |
| 174 current_position_.altitude = position.altitude; | 173 current_position_.altitude = position.altitude; |
| 175 current_position_.accuracy = position.accuracy; | 174 current_position_.accuracy = position.accuracy; |
| 176 current_position_.altitude_accuracy = position.altitude_accuracy; | 175 current_position_.altitude_accuracy = position.altitude_accuracy; |
| 177 current_position_.heading = position.heading; | 176 current_position_.heading = position.heading; |
| 178 current_position_.speed = position.speed; | 177 current_position_.speed = position.speed; |
| 179 current_position_.timestamp = position.timestamp.ToDoubleT(); | 178 current_position_.timestamp = position.timestamp.ToDoubleT(); |
| 180 current_position_.error_code = | 179 current_position_.error_code = |
| 181 MojoGeoposition::ErrorCode(position.error_code); | 180 blink::mojom::Geoposition::ErrorCode(position.error_code); |
| 182 current_position_.error_message = position.error_message; | 181 current_position_.error_message = position.error_message; |
| 183 | 182 |
| 184 has_position_to_report_ = true; | 183 has_position_to_report_ = true; |
| 185 | 184 |
| 186 if (!position_callback_.is_null()) | 185 if (!position_callback_.is_null()) |
| 187 ReportCurrentPosition(); | 186 ReportCurrentPosition(); |
| 188 } | 187 } |
| 189 | 188 |
| 190 void GeolocationServiceImpl::ReportCurrentPosition() { | 189 void GeolocationServiceImpl::ReportCurrentPosition() { |
| 191 position_callback_.Run(current_position_.Clone()); | 190 position_callback_.Run(current_position_.Clone()); |
| 192 position_callback_.reset(); | 191 position_callback_.reset(); |
| 193 has_position_to_report_ = false; | 192 has_position_to_report_ = false; |
| 194 } | 193 } |
| 195 | 194 |
| 196 } // namespace content | 195 } // namespace content |
| OLD | NEW |