| 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 // This file contains the class definitions for the CoreLocation data provider | 5 // This file contains the class definitions for the CoreLocation data provider |
| 6 // class and the accompanying Objective C wrapper class. This data provider | 6 // class and the accompanying Objective C wrapper class. This data provider |
| 7 // is used to allow the CoreLocation wrapper to run on the UI thread, since | 7 // is used to allow the CoreLocation wrapper to run on the UI thread, since |
| 8 // CLLocationManager's start and stop updating methods must be called from a | 8 // CLLocationManager's start and stop updating methods must be called from a |
| 9 // thread with an active NSRunLoop. Currently only the UI thread appears to | 9 // thread with an active NSRunLoop. Currently only the UI thread appears to |
| 10 // fill that requirement. | 10 // fill that requirement. |
| 11 | 11 |
| (...skipping 121 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 133 } | 133 } |
| 134 } | 134 } |
| 135 | 135 |
| 136 - (void)stopLocation { | 136 - (void)stopLocation { |
| 137 [locationManager_ stopUpdatingLocation]; | 137 [locationManager_ stopUpdatingLocation]; |
| 138 } | 138 } |
| 139 | 139 |
| 140 - (void)locationManager:(CLLocationManager*)manager | 140 - (void)locationManager:(CLLocationManager*)manager |
| 141 didUpdateToLocation:(CLLocation*)newLocation | 141 didUpdateToLocation:(CLLocation*)newLocation |
| 142 fromLocation:(CLLocation*)oldLocation { | 142 fromLocation:(CLLocation*)oldLocation { |
| 143 Geoposition position; | 143 content::Geoposition position; |
| 144 position.latitude = [newLocation coordinate].latitude; | 144 position.latitude = [newLocation coordinate].latitude; |
| 145 position.longitude = [newLocation coordinate].longitude; | 145 position.longitude = [newLocation coordinate].longitude; |
| 146 position.altitude = [newLocation altitude]; | 146 position.altitude = [newLocation altitude]; |
| 147 position.accuracy = [newLocation horizontalAccuracy]; | 147 position.accuracy = [newLocation horizontalAccuracy]; |
| 148 position.altitude_accuracy = [newLocation verticalAccuracy]; | 148 position.altitude_accuracy = [newLocation verticalAccuracy]; |
| 149 position.speed = [newLocation speed]; | 149 position.speed = [newLocation speed]; |
| 150 position.heading = [newLocation course]; | 150 position.heading = [newLocation course]; |
| 151 position.timestamp = base::Time::Now(); | 151 position.timestamp = base::Time::Now(); |
| 152 position.error_code = Geoposition::ERROR_CODE_NONE; | 152 position.error_code = content::Geoposition::ERROR_CODE_NONE; |
| 153 dataProvider_->UpdatePosition(&position); | 153 dataProvider_->UpdatePosition(&position); |
| 154 } | 154 } |
| 155 | 155 |
| 156 - (void)locationManager:(CLLocationManager*)manager | 156 - (void)locationManager:(CLLocationManager*)manager |
| 157 didFailWithError:(NSError*)error { | 157 didFailWithError:(NSError*)error { |
| 158 Geoposition position; | 158 content::Geoposition position; |
| 159 switch ([error code]) { | 159 switch ([error code]) { |
| 160 case kCLErrorLocationUnknown: | 160 case kCLErrorLocationUnknown: |
| 161 position.error_code = Geoposition::ERROR_CODE_POSITION_UNAVAILABLE; | 161 position.error_code = |
| 162 content::Geoposition::ERROR_CODE_POSITION_UNAVAILABLE; |
| 162 break; | 163 break; |
| 163 case kCLErrorDenied: | 164 case kCLErrorDenied: |
| 164 position.error_code = Geoposition::ERROR_CODE_PERMISSION_DENIED; | 165 position.error_code = content::Geoposition::ERROR_CODE_PERMISSION_DENIED; |
| 165 break; | 166 break; |
| 166 default: | 167 default: |
| 167 NOTREACHED() << "Unknown CoreLocation error: " << [error code]; | 168 NOTREACHED() << "Unknown CoreLocation error: " << [error code]; |
| 168 return; | 169 return; |
| 169 } | 170 } |
| 170 dataProvider_->UpdatePosition(&position); | 171 dataProvider_->UpdatePosition(&position); |
| 171 } | 172 } |
| 172 | 173 |
| 173 - (BOOL)loadCoreLocationBundle { | 174 - (BOOL)loadCoreLocationBundle { |
| 174 if (!bundle_) { | 175 if (!bundle_) { |
| (...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 216 } | 217 } |
| 217 | 218 |
| 218 // Clears provider_ so that any leftover messages from CoreLocation get ignored | 219 // Clears provider_ so that any leftover messages from CoreLocation get ignored |
| 219 void CoreLocationDataProviderMac::StopUpdating() { | 220 void CoreLocationDataProviderMac::StopUpdating() { |
| 220 provider_ = NULL; | 221 provider_ = NULL; |
| 221 BrowserThread::PostTask( | 222 BrowserThread::PostTask( |
| 222 BrowserThread::UI, FROM_HERE, | 223 BrowserThread::UI, FROM_HERE, |
| 223 base::Bind(&CoreLocationDataProviderMac::StopUpdatingTask, this)); | 224 base::Bind(&CoreLocationDataProviderMac::StopUpdatingTask, this)); |
| 224 } | 225 } |
| 225 | 226 |
| 226 void CoreLocationDataProviderMac::UpdatePosition(Geoposition *position) { | 227 void CoreLocationDataProviderMac::UpdatePosition( |
| 228 content::Geoposition *position) { |
| 227 GeolocationProvider::GetInstance()->message_loop()->PostTask( | 229 GeolocationProvider::GetInstance()->message_loop()->PostTask( |
| 228 FROM_HERE, | 230 FROM_HERE, |
| 229 base::Bind(&CoreLocationDataProviderMac::PositionUpdated, this, | 231 base::Bind(&CoreLocationDataProviderMac::PositionUpdated, this, |
| 230 *position)); | 232 *position)); |
| 231 } | 233 } |
| 232 | 234 |
| 233 // Runs in BrowserThread::UI | 235 // Runs in BrowserThread::UI |
| 234 void CoreLocationDataProviderMac::StartUpdatingTask() { | 236 void CoreLocationDataProviderMac::StartUpdatingTask() { |
| 235 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 237 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| 236 [wrapper_ startLocation]; | 238 [wrapper_ startLocation]; |
| 237 } | 239 } |
| 238 | 240 |
| 239 // Runs in BrowserThread::UI | 241 // Runs in BrowserThread::UI |
| 240 void CoreLocationDataProviderMac::StopUpdatingTask() { | 242 void CoreLocationDataProviderMac::StopUpdatingTask() { |
| 241 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 243 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| 242 [wrapper_ stopLocation]; | 244 [wrapper_ stopLocation]; |
| 243 } | 245 } |
| 244 | 246 |
| 245 void CoreLocationDataProviderMac::PositionUpdated(Geoposition position) { | 247 void CoreLocationDataProviderMac::PositionUpdated( |
| 248 content::Geoposition position) { |
| 246 DCHECK(MessageLoop::current() == | 249 DCHECK(MessageLoop::current() == |
| 247 GeolocationProvider::GetInstance()->message_loop()); | 250 GeolocationProvider::GetInstance()->message_loop()); |
| 248 if (provider_) | 251 if (provider_) |
| 249 provider_->SetPosition(&position); | 252 provider_->SetPosition(&position); |
| 250 } | 253 } |
| OLD | NEW |