| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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 // This file implements a mock location provider and the factory functions for | 5 // This file implements a fake location provider and the factory functions for |
| 6 // various ways of creating it. | 6 // various ways of creating it. |
| 7 // TODO(lethalantidote): Convert location_arbitrator_impl to use actual mock |
| 8 // instead of FakeLocationProvider. |
| 7 | 9 |
| 8 #include "device/geolocation/mock_location_provider.h" | 10 #include "device/geolocation/fake_location_provider.h" |
| 9 | 11 |
| 10 #include "base/bind.h" | 12 #include "base/bind.h" |
| 11 #include "base/bind_helpers.h" | 13 #include "base/bind_helpers.h" |
| 12 #include "base/compiler_specific.h" | 14 #include "base/compiler_specific.h" |
| 13 #include "base/location.h" | 15 #include "base/location.h" |
| 14 #include "base/logging.h" | 16 #include "base/logging.h" |
| 15 #include "base/memory/weak_ptr.h" | 17 #include "base/memory/weak_ptr.h" |
| 16 #include "base/threading/thread_task_runner_handle.h" | 18 #include "base/threading/thread_task_runner_handle.h" |
| 17 | 19 |
| 18 namespace device { | 20 namespace device { |
| 19 | 21 |
| 20 MockLocationProvider::MockLocationProvider() | 22 FakeLocationProvider::FakeLocationProvider() |
| 21 : state_(STOPPED), | 23 : provider_task_runner_(base::ThreadTaskRunnerHandle::Get()) {} |
| 22 is_permission_granted_(false), | |
| 23 provider_task_runner_(base::ThreadTaskRunnerHandle::Get()) {} | |
| 24 | 24 |
| 25 MockLocationProvider::~MockLocationProvider() {} | 25 FakeLocationProvider::~FakeLocationProvider() {} |
| 26 | 26 |
| 27 void MockLocationProvider::HandlePositionChanged(const Geoposition& position) { | 27 void FakeLocationProvider::HandlePositionChanged(const Geoposition& position) { |
| 28 if (provider_task_runner_->BelongsToCurrentThread()) { | 28 if (provider_task_runner_->BelongsToCurrentThread()) { |
| 29 // The location arbitrator unit tests rely on this method running | 29 // The location arbitrator unit tests rely on this method running |
| 30 // synchronously. | 30 // synchronously. |
| 31 position_ = position; | 31 position_ = position; |
| 32 NotifyCallback(position_); | 32 NotifyCallback(position_); |
| 33 } else { | 33 } else { |
| 34 provider_task_runner_->PostTask( | 34 provider_task_runner_->PostTask( |
| 35 FROM_HERE, base::Bind(&MockLocationProvider::HandlePositionChanged, | 35 FROM_HERE, base::Bind(&FakeLocationProvider::HandlePositionChanged, |
| 36 base::Unretained(this), position)); | 36 base::Unretained(this), position)); |
| 37 } | 37 } |
| 38 } | 38 } |
| 39 | 39 |
| 40 bool MockLocationProvider::StartProvider(bool high_accuracy) { | 40 bool FakeLocationProvider::StartProvider(bool high_accuracy) { |
| 41 state_ = high_accuracy ? HIGH_ACCURACY : LOW_ACCURACY; | 41 state_ = high_accuracy ? HIGH_ACCURACY : LOW_ACCURACY; |
| 42 return true; | 42 return true; |
| 43 } | 43 } |
| 44 | 44 |
| 45 void MockLocationProvider::StopProvider() { | 45 void FakeLocationProvider::StopProvider() { |
| 46 state_ = STOPPED; | 46 state_ = STOPPED; |
| 47 } | 47 } |
| 48 | 48 |
| 49 const Geoposition& MockLocationProvider::GetPosition() { | 49 const Geoposition& FakeLocationProvider::GetPosition() { |
| 50 return position_; | 50 return position_; |
| 51 } | 51 } |
| 52 | 52 |
| 53 void MockLocationProvider::OnPermissionGranted() { | 53 void FakeLocationProvider::OnPermissionGranted() { |
| 54 is_permission_granted_ = true; | 54 is_permission_granted_ = true; |
| 55 } | 55 } |
| 56 | 56 |
| 57 } // namespace device | 57 } // namespace device |
| OLD | NEW |