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

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

Issue 2328453003: Makes use of EngineGeolocationFeature weak_ptr threadsafe. (Closed)
Patch Set: Get rid of ui/gl/BUILD.gn change Created 4 years, 3 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" 7 #include "base/bind.h"
8 #include "base/bind_helpers.h" 8 #include "base/bind_helpers.h"
9 #include "base/memory/weak_ptr.h" 9 #include "base/memory/weak_ptr.h"
10 #include "base/task_runner.h"
11 #include "base/threading/thread_task_runner_handle.h"
10 #include "device/geolocation/geoposition.h" 12 #include "device/geolocation/geoposition.h"
11 13
12 namespace blimp { 14 namespace blimp {
13 namespace engine { 15 namespace engine {
14 16
15 BlimpLocationProvider::BlimpLocationProvider( 17 BlimpLocationProvider::BlimpLocationProvider(
16 base::WeakPtr<BlimpLocationProvider::Delegate> delegate) 18 base::WeakPtr<BlimpLocationProvider::Delegate> delegate,
17 : delegate_(delegate), is_started_(false) {} 19 scoped_refptr<base::SingleThreadTaskRunner> delegate_task_runner)
20 : delegate_(delegate),
21 delegate_task_runner_(delegate_task_runner),
22 is_started_(false) {}
18 23
19 BlimpLocationProvider::~BlimpLocationProvider() { 24 BlimpLocationProvider::~BlimpLocationProvider() {
20 if (is_started_) { 25 if (is_started_) {
21 StopProvider(); 26 StopProvider();
22 } 27 }
23 } 28 }
24 29
25 bool BlimpLocationProvider::StartProvider(bool high_accuracy) { 30 bool BlimpLocationProvider::StartProvider(bool high_accuracy) {
26 if (delegate_) { 31 is_started_ = true;
27 if (high_accuracy) { 32 if (high_accuracy) {
28 delegate_->RequestAccuracy( 33 delegate_task_runner_->PostTask(
29 GeolocationSetInterestLevelMessage::HIGH_ACCURACY); 34 FROM_HERE,
30 } else { 35 base::Bind(&BlimpLocationProvider::Delegate::RequestAccuracy, delegate_,
31 delegate_->RequestAccuracy( 36 GeolocationSetInterestLevelMessage::HIGH_ACCURACY));
32 GeolocationSetInterestLevelMessage::LOW_ACCURACY); 37 } else {
33 } 38 delegate_task_runner_->PostTask(
34 is_started_ = true; 39 FROM_HERE,
40 base::Bind(&BlimpLocationProvider::Delegate::RequestAccuracy, delegate_,
41 GeolocationSetInterestLevelMessage::LOW_ACCURACY));
35 } 42 }
36 return is_started_; 43 return is_started_;
37 } 44 }
38 45
39 void BlimpLocationProvider::StopProvider() { 46 void BlimpLocationProvider::StopProvider() {
40 DCHECK(is_started_); 47 DCHECK(is_started_);
41 if (delegate_) { 48 delegate_task_runner_->PostTask(
42 delegate_->RequestAccuracy(GeolocationSetInterestLevelMessage::NO_INTEREST); 49 FROM_HERE,
43 is_started_ = false; 50 base::Bind(&BlimpLocationProvider::Delegate::RequestAccuracy, delegate_,
44 } 51 GeolocationSetInterestLevelMessage::NO_INTEREST));
52 is_started_ = false;
45 } 53 }
46 54
47 const device::Geoposition& BlimpLocationProvider::GetPosition() { 55 const device::Geoposition& BlimpLocationProvider::GetPosition() {
48 return cached_position_; 56 return cached_position_;
49 } 57 }
50 58
51 void BlimpLocationProvider::OnPermissionGranted() { 59 void BlimpLocationProvider::OnPermissionGranted() {
52 DCHECK(is_started_); 60 DCHECK(is_started_);
53 if (delegate_) { 61 delegate_task_runner_->PostTask(
54 delegate_->OnPermissionGranted(); 62 FROM_HERE,
55 } 63 base::Bind(&BlimpLocationProvider::Delegate::OnPermissionGranted,
64 delegate_));
56 } 65 }
57 66
58 void BlimpLocationProvider::SetUpdateCallback( 67 void BlimpLocationProvider::SetUpdateCallback(
59 const LocationProviderUpdateCallback& callback) { 68 const LocationProviderUpdateCallback& callback) {
60 if (delegate_) { 69 delegate_task_runner_->PostTask(
Kevin M 2016/09/09 17:07:04 You can actually bind a callback which manages its
CJ 2016/09/09 19:52:41 Done.
61 delegate_->SetUpdateCallback(base::Bind(callback, base::Unretained(this))); 70 FROM_HERE, base::Bind(&BlimpLocationProvider::Delegate::SetUpdateCallback,
62 } 71 delegate_, base::ThreadTaskRunnerHandle::Get(),
72 base::Bind(callback, base::Unretained(this))));
63 } 73 }
64 74
65 } // namespace engine 75 } // namespace engine
66 } // namespace blimp 76 } // namespace blimp
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698