diff options
43 files changed, 375 insertions, 354 deletions
diff --git a/chrome/browser/automation/testing_automation_provider.cc b/chrome/browser/automation/testing_automation_provider.cc index 8d1a45b..c279674 100644 --- a/chrome/browser/automation/testing_automation_provider.cc +++ b/chrome/browser/automation/testing_automation_provider.cc @@ -139,6 +139,7 @@ #include "content/public/browser/web_contents.h" #include "content/public/common/child_process_host.h" #include "content/public/common/common_param_traits.h" +#include "content/public/common/geoposition.h" #include "content/public/common/ssl_status.h" #include "net/cookies/cookie_store.h" #include "third_party/WebKit/Source/WebKit/chromium/public/WebInputEvent.h" @@ -4928,8 +4929,14 @@ void TestingAutomationProvider::OverrideGeoposition( "Missing or invalid geolocation parameters"); return; } + content::Geoposition position; + position.latitude = latitude; + position.longitude = longitude; + position.altitude = altitude; + position.accuracy = 0.; + position.timestamp = base::Time::Now(); content::OverrideLocationForTesting( - latitude, longitude, altitude, + position, base::Bind(&SendSuccessIfAlive, AsWeakPtr(), reply_message)); } diff --git a/chrome/test/base/ui_test_utils.cc b/chrome/test/base/ui_test_utils.cc index 3bb8ad3..272f4a0 100644 --- a/chrome/test/base/ui_test_utils.cc +++ b/chrome/test/base/ui_test_utils.cc @@ -23,6 +23,7 @@ #include "base/rand_util.h" #include "base/string_number_conversions.h" #include "base/test/test_timeouts.h" +#include "base/time.h" #include "base/utf_string_conversions.h" #include "base/values.h" #include "chrome/browser/bookmarks/bookmark_model.h" @@ -57,6 +58,7 @@ #include "content/public/browser/web_contents.h" #include "content/public/browser/web_contents_observer.h" #include "content/public/browser/web_contents_view.h" +#include "content/public/common/geoposition.h" #include "content/test/test_navigation_observer.h" #include "googleurl/src/gurl.h" #include "net/base/net_util.h" @@ -1192,8 +1194,14 @@ bool TakeEntirePageSnapshot(RenderViewHost* rvh, SkBitmap* bitmap) { } void OverrideGeolocation(double latitude, double longitude) { - content::OverrideLocationForTesting( - latitude, longitude, 0, base::Bind(MessageLoop::QuitClosure())); + content::Geoposition position; + position.latitude = latitude; + position.longitude = longitude; + position.altitude = 0.; + position.accuracy = 0.; + position.timestamp = base::Time::Now(); + content::OverrideLocationForTesting(position, + base::Bind(MessageLoop::QuitClosure())); RunMessageLoop(); } diff --git a/content/browser/geolocation/core_location_data_provider_mac.h b/content/browser/geolocation/core_location_data_provider_mac.h index aa4eec3..167c5bc 100644 --- a/content/browser/geolocation/core_location_data_provider_mac.h +++ b/content/browser/geolocation/core_location_data_provider_mac.h @@ -1,4 +1,4 @@ -// Copyright (c) 2011 The Chromium Authors. All rights reserved. +// Copyright (c) 2012 The Chromium Authors. All rights reserved. // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. @@ -12,8 +12,8 @@ #include "base/memory/ref_counted.h" #include "base/memory/scoped_nsobject.h" -#include "content/common/geoposition.h" #include "content/public/browser/browser_thread.h" +#include "content/public/common/geoposition.h" #import <Foundation/Foundation.h> @@ -30,7 +30,7 @@ class CoreLocationDataProviderMac bool StartUpdating(CoreLocationProviderMac* provider); void StopUpdating(); - void UpdatePosition(Geoposition *position); + void UpdatePosition(content::Geoposition* position); protected: friend class base::RefCountedThreadSafe<CoreLocationDataProviderMac>; @@ -41,7 +41,7 @@ class CoreLocationDataProviderMac void StartUpdatingTask(); void StopUpdatingTask(); // This must execute in the origin thread (IO thread) - void PositionUpdated(Geoposition position); + void PositionUpdated(content::Geoposition position); // The wrapper class that supplies this class with position data scoped_nsobject<CoreLocationWrapperMac> wrapper_; diff --git a/content/browser/geolocation/core_location_data_provider_mac.mm b/content/browser/geolocation/core_location_data_provider_mac.mm index 5133cd6..de07254 100644 --- a/content/browser/geolocation/core_location_data_provider_mac.mm +++ b/content/browser/geolocation/core_location_data_provider_mac.mm @@ -1,4 +1,4 @@ -// Copyright (c) 2011 The Chromium Authors. All rights reserved. +// Copyright (c) 2012 The Chromium Authors. All rights reserved. // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. @@ -140,7 +140,7 @@ enum { - (void)locationManager:(CLLocationManager*)manager didUpdateToLocation:(CLLocation*)newLocation fromLocation:(CLLocation*)oldLocation { - Geoposition position; + content::Geoposition position; position.latitude = [newLocation coordinate].latitude; position.longitude = [newLocation coordinate].longitude; position.altitude = [newLocation altitude]; @@ -149,19 +149,20 @@ enum { position.speed = [newLocation speed]; position.heading = [newLocation course]; position.timestamp = base::Time::Now(); - position.error_code = Geoposition::ERROR_CODE_NONE; + position.error_code = content::Geoposition::ERROR_CODE_NONE; dataProvider_->UpdatePosition(&position); } - (void)locationManager:(CLLocationManager*)manager didFailWithError:(NSError*)error { - Geoposition position; + content::Geoposition position; switch ([error code]) { case kCLErrorLocationUnknown: - position.error_code = Geoposition::ERROR_CODE_POSITION_UNAVAILABLE; + position.error_code = + content::Geoposition::ERROR_CODE_POSITION_UNAVAILABLE; break; case kCLErrorDenied: - position.error_code = Geoposition::ERROR_CODE_PERMISSION_DENIED; + position.error_code = content::Geoposition::ERROR_CODE_PERMISSION_DENIED; break; default: NOTREACHED() << "Unknown CoreLocation error: " << [error code]; @@ -223,7 +224,8 @@ void CoreLocationDataProviderMac::StopUpdating() { base::Bind(&CoreLocationDataProviderMac::StopUpdatingTask, this)); } -void CoreLocationDataProviderMac::UpdatePosition(Geoposition *position) { +void CoreLocationDataProviderMac::UpdatePosition( + content::Geoposition *position) { GeolocationProvider::GetInstance()->message_loop()->PostTask( FROM_HERE, base::Bind(&CoreLocationDataProviderMac::PositionUpdated, this, @@ -242,7 +244,8 @@ void CoreLocationDataProviderMac::StopUpdatingTask() { [wrapper_ stopLocation]; } -void CoreLocationDataProviderMac::PositionUpdated(Geoposition position) { +void CoreLocationDataProviderMac::PositionUpdated( + content::Geoposition position) { DCHECK(MessageLoop::current() == GeolocationProvider::GetInstance()->message_loop()); if (provider_) diff --git a/content/browser/geolocation/core_location_provider_mac.h b/content/browser/geolocation/core_location_provider_mac.h index 4ad5ee4..4266d5f 100644 --- a/content/browser/geolocation/core_location_provider_mac.h +++ b/content/browser/geolocation/core_location_provider_mac.h @@ -1,4 +1,4 @@ -// Copyright (c) 2011 The Chromium Authors. All rights reserved. +// Copyright (c) 2012 The Chromium Authors. All rights reserved. // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. @@ -11,7 +11,7 @@ #pragma once #include "content/browser/geolocation/location_provider.h" -#include "content/common/geoposition.h" +#include "content/public/common/geoposition.h" class CoreLocationDataProviderMac; @@ -23,15 +23,15 @@ class CoreLocationProviderMac : public LocationProviderBase { // LocationProvider virtual bool StartProvider(bool high_accuracy) OVERRIDE; virtual void StopProvider() OVERRIDE; - virtual void GetPosition(Geoposition* position) OVERRIDE; + virtual void GetPosition(content::Geoposition* position) OVERRIDE; // Receives new positions and calls UpdateListeners - void SetPosition(Geoposition* position); + void SetPosition(content::Geoposition* position); private: bool is_updating_; CoreLocationDataProviderMac* data_provider_; - Geoposition position_; + content::Geoposition position_; }; #endif // CONTENT_BROWSER_GEOLOCATION_CORE_LOCATION_PROVIDER_MAC_H_ diff --git a/content/browser/geolocation/core_location_provider_mac.mm b/content/browser/geolocation/core_location_provider_mac.mm index 826a42f..80ffef9 100644 --- a/content/browser/geolocation/core_location_provider_mac.mm +++ b/content/browser/geolocation/core_location_provider_mac.mm @@ -1,4 +1,4 @@ -// Copyright (c) 2010 The Chromium Authors. All rights reserved. +// Copyright (c) 2012 The Chromium Authors. All rights reserved. // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. @@ -36,17 +36,18 @@ void CoreLocationProviderMac::StopProvider() { is_updating_ = false; } -void CoreLocationProviderMac::GetPosition(Geoposition* position) { +void CoreLocationProviderMac::GetPosition(content::Geoposition* position) { DCHECK(position); *position = position_; - DCHECK(position->IsInitialized()); + DCHECK(position->Validate() || + position->error_code != content::Geoposition::ERROR_CODE_NONE); } -void CoreLocationProviderMac::SetPosition(Geoposition* position) { +void CoreLocationProviderMac::SetPosition(content::Geoposition* position) { DCHECK(position); position_ = *position; - DCHECK(position->IsInitialized()); - + DCHECK(position->Validate() || + position->error_code != content::Geoposition::ERROR_CODE_NONE); UpdateListeners(); } diff --git a/content/browser/geolocation/geolocation.cc b/content/browser/geolocation/geolocation.cc index 789d9a3..920ab31 100644 --- a/content/browser/geolocation/geolocation.cc +++ b/content/browser/geolocation/geolocation.cc @@ -10,25 +10,17 @@ #include "base/memory/ref_counted.h" #include "base/message_loop_proxy.h" #include "content/browser/geolocation/geolocation_provider.h" -#include "content/common/geoposition.h" #include "content/public/browser/browser_thread.h" +#include "content/public/common/geoposition.h" namespace content { namespace { void OverrideLocationForTestingOnIOThread( - double latitude, - double longitude, - double altitude, + const Geoposition& position, const base::Closure& completion_callback, scoped_refptr<base::MessageLoopProxy> callback_loop) { - Geoposition position; - position.latitude = latitude; - position.longitude = longitude; - position.altitude = altitude; - position.accuracy = 0; - position.timestamp = base::Time::Now(); GeolocationProvider::GetInstance()->OverrideLocationForTesting(position); callback_loop->PostTask(FROM_HERE, completion_callback); } @@ -36,14 +28,12 @@ void OverrideLocationForTestingOnIOThread( } // namespace void OverrideLocationForTesting( - double latitude, - double longitude, - double altitude, + const Geoposition& position, const base::Closure& completion_callback) { - base::Closure closure = base::Bind( - &OverrideLocationForTestingOnIOThread, - latitude, longitude, altitude, completion_callback, - base::MessageLoopProxy::current()); + base::Closure closure = base::Bind(&OverrideLocationForTestingOnIOThread, + position, + completion_callback, + base::MessageLoopProxy::current()); if (!BrowserThread::CurrentlyOn(BrowserThread::IO)) { BrowserThread::PostTask(BrowserThread::IO, FROM_HERE, closure); } else { diff --git a/content/browser/geolocation/geolocation_dispatcher_host.cc b/content/browser/geolocation/geolocation_dispatcher_host.cc index 5ee8af0..4822286 100644 --- a/content/browser/geolocation/geolocation_dispatcher_host.cc +++ b/content/browser/geolocation/geolocation_dispatcher_host.cc @@ -14,11 +14,12 @@ #include "content/browser/renderer_host/render_process_host_impl.h" #include "content/browser/renderer_host/render_view_host_impl.h" #include "content/public/browser/geolocation_permission_context.h" +#include "content/public/common/geoposition.h" #include "content/common/geolocation_messages.h" -#include "content/common/geoposition.h" using content::BrowserThread; using content::GeolocationPermissionContext; +using content::Geoposition; using content::RenderViewHostImpl; namespace { diff --git a/content/browser/geolocation/geolocation_observer.h b/content/browser/geolocation/geolocation_observer.h index 3110e00..ed5dc85 100644 --- a/content/browser/geolocation/geolocation_observer.h +++ b/content/browser/geolocation/geolocation_observer.h @@ -1,4 +1,4 @@ -// Copyright (c) 2011 The Chromium Authors. All rights reserved. +// Copyright (c) 2012 The Chromium Authors. All rights reserved. // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. @@ -9,7 +9,9 @@ #include "base/basictypes.h" #include "content/common/content_export.h" +namespace content { struct Geoposition; +} // This interface is implemented by observers of GeolocationProvider as // well as GeolocationProvider itself as an observer of GeolocationArbitrator. @@ -18,7 +20,7 @@ class CONTENT_EXPORT GeolocationObserver { // This will be called whenever the 'best available' location is updated, // or when an error is encountered meaning no location data will be // available in the forseeable future. - virtual void OnLocationUpdate(const Geoposition& position) = 0; + virtual void OnLocationUpdate(const content::Geoposition& position) = 0; protected: GeolocationObserver() {} diff --git a/content/browser/geolocation/geolocation_provider.cc b/content/browser/geolocation/geolocation_provider.cc index b491826..d61c7c7 100644 --- a/content/browser/geolocation/geolocation_provider.cc +++ b/content/browser/geolocation/geolocation_provider.cc @@ -33,7 +33,8 @@ void GeolocationProvider::AddObserver(GeolocationObserver* observer, DCHECK(OnClientThread()); observers_[observer] = update_options; OnObserversChanged(); - if (position_.IsInitialized()) + if (position_.Validate() || + position_.error_code != content::Geoposition::ERROR_CODE_NONE) observer->OnLocationUpdate(position_); } @@ -67,9 +68,11 @@ void GeolocationProvider::OnObserversChanged() { message_loop()->PostTask(FROM_HERE, task); } -void GeolocationProvider::NotifyObservers(const Geoposition& position) { +void GeolocationProvider::NotifyObservers( + const content::Geoposition& position) { DCHECK(OnClientThread()); - DCHECK(position.IsInitialized()); + DCHECK(position.Validate() || + position.error_code != content::Geoposition::ERROR_CODE_NONE); position_ = position; ObserverMap::const_iterator it = observers_.begin(); while (it != observers_.end()) { @@ -126,7 +129,8 @@ void GeolocationProvider::CleanUp() { arbitrator_ = NULL; } -void GeolocationProvider::OnLocationUpdate(const Geoposition& position) { +void GeolocationProvider::OnLocationUpdate( + const content::Geoposition& position) { DCHECK(OnGeolocationThread()); // Will be true only in testing. if (ignore_location_updates_) @@ -138,7 +142,7 @@ void GeolocationProvider::OnLocationUpdate(const Geoposition& position) { } void GeolocationProvider::OverrideLocationForTesting( - const Geoposition& position) { + const content::Geoposition& position) { DCHECK(OnClientThread()); position_ = position; ignore_location_updates_ = true; diff --git a/content/browser/geolocation/geolocation_provider.h b/content/browser/geolocation/geolocation_provider.h index f816880..b28b4ee 100644 --- a/content/browser/geolocation/geolocation_provider.h +++ b/content/browser/geolocation/geolocation_provider.h @@ -11,7 +11,7 @@ #include "base/threading/thread.h" #include "content/browser/geolocation/geolocation_observer.h" #include "content/common/content_export.h" -#include "content/common/geoposition.h" +#include "content/public/common/geoposition.h" class GeolocationArbitrator; @@ -46,12 +46,13 @@ class CONTENT_EXPORT GeolocationProvider bool HasPermissionBeenGranted() const; // GeolocationObserver - virtual void OnLocationUpdate(const Geoposition& position) OVERRIDE; + virtual void OnLocationUpdate(const content::Geoposition& position) OVERRIDE; // Overrides the location for automation/testing. Updates any current // observers with the overriden position. Any further updates from location // providers will be ignored. - void OverrideLocationForTesting(const Geoposition& override_position); + void OverrideLocationForTesting( + const content::Geoposition& override_position); // Gets a pointer to the singleton instance of the location relayer, which // is in turn bound to the browser's global context objects. Ownership is NOT @@ -84,7 +85,7 @@ class CONTENT_EXPORT GeolocationProvider void InformProvidersPermissionGranted(); // Notifies observers when a new position fix is available. - void NotifyObservers(const Geoposition& position); + void NotifyObservers(const content::Geoposition& position); // Thread virtual void Init() OVERRIDE; @@ -95,7 +96,7 @@ class CONTENT_EXPORT GeolocationProvider // Only used on client thread ObserverMap observers_; bool is_permission_granted_; - Geoposition position_; + content::Geoposition position_; // True only in testing, where we want to use a custom position. bool ignore_location_updates_; diff --git a/content/browser/geolocation/geolocation_provider_unittest.cc b/content/browser/geolocation/geolocation_provider_unittest.cc index 4262909..ca1e122 100644 --- a/content/browser/geolocation/geolocation_provider_unittest.cc +++ b/content/browser/geolocation/geolocation_provider_unittest.cc @@ -14,6 +14,7 @@ using content::AccessTokenStore; using content::FakeAccessTokenStore; +using content::Geoposition; using testing::_; using testing::DoAll; using testing::DoDefault; diff --git a/content/browser/geolocation/gps_location_provider_linux.cc b/content/browser/geolocation/gps_location_provider_linux.cc index e5103fa..2adeced 100644 --- a/content/browser/geolocation/gps_location_provider_linux.cc +++ b/content/browser/geolocation/gps_location_provider_linux.cc @@ -26,13 +26,13 @@ const int kMovementThresholdMeters = 20; // The arbitrary delta is decreased (Gears used 100 meters); if we need to // decrease it any further we'll likely want to do some smarter filtering to // remove GPS location jitter noise. -bool PositionsDifferSiginificantly(const Geoposition& position_1, - const Geoposition& position_2) { - const bool pos_1_valid = position_1.IsValidFix(); - if (pos_1_valid != position_2.IsValidFix()) +bool PositionsDifferSiginificantly(const content::Geoposition& position_1, + const content::Geoposition& position_2) { + const bool pos_1_valid = position_1.Validate(); + if (pos_1_valid != position_2.Validate()) return true; if (!pos_1_valid) { - DCHECK(!position_2.IsValidFix()); + DCHECK(!position_2.Validate()); return false; } double delta = std::sqrt( @@ -66,7 +66,7 @@ bool GpsLocationProviderLinux::StartProvider(bool high_accuracy) { DCHECK(weak_factory_.HasWeakPtrs()); return true; } - position_.error_code = Geoposition::ERROR_CODE_POSITION_UNAVAILABLE; + position_.error_code = content::Geoposition::ERROR_CODE_POSITION_UNAVAILABLE; gps_.reset(libgps_factory_()); if (gps_ == NULL) { DLOG(WARNING) << "libgps could not be loaded"; @@ -81,10 +81,11 @@ void GpsLocationProviderLinux::StopProvider() { gps_.reset(); } -void GpsLocationProviderLinux::GetPosition(Geoposition* position) { +void GpsLocationProviderLinux::GetPosition(content::Geoposition* position) { DCHECK(position); *position = position_; - DCHECK(position->IsInitialized()); + DCHECK(position->Validate() || + position->error_code != content::Geoposition::ERROR_CODE_NONE); } void GpsLocationProviderLinux::UpdatePosition() { @@ -98,17 +99,19 @@ void GpsLocationProviderLinux::DoGpsPollTask() { return; } - Geoposition new_position; + content::Geoposition new_position; if (!gps_->Read(&new_position)) { ScheduleNextGpsPoll(poll_period_stationary_millis_); return; } - DCHECK(new_position.IsInitialized()); + DCHECK(new_position.Validate() || + new_position.error_code != content::Geoposition::ERROR_CODE_NONE); const bool differ = PositionsDifferSiginificantly(position_, new_position); ScheduleNextGpsPoll(differ ? poll_period_moving_millis_ : poll_period_stationary_millis_); - if (differ || new_position.error_code != Geoposition::ERROR_CODE_NONE) { + if (differ || + new_position.error_code != content::Geoposition::ERROR_CODE_NONE) { // Update if the new location is interesting or we have an error to report. position_ = new_position; UpdateListeners(); diff --git a/content/browser/geolocation/gps_location_provider_linux.h b/content/browser/geolocation/gps_location_provider_linux.h index c004e06..2cb4c82 100644 --- a/content/browser/geolocation/gps_location_provider_linux.h +++ b/content/browser/geolocation/gps_location_provider_linux.h @@ -16,7 +16,7 @@ #include "base/memory/weak_ptr.h" #include "content/browser/geolocation/location_provider.h" #include "content/common/content_export.h" -#include "content/common/geoposition.h" +#include "content/public/common/geoposition.h" class LibGps; @@ -46,7 +46,7 @@ class CONTENT_EXPORT GpsLocationProviderLinux : public LocationProviderBase { // LocationProvider virtual bool StartProvider(bool high_accuracy) OVERRIDE; virtual void StopProvider() OVERRIDE; - virtual void GetPosition(Geoposition* position) OVERRIDE; + virtual void GetPosition(content::Geoposition* position) OVERRIDE; virtual void UpdatePosition() OVERRIDE; private: @@ -62,7 +62,7 @@ class CONTENT_EXPORT GpsLocationProviderLinux : public LocationProviderBase { const LibGpsFactory libgps_factory_; scoped_ptr<LibGps> gps_; - Geoposition position_; + content::Geoposition position_; // Holder for the tasks which run on the thread; takes care of cleanup. base::WeakPtrFactory<GpsLocationProviderLinux> weak_factory_; diff --git a/content/browser/geolocation/gps_location_provider_unittest_linux.cc b/content/browser/geolocation/gps_location_provider_unittest_linux.cc index ea5f5bb..4a84c6a 100644 --- a/content/browser/geolocation/gps_location_provider_unittest_linux.cc +++ b/content/browser/geolocation/gps_location_provider_unittest_linux.cc @@ -18,7 +18,7 @@ class MockLibGps : public LibGps { MockLibGps(); ~MockLibGps(); - virtual bool GetPositionIfFixed(Geoposition* position) { + virtual bool GetPositionIfFixed(content::Geoposition* position) { CHECK(position); ++get_position_calls_; *position = get_position_; @@ -47,7 +47,7 @@ class MockLibGps : public LibGps { int gps_open_ret_; int gps_read_calls_; int gps_read_ret_; - Geoposition get_position_; + content::Geoposition get_position_; static MockLibGps* g_instance_; }; @@ -78,9 +78,9 @@ class GeolocationGpsProviderLinuxTests : public testing::Test { scoped_ptr<GpsLocationProviderLinux> provider_; }; -void CheckValidPosition(const Geoposition& expected, - const Geoposition& actual) { - EXPECT_TRUE(actual.IsValidFix()); +void CheckValidPosition(const content::Geoposition& expected, + const content::Geoposition& actual) { + EXPECT_TRUE(actual.Validate()); EXPECT_DOUBLE_EQ(expected.latitude, actual.latitude); EXPECT_DOUBLE_EQ(expected.longitude, actual.longitude); EXPECT_DOUBLE_EQ(expected.accuracy, actual.accuracy); @@ -96,7 +96,8 @@ MockLibGps::MockLibGps() gps_open_ret_(0), gps_read_calls_(0), gps_read_ret_(0) { - get_position_.error_code = Geoposition::ERROR_CODE_POSITION_UNAVAILABLE; + get_position_.error_code = + content::Geoposition::ERROR_CODE_POSITION_UNAVAILABLE; EXPECT_FALSE(g_instance_); g_instance_ = this; } @@ -121,11 +122,11 @@ TEST_F(GeolocationGpsProviderLinuxTests, NoLibGpsInstalled) { ASSERT_TRUE(provider_.get()); const bool ok = provider_->StartProvider(true); EXPECT_FALSE(ok); - Geoposition position; + content::Geoposition position; provider_->GetPosition(&position); - EXPECT_TRUE(position.IsInitialized()); - EXPECT_FALSE(position.IsValidFix()); - EXPECT_EQ(Geoposition::ERROR_CODE_POSITION_UNAVAILABLE, position.error_code); + EXPECT_FALSE(position.Validate()); + EXPECT_EQ(content::Geoposition::ERROR_CODE_POSITION_UNAVAILABLE, + position.error_code); } #if defined(OS_CHROMEOS) @@ -138,19 +139,19 @@ TEST_F(GeolocationGpsProviderLinuxTests, GetPosition) { EXPECT_EQ(0, MockLibGps::g_instance_->get_position_calls_); EXPECT_EQ(0, MockLibGps::g_instance_->gps_open_calls_); EXPECT_EQ(0, MockLibGps::g_instance_->gps_read_calls_); - Geoposition position; + content::Geoposition position; provider_->GetPosition(&position); - EXPECT_TRUE(position.IsInitialized()); - EXPECT_FALSE(position.IsValidFix()); - EXPECT_EQ(Geoposition::ERROR_CODE_POSITION_UNAVAILABLE, position.error_code); + EXPECT_FALSE(position.Validate()); + EXPECT_EQ(content::Geoposition::ERROR_CODE_POSITION_UNAVAILABLE, + position.error_code); MockLibGps::g_instance_->get_position_.error_code = - Geoposition::ERROR_CODE_NONE; + content::Geoposition::ERROR_CODE_NONE; MockLibGps::g_instance_->get_position_.latitude = 4.5; MockLibGps::g_instance_->get_position_.longitude = -34.1; MockLibGps::g_instance_->get_position_.accuracy = 345; MockLibGps::g_instance_->get_position_.timestamp = base::Time::FromDoubleT(200); - EXPECT_TRUE(MockLibGps::g_instance_->get_position_.IsValidFix()); + EXPECT_TRUE(MockLibGps::g_instance_->get_position_.Validate()); MessageLoop::current()->Run(); EXPECT_EQ(1, MockLibGps::g_instance_->get_position_calls_); EXPECT_EQ(1, MockLibGps::g_instance_->gps_open_calls_); @@ -183,15 +184,15 @@ TEST_F(GeolocationGpsProviderLinuxTests, LibGpsReconnect) { // Let gps_open() fails, and so will LibGps::Start(). // Reconnect will happen in 1000ms. MockLibGps::g_instance_->gps_open_ret_ = 1; - Geoposition position; + content::Geoposition position; MockLibGps::g_instance_->get_position_.error_code = - Geoposition::ERROR_CODE_NONE; + content::Geoposition::ERROR_CODE_NONE; MockLibGps::g_instance_->get_position_.latitude = 4.5; MockLibGps::g_instance_->get_position_.longitude = -34.1; MockLibGps::g_instance_->get_position_.accuracy = 345; MockLibGps::g_instance_->get_position_.timestamp = base::Time::FromDoubleT(200); - EXPECT_TRUE(MockLibGps::g_instance_->get_position_.IsValidFix()); + EXPECT_TRUE(MockLibGps::g_instance_->get_position_.Validate()); // This task makes gps_open() and LibGps::Start() to succeed after // 1500ms. MessageLoop::current()->PostDelayedTask( @@ -200,8 +201,7 @@ TEST_F(GeolocationGpsProviderLinuxTests, LibGpsReconnect) { base::TimeDelta::FromMilliseconds(1500)); MessageLoop::current()->Run(); provider_->GetPosition(&position); - EXPECT_TRUE(position.IsInitialized()); - EXPECT_TRUE(position.IsValidFix()); + EXPECT_TRUE(position.Validate()); // 3 gps_open() calls are expected (2 failures and 1 success) EXPECT_EQ(1, MockLibGps::g_instance_->get_position_calls_); EXPECT_EQ(3, MockLibGps::g_instance_->gps_open_calls_); diff --git a/content/browser/geolocation/libgps_wrapper_linux.cc b/content/browser/geolocation/libgps_wrapper_linux.cc index 25abca2..f140335 100644 --- a/content/browser/geolocation/libgps_wrapper_linux.cc +++ b/content/browser/geolocation/libgps_wrapper_linux.cc @@ -1,4 +1,4 @@ -// Copyright (c) 2011 The Chromium Authors. All rights reserved. +// Copyright (c) 2012 The Chromium Authors. All rights reserved. // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. @@ -10,7 +10,7 @@ #include "base/logging.h" #include "base/stringprintf.h" -#include "content/common/geoposition.h" +#include "content/public/common/geoposition.h" #include "third_party/gpsd/release-3.1/gps.h" COMPILE_ASSERT(GPSD_API_MAJOR_VERSION == 5, GPSD_API_version_is_not_5); @@ -96,9 +96,9 @@ void LibGps::Stop() { is_open_ = false; } -bool LibGps::Read(Geoposition* position) { +bool LibGps::Read(content::Geoposition* position) { DCHECK(position); - position->error_code = Geoposition::ERROR_CODE_POSITION_UNAVAILABLE; + position->error_code = content::Geoposition::ERROR_CODE_POSITION_UNAVAILABLE; if (!is_open_) { DLOG(WARNING) << "No gpsd connection"; position->error_message = "No gpsd connection"; @@ -117,23 +117,24 @@ bool LibGps::Read(Geoposition* position) { return false; } - position->error_code = Geoposition::ERROR_CODE_NONE; + position->error_code = content::Geoposition::ERROR_CODE_NONE; position->timestamp = base::Time::Now(); - if (!position->IsValidFix()) { + if (!position->Validate()) { // GetPositionIfFixed returned true, yet we've not got a valid fix. // This shouldn't happen; something went wrong in the conversion. NOTREACHED() << "Invalid position from GetPositionIfFixed: lat,long " << position->latitude << "," << position->longitude << " accuracy " << position->accuracy << " time " << position->timestamp.ToDoubleT(); - position->error_code = Geoposition::ERROR_CODE_POSITION_UNAVAILABLE; + position->error_code = + content::Geoposition::ERROR_CODE_POSITION_UNAVAILABLE; position->error_message = "Bad fix from gps"; return false; } return true; } -bool LibGps::GetPositionIfFixed(Geoposition* position) { +bool LibGps::GetPositionIfFixed(content::Geoposition* position) { DCHECK(position); if (gps_data_->status == STATUS_NO_FIX) { DVLOG(2) << "Status_NO_FIX"; diff --git a/content/browser/geolocation/libgps_wrapper_linux.h b/content/browser/geolocation/libgps_wrapper_linux.h index 8840551..82b438b 100644 --- a/content/browser/geolocation/libgps_wrapper_linux.h +++ b/content/browser/geolocation/libgps_wrapper_linux.h @@ -1,4 +1,4 @@ -// Copyright (c) 2011 The Chromium Authors. All rights reserved. +// Copyright (c) 2012 The Chromium Authors. All rights reserved. // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. @@ -14,7 +14,10 @@ #include "content/common/content_export.h" struct gps_data_t; + +namespace content { struct Geoposition; +} class CONTENT_EXPORT LibGps { public: @@ -25,7 +28,7 @@ class CONTENT_EXPORT LibGps { bool Start(); void Stop(); - bool Read(Geoposition* position); + bool Read(content::Geoposition* position); protected: typedef int (*gps_open_fn)(const char*, const char*, struct gps_data_t*); @@ -38,7 +41,7 @@ class CONTENT_EXPORT LibGps { gps_read_fn gps_read); // Returns false if there is not fix available. - virtual bool GetPositionIfFixed(Geoposition* position); + virtual bool GetPositionIfFixed(content::Geoposition* position); private: void* dl_handle_; diff --git a/content/browser/geolocation/location_arbitrator.cc b/content/browser/geolocation/location_arbitrator.cc index 5ae3e38..10617f5 100644 --- a/content/browser/geolocation/location_arbitrator.cc +++ b/content/browser/geolocation/location_arbitrator.cc @@ -13,6 +13,7 @@ #include "googleurl/src/gurl.h" using content::AccessTokenStore; +using content::Geoposition; namespace { @@ -124,7 +125,8 @@ void GeolocationArbitrator::LocationUpdateAvailable( DCHECK(provider); Geoposition new_position; provider->GetPosition(&new_position); - DCHECK(new_position.IsInitialized()); + DCHECK(new_position.Validate() || + new_position.error_code != content::Geoposition::ERROR_CODE_NONE); if (!IsNewPositionBetter(position_, new_position, provider == position_provider_)) return; @@ -138,11 +140,11 @@ bool GeolocationArbitrator::IsNewPositionBetter( bool from_same_provider) const { // Updates location_info if it's better than what we currently have, // or if it's a newer update from the same provider. - if (!old_position.IsValidFix()) { + if (!old_position.Validate()) { // Older location wasn't locked. return true; } - if (new_position.IsValidFix()) { + if (new_position.Validate()) { // New location is locked, let's check if it's any better. if (old_position.accuracy >= new_position.accuracy) { // Accuracy is better. diff --git a/content/browser/geolocation/location_arbitrator.h b/content/browser/geolocation/location_arbitrator.h index cbecf64..5104023 100644 --- a/content/browser/geolocation/location_arbitrator.h +++ b/content/browser/geolocation/location_arbitrator.h @@ -12,8 +12,8 @@ #include "content/browser/geolocation/location_provider.h" #include "content/browser/geolocation/geolocation_observer.h" #include "content/common/content_export.h" -#include "content/common/geoposition.h" #include "content/public/browser/access_token_store.h" +#include "content/public/common/geoposition.h" #include "net/url_request/url_request_context_getter.h" class GeolocationArbitratorDependencyFactory; @@ -27,8 +27,6 @@ namespace net { class URLRequestContextGetter; } -struct Geoposition; - // This class is responsible for handling updates from multiple underlying // providers and resolving them to a single 'best' location fix at any given // moment. @@ -84,8 +82,8 @@ class CONTENT_EXPORT GeolocationArbitrator // Returns true if |new_position| is an improvement over |old_position|. // Set |from_same_provider| to true if both the positions came from the same // provider. - bool IsNewPositionBetter(const Geoposition& old_position, - const Geoposition& new_position, + bool IsNewPositionBetter(const content::Geoposition& old_position, + const content::Geoposition& new_position, bool from_same_provider) const; scoped_refptr<GeolocationArbitratorDependencyFactory> dependency_factory_; @@ -98,7 +96,7 @@ class CONTENT_EXPORT GeolocationArbitrator const LocationProviderBase* position_provider_; bool is_permission_granted_; // The current best estimate of our position. - Geoposition position_; + content::Geoposition position_; DISALLOW_COPY_AND_ASSIGN(GeolocationArbitrator); }; diff --git a/content/browser/geolocation/location_arbitrator_unittest.cc b/content/browser/geolocation/location_arbitrator_unittest.cc index 08caed5..1504343 100644 --- a/content/browser/geolocation/location_arbitrator_unittest.cc +++ b/content/browser/geolocation/location_arbitrator_unittest.cc @@ -9,12 +9,13 @@ #include "content/browser/geolocation/location_arbitrator.h" #include "content/browser/geolocation/location_provider.h" #include "content/browser/geolocation/mock_location_provider.h" -#include "content/common/geoposition.h" +#include "content/public/common/geoposition.h" #include "testing/gmock/include/gmock/gmock.h" #include "testing/gtest/include/gtest/gtest.h" using content::AccessTokenStore; using content::FakeAccessTokenStore; +using content::Geoposition; using ::testing::NiceMock; namespace { @@ -24,7 +25,7 @@ class MockLocationObserver : public GeolocationObserver { void InvalidateLastPosition() { last_position_.latitude = 100; last_position_.error_code = Geoposition::ERROR_CODE_NONE; - ASSERT_FALSE(last_position_.IsInitialized()); + ASSERT_FALSE(last_position_.Validate()); } // Delegate virtual void OnLocationUpdate(const Geoposition& position) { @@ -54,8 +55,7 @@ void SetPositionFix(MockLocationProvider* provider, position.longitude = longitude; position.accuracy = accuracy; position.timestamp = GetTimeNowForTest(); - ASSERT_TRUE(position.IsInitialized()); - ASSERT_TRUE(position.IsValidFix()); + ASSERT_TRUE(position.Validate()); provider->HandlePositionChanged(position); } @@ -126,7 +126,7 @@ class GeolocationLocationArbitratorTest : public testing::Test { double longitude, double accuracy) { Geoposition geoposition = observer_->last_position_; - EXPECT_TRUE(geoposition.IsValidFix()); + EXPECT_TRUE(geoposition.Validate()); EXPECT_DOUBLE_EQ(latitude, geoposition.latitude); EXPECT_DOUBLE_EQ(longitude, geoposition.longitude); EXPECT_DOUBLE_EQ(accuracy, geoposition.accuracy); @@ -187,11 +187,15 @@ TEST_F(GeolocationLocationArbitratorTest, NormalUsage) { EXPECT_TRUE(cell()->has_listeners()); EXPECT_EQ(MockLocationProvider::LOW_ACCURACY, cell()->state_); EXPECT_EQ(MockLocationProvider::LOW_ACCURACY, gps()->state_); - EXPECT_FALSE(observer_->last_position_.IsInitialized()); + EXPECT_FALSE(observer_->last_position_.Validate()); + EXPECT_EQ(content::Geoposition::ERROR_CODE_NONE, + observer_->last_position_.error_code); SetReferencePosition(cell()); - EXPECT_TRUE(observer_->last_position_.IsInitialized()); + EXPECT_TRUE(observer_->last_position_.Validate() || + observer_->last_position_.error_code != + content::Geoposition::ERROR_CODE_NONE); EXPECT_EQ(cell()->position_.latitude, observer_->last_position_.latitude); @@ -226,7 +230,7 @@ TEST_F(GeolocationLocationArbitratorTest, Arbitration) { SetPositionFix(cell(), 1, 2, 150); // First position available - EXPECT_TRUE(observer_->last_position_.IsValidFix()); + EXPECT_TRUE(observer_->last_position_.Validate()); CheckLastPositionInfo(1, 2, 150); SetPositionFix(gps(), 3, 4, 50); diff --git a/content/browser/geolocation/location_provider.h b/content/browser/geolocation/location_provider.h index 1d845b6..7f94098 100644 --- a/content/browser/geolocation/location_provider.h +++ b/content/browser/geolocation/location_provider.h @@ -19,11 +19,11 @@ #include "base/threading/non_thread_safe.h" #include "content/common/content_export.h" -struct Geoposition; class GURL; namespace content { class AccessTokenStore; +struct Geoposition; } namespace net { @@ -69,7 +69,7 @@ class CONTENT_EXPORT LocationProviderBase virtual bool StartProvider(bool high_accuracy) = 0; virtual void StopProvider() = 0; // Gets the current best position estimate. - virtual void GetPosition(Geoposition* position) = 0; + virtual void GetPosition(content::Geoposition* position) = 0; // Provides a hint to the provider that new location data is needed as soon // as possible. Default implementation does nothing. virtual void UpdatePosition() {} diff --git a/content/browser/geolocation/mock_location_provider.cc b/content/browser/geolocation/mock_location_provider.cc index fc9abd3..35109ef 100644 --- a/content/browser/geolocation/mock_location_provider.cc +++ b/content/browser/geolocation/mock_location_provider.cc @@ -32,7 +32,8 @@ MockLocationProvider::~MockLocationProvider() { *self_ref_ = NULL; } -void MockLocationProvider::HandlePositionChanged(const Geoposition& position) { +void MockLocationProvider::HandlePositionChanged( + const content::Geoposition& position) { if (provider_loop_->BelongsToCurrentThread()) { // The location arbitrator unit tests rely on this method running // synchronously. @@ -55,7 +56,7 @@ void MockLocationProvider::StopProvider() { state_ = STOPPED; } -void MockLocationProvider::GetPosition(Geoposition* position) { +void MockLocationProvider::GetPosition(content::Geoposition* position) { *position = position_; } @@ -82,7 +83,8 @@ class AutoMockLocationProvider : public MockLocationProvider { // contemporary. position_.timestamp = base::Time::Now(); } else { - position_.error_code = Geoposition::ERROR_CODE_POSITION_UNAVAILABLE; + position_.error_code = + content::Geoposition::ERROR_CODE_POSITION_UNAVAILABLE; } } virtual bool StartProvider(bool high_accuracy) { diff --git a/content/browser/geolocation/mock_location_provider.h b/content/browser/geolocation/mock_location_provider.h index 69411c3..70a49ca 100644 --- a/content/browser/geolocation/mock_location_provider.h +++ b/content/browser/geolocation/mock_location_provider.h @@ -11,7 +11,7 @@ #include "base/memory/scoped_ptr.h" #include "base/threading/thread.h" #include "content/browser/geolocation/location_provider.h" -#include "content/common/geoposition.h" +#include "content/public/common/geoposition.h" // Mock implementation of a location provider for testing. class MockLocationProvider : public LocationProviderBase { @@ -22,15 +22,15 @@ class MockLocationProvider : public LocationProviderBase { virtual ~MockLocationProvider(); // Updates listeners with the new position. - void HandlePositionChanged(const Geoposition& position); + void HandlePositionChanged(const content::Geoposition& position); // LocationProviderBase implementation. virtual bool StartProvider(bool high_accuracy) OVERRIDE; virtual void StopProvider() OVERRIDE; - virtual void GetPosition(Geoposition* position) OVERRIDE; + virtual void GetPosition(content::Geoposition* position) OVERRIDE; virtual void OnPermissionGranted() OVERRIDE; - Geoposition position_; + content::Geoposition position_; enum State { STOPPED, LOW_ACCURACY, HIGH_ACCURACY } state_; bool is_permission_granted_; MockLocationProvider** self_ref_; diff --git a/content/browser/geolocation/network_location_provider.cc b/content/browser/geolocation/network_location_provider.cc index 5312aaf..2e37ede 100644 --- a/content/browser/geolocation/network_location_provider.cc +++ b/content/browser/geolocation/network_location_provider.cc @@ -10,6 +10,7 @@ #include "content/public/browser/access_token_store.h" using content::AccessTokenStore; +using content::Geoposition; namespace { // The maximum period of time we'll wait for a complete set of device data @@ -178,7 +179,7 @@ void NetworkLocationProvider::LocationResponseAvailable( DCHECK(CalledOnValidThread()); // Record the position and update our cache. position_ = position; - if (position.IsValidFix()) { + if (position.Validate()) { position_cache_->CachePosition(wifi_data, position); } @@ -243,7 +244,7 @@ void NetworkLocationProvider::RequestPosition() { DCHECK(!device_data_updated_timestamp_.is_null()) << "Timestamp must be set before looking up position"; if (cached_position) { - DCHECK(cached_position->IsValidFix()); + DCHECK(cached_position->Validate()); // Record the position and update its timestamp. position_ = *cached_position; // The timestamp of a position fix is determined by the timestamp diff --git a/content/browser/geolocation/network_location_provider.h b/content/browser/geolocation/network_location_provider.h index 03ae8fa..050be60 100644 --- a/content/browser/geolocation/network_location_provider.h +++ b/content/browser/geolocation/network_location_provider.h @@ -18,7 +18,7 @@ #include "content/browser/geolocation/location_provider.h" #include "content/browser/geolocation/network_location_request.h" #include "content/common/content_export.h" -#include "content/common/geoposition.h" +#include "content/public/common/geoposition.h" namespace content { class AccessTokenStore; @@ -45,12 +45,12 @@ class NetworkLocationProvider // evict old entries in FIFO orderer of being added. // Returns true on success, false otherwise. bool CachePosition(const WifiData& wifi_data, - const Geoposition& position); + const content::Geoposition& position); // Searches for a cached position response for the current set of device // data. Returns NULL if the position is not in the cache, or the cached // position if available. Ownership remains with the cache. - const Geoposition* FindPosition(const WifiData& wifi_data); + const content::Geoposition* FindPosition(const WifiData& wifi_data); private: // Makes the key for the map of cached positions, using a set of @@ -61,7 +61,7 @@ class NetworkLocationProvider // The cache of positions. This is stored as a map keyed on a string that // represents a set of device data, and a list to provide // least-recently-added eviction. - typedef std::map<string16, Geoposition> CacheMap; + typedef std::map<string16, content::Geoposition> CacheMap; CacheMap cache_; typedef std::list<CacheMap::iterator> CacheAgeList; CacheAgeList cache_age_list_; // Oldest first. @@ -76,7 +76,7 @@ class NetworkLocationProvider // LocationProviderBase implementation virtual bool StartProvider(bool high_accuracy) OVERRIDE; virtual void StopProvider() OVERRIDE; - virtual void GetPosition(Geoposition *position) OVERRIDE; + virtual void GetPosition(content::Geoposition *position) OVERRIDE; virtual void UpdatePosition() OVERRIDE; virtual void OnPermissionGranted() OVERRIDE; @@ -94,7 +94,7 @@ class NetworkLocationProvider virtual void DeviceDataUpdateAvailable(WifiDataProvider* provider) OVERRIDE; // NetworkLocationRequest::ListenerInterface implementation. - virtual void LocationResponseAvailable(const Geoposition& position, + virtual void LocationResponseAvailable(const content::Geoposition& position, bool server_error, const string16& access_token, const RadioData& radio_data, @@ -120,7 +120,7 @@ class NetworkLocationProvider string16 access_token_; // The current best position estimate. - Geoposition position_; + content::Geoposition position_; // Whether permission has been granted for the provider to operate. bool is_permission_granted_; diff --git a/content/browser/geolocation/network_location_provider_unittest.cc b/content/browser/geolocation/network_location_provider_unittest.cc index a98b747..6735acc 100644 --- a/content/browser/geolocation/network_location_provider_unittest.cc +++ b/content/browser/geolocation/network_location_provider_unittest.cc @@ -16,6 +16,7 @@ #include "testing/gtest/include/gtest/gtest.h" using content::FakeAccessTokenStore; +using content::Geoposition; namespace { @@ -373,7 +374,7 @@ TEST_F(GeolocationNetworkProviderTest, MultipleWifiScansComplete) { Geoposition position; provider->GetPosition(&position); - EXPECT_FALSE(position.IsValidFix()); + EXPECT_FALSE(position.Validate()); // Now wifi data arrives -- SetData will notify listeners. const int kFirstScanAps = 6; @@ -406,8 +407,8 @@ TEST_F(GeolocationNetworkProviderTest, MultipleWifiScansComplete) { EXPECT_EQ(51.0, position.latitude); EXPECT_EQ(-0.1, position.longitude); EXPECT_EQ(1200.4, position.accuracy); - EXPECT_TRUE(position.is_valid_timestamp()); - EXPECT_TRUE(position.IsValidFix()); + EXPECT_FALSE(position.timestamp.is_null()); + EXPECT_TRUE(position.Validate()); // Token should be in the store. EXPECT_EQ(UTF8ToUTF16(REFERENCE_ACCESS_TOKEN), @@ -424,7 +425,7 @@ TEST_F(GeolocationNetworkProviderTest, MultipleWifiScansComplete) { provider->GetPosition(&position); EXPECT_EQ(51.0, position.latitude); EXPECT_EQ(-0.1, position.longitude); - EXPECT_TRUE(position.IsValidFix()); + EXPECT_TRUE(position.Validate()); // Now a third scan with more than twice the original amount -> new request. const int kThirdScanAps = kFirstScanAps * 2 + 1; @@ -445,8 +446,7 @@ TEST_F(GeolocationNetworkProviderTest, MultipleWifiScansComplete) { // Error means we now no longer have a fix. provider->GetPosition(&position); - EXPECT_FALSE(position.is_valid_latlong()); - EXPECT_FALSE(position.IsValidFix()); + EXPECT_FALSE(position.Validate()); // Wifi scan returns to original set: should be serviced from cache. wifi_data_provider_->SetData(CreateReferenceWifiScanData(kFirstScanAps)); @@ -456,7 +456,7 @@ TEST_F(GeolocationNetworkProviderTest, MultipleWifiScansComplete) { provider->GetPosition(&position); EXPECT_EQ(51.0, position.latitude); EXPECT_EQ(-0.1, position.longitude); - EXPECT_TRUE(position.IsValidFix()); + EXPECT_TRUE(position.Validate()); } TEST_F(GeolocationNetworkProviderTest, NoRequestOnStartupUntilWifiData) { diff --git a/content/browser/geolocation/network_location_request.cc b/content/browser/geolocation/network_location_request.cc index c8702b2..3ea8def 100644 --- a/content/browser/geolocation/network_location_request.cc +++ b/content/browser/geolocation/network_location_request.cc @@ -12,8 +12,8 @@ #include "base/string_number_conversions.h" #include "base/utf_string_conversions.h" #include "base/values.h" -#include "content/common/geoposition.h" #include "content/common/net/url_fetcher_impl.h" +#include "content/public/common/geoposition.h" #include "net/base/escape.h" #include "net/base/load_flags.h" #include "net/url_request/url_request_context_getter.h" @@ -44,15 +44,15 @@ void GetLocationFromResponse(bool http_post_result, const std::string& response_body, const base::Time& timestamp, const GURL& server_url, - Geoposition* position, + content::Geoposition* position, string16* access_token); // Parses the server response body. Returns true if parsing was successful. // Sets |*position| to the parsed location if a valid fix was received, -// otherwise leaves it unchanged (i.e. IsInitialized() == false). +// otherwise leaves it unchanged. bool ParseServerResponse(const std::string& response_body, const base::Time& timestamp, - Geoposition* position, + content::Geoposition* position, string16* access_token); void AddWifiData(const WifiData& wifi_data, int age_milliseconds, @@ -106,7 +106,7 @@ void NetworkLocationRequest::OnURLFetchComplete( net::URLRequestStatus status = source->GetStatus(); int response_code = source->GetResponseCode(); - Geoposition position; + content::Geoposition position; string16 access_token; std::string data; source->GetResponseAsString(&data); @@ -237,8 +237,9 @@ void AddWifiData(const WifiData& wifi_data, void FormatPositionError(const GURL& server_url, const std::string& message, - Geoposition* position) { - position->error_code = Geoposition::ERROR_CODE_POSITION_UNAVAILABLE; + content::Geoposition* position) { + position->error_code = + content::Geoposition::ERROR_CODE_POSITION_UNAVAILABLE; position->error_message = "Network location provider at '"; position->error_message += server_url.possibly_invalid_spec(); position->error_message += "' : "; @@ -253,7 +254,7 @@ void GetLocationFromResponse(bool http_post_result, const std::string& response_body, const base::Time& timestamp, const GURL& server_url, - Geoposition* position, + content::Geoposition* position, string16* access_token) { DCHECK(position); DCHECK(access_token); @@ -279,7 +280,7 @@ void GetLocationFromResponse(bool http_post_result, } // The response was successfully parsed, but it may not be a valid // position fix. - if (!position->IsValidFix()) { + if (!position->Validate()) { FormatPositionError(server_url, "Did not provide a good position fix", position); return; @@ -308,10 +309,11 @@ bool GetAsDouble(const DictionaryValue& object, bool ParseServerResponse(const std::string& response_body, const base::Time& timestamp, - Geoposition* position, + content::Geoposition* position, string16* access_token) { DCHECK(position); - DCHECK(!position->IsInitialized()); + DCHECK(!position->Validate()); + DCHECK(position->error_code == content::Geoposition::ERROR_CODE_NONE); DCHECK(access_token); DCHECK(!timestamp.is_null()); diff --git a/content/browser/geolocation/network_location_request.h b/content/browser/geolocation/network_location_request.h index 52d7905..f75d59d 100644 --- a/content/browser/geolocation/network_location_request.h +++ b/content/browser/geolocation/network_location_request.h @@ -14,9 +14,12 @@ #include "content/public/common/url_fetcher_delegate.h" #include "googleurl/src/gurl.h" -struct Geoposition; class URLFetcher; +namespace content { +struct Geoposition; +} + namespace net { class URLRequestContextGetter; } @@ -33,7 +36,7 @@ class NetworkLocationRequest : private content::URLFetcherDelegate { // Updates the listener with a new position. server_error indicates whether // was a server or network error - either no response or a 500 error code. virtual void LocationResponseAvailable( - const Geoposition& position, + const content::Geoposition& position, bool server_error, const string16& access_token, const RadioData& radio_data, diff --git a/content/browser/geolocation/win7_location_api_unittest_win.cc b/content/browser/geolocation/win7_location_api_unittest_win.cc index 88ad510..1adf934 100644 --- a/content/browser/geolocation/win7_location_api_unittest_win.cc +++ b/content/browser/geolocation/win7_location_api_unittest_win.cc @@ -13,7 +13,7 @@ #include "base/message_loop.h" #include "base/time.h" #include "content/browser/geolocation/win7_location_api_win.h" -#include "content/common/geoposition.h" +#include "content/public/common/geoposition.h" #include "testing/gmock/include/gmock/gmock.h" #include "testing/gtest/include/gtest/gtest.h" @@ -311,18 +311,18 @@ TEST_F(GeolocationApiWin7Tests, PermissionDenied) { EXPECT_CALL(*locator_, GetReport(_, _)) .Times(AtLeast(1)) .WillRepeatedly(Return(E_ACCESSDENIED)); - Geoposition position; + content::Geoposition position; api_->GetPosition(&position); - EXPECT_EQ(Geoposition::ERROR_CODE_PERMISSION_DENIED, + EXPECT_EQ(content::Geoposition::ERROR_CODE_PERMISSION_DENIED, position.error_code); } TEST_F(GeolocationApiWin7Tests, GetValidPosition) { EXPECT_CALL(*locator_, GetReport(_, _)) .Times(AtLeast(1)); - Geoposition position; + content::Geoposition position; api_->GetPosition(&position); - EXPECT_TRUE(position.IsValidFix()); + EXPECT_TRUE(position.Validate()); } TEST_F(GeolocationApiWin7Tests, GetInvalidPosition) { @@ -331,9 +331,9 @@ TEST_F(GeolocationApiWin7Tests, GetInvalidPosition) { .WillRepeatedly(Return(HRESULT_FROM_WIN32(ERROR_NO_DATA))); EXPECT_CALL(*locator_, GetReport(_, _)) .Times(AtLeast(1)); - Geoposition position; + content::Geoposition position; api_->GetPosition(&position); - EXPECT_FALSE(position.IsValidFix()); + EXPECT_FALSE(position.Validate()); } } // namespace diff --git a/content/browser/geolocation/win7_location_api_win.cc b/content/browser/geolocation/win7_location_api_win.cc index f66b6e2..122ffe2 100644 --- a/content/browser/geolocation/win7_location_api_win.cc +++ b/content/browser/geolocation/win7_location_api_win.cc @@ -1,4 +1,4 @@ -// Copyright (c) 2011 The Chromium Authors. All rights reserved. +// Copyright (c) 2012 The Chromium Authors. All rights reserved. // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. @@ -10,8 +10,8 @@ #include "base/logging.h" #include "base/memory/scoped_ptr.h" #include "base/path_service.h" -#include "content/common/geoposition.h" #include "content/public/common/content_switches.h" +#include "content/public/common/geoposition.h" namespace { const double kKnotsToMetresPerSecondConversionFactor = 0.5144; @@ -89,35 +89,36 @@ Win7LocationApi* Win7LocationApi::CreateForTesting( return result; } -void Win7LocationApi::GetPosition(Geoposition* position) { +void Win7LocationApi::GetPosition(content::Geoposition* position) { DCHECK(position); - position->error_code = Geoposition::ERROR_CODE_POSITION_UNAVAILABLE; + position->error_code = content::Geoposition::ERROR_CODE_POSITION_UNAVAILABLE; if (!locator_) return; // Try to get a position fix if (!GetPositionIfFixed(position)) return; - position->error_code = Geoposition::ERROR_CODE_NONE; - if (!position->IsValidFix()) { + position->error_code = content::Geoposition::ERROR_CODE_NONE; + if (!position->Validate()) { // GetPositionIfFixed returned true, yet we've not got a valid fix. // This shouldn't happen; something went wrong in the conversion. NOTREACHED() << "Invalid position from GetPositionIfFixed: lat,long " << position->latitude << "," << position->longitude << " accuracy " << position->accuracy << " time " << position->timestamp.ToDoubleT(); - position->error_code = Geoposition::ERROR_CODE_POSITION_UNAVAILABLE; + position->error_code = + content::Geoposition::ERROR_CODE_POSITION_UNAVAILABLE; position->error_message = "Bad fix from Win7 provider"; } } -bool Win7LocationApi::GetPositionIfFixed(Geoposition* position) { +bool Win7LocationApi::GetPositionIfFixed(content::Geoposition* position) { HRESULT result_type; CComPtr<ILocationReport> location_report; 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) - position->error_code = Geoposition::ERROR_CODE_PERMISSION_DENIED; + position->error_code = content::Geoposition::ERROR_CODE_PERMISSION_DENIED; // Checks for any other errors while requesting a location report. if (!SUCCEEDED(result_type)) return false; diff --git a/content/browser/geolocation/win7_location_api_win.h b/content/browser/geolocation/win7_location_api_win.h index a7be43c..3f913d3 100644 --- a/content/browser/geolocation/win7_location_api_win.h +++ b/content/browser/geolocation/win7_location_api_win.h @@ -1,4 +1,4 @@ -// Copyright (c) 2011 The Chromium Authors. All rights reserved. +// Copyright (c) 2012 The Chromium Authors. All rights reserved. // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. @@ -15,7 +15,9 @@ #include "base/win/scoped_com_initializer.h" #include "content/common/content_export.h" +namespace content { struct Geoposition; +} // PropVariantToDouble typedef HRESULT (WINAPI* PropVariantToDoubleFunction) @@ -33,7 +35,7 @@ class CONTENT_EXPORT Win7LocationApi { ILocation* locator); // Gives the best available position. // Returns false if no valid position is available. - virtual void GetPosition(Geoposition* position); + virtual void GetPosition(content::Geoposition* position); // Changes the "accuracy" needed. Affects power levels of devices. virtual bool SetHighAccuracy(bool acc); @@ -48,7 +50,7 @@ class CONTENT_EXPORT Win7LocationApi { // Provides the best position fix if one is available. // Does this by requesting a location report and querying it to obtain // location information. - virtual bool GetPositionIfFixed(Geoposition* position); + virtual bool GetPositionIfFixed(content::Geoposition* position); // Ensure that COM has been initialized for this thread. base::win::ScopedCOMInitializer com_initializer_; diff --git a/content/browser/geolocation/win7_location_provider_unittest_win.cc b/content/browser/geolocation/win7_location_provider_unittest_win.cc index d4b09b0..d67be50 100644 --- a/content/browser/geolocation/win7_location_provider_unittest_win.cc +++ b/content/browser/geolocation/win7_location_provider_unittest_win.cc @@ -1,15 +1,14 @@ -// Copyright (c) 2010 The Chromium Authors. All rights reserved. +// Copyright (c) 2012 The Chromium Authors. All rights reserved. // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. #include "base/message_loop.h" #include "content/browser/geolocation/win7_location_provider_win.h" #include "content/browser/geolocation/win7_location_api_win.h" +#include "content/public/common/geoposition.h" #include "testing/gmock/include/gmock/gmock.h" #include "testing/gtest/include/gtest/gtest.h" -struct Geoposition; - using testing::_; using testing::AtLeast; using testing::DoDefault; @@ -27,26 +26,27 @@ class MockWin7LocationApi : public Win7LocationApi { // Used to signal when the destructor is called. MOCK_METHOD0(Die, void()); // Win7LocationApi - MOCK_METHOD1(GetPosition, void(Geoposition*)); + MOCK_METHOD1(GetPosition, void(content::Geoposition*)); MOCK_METHOD1(SetHighAccuracy, bool(bool)); virtual ~MockWin7LocationApi() { Die(); } - void GetPositionValid(Geoposition* position) { + void GetPositionValid(content::Geoposition* position) { position->latitude = 4.5; position->longitude = -34.1; position->accuracy = 0.5; position->timestamp = base::Time::FromDoubleT(200); - position->error_code = Geoposition::ERROR_CODE_NONE; + position->error_code = content::Geoposition::ERROR_CODE_NONE; } - void GetPositionInvalid(Geoposition* position) { + void GetPositionInvalid(content::Geoposition* position) { position->latitude = 4.5; position->longitude = -340000.1; position->accuracy = 0.5; position->timestamp = base::Time::FromDoubleT(200); - position->error_code = Geoposition::ERROR_CODE_POSITION_UNAVAILABLE; + position->error_code = + content::Geoposition::ERROR_CODE_POSITION_UNAVAILABLE; } private: @@ -119,9 +119,9 @@ TEST_F(GeolocationProviderWin7Tests, GetValidPosition) { .WillOnce(Return(true)); EXPECT_TRUE(provider_->StartProvider(true)); main_message_loop_.Run(); - Geoposition position; + content::Geoposition position; provider_->GetPosition(&position); - EXPECT_TRUE(position.IsValidFix()); + EXPECT_TRUE(position.Validate()); } TEST_F(GeolocationProviderWin7Tests, GetInvalidPosition) { @@ -133,9 +133,9 @@ TEST_F(GeolocationProviderWin7Tests, GetInvalidPosition) { .WillOnce(Return(true)); EXPECT_TRUE(provider_->StartProvider(true)); main_message_loop_.Run(); - Geoposition position; + content::Geoposition position; provider_->GetPosition(&position); - EXPECT_FALSE(position.IsValidFix()); + EXPECT_FALSE(position.Validate()); } } // namespace diff --git a/content/browser/geolocation/win7_location_provider_win.cc b/content/browser/geolocation/win7_location_provider_win.cc index cfcf3f3..780df8c 100644 --- a/content/browser/geolocation/win7_location_provider_win.cc +++ b/content/browser/geolocation/win7_location_provider_win.cc @@ -24,13 +24,13 @@ const int kMovementThresholdMeters = 20; // The arbitrary delta is decreased (Gears used 100 meters); if we need to // decrease it any further we'll likely want to do some smarter filtering to // remove GPS location jitter noise. -bool PositionsDifferSiginificantly(const Geoposition& position_1, - const Geoposition& position_2) { - const bool pos_1_valid = position_1.IsValidFix(); - if (pos_1_valid != position_2.IsValidFix()) +bool PositionsDifferSiginificantly(const content::Geoposition& position_1, + const content::Geoposition& position_2) { + const bool pos_1_valid = position_1.Validate(); + if (pos_1_valid != position_2.Validate()) return true; if (!pos_1_valid) { - DCHECK(!position_2.IsValidFix()); + DCHECK(!position_2.Validate()); return false; } double delta = std::sqrt( @@ -66,7 +66,7 @@ void Win7LocationProvider::StopProvider() { weak_factory_.InvalidateWeakPtrs(); } -void Win7LocationProvider::GetPosition(Geoposition* position) { +void Win7LocationProvider::GetPosition(content::Geoposition* position) { DCHECK(position); *position = position_; } @@ -76,12 +76,13 @@ void Win7LocationProvider::UpdatePosition() { } void Win7LocationProvider::DoPollTask() { - Geoposition new_position; + content::Geoposition new_position; api_->GetPosition(&new_position); const bool differ = PositionsDifferSiginificantly(position_, new_position); ScheduleNextPoll(differ ? kPollPeriodMovingMillis : kPollPeriodStationaryMillis); - if (differ || new_position.error_code != Geoposition::ERROR_CODE_NONE) { + if (differ || + new_position.error_code != content::Geoposition::ERROR_CODE_NONE) { // Update if the new location is interesting or we have an error to report position_ = new_position; UpdateListeners(); diff --git a/content/browser/geolocation/win7_location_provider_win.h b/content/browser/geolocation/win7_location_provider_win.h index 1a918e7..ae14be7 100644 --- a/content/browser/geolocation/win7_location_provider_win.h +++ b/content/browser/geolocation/win7_location_provider_win.h @@ -11,7 +11,7 @@ #include "content/browser/geolocation/location_provider.h" #include "content/browser/geolocation/win7_location_api_win.h" #include "content/common/content_export.h" -#include "content/common/geoposition.h" +#include "content/public/common/geoposition.h" // Location provider for Windows 7 that uses the Location and Sensors platform // to obtain position fixes. @@ -27,7 +27,7 @@ class CONTENT_EXPORT Win7LocationProvider : public LocationProviderBase { // LocationProvider. virtual bool StartProvider(bool high_accuracy) OVERRIDE; virtual void StopProvider() OVERRIDE; - virtual void GetPosition(Geoposition* position) OVERRIDE; + virtual void GetPosition(content::Geoposition* position) OVERRIDE; virtual void UpdatePosition() OVERRIDE; private: @@ -37,7 +37,7 @@ class CONTENT_EXPORT Win7LocationProvider : public LocationProviderBase { void ScheduleNextPoll(int interval); scoped_ptr<Win7LocationApi> api_; - Geoposition position_; + content::Geoposition position_; // Holder for the tasks which run on the thread; takes care of cleanup. base::WeakPtrFactory<Win7LocationProvider> weak_factory_; }; diff --git a/content/common/geolocation_messages.h b/content/common/geolocation_messages.h index b945de5..eac9200 100644 --- a/content/common/geolocation_messages.h +++ b/content/common/geolocation_messages.h @@ -1,19 +1,19 @@ -// Copyright (c) 2011 The Chromium Authors. All rights reserved. +// Copyright (c) 2012 The Chromium Authors. All rights reserved. // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. // IPC messages for geolocation. // Multiply-included message file, hence no include guard. -#include "content/common/geoposition.h" +#include "content/public/common/geoposition.h" #include "googleurl/src/gurl.h" #include "ipc/ipc_message_macros.h" #define IPC_MESSAGE_START GeolocationMsgStart -IPC_ENUM_TRAITS(Geoposition::ErrorCode) +IPC_ENUM_TRAITS(content::Geoposition::ErrorCode) -IPC_STRUCT_TRAITS_BEGIN(Geoposition) +IPC_STRUCT_TRAITS_BEGIN(content::Geoposition) IPC_STRUCT_TRAITS_MEMBER(latitude) IPC_STRUCT_TRAITS_MEMBER(longitude) IPC_STRUCT_TRAITS_MEMBER(altitude) @@ -37,7 +37,7 @@ IPC_MESSAGE_ROUTED2(GeolocationMsg_PermissionSet, // permission and we have a position available or an error occurs (such as // permission denied, position unavailable, etc.) IPC_MESSAGE_ROUTED1(GeolocationMsg_PositionUpdated, - Geoposition /* geoposition */) + content::Geoposition /* geoposition */) // Messages sent from the renderer to the browser. diff --git a/content/common/geoposition.cc b/content/common/geoposition.cc deleted file mode 100644 index 4beac74..0000000 --- a/content/common/geoposition.cc +++ /dev/null @@ -1,66 +0,0 @@ -// Copyright (c) 2010 The Chromium Authors. All rights reserved. -// Use of this source code is governed by a BSD-style license that can be -// found in the LICENSE file. - -#include "content/common/geoposition.h" - -namespace { -// Sentinel values to mark invalid data. (WebKit carries companion is_valid -// bools for this purpose; we may eventually follow that approach, but -// sentinels worked OK in the Gears code this is based on.) -const double kBadLatitudeLongitude = 200; -// Lowest point on land is at approximately -400 meters. -const int kBadAltitude = -10000; -const int kBadAccuracy = -1; // Accuracy must be non-negative. -const int64 kBadTimestamp = kint64min; -const int kBadHeading = -1; // Heading must be non-negative. -const int kBadSpeed = -1; -} - -Geoposition::Geoposition() - : latitude(kBadLatitudeLongitude), - longitude(kBadLatitudeLongitude), - altitude(kBadAltitude), - accuracy(kBadAccuracy), - altitude_accuracy(kBadAccuracy), - heading(kBadHeading), - speed(kBadSpeed), - error_code(ERROR_CODE_NONE) { -} - -bool Geoposition::is_valid_latlong() const { - return latitude >= -90.0 && latitude <= 90.0 && - longitude >= -180.0 && longitude <= 180.0; -} - -bool Geoposition::is_valid_altitude() const { - return altitude > kBadAltitude; -} - -bool Geoposition::is_valid_accuracy() const { - return accuracy >= 0.0; -} - -bool Geoposition::is_valid_altitude_accuracy() const { - return altitude_accuracy >= 0.0; -} - -bool Geoposition::is_valid_heading() const { - return heading >= 0 && heading <= 360; -} - -bool Geoposition::is_valid_speed() const { - return speed >= 0; -} - -bool Geoposition::is_valid_timestamp() const { - return !timestamp.is_null(); -} - -bool Geoposition::IsValidFix() const { - return is_valid_latlong() && is_valid_accuracy() && is_valid_timestamp(); -} - -bool Geoposition::IsInitialized() const { - return error_code != ERROR_CODE_NONE || IsValidFix(); -} diff --git a/content/common/geoposition.h b/content/common/geoposition.h deleted file mode 100644 index cff59ae..0000000 --- a/content/common/geoposition.h +++ /dev/null @@ -1,66 +0,0 @@ -// Copyright (c) 2011 The Chromium Authors. All rights reserved. -// Use of this source code is governed by a BSD-style license that can be -// found in the LICENSE file. - -// This file declares the Position structure, which is used to represent a -// position fix. Originally derived from -// http://gears.googlecode.com/svn/trunk/gears/geolocation/geolocation.h - -#ifndef CONTENT_COMMON_GEOPOSITION_H_ -#define CONTENT_COMMON_GEOPOSITION_H_ -#pragma once - -#include <string> -#include "base/time.h" -#include "content/common/content_export.h" - -// The internal representation of a geo position. Some properties use different -// types when passed to JavaScript. -struct CONTENT_EXPORT Geoposition { - public: - // Error codes for returning to JavaScript. These values are defined by the - // W3C spec. Note that Gears does not use all of these codes, but we need - // values for all of them to allow us to provide the constants on the error - // object. - enum ErrorCode { - ERROR_CODE_NONE = 0, // Chrome addition - ERROR_CODE_PERMISSION_DENIED = 1, - ERROR_CODE_POSITION_UNAVAILABLE = 2, - ERROR_CODE_TIMEOUT = 3, - }; - - Geoposition(); - - bool is_valid_latlong() const; - bool is_valid_altitude() const; - bool is_valid_accuracy() const; - bool is_valid_altitude_accuracy() const; - bool is_valid_heading() const; - bool is_valid_speed() const; - bool is_valid_timestamp() const; - - // A valid fix has a valid latitude, longitude, accuracy and timestamp. - bool IsValidFix() const; - - // A position is considered initialized if it has either a valid fix or - // an error code other than NONE. - bool IsInitialized() const; - - // These properties correspond to the JavaScript Position object. - double latitude; // In degrees - double longitude; // In degrees - double altitude; // In metres - double accuracy; // In metres - double altitude_accuracy; // In metres - double heading; // In degrees clockwise relative to the true north - double speed; // In meters per second - // Timestamp for this position fix object taken from the host computer's - // system clock (i.e. from Time::Now(), not the source device's clock). - base::Time timestamp; - - // These properties are returned to JavaScript as a PositionError object. - ErrorCode error_code; - std::string error_message; // Human-readable error message -}; - -#endif // CONTENT_COMMON_GEOPOSITION_H_ diff --git a/content/content_common.gypi b/content/content_common.gypi index 9045229..5d2e2f7 100644 --- a/content/content_common.gypi +++ b/content/content_common.gypi @@ -49,6 +49,8 @@ 'public/common/file_chooser_params.h', 'public/common/frame_navigate_params.cc', 'public/common/frame_navigate_params.h', + 'public/common/geoposition.cc', + 'public/common/geoposition.h', 'public/common/gpu_feature_type.h', 'public/common/gpu_info.cc', 'public/common/gpu_info.h', @@ -161,8 +163,6 @@ 'common/gamepad_seqlock.cc', 'common/gamepad_seqlock.h', 'common/geolocation_messages.h', - 'common/geoposition.cc', - 'common/geoposition.h', 'common/gpu/client/command_buffer_proxy_impl.cc', 'common/gpu/client/command_buffer_proxy_impl.h', 'common/gpu/client/gl_helper.cc', diff --git a/content/public/browser/geolocation.h b/content/public/browser/geolocation.h index f66c8ed..23868e9 100644 --- a/content/public/browser/geolocation.h +++ b/content/public/browser/geolocation.h @@ -11,6 +11,8 @@ namespace content { +struct Geoposition; + // Overrides the current location for testing. This function may be called on // any thread. The completion callback will be invoked asynchronously on the // calling thread when the override operation is completed. @@ -18,9 +20,7 @@ namespace content { // to provide fake location results when not testing the innards of the // geolocation code. void CONTENT_EXPORT OverrideLocationForTesting( - double latitude, - double longitude, - double altitude, + const Geoposition& position, const base::Closure& completion_callback); } // namespace content diff --git a/content/public/common/geoposition.cc b/content/public/common/geoposition.cc new file mode 100644 index 0000000..3a0f1f0 --- /dev/null +++ b/content/public/common/geoposition.cc @@ -0,0 +1,39 @@ +// Copyright (c) 2012 The Chromium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +#include "content/public/common/geoposition.h" + +namespace { +// Sentinel values to mark invalid data. (WebKit carries companion is_valid +// bools for this purpose; we may eventually follow that approach, but +// sentinels worked OK in the Gears code this is based on.) +const double kBadLatitudeLongitude = 200; +// Lowest point on land is at approximately -400 meters. +const int kBadAltitude = -10000; +const int kBadAccuracy = -1; // Accuracy must be non-negative. +const int kBadHeading = -1; // Heading must be non-negative. +const int kBadSpeed = -1; +} + +namespace content { + +Geoposition::Geoposition() + : latitude(kBadLatitudeLongitude), + longitude(kBadLatitudeLongitude), + altitude(kBadAltitude), + accuracy(kBadAccuracy), + altitude_accuracy(kBadAccuracy), + heading(kBadHeading), + speed(kBadSpeed), + error_code(ERROR_CODE_NONE) { +} + +bool Geoposition::Validate() const { + return latitude >= -90. && latitude <= 90. && + longitude >= -180. && longitude <= 180. && + accuracy >= 0. && + !timestamp.is_null(); +} + +} // namespace content diff --git a/content/public/common/geoposition.h b/content/public/common/geoposition.h new file mode 100644 index 0000000..22e7030 --- /dev/null +++ b/content/public/common/geoposition.h @@ -0,0 +1,67 @@ +// Copyright (c) 2012 The Chromium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +// This file declares the Geoposition structure, used to represent a position +// fix. It was originally derived from: +// http://gears.googlecode.com/svn/trunk/gears/geolocation/geolocation.h + +#ifndef CONTENT_PUBLIC_COMMON_GEOPOSITION_H_ +#define CONTENT_PUBLIC_COMMON_GEOPOSITION_H_ +#pragma once + +#include <string> + +#include "base/time.h" +#include "content/common/content_export.h" + +namespace content { + +struct CONTENT_EXPORT Geoposition { + public: + // These values follow the W3C geolocation specification and can be returned + // to JavaScript without the need for a conversion. + enum ErrorCode { + ERROR_CODE_NONE = 0, // Chrome addition. + ERROR_CODE_PERMISSION_DENIED = 1, + ERROR_CODE_POSITION_UNAVAILABLE = 2, + ERROR_CODE_TIMEOUT = 3, + }; + + // All fields are initialized to sentinel values marking them as invalid. The + // error code is set to ERROR_CODE_NONE. + Geoposition(); + + // A valid fix has a valid latitude, longitude, accuracy and timestamp. + bool Validate() const; + + // These properties correspond to those of the JavaScript Position object + // although their types may differ. + // Latitude in decimal degrees north (WGS84 coordinate frame). + double latitude; + // Longitude in decimal degrees west (WGS84 coordinate frame). + double longitude; + // Altitude in meters (above WGS84 datum). + double altitude; + // Accuracy of horizontal position in meters. + double accuracy; + // Accuracy of altitude in meters. + double altitude_accuracy; + // Heading in decimal degrees clockwise from true north. + double heading; + // Horizontal component of device velocity in meters per second. + double speed; + // Time of position measurement in milisecons since Epoch in UTC time. This is + // taken from the host computer's system clock (i.e. from Time::Now(), not the + // source device's clock). + base::Time timestamp; + + // Error code, see enum above. + ErrorCode error_code; + // Human-readable error message. + std::string error_message; +}; + +} // namespace content + +#endif // CONTENT_COMMON_GEOPOSITION_H_ diff --git a/content/renderer/geolocation_dispatcher.cc b/content/renderer/geolocation_dispatcher.cc index d745ba4..9551a2f 100644 --- a/content/renderer/geolocation_dispatcher.cc +++ b/content/renderer/geolocation_dispatcher.cc @@ -1,4 +1,4 @@ -// Copyright (c) 2011 The Chromium Authors. All rights reserved. +// Copyright (c) 2012 The Chromium Authors. All rights reserved. // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. @@ -112,35 +112,38 @@ void GeolocationDispatcher::OnPermissionSet(int bridge_id, bool is_allowed) { } // We have an updated geolocation position or error code. -void GeolocationDispatcher::OnPositionUpdated(const Geoposition& geoposition) { +void GeolocationDispatcher::OnPositionUpdated( + const content::Geoposition& geoposition) { // It is possible for the browser process to have queued an update message // before receiving the stop updating message. if (!updating_) return; - DCHECK(geoposition.IsInitialized()); - if (geoposition.IsValidFix()) { + if (geoposition.Validate()) { controller_->positionChanged( WebGeolocationPosition( geoposition.timestamp.ToDoubleT(), geoposition.latitude, geoposition.longitude, geoposition.accuracy, - geoposition.is_valid_altitude(), geoposition.altitude, - geoposition.is_valid_altitude_accuracy(), + // Lowest point on land is at approximately -400 meters. + geoposition.altitude > -10000., + geoposition.altitude, + geoposition.altitude_accuracy >= 0., geoposition.altitude_accuracy, - geoposition.is_valid_heading(), geoposition.heading, - geoposition.is_valid_speed(), geoposition.speed)); + geoposition.heading >= 0. && geoposition.heading <= 360., + geoposition.heading, + geoposition.speed >= 0., + geoposition.speed)); } else { WebGeolocationError::Error code; switch (geoposition.error_code) { - case Geoposition::ERROR_CODE_PERMISSION_DENIED: + case content::Geoposition::ERROR_CODE_PERMISSION_DENIED: code = WebGeolocationError::ErrorPermissionDenied; break; - case Geoposition::ERROR_CODE_POSITION_UNAVAILABLE: + case content::Geoposition::ERROR_CODE_POSITION_UNAVAILABLE: code = WebGeolocationError::ErrorPositionUnavailable; break; default: - DCHECK(false); NOTREACHED() << geoposition.error_code; return; } diff --git a/content/renderer/geolocation_dispatcher.h b/content/renderer/geolocation_dispatcher.h index ff38665..68a3d80 100644 --- a/content/renderer/geolocation_dispatcher.h +++ b/content/renderer/geolocation_dispatcher.h @@ -1,4 +1,4 @@ -// Copyright (c) 2011 The Chromium Authors. All rights reserved. +// Copyright (c) 2012 The Chromium Authors. All rights reserved. // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. @@ -12,7 +12,10 @@ #include "third_party/WebKit/Source/WebKit/chromium/public/WebGeolocationController.h" class RenderViewImpl; + +namespace content { struct Geoposition; +} namespace WebKit { class WebGeolocationController; @@ -50,7 +53,7 @@ class GeolocationDispatcher : public content::RenderViewObserver, void OnPermissionSet(int bridge_id, bool is_allowed); // We have an updated geolocation position or error code. - void OnPositionUpdated(const Geoposition& geoposition); + void OnPositionUpdated(const content::Geoposition& geoposition); // The controller_ is valid for the lifetime of the underlying // WebCore::GeolocationController. geolocationDestroyed() is |