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

Side by Side Diff: blimp/engine/feature/geolocation/engine_geolocation_feature.cc

Issue 2249283003: Hooks together Geolocation Feature in the Client and Engine. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@lai
Patch Set: In response to Wez's #48 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 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 "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
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
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());
Kevin M 2016/09/01 20:01:07 This probably doesn't need a helper function - may
CJ 2016/09/01 22:59:42 Done.
158 }
159
160 void EngineGeolocationFeature::SetTaskRunner(
Kevin M 2016/09/01 20:01:07 Recommend renaming |task_runner_| to |callback_tas
CJ 2016/09/01 22:59:42 Done.
161 scoped_refptr<base::SingleThreadTaskRunner> runner) {
162 task_runner_ = std::move(runner);
154 } 163 }
155 164
156 } // namespace engine 165 } // namespace engine
157 } // namespace blimp 166 } // namespace blimp
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698