OLD | NEW |
---|---|
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 } | |
13 | 21 |
14 BlimpLocationProvider::~BlimpLocationProvider() { | 22 BlimpLocationProvider::~BlimpLocationProvider() { |
15 StopProvider(); | 23 StopProvider(); |
Wez
2016/07/18 23:55:21
What's the rationale for removing this call? Don't
CJ
2016/07/19 20:04:17
Due to my misunderstanding on how EXPECT_CALL work
| |
16 } | 24 } |
17 | 25 |
18 bool BlimpLocationProvider::StartProvider(bool high_accuracy) { | 26 bool BlimpLocationProvider::StartProvider(bool high_accuracy) { |
19 NOTIMPLEMENTED(); | 27 if (delegate_) { |
20 return true; | 28 if (high_accuracy) { |
29 delegate_->RequestAccuracy( | |
30 GeolocationSetInterestLevelMessage::HIGH_ACCURACY); | |
31 } else { | |
32 delegate_->RequestAccuracy( | |
33 GeolocationSetInterestLevelMessage::LOW_ACCURACY); | |
34 } | |
35 return true; | |
36 } | |
37 return false; | |
21 } | 38 } |
22 | 39 |
23 void BlimpLocationProvider::StopProvider() { | 40 void BlimpLocationProvider::StopProvider() { |
41 if (delegate_) { | |
42 delegate_->RequestAccuracy(GeolocationSetInterestLevelMessage::NO_INTEREST); | |
43 } | |
24 } | 44 } |
25 | 45 |
26 void BlimpLocationProvider::GetPosition(content::Geoposition* position) { | 46 void BlimpLocationProvider::GetPosition(content::Geoposition* position) { |
27 DCHECK(position); | 47 DCHECK(position); |
Wez
2016/07/15 01:46:17
nit: No need for this, since *position = foo will
CJ
2016/07/18 21:11:56
Done.
| |
28 | 48 |
29 *position = position_; | 49 *position = position_; |
30 } | 50 } |
31 | 51 |
32 void BlimpLocationProvider::RequestRefresh() { | 52 void BlimpLocationProvider::RequestRefresh() { |
33 NOTIMPLEMENTED(); | 53 if (delegate_) { |
54 delegate_->RequestRefresh(); | |
55 } | |
34 } | 56 } |
35 | 57 |
36 void BlimpLocationProvider::OnPermissionGranted() { | 58 void BlimpLocationProvider::OnPermissionGranted() { |
37 RequestRefresh(); | 59 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 } | 60 } |
53 | 61 |
54 void BlimpLocationProvider::SetUpdateCallback( | 62 void BlimpLocationProvider::SetUpdateCallback( |
55 const LocationProviderUpdateCallback& callback) { | 63 const LocationProviderUpdateCallback& callback) { |
56 DCHECK(!callback.is_null()); | 64 delegate_->SetUpdateCallback(base::Bind(callback, base::Unretained(this))); |
Wez
2016/07/15 01:46:17
So we are able to assume that the caller will call
CJ
2016/07/18 21:11:56
There shouldn't be any lag between two SetUpdateCa
Wez
2016/07/18 23:55:21
That's what I'm getting at - are we able to assume
CJ
2016/07/19 20:04:17
It seems pretty sequential, but a check was added
| |
57 | |
58 callback_ = callback; | |
59 } | 65 } |
60 | 66 |
61 } // namespace engine | 67 } // namespace engine |
62 } // namespace blimp | 68 } // namespace blimp |
OLD | NEW |