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