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/geolocation_dispatcher_host.h" | 5 #include "content/browser/geolocation/geolocation_dispatcher_host.h" |
6 | 6 |
7 #include <map> | 7 #include <map> |
8 #include <set> | 8 #include <set> |
9 #include <utility> | 9 #include <utility> |
10 | 10 |
11 #include "base/bind.h" | 11 #include "base/bind.h" |
12 #include "base/metrics/histogram.h" | 12 #include "base/metrics/histogram.h" |
13 #include "content/browser/geolocation/geolocation_provider_impl.h" | 13 #include "content/browser/geolocation/geolocation_provider_impl.h" |
14 #include "content/browser/renderer_host/render_message_filter.h" | 14 #include "content/browser/renderer_host/render_message_filter.h" |
15 #include "content/browser/renderer_host/render_process_host_impl.h" | 15 #include "content/browser/renderer_host/render_process_host_impl.h" |
16 #include "content/browser/renderer_host/render_view_host_impl.h" | 16 #include "content/browser/renderer_host/render_view_host_impl.h" |
17 #include "content/public/browser/geolocation_permission_context.h" | 17 #include "content/public/browser/geolocation_permission_context.h" |
18 #include "content/public/common/geoposition.h" | 18 #include "content/public/common/geoposition.h" |
19 #include "content/common/geolocation_messages.h" | 19 #include "content/common/geolocation_messages.h" |
20 | 20 |
21 namespace content { | 21 namespace content { |
22 namespace { | 22 namespace { |
23 | 23 |
| 24 // Geoposition error codes for reporting in UMA. |
| 25 enum GeopositionErrorCode { |
| 26 // NOTE: Do not renumber these as that would confuse interpretation of |
| 27 // previously logged data. When making changes, also update the enum list |
| 28 // in tools/metrics/histograms/histograms.xml to keep it in sync. |
| 29 |
| 30 // There was no error. |
| 31 GEOPOSITION_ERROR_CODE_NONE = 0, |
| 32 |
| 33 // User denied use of geolocation. |
| 34 GEOPOSITION_ERROR_CODE_PERMISSION_DENIED = 1, |
| 35 |
| 36 // Geoposition could not be determined. |
| 37 GEOPOSITION_ERROR_CODE_POSITION_UNAVAILABLE = 2, |
| 38 |
| 39 // Timeout. |
| 40 GEOPOSITION_ERROR_CODE_TIMEOUT = 3, |
| 41 |
| 42 // NOTE: Add entries only immediately above this line. |
| 43 GEOPOSITION_ERROR_CODE_COUNT = 4 |
| 44 }; |
| 45 |
| 46 void RecordGeopositionErrorCode(Geoposition::ErrorCode error_code) { |
| 47 GeopositionErrorCode code = GEOPOSITION_ERROR_CODE_NONE; |
| 48 switch (error_code) { |
| 49 case Geoposition::ERROR_CODE_NONE: |
| 50 code = GEOPOSITION_ERROR_CODE_NONE; |
| 51 break; |
| 52 case Geoposition::ERROR_CODE_PERMISSION_DENIED: |
| 53 code = GEOPOSITION_ERROR_CODE_PERMISSION_DENIED; |
| 54 break; |
| 55 case Geoposition::ERROR_CODE_POSITION_UNAVAILABLE: |
| 56 code = GEOPOSITION_ERROR_CODE_POSITION_UNAVAILABLE; |
| 57 break; |
| 58 case Geoposition::ERROR_CODE_TIMEOUT: |
| 59 code = GEOPOSITION_ERROR_CODE_TIMEOUT; |
| 60 break; |
| 61 } |
| 62 UMA_HISTOGRAM_ENUMERATION("Geolocation.LocationUpdate.ErrorCode", |
| 63 code, |
| 64 GEOPOSITION_ERROR_CODE_COUNT); |
| 65 } |
| 66 |
24 void NotifyGeolocationProviderPermissionGranted() { | 67 void NotifyGeolocationProviderPermissionGranted() { |
25 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); | 68 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); |
26 GeolocationProviderImpl::GetInstance()->UserDidOptIntoLocationServices(); | 69 GeolocationProviderImpl::GetInstance()->UserDidOptIntoLocationServices(); |
27 } | 70 } |
28 | 71 |
29 void SendGeolocationPermissionResponse(int render_process_id, | 72 void SendGeolocationPermissionResponse(int render_process_id, |
30 int render_view_id, | 73 int render_view_id, |
31 int bridge_id, | 74 int bridge_id, |
32 bool allowed) { | 75 bool allowed) { |
33 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 76 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
(...skipping 107 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
141 IPC_MESSAGE_HANDLER(GeolocationHostMsg_StartUpdating, OnStartUpdating) | 184 IPC_MESSAGE_HANDLER(GeolocationHostMsg_StartUpdating, OnStartUpdating) |
142 IPC_MESSAGE_HANDLER(GeolocationHostMsg_StopUpdating, OnStopUpdating) | 185 IPC_MESSAGE_HANDLER(GeolocationHostMsg_StopUpdating, OnStopUpdating) |
143 IPC_MESSAGE_UNHANDLED(handled = false) | 186 IPC_MESSAGE_UNHANDLED(handled = false) |
144 IPC_END_MESSAGE_MAP() | 187 IPC_END_MESSAGE_MAP() |
145 return handled; | 188 return handled; |
146 } | 189 } |
147 | 190 |
148 void GeolocationDispatcherHostImpl::OnLocationUpdate( | 191 void GeolocationDispatcherHostImpl::OnLocationUpdate( |
149 const Geoposition& geoposition) { | 192 const Geoposition& geoposition) { |
150 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); | 193 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); |
| 194 RecordGeopositionErrorCode(geoposition.error_code); |
151 for (std::map<int, RendererGeolocationOptions>::iterator it = | 195 for (std::map<int, RendererGeolocationOptions>::iterator it = |
152 geolocation_renderers_.begin(); | 196 geolocation_renderers_.begin(); |
153 it != geolocation_renderers_.end(); ++it) { | 197 it != geolocation_renderers_.end(); ++it) { |
154 if (!(it->second.is_paused)) | 198 if (!(it->second.is_paused)) |
155 Send(new GeolocationMsg_PositionUpdated(it->first, geoposition)); | 199 Send(new GeolocationMsg_PositionUpdated(it->first, geoposition)); |
156 } | 200 } |
157 } | 201 } |
158 | 202 |
159 void GeolocationDispatcherHostImpl::OnRequestPermission( | 203 void GeolocationDispatcherHostImpl::OnRequestPermission( |
160 int render_view_id, | 204 int render_view_id, |
(...skipping 135 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
296 } | 340 } |
297 | 341 |
298 GeolocationDispatcherHost::GeolocationDispatcherHost() | 342 GeolocationDispatcherHost::GeolocationDispatcherHost() |
299 : BrowserMessageFilter(GeolocationMsgStart) { | 343 : BrowserMessageFilter(GeolocationMsgStart) { |
300 } | 344 } |
301 | 345 |
302 GeolocationDispatcherHost::~GeolocationDispatcherHost() { | 346 GeolocationDispatcherHost::~GeolocationDispatcherHost() { |
303 } | 347 } |
304 | 348 |
305 } // namespace content | 349 } // namespace content |
OLD | NEW |