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

Unified Diff: content/browser/geofencing/mock_geofencing_service.cc

Issue 1972733002: Delete geofencing implementation. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: mark histogram suffix as obsolete Created 4 years, 7 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
Index: content/browser/geofencing/mock_geofencing_service.cc
diff --git a/content/browser/geofencing/mock_geofencing_service.cc b/content/browser/geofencing/mock_geofencing_service.cc
deleted file mode 100644
index 55a9e3d4b2b87ce0078318aeb55526619b9f98a6..0000000000000000000000000000000000000000
--- a/content/browser/geofencing/mock_geofencing_service.cc
+++ /dev/null
@@ -1,126 +0,0 @@
-// Copyright 2014 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.
-
-// MSVC++ requires this to be set before any other includes to get M_PI.
-#define _USE_MATH_DEFINES
-
-#include "content/browser/geofencing/mock_geofencing_service.h"
-
-#include <cmath>
-
-#include "base/bind.h"
-#include "base/location.h"
-#include "base/single_thread_task_runner.h"
-#include "base/threading/thread_task_runner_handle.h"
-#include "content/browser/geofencing/geofencing_registration_delegate.h"
-#include "third_party/WebKit/public/platform/WebCircularGeofencingRegion.h"
-
-namespace content {
-
-namespace {
-
-void RegisterRegionResult(GeofencingRegistrationDelegate* delegate,
- int64_t geofencing_registration_id,
- GeofencingStatus status) {
- base::ThreadTaskRunnerHandle::Get()->PostTask(
- FROM_HERE,
- base::Bind(&GeofencingRegistrationDelegate::RegistrationFinished,
- base::Unretained(delegate), geofencing_registration_id,
- status));
-}
-
-double DegreesToRadians(float degrees) {
- return (M_PI * degrees) / 180.f;
-}
-
-double Haversin(double theta) {
- double temp = sin(theta / 2);
- return temp * temp;
-}
-
-// Calculates the distance in meters between two points with coordinates in
-// degrees.
-double Distance(double lat1, double long1, double lat2, double long2) {
- double R = 6371000; // radius of earth in meters
- double phi1 = DegreesToRadians(lat1);
- double phi2 = DegreesToRadians(lat2);
- double dphi = DegreesToRadians(lat2 - lat1);
- double dlambda = DegreesToRadians(long2 - long1);
- double haversine = Haversin(dphi) + cos(phi1) * cos(phi2) * Haversin(dlambda);
- return 2 * R * asin(sqrt(haversine));
-}
-
-// Returns true iff the provided coordinate is inside the region.
-bool PositionInRegion(double latitude,
- double longitude,
- const blink::WebCircularGeofencingRegion& region) {
- return Distance(latitude, longitude, region.latitude, region.longitude) <=
- region.radius;
-}
-}
-
-struct MockGeofencingService::Registration {
- blink::WebCircularGeofencingRegion region;
- GeofencingRegistrationDelegate* delegate;
- // True iff the last event emitted for this region was a RegionEntered event.
- bool is_inside;
-};
-
-MockGeofencingService::MockGeofencingService(bool service_available)
- : available_(service_available),
- next_id_(0),
- has_position_(false),
- last_latitude_(0),
- last_longitude_(0) {
-}
-
-MockGeofencingService::~MockGeofencingService() {
-}
-
-void MockGeofencingService::SetMockPosition(double latitude, double longitude) {
- has_position_ = true;
- last_latitude_ = latitude;
- last_longitude_ = longitude;
- for (auto& registration : registrations_) {
- bool is_inside =
- PositionInRegion(latitude, longitude, registration.second.region);
- if (is_inside != registration.second.is_inside) {
- if (is_inside)
- registration.second.delegate->RegionEntered(registration.first);
- else
- registration.second.delegate->RegionExited(registration.first);
- }
- registration.second.is_inside = is_inside;
- }
-}
-
-bool MockGeofencingService::IsServiceAvailable() {
- return available_;
-}
-
-int64_t MockGeofencingService::RegisterRegion(
- const blink::WebCircularGeofencingRegion& region,
- GeofencingRegistrationDelegate* delegate) {
- int64_t id = next_id_++;
- Registration& registration = registrations_[id];
- registration.region = region;
- registration.delegate = delegate;
- registration.is_inside =
- has_position_ &&
- PositionInRegion(last_latitude_, last_longitude_, region);
- RegisterRegionResult(delegate, id, GEOFENCING_STATUS_OK);
- if (registration.is_inside) {
- base::ThreadTaskRunnerHandle::Get()->PostTask(
- FROM_HERE, base::Bind(&GeofencingRegistrationDelegate::RegionEntered,
- base::Unretained(delegate), id));
- }
- return id;
-}
-
-void MockGeofencingService::UnregisterRegion(
- int64_t geofencing_registration_id) {
- registrations_.erase(geofencing_registration_id);
-}
-
-} // namespace content
« no previous file with comments | « content/browser/geofencing/mock_geofencing_service.h ('k') | content/browser/renderer_host/render_process_host_impl.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698