diff options
author | bulach@chromium.org <bulach@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2010-02-18 16:44:22 +0000 |
---|---|---|
committer | bulach@chromium.org <bulach@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2010-02-18 16:44:22 +0000 |
commit | 434afdcf94e2319ff03872db312d489a44637508 (patch) | |
tree | 3414ee5da70cb7ada1074c36cfc001e4ebfd5438 /chrome/common/geoposition.cc | |
parent | f01e0a37fa8f328b8694c9abc69ecc62fbc9690a (diff) | |
download | chromium_src-434afdcf94e2319ff03872db312d489a44637508.zip chromium_src-434afdcf94e2319ff03872db312d489a44637508.tar.gz chromium_src-434afdcf94e2319ff03872db312d489a44637508.tar.bz2 |
Initial Geolocation implementation
Adds IPC plumbing.
Adds Infobar buttons for requesting permission
TEST=geolocation_browsertest.cc
Review URL: http://codereview.chromium.org/548188
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@39366 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome/common/geoposition.cc')
-rw-r--r-- | chrome/common/geoposition.cc | 67 |
1 files changed, 67 insertions, 0 deletions
diff --git a/chrome/common/geoposition.cc b/chrome/common/geoposition.cc new file mode 100644 index 0000000..d4989ed --- /dev/null +++ b/chrome/common/geoposition.cc @@ -0,0 +1,67 @@ +// Copyright (c) 2010 The Chromium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +#include "chrome/common/geoposition.h" + +namespace { +// Sentinel values to mark invalid data. (WebKit carries companion is_valid +// bools for this purpose; we may eventually follow that approach, but +// sentinels worked OK in the gears code this is based on.) +const double kBadLatitudeLongitude = 200; +// Lowest point on land is at approximately -400 meters. +const int kBadAltitude = -10000; +const int kBadAccuracy = -1; // Accuracy must be non-negative. +const int64 kBadTimestamp = kint64min; +const int kBadHeading = -1; // Heading must be non-negative. +const int kBadSpeed = -1; +} + +Geoposition::Geoposition() + : latitude(kBadLatitudeLongitude), + longitude(kBadLatitudeLongitude), + altitude(kBadAltitude), + accuracy(kBadAccuracy), + altitude_accuracy(kBadAccuracy), + heading(kBadHeading), + speed(kBadSpeed), + timestamp(kBadTimestamp), + error_code(ERROR_CODE_NONE) { +} + +bool Geoposition::is_valid_latlong() const { + return latitude >= -90.0 && latitude <= 90.0 && + longitude >= -180.0 && longitude <= 180.0; +} + +bool Geoposition::is_valid_altitude() const { + return altitude > kBadAltitude; +} + +bool Geoposition::is_valid_accuracy() const { + return accuracy >= 0.0; +} + +bool Geoposition::is_valid_altitude_accuracy() const { + return altitude_accuracy >= 0.0; +} + +bool Geoposition::is_valid_heading() const { + return heading >= 0 && heading <= 360; +} + +bool Geoposition::is_valid_speed() const { + return speed >= 0; +} + +bool Geoposition::is_valid_timestamp() const { + return timestamp != kBadTimestamp; +} + +bool Geoposition::IsValidFix() const { + return is_valid_latlong() && is_valid_accuracy() && is_valid_timestamp(); +} + +bool Geoposition::IsInitialized() const { + return error_code != ERROR_CODE_NONE || IsValidFix(); +} |