| OLD | NEW |
| 1 // Copyright (c) 2011 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/win7_location_api_win.h" | 5 #include "content/browser/geolocation/win7_location_api_win.h" |
| 6 | 6 |
| 7 #include "base/base_paths_win.h" | 7 #include "base/base_paths_win.h" |
| 8 #include "base/command_line.h" | 8 #include "base/command_line.h" |
| 9 #include "base/file_path.h" | 9 #include "base/file_path.h" |
| 10 #include "base/logging.h" | 10 #include "base/logging.h" |
| 11 #include "base/memory/scoped_ptr.h" | 11 #include "base/memory/scoped_ptr.h" |
| 12 #include "base/path_service.h" | 12 #include "base/path_service.h" |
| 13 #include "content/common/geoposition.h" | |
| 14 #include "content/public/common/content_switches.h" | 13 #include "content/public/common/content_switches.h" |
| 14 #include "content/public/common/geoposition.h" |
| 15 | 15 |
| 16 namespace { | 16 namespace { |
| 17 const double kKnotsToMetresPerSecondConversionFactor = 0.5144; | 17 const double kKnotsToMetresPerSecondConversionFactor = 0.5144; |
| 18 | 18 |
| 19 void ConvertKnotsToMetresPerSecond(double* knots) { | 19 void ConvertKnotsToMetresPerSecond(double* knots) { |
| 20 *knots *= kKnotsToMetresPerSecondConversionFactor; | 20 *knots *= kKnotsToMetresPerSecondConversionFactor; |
| 21 } | 21 } |
| 22 | 22 |
| 23 HINSTANCE LoadWin7Library(const string16& lib_name) { | 23 HINSTANCE LoadWin7Library(const string16& lib_name) { |
| 24 FilePath sys_dir; | 24 FilePath sys_dir; |
| (...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 82 } | 82 } |
| 83 | 83 |
| 84 Win7LocationApi* Win7LocationApi::CreateForTesting( | 84 Win7LocationApi* Win7LocationApi::CreateForTesting( |
| 85 PropVariantToDoubleFunction PropVariantToDouble_function, | 85 PropVariantToDoubleFunction PropVariantToDouble_function, |
| 86 ILocation* locator) { | 86 ILocation* locator) { |
| 87 Win7LocationApi* result = new Win7LocationApi; | 87 Win7LocationApi* result = new Win7LocationApi; |
| 88 result->Init(NULL, PropVariantToDouble_function, locator); | 88 result->Init(NULL, PropVariantToDouble_function, locator); |
| 89 return result; | 89 return result; |
| 90 } | 90 } |
| 91 | 91 |
| 92 void Win7LocationApi::GetPosition(Geoposition* position) { | 92 void Win7LocationApi::GetPosition(content::Geoposition* position) { |
| 93 DCHECK(position); | 93 DCHECK(position); |
| 94 position->error_code = Geoposition::ERROR_CODE_POSITION_UNAVAILABLE; | 94 position->error_code = content::Geoposition::ERROR_CODE_POSITION_UNAVAILABLE; |
| 95 if (!locator_) | 95 if (!locator_) |
| 96 return; | 96 return; |
| 97 // Try to get a position fix | 97 // Try to get a position fix |
| 98 if (!GetPositionIfFixed(position)) | 98 if (!GetPositionIfFixed(position)) |
| 99 return; | 99 return; |
| 100 position->error_code = Geoposition::ERROR_CODE_NONE; | 100 position->error_code = content::Geoposition::ERROR_CODE_NONE; |
| 101 if (!position->IsValidFix()) { | 101 if (!position->Validate()) { |
| 102 // GetPositionIfFixed returned true, yet we've not got a valid fix. | 102 // GetPositionIfFixed returned true, yet we've not got a valid fix. |
| 103 // This shouldn't happen; something went wrong in the conversion. | 103 // This shouldn't happen; something went wrong in the conversion. |
| 104 NOTREACHED() << "Invalid position from GetPositionIfFixed: lat,long " | 104 NOTREACHED() << "Invalid position from GetPositionIfFixed: lat,long " |
| 105 << position->latitude << "," << position->longitude | 105 << position->latitude << "," << position->longitude |
| 106 << " accuracy " << position->accuracy << " time " | 106 << " accuracy " << position->accuracy << " time " |
| 107 << position->timestamp.ToDoubleT(); | 107 << position->timestamp.ToDoubleT(); |
| 108 position->error_code = Geoposition::ERROR_CODE_POSITION_UNAVAILABLE; | 108 position->error_code = |
| 109 content::Geoposition::ERROR_CODE_POSITION_UNAVAILABLE; |
| 109 position->error_message = "Bad fix from Win7 provider"; | 110 position->error_message = "Bad fix from Win7 provider"; |
| 110 } | 111 } |
| 111 } | 112 } |
| 112 | 113 |
| 113 bool Win7LocationApi::GetPositionIfFixed(Geoposition* position) { | 114 bool Win7LocationApi::GetPositionIfFixed(content::Geoposition* position) { |
| 114 HRESULT result_type; | 115 HRESULT result_type; |
| 115 CComPtr<ILocationReport> location_report; | 116 CComPtr<ILocationReport> location_report; |
| 116 CComPtr<ILatLongReport> lat_long_report; | 117 CComPtr<ILatLongReport> lat_long_report; |
| 117 result_type = locator_->GetReport(IID_ILatLongReport, &location_report); | 118 result_type = locator_->GetReport(IID_ILatLongReport, &location_report); |
| 118 // Checks to see if location access is allowed. | 119 // Checks to see if location access is allowed. |
| 119 if (result_type == E_ACCESSDENIED) | 120 if (result_type == E_ACCESSDENIED) |
| 120 position->error_code = Geoposition::ERROR_CODE_PERMISSION_DENIED; | 121 position->error_code = content::Geoposition::ERROR_CODE_PERMISSION_DENIED; |
| 121 // Checks for any other errors while requesting a location report. | 122 // Checks for any other errors while requesting a location report. |
| 122 if (!SUCCEEDED(result_type)) | 123 if (!SUCCEEDED(result_type)) |
| 123 return false; | 124 return false; |
| 124 result_type = location_report->QueryInterface(&lat_long_report); | 125 result_type = location_report->QueryInterface(&lat_long_report); |
| 125 if (!SUCCEEDED(result_type)) | 126 if (!SUCCEEDED(result_type)) |
| 126 return false; | 127 return false; |
| 127 result_type = lat_long_report->GetLatitude(&position->latitude); | 128 result_type = lat_long_report->GetLatitude(&position->latitude); |
| 128 if (!SUCCEEDED(result_type)) | 129 if (!SUCCEEDED(result_type)) |
| 129 return false; | 130 return false; |
| 130 result_type = lat_long_report->GetLongitude(&position->longitude); | 131 result_type = lat_long_report->GetLongitude(&position->longitude); |
| (...skipping 27 matching lines...) Expand all Loading... |
| 158 return true; | 159 return true; |
| 159 } | 160 } |
| 160 | 161 |
| 161 bool Win7LocationApi::SetHighAccuracy(bool acc) { | 162 bool Win7LocationApi::SetHighAccuracy(bool acc) { |
| 162 HRESULT result_type; | 163 HRESULT result_type; |
| 163 result_type = locator_->SetDesiredAccuracy(IID_ILatLongReport, | 164 result_type = locator_->SetDesiredAccuracy(IID_ILatLongReport, |
| 164 acc ? LOCATION_DESIRED_ACCURACY_HIGH : | 165 acc ? LOCATION_DESIRED_ACCURACY_HIGH : |
| 165 LOCATION_DESIRED_ACCURACY_DEFAULT); | 166 LOCATION_DESIRED_ACCURACY_DEFAULT); |
| 166 return SUCCEEDED(result_type); | 167 return SUCCEEDED(result_type); |
| 167 } | 168 } |
| OLD | NEW |