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 #ifndef CHROME_BROWSER_GEOLOCATION_WIN7_LOCATION_API_WIN_H_ | 5 #ifndef CHROME_BROWSER_GEOLOCATION_WIN7_LOCATION_API_WIN_H_ |
6 #define CHROME_BROWSER_GEOLOCATION_WIN7_LOCATION_API_WIN_H_ | 6 #define CHROME_BROWSER_GEOLOCATION_WIN7_LOCATION_API_WIN_H_ |
7 | 7 |
8 #include <atlbase.h> | 8 #include <atlbase.h> |
9 #include <atlcom.h> | 9 #include <atlcom.h> |
10 #include <locationapi.h> | 10 #include <locationapi.h> |
11 #include <sensors.h> | 11 #include <sensors.h> |
12 #include <Windows.h> | 12 #include <Windows.h> |
13 | 13 |
| 14 #include "app/win/scoped_com_initializer.h" |
14 #include "base/time.h" | 15 #include "base/time.h" |
15 | 16 |
16 struct Geoposition; | 17 struct Geoposition; |
17 | 18 |
18 // PropVariantToDouble | 19 // PropVariantToDouble |
19 typedef HRESULT (WINAPI* PropVariantToDoubleFunction) | 20 typedef HRESULT (WINAPI* PropVariantToDoubleFunction) |
20 (REFPROPVARIANT propvarIn, DOUBLE *pdblRet); | 21 (REFPROPVARIANT propvarIn, DOUBLE *pdblRet); |
21 | 22 |
22 class Win7LocationApi { | 23 class Win7LocationApi { |
23 public: | 24 public: |
24 // Public for testing. See Create() below for normal usage. | |
25 Win7LocationApi(HINSTANCE prop_library, | |
26 PropVariantToDoubleFunction PropVariantToDouble_function, | |
27 ILocation* locator); | |
28 virtual ~Win7LocationApi(); | 25 virtual ~Win7LocationApi(); |
29 | |
30 // Attempts to load propsys.dll, initialise |location_| and requests the user | 26 // Attempts to load propsys.dll, initialise |location_| and requests the user |
31 // for access to location information. Creates and returns ownership of an | 27 // for access to location information. Creates and returns ownership of an |
32 // instance of Win7LocationApi if all succeed. | 28 // instance of Win7LocationApi if all succeed. |
33 static Win7LocationApi* Create(); | 29 static Win7LocationApi* Create(); |
| 30 static Win7LocationApi* CreateForTesting( |
| 31 PropVariantToDoubleFunction PropVariantToDouble_function, |
| 32 ILocation* locator); |
34 // Gives the best available position. | 33 // Gives the best available position. |
35 // Returns false if no valid position is available. | 34 // Returns false if no valid position is available. |
36 virtual void GetPosition(Geoposition* position); | 35 virtual void GetPosition(Geoposition* position); |
37 // Changes the "accuracy" needed. Affects power levels of devices. | 36 // Changes the "accuracy" needed. Affects power levels of devices. |
38 virtual bool SetHighAccuracy(bool acc); | 37 virtual bool SetHighAccuracy(bool acc); |
39 | 38 |
| 39 protected: |
| 40 Win7LocationApi(); |
| 41 |
40 private: | 42 private: |
| 43 void Init(HINSTANCE prop_library, |
| 44 PropVariantToDoubleFunction PropVariantToDouble_function, |
| 45 ILocation* locator); |
| 46 |
41 // Provides the best position fix if one is available. | 47 // Provides the best position fix if one is available. |
42 // Does this by requesting a location report and querying it to obtain | 48 // Does this by requesting a location report and querying it to obtain |
43 // location information. | 49 // location information. |
44 virtual bool GetPositionIfFixed(Geoposition* position); | 50 virtual bool GetPositionIfFixed(Geoposition* position); |
45 | 51 |
| 52 // Ensure that COM has been initialized for this thread. |
| 53 app::win::ScopedCOMInitializer com_initializer_; |
46 // ILocation object that lets us communicate with the Location and | 54 // ILocation object that lets us communicate with the Location and |
47 // Sensors platform. | 55 // Sensors platform. |
48 CComPtr<ILocation> locator_; | 56 CComPtr<ILocation> locator_; |
49 // Holds the opened propsys.dll library that is passed on construction. | 57 // Holds the opened propsys.dll library that is passed on construction. |
50 // This class is responsible for closing it. | 58 // This class is responsible for closing it. |
51 HINSTANCE prop_lib_; | 59 HINSTANCE prop_lib_; |
52 PropVariantToDoubleFunction PropVariantToDouble_function_; | 60 PropVariantToDoubleFunction PropVariantToDouble_function_; |
53 | 61 |
54 DISALLOW_COPY_AND_ASSIGN(Win7LocationApi); | 62 DISALLOW_COPY_AND_ASSIGN(Win7LocationApi); |
55 }; | 63 }; |
56 | 64 |
57 #endif // CHROME_BROWSER_GEOLOCATION_WIN7_LOCATION_API_WIN_H_ | 65 #endif // CHROME_BROWSER_GEOLOCATION_WIN7_LOCATION_API_WIN_H_ |
OLD | NEW |