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/message_loop/message_loop.h" |
14 #include "base/single_thread_task_runner.h" | |
15 #include "base/thread_task_runner_handle.h" | |
16 #include "content/browser/geofencing/geofencing_registration_delegate.h" | 14 #include "content/browser/geofencing/geofencing_registration_delegate.h" |
17 #include "third_party/WebKit/public/platform/WebCircularGeofencingRegion.h" | 15 #include "third_party/WebKit/public/platform/WebCircularGeofencingRegion.h" |
18 | 16 |
19 namespace content { | 17 namespace content { |
20 | 18 |
21 namespace { | 19 namespace { |
22 | 20 |
23 void RegisterRegionResult(GeofencingRegistrationDelegate* delegate, | 21 void RegisterRegionResult(GeofencingRegistrationDelegate* delegate, |
24 int64 geofencing_registration_id, | 22 int64 geofencing_registration_id, |
25 GeofencingStatus status) { | 23 GeofencingStatus status) { |
26 base::ThreadTaskRunnerHandle::Get()->PostTask( | 24 base::MessageLoop::current()->PostTask( |
27 FROM_HERE, | 25 FROM_HERE, |
28 base::Bind(&GeofencingRegistrationDelegate::RegistrationFinished, | 26 base::Bind(&GeofencingRegistrationDelegate::RegistrationFinished, |
29 base::Unretained(delegate), geofencing_registration_id, | 27 base::Unretained(delegate), geofencing_registration_id, |
30 status)); | 28 status)); |
31 } | 29 } |
32 | 30 |
33 double DegreesToRadians(float degrees) { | 31 double DegreesToRadians(float degrees) { |
34 return (M_PI * degrees) / 180.f; | 32 return (M_PI * degrees) / 180.f; |
35 } | 33 } |
36 | 34 |
(...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
104 GeofencingRegistrationDelegate* delegate) { | 102 GeofencingRegistrationDelegate* delegate) { |
105 int64 id = next_id_++; | 103 int64 id = next_id_++; |
106 Registration& registration = registrations_[id]; | 104 Registration& registration = registrations_[id]; |
107 registration.region = region; | 105 registration.region = region; |
108 registration.delegate = delegate; | 106 registration.delegate = delegate; |
109 registration.is_inside = | 107 registration.is_inside = |
110 has_position_ && | 108 has_position_ && |
111 PositionInRegion(last_latitude_, last_longitude_, region); | 109 PositionInRegion(last_latitude_, last_longitude_, region); |
112 RegisterRegionResult(delegate, id, GEOFENCING_STATUS_OK); | 110 RegisterRegionResult(delegate, id, GEOFENCING_STATUS_OK); |
113 if (registration.is_inside) { | 111 if (registration.is_inside) { |
114 base::ThreadTaskRunnerHandle::Get()->PostTask( | 112 base::MessageLoop::current()->PostTask( |
115 FROM_HERE, base::Bind(&GeofencingRegistrationDelegate::RegionEntered, | 113 FROM_HERE, base::Bind(&GeofencingRegistrationDelegate::RegionEntered, |
116 base::Unretained(delegate), id)); | 114 base::Unretained(delegate), id)); |
117 } | 115 } |
118 return id; | 116 return id; |
119 } | 117 } |
120 | 118 |
121 void MockGeofencingService::UnregisterRegion(int64 geofencing_registration_id) { | 119 void MockGeofencingService::UnregisterRegion(int64 geofencing_registration_id) { |
122 registrations_.erase(geofencing_registration_id); | 120 registrations_.erase(geofencing_registration_id); |
123 } | 121 } |
124 | 122 |
125 } // namespace content | 123 } // namespace content |
OLD | NEW |