summaryrefslogtreecommitdiffstats
path: root/chrome/browser/geolocation/mock_location_provider.cc
diff options
context:
space:
mode:
authorjoth@chromium.org <joth@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2010-04-01 11:31:00 +0000
committerjoth@chromium.org <joth@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2010-04-01 11:31:00 +0000
commit1642c6086d35b6767c07eca51d23af8ca6d4f3b7 (patch)
treece445b2f39cb80f159f4f99e6977851df0bb6cf2 /chrome/browser/geolocation/mock_location_provider.cc
parent25212c49c8dff853bb05e52ed4629a8c659004a5 (diff)
downloadchromium_src-1642c6086d35b6767c07eca51d23af8ca6d4f3b7.zip
chromium_src-1642c6086d35b6767c07eca51d23af8ca6d4f3b7.tar.gz
chromium_src-1642c6086d35b6767c07eca51d23af8ca6d4f3b7.tar.bz2
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
Diffstat (limited to 'chrome/browser/geolocation/mock_location_provider.cc')
-rw-r--r--chrome/browser/geolocation/mock_location_provider.cc36
1 files changed, 29 insertions, 7 deletions
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<MockLocationProvider> 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);
}