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

Side by Side Diff: blimp/engine/feature/geolocation/engine_geolocation_feature.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 2016 The Chromium Authors. All rights reserved. 1 // Copyright 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/engine_geolocation_feature.h" 5 #include "blimp/engine/feature/geolocation/engine_geolocation_feature.h"
6 6
7 #include <memory> 7 #include <memory>
8 #include <utility> 8 #include <utility>
9 9
10 #include "base/memory/ptr_util.h" 10 #include "base/memory/ptr_util.h"
11 #include "base/memory/weak_ptr.h" 11 #include "base/memory/weak_ptr.h"
12 #include "base/threading/thread_task_runner_handle.h" 12 #include "base/threading/thread_task_runner_handle.h"
13 #include "blimp/common/create_blimp_message.h" 13 #include "blimp/common/create_blimp_message.h"
14 #include "blimp/common/proto/blimp_message.pb.h" 14 #include "blimp/common/proto/blimp_message.pb.h"
15 #include "blimp/common/proto/geolocation.pb.h" 15 #include "blimp/common/proto/geolocation.pb.h"
16 #include "device/geolocation/geolocation_delegate.h" 16 #include "device/geolocation/geolocation_delegate.h"
17 #include "device/geolocation/location_provider.h" 17 #include "device/geolocation/location_provider.h"
18 #include "device/geolocation/geoposition.h" 18 #include "device/geolocation/geoposition.h"
19 #include "net/base/net_errors.h" 19 #include "net/base/net_errors.h"
20 20
21 namespace blimp { 21 namespace blimp {
22 namespace engine { 22 namespace engine {
23 namespace { 23 namespace {
24 24
25 class BlimpGeolocationDelegate : public device::GeolocationDelegate { 25 class BlimpGeolocationDelegate : public device::GeolocationDelegate {
26 public: 26 public:
27 explicit BlimpGeolocationDelegate( 27 explicit BlimpGeolocationDelegate(
28 base::WeakPtr<BlimpLocationProvider::Delegate> feature_delegate) { 28 base::WeakPtr<BlimpLocationProvider::Delegate> feature_delegate) {
29 feature_delegate_ = feature_delegate; 29 feature_delegate_ = feature_delegate;
30 feature_task_runner_ = base::ThreadTaskRunnerHandle::Get();
Kevin M 2016/09/09 17:07:05 Do we need to store this as a field? Can we just g
CJ 2016/09/09 19:52:41 I don't believe so, since OverrideSystemLocationPr
30 } 31 }
31 32
32 bool UseNetworkLocationProviders() final { return false; } 33 bool UseNetworkLocationProviders() final { return false; }
33 34
34 std::unique_ptr<device::LocationProvider> OverrideSystemLocationProvider() 35 std::unique_ptr<device::LocationProvider> OverrideSystemLocationProvider()
35 final { 36 final {
36 return base::MakeUnique<BlimpLocationProvider>(feature_delegate_); 37 return base::MakeUnique<BlimpLocationProvider>(feature_delegate_,
38 feature_task_runner_);
37 } 39 }
38 40
39 private: 41 private:
40 base::WeakPtr<BlimpLocationProvider::Delegate> feature_delegate_; 42 base::WeakPtr<BlimpLocationProvider::Delegate> feature_delegate_;
43 scoped_refptr<base::SingleThreadTaskRunner> feature_task_runner_;
41 44
42 DISALLOW_COPY_AND_ASSIGN(BlimpGeolocationDelegate); 45 DISALLOW_COPY_AND_ASSIGN(BlimpGeolocationDelegate);
43 }; 46 };
44 47
45 device::Geoposition::ErrorCode ConvertErrorCode( 48 device::Geoposition::ErrorCode ConvertErrorCode(
46 const GeolocationErrorMessage::ErrorCode& error_code) { 49 const GeolocationErrorMessage::ErrorCode& error_code) {
47 switch (error_code) { 50 switch (error_code) {
48 case GeolocationErrorMessage::PERMISSION_DENIED: 51 case GeolocationErrorMessage::PERMISSION_DENIED:
49 return device::Geoposition::ErrorCode::ERROR_CODE_PERMISSION_DENIED; 52 return device::Geoposition::ErrorCode::ERROR_CODE_PERMISSION_DENIED;
50 case GeolocationErrorMessage::POSITION_UNAVAILABLE: 53 case GeolocationErrorMessage::POSITION_UNAVAILABLE:
(...skipping 94 matching lines...) Expand 10 before | Expand all | Expand 10 after
145 std::unique_ptr<BlimpMessage> blimp_message = 148 std::unique_ptr<BlimpMessage> blimp_message =
146 CreateBlimpMessage(&geolocation_message); 149 CreateBlimpMessage(&geolocation_message);
147 150
148 geolocation_message->mutable_request_refresh(); 151 geolocation_message->mutable_request_refresh();
149 152
150 outgoing_message_processor_->ProcessMessage(std::move(blimp_message), 153 outgoing_message_processor_->ProcessMessage(std::move(blimp_message),
151 net::CompletionCallback()); 154 net::CompletionCallback());
152 } 155 }
153 156
154 void EngineGeolocationFeature::SetUpdateCallback( 157 void EngineGeolocationFeature::SetUpdateCallback(
158 scoped_refptr<base::SingleThreadTaskRunner> caller_task_runner,
155 const GeopositionReceivedCallback& callback) { 159 const GeopositionReceivedCallback& callback) {
156 geoposition_received_callback_ = callback; 160 geoposition_received_callback_ = callback;
157
158 // Set |callback_task_runner_| to run on the current thread. 161 // Set |callback_task_runner_| to run on the current thread.
Kevin M 2016/09/09 17:07:05 This doesn't make sense?
CJ 2016/09/09 19:52:41 Done.
159 callback_task_runner_ = base::ThreadTaskRunnerHandle::Get(); 162 callback_task_runner_ = caller_task_runner;
160 } 163 }
161 164
162 } // namespace engine 165 } // namespace engine
163 } // namespace blimp 166 } // namespace blimp
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698