From 1642c6086d35b6767c07eca51d23af8ca6d4f3b7 Mon Sep 17 00:00:00 2001 From: "joth@chromium.org" Date: Thu, 1 Apr 2010 11:31:00 +0000 Subject: Defer sending wifi data via the network provider until permission has been granted to use geolocaiton. Also fixes a long standing todos/bugs that the host sent in the network request was not set correctly, and location results were not always tagged against the correct source data in the cache. BUG=39171 TEST=run with --geolocation-enabled and --log-level=0, check from logs that no location request sent until authorized. Review URL: http://codereview.chromium.org/1541008 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@43339 0039d316-1c4b-4281-b951-d872f2087c98 --- .../browser/geolocation/mock_location_provider.cc | 36 +++++++++++++++++----- 1 file changed, 29 insertions(+), 7 deletions(-) (limited to 'chrome/browser/geolocation/mock_location_provider.cc') diff --git a/chrome/browser/geolocation/mock_location_provider.cc b/chrome/browser/geolocation/mock_location_provider.cc index 7851f30..7a7bb9c 100644 --- a/chrome/browser/geolocation/mock_location_provider.cc +++ b/chrome/browser/geolocation/mock_location_provider.cc @@ -34,12 +34,18 @@ void MockLocationProvider::GetPosition(Geoposition* position) { *position = position_; } +void MockLocationProvider::OnPermissionGranted(const GURL& requesting_frame) { + permission_granted_url_ = requesting_frame; +} + // Mock location provider that automatically calls back it's client when // StartProvider is called. class AutoMockLocationProvider : public MockLocationProvider { public: - explicit AutoMockLocationProvider(bool has_valid_location) - : ALLOW_THIS_IN_INITIALIZER_LIST(task_factory_(this)) { + AutoMockLocationProvider(bool has_valid_location, + bool requires_permission_to_start) + : ALLOW_THIS_IN_INITIALIZER_LIST(task_factory_(this)), + requires_permission_to_start_(requires_permission_to_start) { if (has_valid_location) { position_.accuracy = 3; position_.latitude = 4.3; @@ -51,13 +57,25 @@ class AutoMockLocationProvider : public MockLocationProvider { } virtual bool StartProvider() { MockLocationProvider::StartProvider(); - MessageLoop::current()->PostTask( - FROM_HERE, task_factory_.NewRunnableMethod( - &MockLocationProvider::UpdateListeners)); + if (!requires_permission_to_start_) { + MessageLoop::current()->PostTask( + FROM_HERE, task_factory_.NewRunnableMethod( + &MockLocationProvider::UpdateListeners)); + } return true; } + void OnPermissionGranted(const GURL& requesting_frame) { + MockLocationProvider::OnPermissionGranted(requesting_frame); + if (requires_permission_to_start_) { + MessageLoop::current()->PostTask( + FROM_HERE, task_factory_.NewRunnableMethod( + &MockLocationProvider::UpdateListeners)); + } + } + ScopedRunnableMethodFactory task_factory_; + const bool requires_permission_to_start_; }; LocationProviderBase* NewMockLocationProvider() { @@ -65,9 +83,13 @@ LocationProviderBase* NewMockLocationProvider() { } LocationProviderBase* NewAutoSuccessMockLocationProvider() { - return new AutoMockLocationProvider(true); + return new AutoMockLocationProvider(true, false); } LocationProviderBase* NewAutoFailMockLocationProvider() { - return new AutoMockLocationProvider(false); + return new AutoMockLocationProvider(false, false); +} + +LocationProviderBase* NewAutoSuccessMockNetworkLocationProvider() { + return new AutoMockLocationProvider(true, true); } -- cgit v1.1