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

Unified Diff: Source/modules/geolocation/GeolocationController.cpp

Issue 37863002: Update GeolocationController to call startUpdating() / stopUpdating() only if needed (Closed) Base URL: https://chromium.googlesource.com/chromium/blink.git@master
Patch Set: Unskip test Created 7 years, 2 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 | « Source/modules/geolocation/GeolocationController.h ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: Source/modules/geolocation/GeolocationController.cpp
diff --git a/Source/modules/geolocation/GeolocationController.cpp b/Source/modules/geolocation/GeolocationController.cpp
index 7c80533571d6fa4718d5f0ab4e8bd281191344be..0c7f0e44480d836d8937b8644f8268437c6836fe 100644
--- a/Source/modules/geolocation/GeolocationController.cpp
+++ b/Source/modules/geolocation/GeolocationController.cpp
@@ -36,9 +36,26 @@ namespace WebCore {
GeolocationController::GeolocationController(Page* page, GeolocationClient* client)
: PageLifecycleObserver(page)
, m_client(client)
+ , m_isClientUpdating(false)
{
}
+void GeolocationController::startUpdatingIfNeeded()
+{
+ if (m_isClientUpdating)
+ return;
+ m_isClientUpdating = true;
+ m_client->startUpdating();
+}
+
+void GeolocationController::stopUpdatingIfNeeded()
+{
+ if (!m_isClientUpdating)
+ return;
+ m_isClientUpdating = false;
+ m_client->stopUpdating();
+}
+
GeolocationController::~GeolocationController()
{
ASSERT(m_observers.isEmpty());
@@ -65,7 +82,7 @@ void GeolocationController::addObserver(Geolocation* observer, bool enableHighAc
if (enableHighAccuracy)
m_client->setEnableHighAccuracy(true);
if (wasEmpty && page() && page()->visibilityState() == PageVisibilityStateVisible)
- m_client->startUpdating();
+ startUpdatingIfNeeded();
}
}
@@ -79,7 +96,7 @@ void GeolocationController::removeObserver(Geolocation* observer)
if (m_client) {
if (m_observers.isEmpty())
- m_client->stopUpdating();
+ stopUpdatingIfNeeded();
else if (m_highAccuracyObservers.isEmpty())
m_client->setEnableHighAccuracy(false);
}
@@ -136,9 +153,9 @@ void GeolocationController::pageVisibilityChanged()
return;
if (page() && page()->visibilityState() == PageVisibilityStateVisible)
- m_client->startUpdating();
+ startUpdatingIfNeeded();
else
- m_client->stopUpdating();
+ stopUpdatingIfNeeded();
}
const char* GeolocationController::supplementName()
« no previous file with comments | « Source/modules/geolocation/GeolocationController.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698