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 // This file declares GPS providers that run on linux. Currently, just uses | 5 // This file declares GPS providers that run on linux. Currently, just uses |
6 // the libgps (gpsd) API. Public for testing only - for normal usage this | 6 // the libgps (gpsd) API. Public for testing only - for normal usage this |
7 // header should not be required, as location_provider.h declares the needed | 7 // header should not be required, as location_provider.h declares the needed |
8 // factory function. | 8 // factory function. |
9 | 9 |
10 #ifndef CONTENT_BROWSER_GEOLOCATION_GPS_LOCATION_PROVIDER_LINUX_H_ | 10 #ifndef CONTENT_BROWSER_GEOLOCATION_GPS_LOCATION_PROVIDER_LINUX_H_ |
11 #define CONTENT_BROWSER_GEOLOCATION_GPS_LOCATION_PROVIDER_LINUX_H_ | 11 #define CONTENT_BROWSER_GEOLOCATION_GPS_LOCATION_PROVIDER_LINUX_H_ |
12 #pragma once | 12 #pragma once |
13 | 13 |
14 #include "base/compiler_specific.h" | 14 #include "base/compiler_specific.h" |
15 #include "base/memory/scoped_ptr.h" | 15 #include "base/memory/scoped_ptr.h" |
16 #include "base/memory/weak_ptr.h" | 16 #include "base/memory/weak_ptr.h" |
17 #include "content/browser/geolocation/location_provider.h" | 17 #include "content/browser/geolocation/location_provider.h" |
18 #include "content/common/content_export.h" | 18 #include "content/common/content_export.h" |
19 #include "content/common/geoposition.h" | 19 #include "content/public/common/geoposition.h" |
20 | 20 |
21 class LibGps; | 21 class LibGps; |
22 | 22 |
23 // Location provider for Linux, that uses libgps/gpsd to obtain position fixes. | 23 // Location provider for Linux, that uses libgps/gpsd to obtain position fixes. |
24 // TODO(joth): Currently this runs entirely in the client thread (i.e. Chrome's | 24 // TODO(joth): Currently this runs entirely in the client thread (i.e. Chrome's |
25 // IO thread). As the older libgps API is not designed to support polling, | 25 // IO thread). As the older libgps API is not designed to support polling, |
26 // there's a chance it could block, so better move this into its own worker | 26 // there's a chance it could block, so better move this into its own worker |
27 // thread. | 27 // thread. |
28 class CONTENT_EXPORT GpsLocationProviderLinux : public LocationProviderBase { | 28 class CONTENT_EXPORT GpsLocationProviderLinux : public LocationProviderBase { |
29 public: | 29 public: |
30 typedef LibGps* (*LibGpsFactory)(); | 30 typedef LibGps* (*LibGpsFactory)(); |
31 // |factory| will be used to create the gpsd client library wrapper. (Note | 31 // |factory| will be used to create the gpsd client library wrapper. (Note |
32 // NewSystemLocationProvider() will use the default factory). | 32 // NewSystemLocationProvider() will use the default factory). |
33 explicit GpsLocationProviderLinux(LibGpsFactory libgps_factory); | 33 explicit GpsLocationProviderLinux(LibGpsFactory libgps_factory); |
34 virtual ~GpsLocationProviderLinux(); | 34 virtual ~GpsLocationProviderLinux(); |
35 | 35 |
36 void SetGpsdReconnectIntervalMillis(int value) { | 36 void SetGpsdReconnectIntervalMillis(int value) { |
37 gpsd_reconnect_interval_millis_ = value; | 37 gpsd_reconnect_interval_millis_ = value; |
38 } | 38 } |
39 void SetPollPeriodMovingMillis(int value) { | 39 void SetPollPeriodMovingMillis(int value) { |
40 poll_period_moving_millis_ = value; | 40 poll_period_moving_millis_ = value; |
41 } | 41 } |
42 void SetPollPeriodStationaryMillis(int value) { | 42 void SetPollPeriodStationaryMillis(int value) { |
43 poll_period_stationary_millis_ = value; | 43 poll_period_stationary_millis_ = value; |
44 } | 44 } |
45 | 45 |
46 // LocationProvider | 46 // LocationProvider |
47 virtual bool StartProvider(bool high_accuracy) OVERRIDE; | 47 virtual bool StartProvider(bool high_accuracy) OVERRIDE; |
48 virtual void StopProvider() OVERRIDE; | 48 virtual void StopProvider() OVERRIDE; |
49 virtual void GetPosition(Geoposition* position) OVERRIDE; | 49 virtual void GetPosition(content::Geoposition* position) OVERRIDE; |
50 virtual void UpdatePosition() OVERRIDE; | 50 virtual void UpdatePosition() OVERRIDE; |
51 | 51 |
52 private: | 52 private: |
53 // Task which run in the child thread. | 53 // Task which run in the child thread. |
54 void DoGpsPollTask(); | 54 void DoGpsPollTask(); |
55 | 55 |
56 // Will schedule a poll; i.e. enqueue DoGpsPollTask deferred task. | 56 // Will schedule a poll; i.e. enqueue DoGpsPollTask deferred task. |
57 void ScheduleNextGpsPoll(int interval); | 57 void ScheduleNextGpsPoll(int interval); |
58 | 58 |
59 int gpsd_reconnect_interval_millis_; | 59 int gpsd_reconnect_interval_millis_; |
60 int poll_period_moving_millis_; | 60 int poll_period_moving_millis_; |
61 int poll_period_stationary_millis_; | 61 int poll_period_stationary_millis_; |
62 | 62 |
63 const LibGpsFactory libgps_factory_; | 63 const LibGpsFactory libgps_factory_; |
64 scoped_ptr<LibGps> gps_; | 64 scoped_ptr<LibGps> gps_; |
65 Geoposition position_; | 65 content::Geoposition position_; |
66 | 66 |
67 // Holder for the tasks which run on the thread; takes care of cleanup. | 67 // Holder for the tasks which run on the thread; takes care of cleanup. |
68 base::WeakPtrFactory<GpsLocationProviderLinux> weak_factory_; | 68 base::WeakPtrFactory<GpsLocationProviderLinux> weak_factory_; |
69 }; | 69 }; |
70 | 70 |
71 #endif // CONTENT_BROWSER_GEOLOCATION_GPS_LOCATION_PROVIDER_LINUX_H_ | 71 #endif // CONTENT_BROWSER_GEOLOCATION_GPS_LOCATION_PROVIDER_LINUX_H_ |
OLD | NEW |