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 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 |
12 #include "chrome/browser/geolocation/core_location_data_provider_mac.h" | 12 #include "chrome/browser/geolocation/core_location_data_provider_mac.h" |
13 #include "chrome/browser/geolocation/core_location_provider_mac.h" | 13 #include "chrome/browser/geolocation/core_location_provider_mac.h" |
14 #include "chrome/browser/geolocation/geolocation_provider.h" | |
14 #include "base/logging.h" | 15 #include "base/logging.h" |
15 #include "base/time.h" | 16 #include "base/time.h" |
16 | 17 |
17 // A few required declarations since the CoreLocation headers are not available | 18 // A few required declarations since the CoreLocation headers are not available |
18 // with the Mac OS X 10.5 SDK. | 19 // with the Mac OS X 10.5 SDK. |
19 // TODO(jorgevillatoro): Remove these declarations when we build against 10.6 | 20 // TODO(jorgevillatoro): Remove these declarations when we build against 10.6 |
20 | 21 |
21 // This idea was borrowed from wifi_data_provider_corewlan_mac.mm | 22 // This idea was borrowed from wifi_data_provider_corewlan_mac.mm |
22 typedef double CLLocationDegrees; | 23 typedef double CLLocationDegrees; |
23 typedef double CLLocationAccuracy; | 24 typedef double CLLocationAccuracy; |
(...skipping 152 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
176 | 177 |
177 locationManagerClass_ = [bundle_ classNamed:@"CLLocationManager"]; | 178 locationManagerClass_ = [bundle_ classNamed:@"CLLocationManager"]; |
178 } | 179 } |
179 | 180 |
180 return YES; | 181 return YES; |
181 } | 182 } |
182 | 183 |
183 @end | 184 @end |
184 | 185 |
185 CoreLocationDataProviderMac::CoreLocationDataProviderMac() { | 186 CoreLocationDataProviderMac::CoreLocationDataProviderMac() { |
186 if(!BrowserThread::GetCurrentThreadIdentifier(&origin_thread_id_)) | 187 if(MessageLoop::current() != GeolocationProvider::GetInstance()->message_loop( )) |
bulach
2011/01/06 12:44:59
nit:space after if, and >80cols
if (MessageLoop::
| |
187 NOTREACHED() << | 188 NOTREACHED() << |
188 "CoreLocation data provider must be created in a valid BrowserThread."; | 189 "CoreLocation data provider must be created on the Geolocation thread." ; |
bulach
2011/01/06 12:44:59
nit: >80cols.
| |
189 provider_ = NULL; | 190 provider_ = NULL; |
190 wrapper_.reset([[CoreLocationWrapperMac alloc] initWithDataProvider:this]); | 191 wrapper_.reset([[CoreLocationWrapperMac alloc] initWithDataProvider:this]); |
191 } | 192 } |
192 | 193 |
193 CoreLocationDataProviderMac::~CoreLocationDataProviderMac() { | 194 CoreLocationDataProviderMac::~CoreLocationDataProviderMac() { |
194 } | 195 } |
195 | 196 |
196 // Returns true if the CoreLocation wrapper can load the framework and | 197 // Returns true if the CoreLocation wrapper can load the framework and |
197 // location services are enabled. The pointer argument will only be accessed | 198 // location services are enabled. The pointer toargument will only be accessed |
bulach
2011/01/06 12:44:59
s/to//
| |
198 // in the origin thread. | 199 // in the origin thread. |
199 bool CoreLocationDataProviderMac:: | 200 bool CoreLocationDataProviderMac:: |
200 StartUpdating(CoreLocationProviderMac* provider) { | 201 StartUpdating(CoreLocationProviderMac* provider) { |
201 DCHECK(provider); | 202 DCHECK(provider); |
202 DCHECK(!provider_) << "StartUpdating called twice"; | 203 DCHECK(!provider_) << "StartUpdating called twice"; |
203 if(![wrapper_ locationDataAvailable]) return false; | 204 if(![wrapper_ locationDataAvailable]) return false; |
204 provider_ = provider; | 205 provider_ = provider; |
205 BrowserThread::PostTask(BrowserThread::UI, FROM_HERE, | 206 BrowserThread::PostTask(BrowserThread::UI, FROM_HERE, |
206 NewRunnableMethod(this, &CoreLocationDataProviderMac::StartUpdatingTask)); | 207 NewRunnableMethod(this, &CoreLocationDataProviderMac::StartUpdatingTask)); |
207 return true; | 208 return true; |
208 } | 209 } |
209 | 210 |
210 // Clears provider_ so that any leftover messages from CoreLocation get ignored | 211 // Clears provider_ so that any leftover messages from CoreLocation get ignored |
211 void CoreLocationDataProviderMac::StopUpdating() { | 212 void CoreLocationDataProviderMac::StopUpdating() { |
212 provider_ = NULL; | 213 provider_ = NULL; |
213 BrowserThread::PostTask(BrowserThread::UI, FROM_HERE, | 214 BrowserThread::PostTask(BrowserThread::UI, FROM_HERE, |
214 NewRunnableMethod(this, | 215 NewRunnableMethod(this, |
215 &CoreLocationDataProviderMac::StopUpdatingTask)); | 216 &CoreLocationDataProviderMac::StopUpdatingTask)); |
216 } | 217 } |
217 | 218 |
218 void CoreLocationDataProviderMac::UpdatePosition(Geoposition *position) { | 219 void CoreLocationDataProviderMac::UpdatePosition(Geoposition *position) { |
219 BrowserThread::PostTask(origin_thread_id_, FROM_HERE, | 220 GeolocationProvider::GetInstance()->message_loop()->PostTask(FROM_HERE, |
220 NewRunnableMethod(this, | 221 NewRunnableMethod(this, |
221 &CoreLocationDataProviderMac::PositionUpdated, | 222 &CoreLocationDataProviderMac::PositionUpdated, |
222 *position)); | 223 *position)); |
223 } | 224 } |
224 | 225 |
225 // Runs in BrowserThread::UI | 226 // Runs in BrowserThread::UI |
226 void CoreLocationDataProviderMac::StartUpdatingTask() { | 227 void CoreLocationDataProviderMac::StartUpdatingTask() { |
227 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 228 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
228 [wrapper_ startLocation]; | 229 [wrapper_ startLocation]; |
229 } | 230 } |
230 | 231 |
231 // Runs in BrowserThread::UI | 232 // Runs in BrowserThread::UI |
232 void CoreLocationDataProviderMac::StopUpdatingTask() { | 233 void CoreLocationDataProviderMac::StopUpdatingTask() { |
233 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 234 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
234 [wrapper_ stopLocation]; | 235 [wrapper_ stopLocation]; |
235 } | 236 } |
236 | 237 |
237 void CoreLocationDataProviderMac::PositionUpdated(Geoposition position) { | 238 void CoreLocationDataProviderMac::PositionUpdated(Geoposition position) { |
238 DCHECK(BrowserThread::CurrentlyOn(origin_thread_id_)); | 239 DCHECK(MessageLoop::current() == GeolocationProvider::GetInstance()->message_l oop()); |
bulach
2011/01/06 12:44:59
nit: >80cols
| |
239 if(provider_) | 240 if(provider_) |
240 provider_->SetPosition(&position); | 241 provider_->SetPosition(&position); |
241 } | 242 } |
OLD | NEW |