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

Unified Diff: blimp/engine/feature/geolocation/blimp_location_provider.cc

Issue 2328453003: Makes use of EngineGeolocationFeature weak_ptr threadsafe. (Closed)
Patch Set: Addresses kmarshall's #3 comments. 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..f8459e9f0493348347df9cd2dc49b7549ec6e904 100644
--- a/blimp/engine/feature/geolocation/blimp_location_provider.cc
+++ b/blimp/engine/feature/geolocation/blimp_location_provider.cc
@@ -7,14 +7,30 @@
#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 {
+namespace {
+
+void InvokeGeopositionCallback(
Wez 2016/09/13 20:19:07 Ah, I think we're going to need bind this to the l
CJ 2016/09/13 23:34:02 |callback| is bound to |this|, the BlimpLocationPr
Wez 2016/09/16 00:40:16 Right, but Bind(callback, this) is just used to su
CJ 2016/09/16 22:55:53 Done.
+ scoped_refptr<base::TaskRunner> task_runner,
+ BlimpLocationProvider::Delegate::GeopositionReceivedCallback callback,
+ const device::Geoposition& geoposition) {
+ // this calls task_runner->PostTas
Wez 2016/09/13 20:19:07 ?
CJ 2016/09/13 23:34:02 Done.
+ task_runner->PostTask(FROM_HERE, base::Bind(callback, geoposition));
+}
+
+} // namespace
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 +39,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));
Wez 2016/09/13 20:19:07 nit: You can merge this into a single PostTask wit
CJ 2016/09/13 23:34:02 Done.
+ } 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 +69,20 @@ 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(
+ FROM_HERE,
+ base::Bind(&BlimpLocationProvider::Delegate::SetUpdateCallback, delegate_,
+ base::Bind(&InvokeGeopositionCallback,
+ base::ThreadTaskRunnerHandle::Get(),
+ base::Bind(callback, this))));
}
} // namespace engine

Powered by Google App Engine
This is Rietveld 408576698