Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(799)

Unified Diff: content/browser/geolocation/geolocation_provider.cc

Issue 10344016: Fix the implementation order of GeolocationProvider methods (Closed) Base URL: http://git.chromium.org/chromium/src.git@master
Patch Set: Rebased. Created 8 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: content/browser/geolocation/geolocation_provider.cc
diff --git a/content/browser/geolocation/geolocation_provider.cc b/content/browser/geolocation/geolocation_provider.cc
index da592e205a92fa36a84e3c5dc3c78383d98e6786..f1d2dd59440d34a100f2d04303b64baef62ad6d7 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();
-}
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698