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

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

Issue 2161223003: Adds GeolocationFeature for Blimp Geolocation project. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@engine_feature_prep
Patch Set: Addresses kmarshall's #102 comment. 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 2016 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
6 // various ways of creating it.
7
8 #include "device/geolocation/mock_location_provider.h" 5 #include "device/geolocation/mock_location_provider.h"
9 6
10 #include "base/bind.h"
11 #include "base/bind_helpers.h"
12 #include "base/compiler_specific.h"
13 #include "base/location.h"
14 #include "base/logging.h"
15 #include "base/memory/weak_ptr.h"
16 #include "base/threading/thread_task_runner_handle.h"
17
18 namespace device { 7 namespace device {
19 8
20 MockLocationProvider::MockLocationProvider() 9 MockLocationProvider::MockLocationProvider() {}
21 : state_(STOPPED),
22 is_permission_granted_(false),
23 provider_task_runner_(base::ThreadTaskRunnerHandle::Get()) {}
24 10
25 MockLocationProvider::~MockLocationProvider() {} 11 MockLocationProvider::~MockLocationProvider() {}
26 12
27 void MockLocationProvider::HandlePositionChanged(const Geoposition& position) {
28 if (provider_task_runner_->BelongsToCurrentThread()) {
29 // The location arbitrator unit tests rely on this method running
30 // synchronously.
31 position_ = position;
32 NotifyCallback(position_);
33 } else {
34 provider_task_runner_->PostTask(
35 FROM_HERE, base::Bind(&MockLocationProvider::HandlePositionChanged,
36 base::Unretained(this), position));
37 }
38 }
39
40 bool MockLocationProvider::StartProvider(bool high_accuracy) {
41 state_ = high_accuracy ? HIGH_ACCURACY : LOW_ACCURACY;
42 return true;
43 }
44
45 void MockLocationProvider::StopProvider() {
46 state_ = STOPPED;
47 }
48
49 const Geoposition& MockLocationProvider::GetPosition() {
50 return position_;
51 }
52
53 void MockLocationProvider::OnPermissionGranted() {
54 is_permission_granted_ = true;
55 }
56
57 } // namespace device 13 } // namespace device
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698