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

Side by Side Diff: blimp/engine/feature/geolocation/blimp_location_provider.cc

Issue 2091023006: Adds EngineGeolocationFeature for Blimp Geolocation project. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Comment update Created 4 years, 5 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) 2016 The Chromium Authors. All rights reserved. 1 // Copyright (c) 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 #include "blimp/engine/feature/geolocation/blimp_location_provider.h" 5 #include "blimp/engine/feature/geolocation/blimp_location_provider.h"
6 6
7 #include "base/bind.h"
8 #include "base/bind_helpers.h"
9 #include "base/memory/weak_ptr.h"
7 #include "content/public/common/geoposition.h" 10 #include "content/public/common/geoposition.h"
8 11
9 namespace blimp { 12 namespace blimp {
10 namespace engine { 13 namespace engine {
11 14
12 BlimpLocationProvider::BlimpLocationProvider() {} 15 BlimpLocationProvider::BlimpLocationProvider(
16 base::WeakPtr<BlimpLocationProvider::Delegate> delegate) {
17 DCHECK(delegate);
18
19 delegate_ = delegate;
20 is_started_ = false;
Wez 2016/07/22 01:18:58 nit: Can we move these to be member initializers,
CJ 2016/07/22 20:03:29 Done.
21 }
13 22
14 BlimpLocationProvider::~BlimpLocationProvider() { 23 BlimpLocationProvider::~BlimpLocationProvider() {
15 StopProvider(); 24 StopProvider();
16 } 25 }
17 26
18 bool BlimpLocationProvider::StartProvider(bool high_accuracy) { 27 bool BlimpLocationProvider::StartProvider(bool high_accuracy) {
19 NOTIMPLEMENTED(); 28 if (delegate_) {
20 return true; 29 if (high_accuracy) {
30 delegate_->RequestAccuracy(
31 GeolocationSetInterestLevelMessage::HIGH_ACCURACY);
32 } else {
33 delegate_->RequestAccuracy(
34 GeolocationSetInterestLevelMessage::LOW_ACCURACY);
35 }
36 is_started_ = true;
37 return true;
38 }
39 return false;
21 } 40 }
22 41
23 void BlimpLocationProvider::StopProvider() { 42 void BlimpLocationProvider::StopProvider() {
43 if (delegate_ && is_started_) {
Wez 2016/07/22 01:18:58 Did we establish whether it's valid to call StopPr
CJ 2016/07/22 20:03:29 Done.
44 delegate_->RequestAccuracy(GeolocationSetInterestLevelMessage::NO_INTEREST);
45 is_started_ = false;
46 }
24 } 47 }
25 48
26 void BlimpLocationProvider::GetPosition(content::Geoposition* position) { 49 void BlimpLocationProvider::GetPosition(content::Geoposition* position) {
27 DCHECK(position); 50 *position = cached_position_;
28
29 *position = position_;
30 } 51 }
31 52
32 void BlimpLocationProvider::RequestRefresh() { 53 void BlimpLocationProvider::RequestRefresh() {
33 NOTIMPLEMENTED(); 54 if (delegate_ && is_started_) {
Wez 2016/07/22 01:18:58 Again, is it actually valid for the caller to requ
CJ 2016/07/22 20:03:29 Done.
55 delegate_->RequestRefresh();
56 }
34 } 57 }
35 58
36 void BlimpLocationProvider::OnPermissionGranted() { 59 void BlimpLocationProvider::OnPermissionGranted() {
37 RequestRefresh(); 60 RequestRefresh();
38 NOTIMPLEMENTED();
39 }
40
41 void BlimpLocationProvider::NotifyCallback(
42 const content::Geoposition& position) {
43 DCHECK(!callback_.is_null());
44
45 callback_.Run(this, position);
46 }
47
48 void BlimpLocationProvider::OnLocationResponse(
49 const content::Geoposition& position) {
50 NotifyCallback(position);
51 NOTIMPLEMENTED();
52 } 61 }
53 62
54 void BlimpLocationProvider::SetUpdateCallback( 63 void BlimpLocationProvider::SetUpdateCallback(
55 const LocationProviderUpdateCallback& callback) { 64 const LocationProviderUpdateCallback& callback) {
56 DCHECK(!callback.is_null()); 65 if (delegate_) {
57 66 delegate_->SetUpdateCallback(base::Bind(callback, base::Unretained(this)));
58 callback_ = callback; 67 }
59 } 68 }
60 69
61 } // namespace engine 70 } // namespace engine
62 } // namespace blimp 71 } // namespace blimp
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698