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

Unified 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 side-by-side diff with in-line comments
Download patch
Index: blimp/engine/feature/geolocation/blimp_location_provider.cc
diff --git a/blimp/engine/feature/geolocation/blimp_location_provider.cc b/blimp/engine/feature/geolocation/blimp_location_provider.cc
index 9fd039774ab36b89f777a437f3f36fdd673ecb34..c0864f67180787d27e4f77e50708761ff4fb57c8 100644
--- a/blimp/engine/feature/geolocation/blimp_location_provider.cc
+++ b/blimp/engine/feature/geolocation/blimp_location_provider.cc
@@ -7,14 +7,19 @@
#include "base/bind.h"
#include "base/bind_helpers.h"
#include "base/memory/weak_ptr.h"
+#include "base/task_runner.h"
+#include "base/threading/thread_task_runner_handle.h"
#include "device/geolocation/geoposition.h"
namespace blimp {
namespace engine {
BlimpLocationProvider::BlimpLocationProvider(
- base::WeakPtr<BlimpLocationProvider::Delegate> delegate)
- : delegate_(delegate), is_started_(false) {}
+ base::WeakPtr<BlimpLocationProvider::Delegate> delegate,
+ scoped_refptr<base::SingleThreadTaskRunner> delegate_task_runner)
+ : delegate_(delegate),
+ delegate_task_runner_(delegate_task_runner),
+ is_started_(false) {}
BlimpLocationProvider::~BlimpLocationProvider() {
if (is_started_) {
@@ -23,25 +28,28 @@ BlimpLocationProvider::~BlimpLocationProvider() {
}
bool BlimpLocationProvider::StartProvider(bool high_accuracy) {
- if (delegate_) {
- if (high_accuracy) {
- delegate_->RequestAccuracy(
- GeolocationSetInterestLevelMessage::HIGH_ACCURACY);
- } else {
- delegate_->RequestAccuracy(
- GeolocationSetInterestLevelMessage::LOW_ACCURACY);
- }
- is_started_ = true;
+ is_started_ = true;
+ if (high_accuracy) {
+ delegate_task_runner_->PostTask(
+ FROM_HERE,
+ base::Bind(&BlimpLocationProvider::Delegate::RequestAccuracy, delegate_,
+ GeolocationSetInterestLevelMessage::HIGH_ACCURACY));
+ } else {
+ delegate_task_runner_->PostTask(
+ FROM_HERE,
+ base::Bind(&BlimpLocationProvider::Delegate::RequestAccuracy, delegate_,
+ GeolocationSetInterestLevelMessage::LOW_ACCURACY));
}
return is_started_;
}
void BlimpLocationProvider::StopProvider() {
DCHECK(is_started_);
- if (delegate_) {
- delegate_->RequestAccuracy(GeolocationSetInterestLevelMessage::NO_INTEREST);
- is_started_ = false;
- }
+ delegate_task_runner_->PostTask(
+ FROM_HERE,
+ base::Bind(&BlimpLocationProvider::Delegate::RequestAccuracy, delegate_,
+ GeolocationSetInterestLevelMessage::NO_INTEREST));
+ is_started_ = false;
}
const device::Geoposition& BlimpLocationProvider::GetPosition() {
@@ -50,16 +58,18 @@ const device::Geoposition& BlimpLocationProvider::GetPosition() {
void BlimpLocationProvider::OnPermissionGranted() {
DCHECK(is_started_);
- if (delegate_) {
- delegate_->OnPermissionGranted();
- }
+ delegate_task_runner_->PostTask(
+ FROM_HERE,
+ base::Bind(&BlimpLocationProvider::Delegate::OnPermissionGranted,
+ delegate_));
}
void BlimpLocationProvider::SetUpdateCallback(
const LocationProviderUpdateCallback& callback) {
- if (delegate_) {
- delegate_->SetUpdateCallback(base::Bind(callback, base::Unretained(this)));
- }
+ 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.
+ FROM_HERE, base::Bind(&BlimpLocationProvider::Delegate::SetUpdateCallback,
+ delegate_, base::ThreadTaskRunnerHandle::Get(),
+ base::Bind(callback, base::Unretained(this))));
}
} // namespace engine

Powered by Google App Engine
This is Rietveld 408576698