OLD | NEW |
---|---|
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 "blimp/common/create_blimp_message.h" | 13 #include "blimp/common/create_blimp_message.h" |
13 #include "blimp/common/proto/blimp_message.pb.h" | 14 #include "blimp/common/proto/blimp_message.pb.h" |
14 #include "blimp/common/proto/geolocation.pb.h" | 15 #include "blimp/common/proto/geolocation.pb.h" |
15 #include "device/geolocation/geolocation_delegate.h" | 16 #include "device/geolocation/geolocation_delegate.h" |
16 #include "device/geolocation/location_provider.h" | 17 #include "device/geolocation/location_provider.h" |
17 #include "device/geolocation/geoposition.h" | 18 #include "device/geolocation/geoposition.h" |
18 #include "net/base/net_errors.h" | 19 #include "net/base/net_errors.h" |
19 | 20 |
20 namespace blimp { | 21 namespace blimp { |
21 namespace engine { | 22 namespace engine { |
22 namespace { | 23 namespace { |
24 | |
23 class BlimpGeolocationDelegate : public device::GeolocationDelegate { | 25 class BlimpGeolocationDelegate : public device::GeolocationDelegate { |
24 public: | 26 public: |
25 explicit BlimpGeolocationDelegate( | 27 explicit BlimpGeolocationDelegate( |
26 base::WeakPtr<BlimpLocationProvider::Delegate> feature_delegate) { | 28 base::WeakPtr<BlimpLocationProvider::Delegate> feature_delegate) { |
27 feature_delegate_ = feature_delegate; | 29 feature_delegate_ = feature_delegate; |
28 } | 30 } |
29 | 31 |
30 bool UseNetworkLocationProviders() final { return false; } | 32 bool UseNetworkLocationProviders() final { return false; } |
31 | 33 |
32 std::unique_ptr<device::LocationProvider> OverrideSystemLocationProvider() | 34 std::unique_ptr<device::LocationProvider> OverrideSystemLocationProvider() |
(...skipping 80 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
113 case GeolocationMessage::TYPE_NOT_SET: | 115 case GeolocationMessage::TYPE_NOT_SET: |
114 result = net::ERR_UNEXPECTED; | 116 result = net::ERR_UNEXPECTED; |
115 } | 117 } |
116 if (!callback.is_null()) { | 118 if (!callback.is_null()) { |
117 callback.Run(result); | 119 callback.Run(result); |
118 } | 120 } |
119 } | 121 } |
120 | 122 |
121 void EngineGeolocationFeature::NotifyCallback( | 123 void EngineGeolocationFeature::NotifyCallback( |
122 const device::Geoposition& position) { | 124 const device::Geoposition& position) { |
123 geoposition_received_callback_.Run(position); | 125 task_runner_->PostTask(FROM_HERE, |
126 base::Bind(geoposition_received_callback_, position)); | |
124 } | 127 } |
125 | 128 |
126 void EngineGeolocationFeature::RequestAccuracy( | 129 void EngineGeolocationFeature::RequestAccuracy( |
127 GeolocationSetInterestLevelMessage::Level level) { | 130 GeolocationSetInterestLevelMessage::Level level) { |
128 GeolocationMessage* geolocation_message = nullptr; | 131 GeolocationMessage* geolocation_message = nullptr; |
129 std::unique_ptr<BlimpMessage> blimp_message = | 132 std::unique_ptr<BlimpMessage> blimp_message = |
130 CreateBlimpMessage(&geolocation_message); | 133 CreateBlimpMessage(&geolocation_message); |
131 | 134 |
132 GeolocationSetInterestLevelMessage* geolocation_interest = | 135 GeolocationSetInterestLevelMessage* geolocation_interest = |
133 geolocation_message->mutable_set_interest_level(); | 136 geolocation_message->mutable_set_interest_level(); |
(...skipping 10 matching lines...) Expand all Loading... | |
144 | 147 |
145 geolocation_message->mutable_request_refresh(); | 148 geolocation_message->mutable_request_refresh(); |
146 | 149 |
147 outgoing_message_processor_->ProcessMessage(std::move(blimp_message), | 150 outgoing_message_processor_->ProcessMessage(std::move(blimp_message), |
148 net::CompletionCallback()); | 151 net::CompletionCallback()); |
149 } | 152 } |
150 | 153 |
151 void EngineGeolocationFeature::SetUpdateCallback( | 154 void EngineGeolocationFeature::SetUpdateCallback( |
152 const GeopositionReceivedCallback& callback) { | 155 const GeopositionReceivedCallback& callback) { |
153 geoposition_received_callback_ = callback; | 156 geoposition_received_callback_ = callback; |
157 SetTaskRunner(base::ThreadTaskRunnerHandle::Get()); | |
158 } | |
159 | |
160 void EngineGeolocationFeature::SetTaskRunner( | |
161 scoped_refptr<base::SingleThreadTaskRunner> runner) { | |
162 task_runner_ = std::move(runner); | |
Wez
2016/09/01 02:45:43
Why can't we just assign task_runner_ directly in
CJ
2016/09/01 18:17:05
It's because ThreadTaskRunnerHandle::Get() returns
Wez
2016/09/01 20:08:17
You can just assigned the result of Get() directly
| |
154 } | 163 } |
155 | 164 |
156 } // namespace engine | 165 } // namespace engine |
157 } // namespace blimp | 166 } // namespace blimp |
OLD | NEW |