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

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

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 #ifndef BLIMP_ENGINE_FEATURE_GEOLOCATION_BLIMP_LOCATION_PROVIDER_H_ 5 #ifndef BLIMP_ENGINE_FEATURE_GEOLOCATION_BLIMP_LOCATION_PROVIDER_H_
6 #define BLIMP_ENGINE_FEATURE_GEOLOCATION_BLIMP_LOCATION_PROVIDER_H_ 6 #define BLIMP_ENGINE_FEATURE_GEOLOCATION_BLIMP_LOCATION_PROVIDER_H_
7 7
8 #include "base/memory/weak_ptr.h" 8 #include "base/memory/weak_ptr.h"
9 #include "blimp/common/proto/geolocation.pb.h" 9 #include "blimp/common/proto/geolocation.pb.h"
10 #include "device/geolocation/geoposition.h" 10 #include "device/geolocation/geoposition.h"
11 #include "device/geolocation/location_provider.h" 11 #include "device/geolocation/location_provider.h"
12 12
13 namespace blimp { 13 namespace blimp {
14 namespace engine { 14 namespace engine {
15 15
16 // Location provider for Blimp using the device's provider over the network. 16 // Location provider for Blimp using the device's provider over the network.
Kevin M 2016/09/09 17:07:04 Add good comments about threading requirements her
CJ 2016/09/09 19:52:41 Done.
17 class BlimpLocationProvider : public device::LocationProvider { 17 class BlimpLocationProvider : public device::LocationProvider {
18 public: 18 public:
19 // A delegate that implements a subset of LocationProvider's functions. 19 // A delegate that implements a subset of LocationProvider's functions.
Kevin M 2016/09/09 17:07:04 Also document that all methods will be executed on
CJ 2016/09/09 19:52:41 Done.
20 class Delegate { 20 class Delegate {
21 public: 21 public:
22 using GeopositionReceivedCallback = 22 using GeopositionReceivedCallback =
23 base::Callback<void(const device::Geoposition&)>; 23 base::Callback<void(const device::Geoposition&)>;
24 24
25 virtual ~Delegate() {} 25 virtual ~Delegate() {}
26 26
27 virtual void RequestAccuracy( 27 virtual void RequestAccuracy(
28 GeolocationSetInterestLevelMessage::Level level) = 0; 28 GeolocationSetInterestLevelMessage::Level level) = 0;
29 virtual void OnPermissionGranted() = 0; 29 virtual void OnPermissionGranted() = 0;
30 virtual void SetUpdateCallback( 30 virtual void SetUpdateCallback(
31 scoped_refptr<base::SingleThreadTaskRunner> caller_task_runner,
31 const GeopositionReceivedCallback& callback) = 0; 32 const GeopositionReceivedCallback& callback) = 0;
32 }; 33 };
33 34
34 explicit BlimpLocationProvider(base::WeakPtr<Delegate> delegate); 35 BlimpLocationProvider(
36 base::WeakPtr<Delegate> delegate,
37 scoped_refptr<base::SingleThreadTaskRunner> delegate_task_runner);
35 ~BlimpLocationProvider() override; 38 ~BlimpLocationProvider() override;
36 39
37 // device::LocationProvider implementation. 40 // device::LocationProvider implementation.
38 bool StartProvider(bool high_accuracy) override; 41 bool StartProvider(bool high_accuracy) override;
39 void StopProvider() override; 42 void StopProvider() override;
40 const device::Geoposition& GetPosition() override; 43 const device::Geoposition& GetPosition() override;
41 void OnPermissionGranted() override; 44 void OnPermissionGranted() override;
42 void SetUpdateCallback( 45 void SetUpdateCallback(
43 const LocationProviderUpdateCallback& callback) override; 46 const LocationProviderUpdateCallback& callback) override;
44 47
45 private: 48 private:
46 // This delegate handles a subset of the LocationProvider functionality. 49 // This delegate handles a subset of the LocationProvider functionality.
47 base::WeakPtr<Delegate> delegate_; 50 base::WeakPtr<Delegate> delegate_;
48 51
52 scoped_refptr<base::SingleThreadTaskRunner> delegate_task_runner_;
53
49 device::Geoposition cached_position_; 54 device::Geoposition cached_position_;
50 55
51 // True if a successful StartProvider call has occured. 56 // True if a successful StartProvider call has occured.
52 bool is_started_; 57 bool is_started_;
53 58
54 DISALLOW_COPY_AND_ASSIGN(BlimpLocationProvider); 59 DISALLOW_COPY_AND_ASSIGN(BlimpLocationProvider);
55 }; 60 };
56 61
57 } // namespace engine 62 } // namespace engine
58 } // namespace blimp 63 } // namespace blimp
59 64
60 #endif // BLIMP_ENGINE_FEATURE_GEOLOCATION_BLIMP_LOCATION_PROVIDER_H_ 65 #endif // BLIMP_ENGINE_FEATURE_GEOLOCATION_BLIMP_LOCATION_PROVIDER_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698