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