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

Side by Side Diff: content/browser/geolocation/geolocation_service_impl.cc

Issue 1771743002: Move geolocation and permission mojoms into WebKit/public/platform. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: rebase Created 4 years, 8 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 "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 31 matching lines...) Expand 10 before | Expand all | Expand 10 after
54 break; 53 break;
55 } 54 }
56 UMA_HISTOGRAM_ENUMERATION("Geolocation.LocationUpdate.ErrorCode", 55 UMA_HISTOGRAM_ENUMERATION("Geolocation.LocationUpdate.ErrorCode",
57 code, 56 code,
58 GEOPOSITION_ERROR_CODE_COUNT); 57 GEOPOSITION_ERROR_CODE_COUNT);
59 } 58 }
60 59
61 } // namespace 60 } // namespace
62 61
63 GeolocationServiceImpl::GeolocationServiceImpl( 62 GeolocationServiceImpl::GeolocationServiceImpl(
64 mojo::InterfaceRequest<mojom::GeolocationService> request, 63 mojo::InterfaceRequest<GeolocationService> request,
65 GeolocationServiceContext* context, 64 GeolocationServiceContext* context,
66 const base::Closure& update_callback) 65 const base::Closure& update_callback)
67 : binding_(this, std::move(request)), 66 : binding_(this, std::move(request)),
68 context_(context), 67 context_(context),
69 update_callback_(update_callback), 68 update_callback_(update_callback),
70 high_accuracy_(false), 69 high_accuracy_(false),
71 has_position_to_report_(false) { 70 has_position_to_report_(false) {
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 = mojom::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
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 mojom::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
OLDNEW
« no previous file with comments | « content/browser/geolocation/geolocation_service_impl.h ('k') | content/browser/media/cdm/browser_cdm_manager.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698