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