summaryrefslogtreecommitdiffstats
path: root/chrome/browser
diff options
context:
space:
mode:
authorjknotten@chromium.org <jknotten@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2011-01-06 14:38:14 +0000
committerjknotten@chromium.org <jknotten@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2011-01-06 14:38:14 +0000
commit9115d6dd0c7f7c12cc0f5d3ebb1bec3aae783dab (patch)
treefc83f47217902f13b86fcabad5020797aa86ee71 /chrome/browser
parent8f974ff1019843d30c69e002cfb01a0924bd74ac (diff)
downloadchromium_src-9115d6dd0c7f7c12cc0f5d3ebb1bec3aae783dab.zip
chromium_src-9115d6dd0c7f7c12cc0f5d3ebb1bec3aae783dab.tar.gz
chromium_src-9115d6dd0c7f7c12cc0f5d3ebb1bec3aae783dab.tar.bz2
Fix incorrect assertion following the move of Geolocation provider in to its own thread.
Change r61182 <http://crrev.com/61182> moved the geolocation providers on to their own "Geolocation" thread. The experimental CoreLocation provider needs to be changed accordingly to send position updates to the Geolocation thread instead of browser thread. BUG=67311 TEST=None Review URL: http://codereview.chromium.org/6037016 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@70615 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome/browser')
-rw-r--r--chrome/browser/geolocation/core_location_data_provider_mac.h1
-rw-r--r--chrome/browser/geolocation/core_location_data_provider_mac.mm34
-rw-r--r--chrome/browser/geolocation/core_location_provider_mac.h1
-rw-r--r--chrome/browser/geolocation/core_location_provider_mac.mm16
4 files changed, 32 insertions, 20 deletions
diff --git a/chrome/browser/geolocation/core_location_data_provider_mac.h b/chrome/browser/geolocation/core_location_data_provider_mac.h
index 21ebadc..124ff47 100644
--- a/chrome/browser/geolocation/core_location_data_provider_mac.h
+++ b/chrome/browser/geolocation/core_location_data_provider_mac.h
@@ -47,7 +47,6 @@ class CoreLocationDataProviderMac
scoped_nsobject<CoreLocationWrapperMac> wrapper_;
// The LocationProviderBase class that should receive position data
CoreLocationProviderMac* provider_;
- BrowserThread::ID origin_thread_id_;
};
#endif
diff --git a/chrome/browser/geolocation/core_location_data_provider_mac.mm b/chrome/browser/geolocation/core_location_data_provider_mac.mm
index b20230e..a88c6c4 100644
--- a/chrome/browser/geolocation/core_location_data_provider_mac.mm
+++ b/chrome/browser/geolocation/core_location_data_provider_mac.mm
@@ -11,6 +11,7 @@
#include "chrome/browser/geolocation/core_location_data_provider_mac.h"
#include "chrome/browser/geolocation/core_location_provider_mac.h"
+#include "chrome/browser/geolocation/geolocation_provider.h"
#include "base/logging.h"
#include "base/time.h"
@@ -41,7 +42,7 @@ enum {
- (void)stopUpdatingLocation;
@end
-@interface CLLocation : NSObject <NSCopying, NSCoding>
+@interface CLLocation : NSObject<NSCopying, NSCoding>
@property(readonly) CLLocationCoordinate2D coordinate;
@property(readonly) CLLocationDistance altitude;
@property(readonly) CLLocationAccuracy horizontalAccuracy;
@@ -64,9 +65,9 @@ enum {
// CLLocationManager. The location manaager's start and stop updating
// methods must be called from a thread that has an active run loop (which
// seems to only be the UI thread)
-@interface CoreLocationWrapperMac : NSObject <CLLocationManagerDelegate>
+@interface CoreLocationWrapperMac : NSObject<CLLocationManagerDelegate>
{
-@private
+ @private
NSBundle* bundle_;
Class locationManagerClass_;
id locationManager_;
@@ -119,8 +120,8 @@ enum {
}
- (void)startLocation {
- if([self locationDataAvailable]) {
- if(!locationManager_) {
+ if ([self locationDataAvailable]) {
+ if (!locationManager_) {
locationManager_ = [[locationManagerClass_ alloc] init];
[locationManager_ setDelegate:self];
}
@@ -151,7 +152,7 @@ enum {
- (void)locationManager:(CLLocationManager*)manager
didFailWithError:(NSError*)error {
Geoposition position;
- switch([error code]) {
+ switch ([error code]) {
case kCLErrorLocationUnknown:
position.error_code = Geoposition::ERROR_CODE_POSITION_UNAVAILABLE;
break;
@@ -166,10 +167,10 @@ enum {
}
- (BOOL)loadCoreLocationBundle {
- if(!bundle_) {
+ if (!bundle_) {
bundle_ = [[NSBundle alloc]
initWithPath:@"/System/Library/Frameworks/CoreLocation.framework"];
- if(!bundle_) {
+ if (!bundle_) {
DLOG(WARNING) << "Couldn't load CoreLocation Framework";
return NO;
}
@@ -183,9 +184,11 @@ enum {
@end
CoreLocationDataProviderMac::CoreLocationDataProviderMac() {
- if(!BrowserThread::GetCurrentThreadIdentifier(&origin_thread_id_))
- NOTREACHED() <<
- "CoreLocation data provider must be created in a valid BrowserThread.";
+ if (MessageLoop::current() !=
+ GeolocationProvider::GetInstance()->message_loop()) {
+ NOTREACHED() << "CoreLocation data provider must be created on "
+ "the Geolocation thread.";
+ }
provider_ = NULL;
wrapper_.reset([[CoreLocationWrapperMac alloc] initWithDataProvider:this]);
}
@@ -200,7 +203,7 @@ bool CoreLocationDataProviderMac::
StartUpdating(CoreLocationProviderMac* provider) {
DCHECK(provider);
DCHECK(!provider_) << "StartUpdating called twice";
- if(![wrapper_ locationDataAvailable]) return false;
+ if (![wrapper_ locationDataAvailable]) return false;
provider_ = provider;
BrowserThread::PostTask(BrowserThread::UI, FROM_HERE,
NewRunnableMethod(this, &CoreLocationDataProviderMac::StartUpdatingTask));
@@ -216,7 +219,7 @@ void CoreLocationDataProviderMac::StopUpdating() {
}
void CoreLocationDataProviderMac::UpdatePosition(Geoposition *position) {
- BrowserThread::PostTask(origin_thread_id_, FROM_HERE,
+ GeolocationProvider::GetInstance()->message_loop()->PostTask(FROM_HERE,
NewRunnableMethod(this,
&CoreLocationDataProviderMac::PositionUpdated,
*position));
@@ -235,7 +238,8 @@ void CoreLocationDataProviderMac::StopUpdatingTask() {
}
void CoreLocationDataProviderMac::PositionUpdated(Geoposition position) {
- DCHECK(BrowserThread::CurrentlyOn(origin_thread_id_));
- if(provider_)
+ DCHECK(MessageLoop::current() ==
+ GeolocationProvider::GetInstance()->message_loop());
+ if (provider_)
provider_->SetPosition(&position);
}
diff --git a/chrome/browser/geolocation/core_location_provider_mac.h b/chrome/browser/geolocation/core_location_provider_mac.h
index 0d7d7470..b936bfe 100644
--- a/chrome/browser/geolocation/core_location_provider_mac.h
+++ b/chrome/browser/geolocation/core_location_provider_mac.h
@@ -29,6 +29,7 @@ class CoreLocationProviderMac : public LocationProviderBase {
void SetPosition(Geoposition* position);
private:
+ bool is_updating_;
CoreLocationDataProviderMac* data_provider_;
Geoposition position_;
};
diff --git a/chrome/browser/geolocation/core_location_provider_mac.mm b/chrome/browser/geolocation/core_location_provider_mac.mm
index deb92c9..dbcd7d0 100644
--- a/chrome/browser/geolocation/core_location_provider_mac.mm
+++ b/chrome/browser/geolocation/core_location_provider_mac.mm
@@ -9,7 +9,8 @@
#include "base/command_line.h"
#include "chrome/common/chrome_switches.h"
-CoreLocationProviderMac::CoreLocationProviderMac() {
+CoreLocationProviderMac::CoreLocationProviderMac()
+ : is_updating_(false) {
data_provider_ = new CoreLocationDataProviderMac();
data_provider_->AddRef();
}
@@ -20,12 +21,19 @@ CoreLocationProviderMac::~CoreLocationProviderMac() {
}
bool CoreLocationProviderMac::StartProvider(bool high_accuracy) {
- data_provider_->StartUpdating(this);
+ // StartProvider maybe called multiple times. For example, to update the high
+ // accuracy hint.
+ // TODO(jknotten): Support high_accuracy hint in underlying data provider.
+ if (is_updating_)
+ return true;
+
+ is_updating_ = data_provider_->StartUpdating(this);
return true;
}
void CoreLocationProviderMac::StopProvider() {
data_provider_->StopUpdating();
+ is_updating_ = false;
}
void CoreLocationProviderMac::GetPosition(Geoposition* position) {
@@ -43,8 +51,8 @@ void CoreLocationProviderMac::SetPosition(Geoposition* position) {
}
LocationProviderBase* NewSystemLocationProvider() {
- if(CommandLine::ForCurrentProcess()
- ->HasSwitch(switches::kExperimentalLocationFeatures)) {
+ if (CommandLine::ForCurrentProcess()->HasSwitch(
+ switches::kExperimentalLocationFeatures)) {
return new CoreLocationProviderMac;
}
return NULL;