OLD | NEW |
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 // MSVC++ requires this to be set before any other includes to get M_PI. | 5 // MSVC++ requires this to be set before any other includes to get M_PI. |
6 #define _USE_MATH_DEFINES | 6 #define _USE_MATH_DEFINES |
7 | 7 |
8 #include "content/browser/geofencing/mock_geofencing_service.h" | 8 #include "content/browser/geofencing/mock_geofencing_service.h" |
9 | 9 |
10 #include <cmath> | 10 #include <cmath> |
11 | 11 |
12 #include "base/bind.h" | 12 #include "base/bind.h" |
13 #include "base/location.h" | 13 #include "base/location.h" |
14 #include "base/single_thread_task_runner.h" | 14 #include "base/single_thread_task_runner.h" |
15 #include "base/thread_task_runner_handle.h" | 15 #include "base/thread_task_runner_handle.h" |
16 #include "content/browser/geofencing/geofencing_registration_delegate.h" | 16 #include "content/browser/geofencing/geofencing_registration_delegate.h" |
17 #include "third_party/WebKit/public/platform/WebCircularGeofencingRegion.h" | 17 #include "third_party/WebKit/public/platform/WebCircularGeofencingRegion.h" |
18 | 18 |
19 namespace content { | 19 namespace content { |
20 | 20 |
21 namespace { | 21 namespace { |
22 | 22 |
23 void RegisterRegionResult(GeofencingRegistrationDelegate* delegate, | 23 void RegisterRegionResult(GeofencingRegistrationDelegate* delegate, |
24 int64 geofencing_registration_id, | 24 int64_t geofencing_registration_id, |
25 GeofencingStatus status) { | 25 GeofencingStatus status) { |
26 base::ThreadTaskRunnerHandle::Get()->PostTask( | 26 base::ThreadTaskRunnerHandle::Get()->PostTask( |
27 FROM_HERE, | 27 FROM_HERE, |
28 base::Bind(&GeofencingRegistrationDelegate::RegistrationFinished, | 28 base::Bind(&GeofencingRegistrationDelegate::RegistrationFinished, |
29 base::Unretained(delegate), geofencing_registration_id, | 29 base::Unretained(delegate), geofencing_registration_id, |
30 status)); | 30 status)); |
31 } | 31 } |
32 | 32 |
33 double DegreesToRadians(float degrees) { | 33 double DegreesToRadians(float degrees) { |
34 return (M_PI * degrees) / 180.f; | 34 return (M_PI * degrees) / 180.f; |
(...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
92 registration.second.delegate->RegionExited(registration.first); | 92 registration.second.delegate->RegionExited(registration.first); |
93 } | 93 } |
94 registration.second.is_inside = is_inside; | 94 registration.second.is_inside = is_inside; |
95 } | 95 } |
96 } | 96 } |
97 | 97 |
98 bool MockGeofencingService::IsServiceAvailable() { | 98 bool MockGeofencingService::IsServiceAvailable() { |
99 return available_; | 99 return available_; |
100 } | 100 } |
101 | 101 |
102 int64 MockGeofencingService::RegisterRegion( | 102 int64_t MockGeofencingService::RegisterRegion( |
103 const blink::WebCircularGeofencingRegion& region, | 103 const blink::WebCircularGeofencingRegion& region, |
104 GeofencingRegistrationDelegate* delegate) { | 104 GeofencingRegistrationDelegate* delegate) { |
105 int64 id = next_id_++; | 105 int64_t id = next_id_++; |
106 Registration& registration = registrations_[id]; | 106 Registration& registration = registrations_[id]; |
107 registration.region = region; | 107 registration.region = region; |
108 registration.delegate = delegate; | 108 registration.delegate = delegate; |
109 registration.is_inside = | 109 registration.is_inside = |
110 has_position_ && | 110 has_position_ && |
111 PositionInRegion(last_latitude_, last_longitude_, region); | 111 PositionInRegion(last_latitude_, last_longitude_, region); |
112 RegisterRegionResult(delegate, id, GEOFENCING_STATUS_OK); | 112 RegisterRegionResult(delegate, id, GEOFENCING_STATUS_OK); |
113 if (registration.is_inside) { | 113 if (registration.is_inside) { |
114 base::ThreadTaskRunnerHandle::Get()->PostTask( | 114 base::ThreadTaskRunnerHandle::Get()->PostTask( |
115 FROM_HERE, base::Bind(&GeofencingRegistrationDelegate::RegionEntered, | 115 FROM_HERE, base::Bind(&GeofencingRegistrationDelegate::RegionEntered, |
116 base::Unretained(delegate), id)); | 116 base::Unretained(delegate), id)); |
117 } | 117 } |
118 return id; | 118 return id; |
119 } | 119 } |
120 | 120 |
121 void MockGeofencingService::UnregisterRegion(int64 geofencing_registration_id) { | 121 void MockGeofencingService::UnregisterRegion( |
| 122 int64_t geofencing_registration_id) { |
122 registrations_.erase(geofencing_registration_id); | 123 registrations_.erase(geofencing_registration_id); |
123 } | 124 } |
124 | 125 |
125 } // namespace content | 126 } // namespace content |
OLD | NEW |