summaryrefslogtreecommitdiffstats
path: root/chrome/browser/geolocation/win7_location_api_win.cc
diff options
context:
space:
mode:
authorjknotten@chromium.org <jknotten@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2011-01-12 14:21:56 +0000
committerjknotten@chromium.org <jknotten@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2011-01-12 14:21:56 +0000
commite0c7405b8f24e6c0096285446f94f729e63107df (patch)
tree1761e4f23e2e9060ff7bfa5a9026a4937d73e312 /chrome/browser/geolocation/win7_location_api_win.cc
parent91aaa217affb5e4123383700afffe1a90b84c6d1 (diff)
downloadchromium_src-e0c7405b8f24e6c0096285446f94f729e63107df.zip
chromium_src-e0c7405b8f24e6c0096285446f94f729e63107df.tar.gz
chromium_src-e0c7405b8f24e6c0096285446f94f729e63107df.tar.bz2
Call CoInitialize before using Win 7 Location API.
BUG=66822 TEST=None Review URL: http://codereview.chromium.org/6115004 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@71166 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome/browser/geolocation/win7_location_api_win.cc')
-rw-r--r--chrome/browser/geolocation/win7_location_api_win.cc45
1 files changed, 30 insertions, 15 deletions
diff --git a/chrome/browser/geolocation/win7_location_api_win.cc b/chrome/browser/geolocation/win7_location_api_win.cc
index 7b6c3ca..7df0340 100644
--- a/chrome/browser/geolocation/win7_location_api_win.cc
+++ b/chrome/browser/geolocation/win7_location_api_win.cc
@@ -9,6 +9,7 @@
#include "base/file_path.h"
#include "base/logging.h"
#include "base/path_service.h"
+#include "base/scoped_ptr.h"
#include "chrome/common/chrome_switches.h"
#include "chrome/common/geoposition.h"
@@ -26,13 +27,18 @@ HINSTANCE LoadWin7Library(const string16& lib_name) {
}
}
-Win7LocationApi::Win7LocationApi(
- HINSTANCE prop_library,
+Win7LocationApi::Win7LocationApi()
+ : prop_lib_(0),
+ PropVariantToDouble_function_(0),
+ locator_(0) {
+}
+
+void Win7LocationApi::Init(HINSTANCE prop_library,
PropVariantToDoubleFunction PropVariantToDouble_function,
- ILocation* locator)
- : prop_lib_(prop_library),
- PropVariantToDouble_function_(PropVariantToDouble_function),
- locator_(locator) {
+ ILocation* locator) {
+ prop_lib_ = prop_library;
+ PropVariantToDouble_function_ = PropVariantToDouble_function;
+ locator_ = locator;
}
Win7LocationApi::~Win7LocationApi() {
@@ -44,6 +50,8 @@ Win7LocationApi* Win7LocationApi::Create() {
if (!CommandLine::ForCurrentProcess()
->HasSwitch(switches::kExperimentalLocationFeatures))
return NULL;
+
+ scoped_ptr<Win7LocationApi> result(new Win7LocationApi);
// Load probsys.dll
string16 lib_needed = L"propsys.dll";
HINSTANCE prop_lib = LoadWin7Library(lib_needed);
@@ -69,9 +77,16 @@ Win7LocationApi* Win7LocationApi::Create() {
}
IID reports_needed[] = { IID_ILatLongReport };
result_type = locator->RequestPermissions(NULL, reports_needed, 1, TRUE);
- return new Win7LocationApi(prop_lib,
- PropVariantToDouble_function,
- locator);
+ result->Init(prop_lib, PropVariantToDouble_function, locator);
+ return result.release();
+}
+
+Win7LocationApi* Win7LocationApi::CreateForTesting(
+ PropVariantToDoubleFunction PropVariantToDouble_function,
+ ILocation* locator) {
+ Win7LocationApi* result = new Win7LocationApi;
+ result->Init(NULL, PropVariantToDouble_function, locator);
+ return result;
}
void Win7LocationApi::GetPosition(Geoposition* position) {
@@ -101,19 +116,19 @@ bool Win7LocationApi::GetPositionIfFixed(Geoposition* position) {
CComPtr<ILatLongReport> lat_long_report;
result_type = locator_->GetReport(IID_ILatLongReport, &location_report);
// Checks to see if location access is allowed.
- if (result_type == E_ACCESSDENIED)
+ if (result_type == E_ACCESSDENIED)
position->error_code = Geoposition::ERROR_CODE_PERMISSION_DENIED;
// Checks for any other errors while requesting a location report.
- if(!SUCCEEDED(result_type))
+ if (!SUCCEEDED(result_type))
return false;
result_type = location_report->QueryInterface(&lat_long_report);
- if(!SUCCEEDED(result_type))
+ if (!SUCCEEDED(result_type))
return false;
result_type = lat_long_report->GetLatitude(&position->latitude);
- if(!SUCCEEDED(result_type))
+ if (!SUCCEEDED(result_type))
return false;
result_type = lat_long_report->GetLongitude(&position->longitude);
- if(!SUCCEEDED(result_type))
+ if (!SUCCEEDED(result_type))
return false;
result_type = lat_long_report->GetErrorRadius(&position->accuracy);
if (!SUCCEEDED(result_type) || position->accuracy <= 0)
@@ -124,7 +139,7 @@ bool Win7LocationApi::GetPositionIfFixed(Geoposition* position) {
position->altitude = temp_dbl;
result_type = lat_long_report->GetAltitudeError(&temp_dbl);
if (SUCCEEDED(result_type))
- position->altitude_accuracy = temp_dbl;
+ position->altitude_accuracy = temp_dbl;
PROPVARIANT heading;
PropVariantInit(&heading);
result_type = lat_long_report->GetValue(