OLD | NEW |
1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2010 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 CHROME_BROWSER_GEOLOCATION_GPS_LOCATION_PROVIDER_LINUX_H_ | 10 #ifndef CHROME_BROWSER_GEOLOCATION_GPS_LOCATION_PROVIDER_LINUX_H_ |
11 #define CHROME_BROWSER_GEOLOCATION_GPS_LOCATION_PROVIDER_LINUX_H_ | 11 #define CHROME_BROWSER_GEOLOCATION_GPS_LOCATION_PROVIDER_LINUX_H_ |
12 #pragma once | 12 #pragma once |
13 | 13 |
| 14 #include "base/scoped_ptr.h" |
| 15 #include "base/task.h" |
14 #include "chrome/browser/geolocation/location_provider.h" | 16 #include "chrome/browser/geolocation/location_provider.h" |
15 #include "chrome/common/geoposition.h" | 17 #include "chrome/common/geoposition.h" |
16 | 18 |
17 #include "base/scoped_ptr.h" | |
18 #include "base/task.h" | |
19 | |
20 class LibGps; | 19 class LibGps; |
21 | 20 |
22 // Location provider for Linux, that uses libgps/gpsd to obtain position fixes. | 21 // Location provider for Linux, that uses libgps/gpsd to obtain position fixes. |
23 // TODO(joth): Currently this runs entirely in the client thread (i.e. Chrome's | 22 // TODO(joth): Currently this runs entirely in the client thread (i.e. Chrome's |
24 // IO thread). As the older libgps API is not designed to support polling, | 23 // IO thread). As the older libgps API is not designed to support polling, |
25 // there's a chance it could block, so better move this into its own worker | 24 // there's a chance it could block, so better move this into its own worker |
26 // thread. | 25 // thread. |
27 class GpsLocationProviderLinux : public LocationProviderBase { | 26 class GpsLocationProviderLinux : public LocationProviderBase { |
28 public: | 27 public: |
29 typedef LibGps* (*LibGpsFactory)(); | 28 typedef LibGps* (*LibGpsFactory)(); |
30 // |factory| will be used to create the gpsd client library wrapper. (Note | 29 // |factory| will be used to create the gpsd client library wrapper. (Note |
31 // NewGpsLocationProvider() will use the default factory). | 30 // NewGpsLocationProvider() will use the default factory). |
32 GpsLocationProviderLinux(LibGpsFactory libgps_factory); | 31 explicit GpsLocationProviderLinux(LibGpsFactory libgps_factory); |
33 virtual ~GpsLocationProviderLinux(); | 32 virtual ~GpsLocationProviderLinux(); |
34 | 33 |
35 // LocationProvider | 34 // LocationProvider |
36 virtual bool StartProvider(bool high_accuracy); | 35 virtual bool StartProvider(bool high_accuracy); |
37 virtual void StopProvider(); | 36 virtual void StopProvider(); |
38 virtual void GetPosition(Geoposition* position); | 37 virtual void GetPosition(Geoposition* position); |
39 virtual void UpdatePosition(); | 38 virtual void UpdatePosition(); |
40 virtual void OnPermissionGranted(const GURL& requesting_frame); | 39 virtual void OnPermissionGranted(const GURL& requesting_frame); |
41 | 40 |
42 private: | 41 private: |
43 // Task which run in the child thread. | 42 // Task which run in the child thread. |
44 void DoGpsPollTask(); | 43 void DoGpsPollTask(); |
45 | 44 |
46 // Will schedule a poll; i.e. enqueue DoGpsPollTask deferred task. | 45 // Will schedule a poll; i.e. enqueue DoGpsPollTask deferred task. |
47 void ScheduleNextGpsPoll(int interval); | 46 void ScheduleNextGpsPoll(int interval); |
48 | 47 |
49 const LibGpsFactory libgps_factory_; | 48 const LibGpsFactory libgps_factory_; |
50 scoped_ptr<LibGps> gps_; | 49 scoped_ptr<LibGps> gps_; |
51 Geoposition position_; | 50 Geoposition position_; |
52 | 51 |
53 // Holder for the tasks which run on the thread; takes care of cleanup. | 52 // Holder for the tasks which run on the thread; takes care of cleanup. |
54 ScopedRunnableMethodFactory<GpsLocationProviderLinux> task_factory_; | 53 ScopedRunnableMethodFactory<GpsLocationProviderLinux> task_factory_; |
55 }; | 54 }; |
56 | 55 |
57 #endif // CHROME_BROWSER_GEOLOCATION_GPS_LOCATION_PROVIDER_LINUX_H_ | 56 #endif // CHROME_BROWSER_GEOLOCATION_GPS_LOCATION_PROVIDER_LINUX_H_ |
OLD | NEW |