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

Side by Side Diff: device/geolocation/mock_location_provider.cc

Issue 2226143002: Gets rid of the LocationArbitrator interface, in preference for LocationProvider. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Merge branch 'master' into lai Created 4 years, 4 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 unified diff | Download patch
OLDNEW
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 mock location provider and the factory functions for
6 // various ways of creating it. 6 // various ways of creating it.
7 7
8 #include "device/geolocation/mock_location_provider.h" 8 #include "device/geolocation/mock_location_provider.h"
9 9
10 #include "base/bind.h" 10 #include "base/bind.h"
11 #include "base/bind_helpers.h" 11 #include "base/bind_helpers.h"
12 #include "base/compiler_specific.h" 12 #include "base/compiler_specific.h"
13 #include "base/location.h" 13 #include "base/location.h"
14 #include "base/logging.h" 14 #include "base/logging.h"
15 #include "base/memory/weak_ptr.h" 15 #include "base/memory/weak_ptr.h"
16 #include "base/threading/thread_task_runner_handle.h" 16 #include "base/threading/thread_task_runner_handle.h"
17 17
18 namespace device { 18 namespace device {
19 19
20 MockLocationProvider::MockLocationProvider() 20 MockLocationProvider::MockLocationProvider()
21 : state_(STOPPED), 21 : state_(STOPPED),
22 is_permission_granted_(false), 22 is_permission_granted_(false),
23 provider_task_runner_(base::ThreadTaskRunnerHandle::Get()) {} 23 provider_task_runner_(base::ThreadTaskRunnerHandle::Get()) {}
24 24
25 MockLocationProvider::~MockLocationProvider() {} 25 MockLocationProvider::~MockLocationProvider() {}
26 26
27 bool MockLocationProvider::IsProviderStarted() const {
28 return state_ != STOPPED;
29 }
30
27 void MockLocationProvider::HandlePositionChanged(const Geoposition& position) { 31 void MockLocationProvider::HandlePositionChanged(const Geoposition& position) {
28 if (provider_task_runner_->BelongsToCurrentThread()) { 32 if (provider_task_runner_->BelongsToCurrentThread()) {
29 // The location arbitrator unit tests rely on this method running 33 // The location arbitrator unit tests rely on this method running
30 // synchronously. 34 // synchronously.
31 position_ = position; 35 position_ = position;
32 NotifyCallback(position_); 36 NotifyCallback(position_);
33 } else { 37 } else {
34 provider_task_runner_->PostTask( 38 provider_task_runner_->PostTask(
35 FROM_HERE, base::Bind(&MockLocationProvider::HandlePositionChanged, 39 FROM_HERE, base::Bind(&MockLocationProvider::HandlePositionChanged,
36 base::Unretained(this), position)); 40 base::Unretained(this), position));
37 } 41 }
38 } 42 }
39 43
40 bool MockLocationProvider::StartProvider(bool high_accuracy) { 44 bool MockLocationProvider::StartProvider(bool high_accuracy) {
41 state_ = high_accuracy ? HIGH_ACCURACY : LOW_ACCURACY; 45 state_ = high_accuracy ? HIGH_ACCURACY : LOW_ACCURACY;
42 return true; 46 return true;
43 } 47 }
44 48
45 void MockLocationProvider::StopProvider() { 49 void MockLocationProvider::StopProvider() {
46 state_ = STOPPED; 50 state_ = STOPPED;
47 } 51 }
48 52
49 void MockLocationProvider::GetPosition(Geoposition* position) { 53 const Geoposition& MockLocationProvider::GetPosition() {
50 *position = position_; 54 return position_;
51 } 55 }
52 56
53 void MockLocationProvider::OnPermissionGranted() { 57 void MockLocationProvider::OnPermissionGranted() {
54 is_permission_granted_ = true; 58 is_permission_granted_ = true;
55 } 59 }
56 60
57 // Mock location provider that automatically calls back its client at most 61 // Mock location provider that automatically calls back its client at most
58 // once, when StartProvider or OnPermissionGranted is called. Use 62 // once, when StartProvider or OnPermissionGranted is called. Use
59 // |requires_permission_to_start| to select which event triggers the callback. 63 // |requires_permission_to_start| to select which event triggers the callback.
60 class AutoMockLocationProvider : public MockLocationProvider { 64 class AutoMockLocationProvider : public MockLocationProvider {
(...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after
115 119
116 LocationProvider* NewAutoFailMockLocationProvider() { 120 LocationProvider* NewAutoFailMockLocationProvider() {
117 return new AutoMockLocationProvider(false, false); 121 return new AutoMockLocationProvider(false, false);
118 } 122 }
119 123
120 LocationProvider* NewAutoSuccessMockNetworkLocationProvider() { 124 LocationProvider* NewAutoSuccessMockNetworkLocationProvider() {
121 return new AutoMockLocationProvider(true, true); 125 return new AutoMockLocationProvider(true, true);
122 } 126 }
123 127
124 } // namespace device 128 } // namespace device
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698