This source file includes following definitions.
- IsNegative
- RunImpl
- RunImpl
#include "chrome/browser/extensions/api/location/location_api.h"
#include "chrome/browser/extensions/api/location/location_manager.h"
#include "chrome/browser/profiles/profile.h"
#include "chrome/common/extensions/api/location.h"
#include "extensions/common/error_utils.h"
namespace location = extensions::api::location;
namespace WatchLocation = location::WatchLocation;
namespace ClearWatch = location::ClearWatch;
namespace extensions {
const char kMustBePositive[] = "'*' must be 0 or greater.";
const char kMinDistanceInMeters[] = "minDistanceInMeters";
const char kMinTimeInMilliseconds[] = "minTimeInMilliseconds";
bool IsNegative(double* value) {
return value && *value < 0.0;
}
bool LocationWatchLocationFunction::RunImpl() {
scoped_ptr<WatchLocation::Params> params(
WatchLocation::Params::Create(*args_));
EXTENSION_FUNCTION_VALIDATE(params.get());
double* min_distance_in_meters =
params->request_info.min_distance_in_meters.get();
if (IsNegative(min_distance_in_meters)) {
error_ = ErrorUtils::FormatErrorMessage(
kMustBePositive,
kMinDistanceInMeters);
return false;
}
double* min_time_in_milliseconds =
params->request_info.min_time_in_milliseconds.get();
if (IsNegative(min_time_in_milliseconds)) {
error_ = ErrorUtils::FormatErrorMessage(
kMustBePositive,
kMinTimeInMilliseconds);
return false;
}
LocationManager::Get(GetProfile())
->AddLocationRequest(extension_id(),
params->name,
min_distance_in_meters,
min_time_in_milliseconds);
return true;
}
bool LocationClearWatchFunction::RunImpl() {
scoped_ptr<ClearWatch::Params> params(
ClearWatch::Params::Create(*args_));
EXTENSION_FUNCTION_VALIDATE(params.get());
LocationManager::Get(GetProfile())
->RemoveLocationRequest(extension_id(), params->name);
return true;
}
}