Set default values for timeout and maximumAge of PositionOptions

Geolocation spec defines default values for both timeout and 
maximumAge but current implementation is working with
hasTimeout and hasMaximumAge functions for emulating that.

Setting initial values of timeout and maximumAge is more proper than using these "has" functions.
In addition, hasZeroTimeout can be removed because it is
enough to check timeout is zero or not and clearMaximumAge
can also be removed, as it is enough to set 0 to maximumAge.

BUG=368184

Review URL: https://codereview.chromium.org/297143003

git-svn-id: svn://svn.chromium.org/blink/trunk@175131 bbb929c8-8fbe-4397-9dbb-9b2b20218538
parent 49e1ae4d
...@@ -82,16 +82,11 @@ static PassRefPtrWillBeRawPtr<PositionOptions> createPositionOptions(v8::Local<v ...@@ -82,16 +82,11 @@ static PassRefPtrWillBeRawPtr<PositionOptions> createPositionOptions(v8::Local<v
succeeded = false; succeeded = false;
return nullptr; return nullptr;
} }
double timeoutDouble = timeoutNumber->Value(); if (timeoutNumber->Value() <= 0)
// If the value is positive infinity, there's nothing to do.
if (!(std::isinf(timeoutDouble) && timeoutDouble > 0)) {
if (timeoutDouble <= 0) {
options->setTimeout(0); options->setTimeout(0);
} else { else
options->setTimeout(toUInt32(timeoutValue, Clamp, exceptionState)); options->setTimeout(toUInt32(timeoutValue, Clamp, exceptionState));
} }
}
}
v8::Local<v8::Value> maximumAgeValue = object->Get(v8AtomicString(isolate, "maximumAge")); v8::Local<v8::Value> maximumAgeValue = object->Get(v8AtomicString(isolate, "maximumAge"));
if (maximumAgeValue.IsEmpty()) { if (maximumAgeValue.IsEmpty()) {
...@@ -104,18 +99,11 @@ static PassRefPtrWillBeRawPtr<PositionOptions> createPositionOptions(v8::Local<v ...@@ -104,18 +99,11 @@ static PassRefPtrWillBeRawPtr<PositionOptions> createPositionOptions(v8::Local<v
succeeded = false; succeeded = false;
return nullptr; return nullptr;
} }
double maximumAgeDouble = maximumAgeNumber->Value(); if (maximumAgeNumber->Value() <= 0)
if (std::isinf(maximumAgeDouble) && maximumAgeDouble > 0) {
// If the value is positive infinity, clear maximumAge.
options->clearMaximumAge();
} else {
if (maximumAgeDouble <= 0) {
options->setMaximumAge(0); options->setMaximumAge(0);
} else { else
options->setMaximumAge(toUInt32(maximumAgeValue, Clamp, exceptionState)); options->setMaximumAge(toUInt32(maximumAgeValue, Clamp, exceptionState));
} }
}
}
return options.release(); return options.release();
} }
......
...@@ -119,11 +119,6 @@ void Geolocation::GeoNotifier::setUseCachedPosition() ...@@ -119,11 +119,6 @@ void Geolocation::GeoNotifier::setUseCachedPosition()
m_timer.startOneShot(0, FROM_HERE); m_timer.startOneShot(0, FROM_HERE);
} }
bool Geolocation::GeoNotifier::hasZeroTimeout() const
{
return m_options->hasTimeout() && m_options->timeout() == 0;
}
void Geolocation::GeoNotifier::runSuccessCallback(Geoposition* position) void Geolocation::GeoNotifier::runSuccessCallback(Geoposition* position)
{ {
// If we are here and the Geolocation permission is not approved, something has // If we are here and the Geolocation permission is not approved, something has
...@@ -140,9 +135,8 @@ void Geolocation::GeoNotifier::runErrorCallback(PositionError* error) ...@@ -140,9 +135,8 @@ void Geolocation::GeoNotifier::runErrorCallback(PositionError* error)
m_errorCallback->handleEvent(error); m_errorCallback->handleEvent(error);
} }
void Geolocation::GeoNotifier::startTimerIfNeeded() void Geolocation::GeoNotifier::startTimer()
{ {
if (m_options->hasTimeout())
m_timer.startOneShot(m_options->timeout() / 1000.0, FROM_HERE); m_timer.startOneShot(m_options->timeout() / 1000.0, FROM_HERE);
} }
...@@ -350,14 +344,14 @@ void Geolocation::startRequest(GeoNotifier *notifier) ...@@ -350,14 +344,14 @@ void Geolocation::startRequest(GeoNotifier *notifier)
notifier->setFatalError(PositionError::create(PositionError::PERMISSION_DENIED, permissionDeniedErrorMessage)); notifier->setFatalError(PositionError::create(PositionError::PERMISSION_DENIED, permissionDeniedErrorMessage));
else if (haveSuitableCachedPosition(notifier->options())) else if (haveSuitableCachedPosition(notifier->options()))
notifier->setUseCachedPosition(); notifier->setUseCachedPosition();
else if (notifier->hasZeroTimeout()) else if (!notifier->options()->timeout())
notifier->startTimerIfNeeded(); notifier->startTimer();
else if (!isAllowed()) { else if (!isAllowed()) {
// if we don't yet have permission, request for permission before calling startUpdating() // if we don't yet have permission, request for permission before calling startUpdating()
m_pendingForPermissionNotifiers.add(notifier); m_pendingForPermissionNotifiers.add(notifier);
requestPermission(); requestPermission();
} else if (startUpdating(notifier)) } else if (startUpdating(notifier))
notifier->startTimerIfNeeded(); notifier->startTimer();
else else
notifier->setFatalError(PositionError::create(PositionError::POSITION_UNAVAILABLE, failedToStartServiceErrorMessage)); notifier->setFatalError(PositionError::create(PositionError::POSITION_UNAVAILABLE, failedToStartServiceErrorMessage));
} }
...@@ -408,8 +402,8 @@ void Geolocation::makeCachedPositionCallbacks() ...@@ -408,8 +402,8 @@ void Geolocation::makeCachedPositionCallbacks()
if (m_oneShots.contains(notifier)) if (m_oneShots.contains(notifier))
m_oneShots.remove(notifier); m_oneShots.remove(notifier);
else if (m_watchers.contains(notifier)) { else if (m_watchers.contains(notifier)) {
if (notifier->hasZeroTimeout() || startUpdating(notifier)) if (!notifier->options()->timeout() || startUpdating(notifier))
notifier->startTimerIfNeeded(); notifier->startTimer();
else else
notifier->setFatalError(PositionError::create(PositionError::POSITION_UNAVAILABLE, failedToStartServiceErrorMessage)); notifier->setFatalError(PositionError::create(PositionError::POSITION_UNAVAILABLE, failedToStartServiceErrorMessage));
} }
...@@ -435,8 +429,6 @@ bool Geolocation::haveSuitableCachedPosition(PositionOptions* options) ...@@ -435,8 +429,6 @@ bool Geolocation::haveSuitableCachedPosition(PositionOptions* options)
Geoposition* cachedPosition = lastPosition(); Geoposition* cachedPosition = lastPosition();
if (!cachedPosition) if (!cachedPosition)
return false; return false;
if (!options->hasMaximumAge())
return true;
if (!options->maximumAge()) if (!options->maximumAge())
return false; return false;
DOMTimeStamp currentTimeMillis = convertSecondsToDOMTimeStamp(currentTime()); DOMTimeStamp currentTimeMillis = convertSecondsToDOMTimeStamp(currentTime());
...@@ -698,7 +690,7 @@ void Geolocation::handlePendingPermissionNotifiers() ...@@ -698,7 +690,7 @@ void Geolocation::handlePendingPermissionNotifiers()
// start all pending notification requests as permission granted. // start all pending notification requests as permission granted.
// The notifier is always ref'ed by m_oneShots or m_watchers. // The notifier is always ref'ed by m_oneShots or m_watchers.
if (startUpdating(notifier)) if (startUpdating(notifier))
notifier->startTimerIfNeeded(); notifier->startTimer();
else else
notifier->setFatalError(PositionError::create(PositionError::POSITION_UNAVAILABLE, failedToStartServiceErrorMessage)); notifier->setFatalError(PositionError::create(PositionError::POSITION_UNAVAILABLE, failedToStartServiceErrorMessage));
} else { } else {
......
...@@ -117,9 +117,7 @@ private: ...@@ -117,9 +117,7 @@ private:
void runSuccessCallback(Geoposition*); void runSuccessCallback(Geoposition*);
void runErrorCallback(PositionError*); void runErrorCallback(PositionError*);
// Starts the timer if a timeout was specified on the options. void startTimer();
void startTimerIfNeeded();
void stopTimer(); void stopTimer();
// Runs the error callback if there is a fatal error. Otherwise, if a // Runs the error callback if there is a fatal error. Otherwise, if a
...@@ -127,8 +125,6 @@ private: ...@@ -127,8 +125,6 @@ private:
// Otherwise, the notifier has expired, and its error callback is run. // Otherwise, the notifier has expired, and its error callback is run.
void timerFired(Timer<GeoNotifier>*); void timerFired(Timer<GeoNotifier>*);
bool hasZeroTimeout() const;
private: private:
GeoNotifier(Geolocation*, PassOwnPtr<PositionCallback>, PassOwnPtr<PositionErrorCallback>, PassRefPtrWillBeRawPtr<PositionOptions>); GeoNotifier(Geolocation*, PassOwnPtr<PositionCallback>, PassOwnPtr<PositionErrorCallback>, PassRefPtrWillBeRawPtr<PositionOptions>);
......
...@@ -28,6 +28,7 @@ ...@@ -28,6 +28,7 @@
#include "platform/heap/Handle.h" #include "platform/heap/Handle.h"
#include "wtf/RefCounted.h" #include "wtf/RefCounted.h"
#include <limits.h>
namespace WebCore { namespace WebCore {
...@@ -38,43 +39,36 @@ public: ...@@ -38,43 +39,36 @@ public:
bool enableHighAccuracy() const { return m_highAccuracy; } bool enableHighAccuracy() const { return m_highAccuracy; }
void setEnableHighAccuracy(bool enable) { m_highAccuracy = enable; } void setEnableHighAccuracy(bool enable) { m_highAccuracy = enable; }
bool hasTimeout() const { return m_hasTimeout; }
unsigned timeout() const unsigned timeout() const
{ {
ASSERT(hasTimeout());
return m_timeout; return m_timeout;
} }
void setTimeout(unsigned timeout) void setTimeout(unsigned timeout)
{ {
m_hasTimeout = true;
m_timeout = timeout; m_timeout = timeout;
} }
bool hasMaximumAge() const { return m_hasMaximumAge; }
unsigned maximumAge() const unsigned maximumAge() const
{ {
ASSERT(hasMaximumAge());
return m_maximumAge; return m_maximumAge;
} }
void clearMaximumAge() { m_hasMaximumAge = false; }
void setMaximumAge(unsigned age) void setMaximumAge(unsigned age)
{ {
m_hasMaximumAge = true;
m_maximumAge = age; m_maximumAge = age;
} }
private: private:
PositionOptions() PositionOptions()
: m_highAccuracy(false) : m_highAccuracy(false)
, m_hasTimeout(false) , m_maximumAge(0)
, m_timeout(std::numeric_limits<unsigned>::max())
{ {
setMaximumAge(0); setMaximumAge(0);
} }
bool m_highAccuracy; bool m_highAccuracy;
bool m_hasTimeout; int m_maximumAge;
unsigned m_timeout; int m_timeout;
bool m_hasMaximumAge;
unsigned m_maximumAge;
}; };
} // namespace WebCore } // namespace WebCore
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment