diff options
author | bartfab@chromium.org <bartfab@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2012-05-04 14:28:11 +0000 |
---|---|---|
committer | bartfab@chromium.org <bartfab@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2012-05-04 14:28:11 +0000 |
commit | 4505232f6b7dab47ff6e8bef4ee606001973c0f6 (patch) | |
tree | ddbc930b1e40ffe6ecb45cf002acdf87b7c071b4 /content/browser/geolocation | |
parent | e2a04b06bdc075b67228f6e077bc8e84e802fc03 (diff) | |
download | chromium_src-4505232f6b7dab47ff6e8bef4ee606001973c0f6.zip chromium_src-4505232f6b7dab47ff6e8bef4ee606001973c0f6.tar.gz chromium_src-4505232f6b7dab47ff6e8bef4ee606001973c0f6.tar.bz2 |
Fix the implementation order of GeolocationProvider methods
The GeolocationProvider methods are implemented in more-or-less
random order. This CL arranges them so that they follow the
order in the header file.
This CL depends on https://chromiumcodereview.appspot.com/10344004/
BUG=chromium-os:18710
TEST=unit_tests, content_unittests
Review URL: http://codereview.chromium.org/10344016
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@135337 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'content/browser/geolocation')
-rw-r--r-- | content/browser/geolocation/geolocation_provider.cc | 168 |
1 files changed, 84 insertions, 84 deletions
diff --git a/content/browser/geolocation/geolocation_provider.cc b/content/browser/geolocation/geolocation_provider.cc index da592e2..f1d2dd5 100644 --- a/content/browser/geolocation/geolocation_provider.cc +++ b/content/browser/geolocation/geolocation_provider.cc @@ -16,26 +16,6 @@ using content::BrowserThread; -GeolocationProvider* GeolocationProvider::GetInstance() { - DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); - return Singleton<GeolocationProvider>::get(); -} - -GeolocationProvider::GeolocationProvider() - : base::Thread("Geolocation"), - is_permission_granted_(false), - ignore_location_updates_(false), - arbitrator_(NULL) { - DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); -} - -GeolocationProvider::~GeolocationProvider() { - // All observers should have unregistered before this singleton is destructed. - DCHECK(observers_.empty()); - Stop(); - DCHECK(!arbitrator_); -} - void GeolocationProvider::AddObserver(GeolocationObserver* observer, const GeolocationObserverOptions& update_options) { DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); @@ -62,6 +42,63 @@ void GeolocationProvider::RequestCallback( OnPermissionGranted(); } +void GeolocationProvider::OnPermissionGranted() { + DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); + bool was_permission_granted = is_permission_granted_; + is_permission_granted_ = true; + if (IsRunning() && !was_permission_granted) + InformProvidersPermissionGranted(); +} + +bool GeolocationProvider::HasPermissionBeenGranted() const { + DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); + return is_permission_granted_; +} + +void GeolocationProvider::OnLocationUpdate( + const content::Geoposition& position) { + DCHECK(OnGeolocationThread()); + // Will be true only in testing. + if (ignore_location_updates_) + return; + BrowserThread::PostTask(BrowserThread::IO, + FROM_HERE, + base::Bind(&GeolocationProvider::NotifyClients, + base::Unretained(this), position)); +} + +void GeolocationProvider::OverrideLocationForTesting( + const content::Geoposition& position) { + DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); + position_ = position; + ignore_location_updates_ = true; + NotifyClients(position); +} + +GeolocationProvider* GeolocationProvider::GetInstance() { + DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); + return Singleton<GeolocationProvider>::get(); +} + +GeolocationProvider::GeolocationProvider() + : base::Thread("Geolocation"), + is_permission_granted_(false), + ignore_location_updates_(false), + arbitrator_(NULL) { + DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); +} + +GeolocationProvider::~GeolocationProvider() { + // All observers should have unregistered before this singleton is destructed. + DCHECK(observers_.empty()); + Stop(); + DCHECK(!arbitrator_); +} + +bool GeolocationProvider::OnGeolocationThread() const { + return MessageLoop::current() == message_loop(); +} + void GeolocationProvider::OnClientsChanged() { DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); base::Closure task; @@ -91,6 +128,33 @@ void GeolocationProvider::OnClientsChanged() { message_loop()->PostTask(FROM_HERE, task); } +void GeolocationProvider::StopProviders() { + DCHECK(OnGeolocationThread()); + DCHECK(arbitrator_); + arbitrator_->StopProviders(); +} + +void GeolocationProvider::StartProviders( + const GeolocationObserverOptions& options) { + DCHECK(OnGeolocationThread()); + DCHECK(arbitrator_); + arbitrator_->StartProviders(options); +} + +void GeolocationProvider::InformProvidersPermissionGranted() { + DCHECK(IsRunning()); + if (!OnGeolocationThread()) { + message_loop()->PostTask( + FROM_HERE, + base::Bind(&GeolocationProvider::InformProvidersPermissionGranted, + base::Unretained(this))); + return; + } + DCHECK(OnGeolocationThread()); + DCHECK(arbitrator_); + arbitrator_->OnPermissionGranted(); +} + void GeolocationProvider::NotifyClients(const content::Geoposition& position) { DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); DCHECK(position.Validate() || @@ -117,41 +181,6 @@ void GeolocationProvider::NotifyClients(const content::Geoposition& position) { } } -void GeolocationProvider::StartProviders( - const GeolocationObserverOptions& options) { - DCHECK(OnGeolocationThread()); - DCHECK(arbitrator_); - arbitrator_->StartProviders(options); -} - -void GeolocationProvider::StopProviders() { - DCHECK(OnGeolocationThread()); - DCHECK(arbitrator_); - arbitrator_->StopProviders(); -} - -void GeolocationProvider::OnPermissionGranted() { - DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); - bool was_permission_granted = is_permission_granted_; - is_permission_granted_ = true; - if (IsRunning() && !was_permission_granted) - InformProvidersPermissionGranted(); -} - -void GeolocationProvider::InformProvidersPermissionGranted() { - DCHECK(IsRunning()); - if (!OnGeolocationThread()) { - message_loop()->PostTask( - FROM_HERE, - base::Bind(&GeolocationProvider::InformProvidersPermissionGranted, - base::Unretained(this))); - return; - } - DCHECK(OnGeolocationThread()); - DCHECK(arbitrator_); - arbitrator_->OnPermissionGranted(); -} - void GeolocationProvider::Init() { DCHECK(OnGeolocationThread()); DCHECK(!arbitrator_); @@ -163,32 +192,3 @@ void GeolocationProvider::CleanUp() { delete arbitrator_; arbitrator_ = NULL; } - -void GeolocationProvider::OnLocationUpdate( - const content::Geoposition& position) { - DCHECK(OnGeolocationThread()); - // Will be true only in testing. - if (ignore_location_updates_) - return; - BrowserThread::PostTask(BrowserThread::IO, - FROM_HERE, - base::Bind(&GeolocationProvider::NotifyClients, - base::Unretained(this), position)); -} - -void GeolocationProvider::OverrideLocationForTesting( - const content::Geoposition& position) { - DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); - position_ = position; - ignore_location_updates_ = true; - NotifyClients(position); -} - -bool GeolocationProvider::HasPermissionBeenGranted() const { - DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); - return is_permission_granted_; -} - -bool GeolocationProvider::OnGeolocationThread() const { - return MessageLoop::current() == message_loop(); -} |