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

Side by Side Diff: blimp/64

Issue 2091023006: Adds EngineGeolocationFeature for Blimp Geolocation project. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Updating repo to see if try is fixed Created 4 years, 5 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
« no previous file with comments | « no previous file | blimp/common/create_blimp_message.h » ('j') | blimp/common/logging.cc » ('J')
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
1 // Copyright 2016 The Chromium Authors. All rights reserved.
Wez 2016/07/12 21:35:12 Looks like you copied a file into your working tre
CJ 2016/07/13 21:49:19 Yeah not even sure where this came from. Sorry abo
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4
5 #include "base/memory/weak_ptr.h"
6 #include "blimp/common/create_blimp_message.h"
7 #include "blimp/common/proto/blimp_message.pb.h"
8 #include "blimp/common/proto/geolocation.pb.h"
9 #include "blimp/engine/feature/geolocation/engine_geolocation_feature.h"
10 #include "content/public/browser/location_provider.h"
11 #include "content/public/common/geoposition.h"
12 #include "net/base/net_errors.h"
13
14 #include "blimp/common/logging.h"
15
16 namespace blimp {
17 namespace engine {
18 namespace {
19
20 content::Geoposition::ErrorCode GetErrorCode(
21 const ErrorMessage::ErrorCode& error_code) {
22 switch (error_code) {
23 case ErrorMessage::ERROR_CODE_NONE:
24 return content::Geoposition::ErrorCode::ERROR_CODE_NONE;
25 case ErrorMessage::ERROR_CODE_PERMISSION_DENIED:
26 return content::Geoposition::ErrorCode::ERROR_CODE_PERMISSION_DENIED;
27 case ErrorMessage::ERROR_CODE_POSITION_UNAVAILABLE:
28 return content::Geoposition::ErrorCode::ERROR_CODE_POSITION_UNAVAILABLE;
29 case ErrorMessage::ERROR_CODE_TIMEOUT:
30 return content::Geoposition::ErrorCode::ERROR_CODE_TIMEOUT;
31 }
32 }
33
34 void ConvertLocationMessage(content::Geoposition* output,
35 const LocationMessage& location) {
36 output->latitude = location.latitude();
37 output->longitude = location.longitude();
38 output->altitude = location.altitude();
39 output->accuracy = location.accuracy();
40 output->altitude_accuracy = location.altitude_accuracy();
41 output->heading = location.heading();
42 output->speed = location.speed();
43 output->timestamp = base::Time::FromJsTime(location.timestamp_millis());
44 }
45
46 } // namespace
47
48 EngineGeolocationFeature::EngineGeolocationFeature() : weak_factory_(this) {}
49
50 EngineGeolocationFeature::~EngineGeolocationFeature() {}
51
52 void EngineGeolocationFeature::set_outgoing_message_processor(
53 std::unique_ptr<BlimpMessageProcessor> message_processor) {
54 DCHECK(message_processor);
55 outgoing_message_processor_ = std::move(message_processor);
56 }
57
58 base::WeakPtr<EngineGeolocationFeature> EngineGeolocationFeature::GetWeakPtr() {
59 return weak_factory_.GetWeakPtr();
60 }
61
62 void EngineGeolocationFeature::UpdateListenState(
63 bool enable_high_accuracy) {
64 GeolocationMessage* geolocation_message;
65 std::unique_ptr<BlimpMessage> blimp_message =
66 CreateBlimpMessage(&geolocation_message);
67
68 UpdateListenStateMessage* details =
69 geolocation_message->mutable_update_listen_state();
70 if (enable_high_accuracy) {
71 details->set_listen_state(UpdateListenStateMessage::ACCURACY_HIGH);
72 } else {
73 details->set_listen_state(UpdateListenStateMessage::ACCURACY_LOW);
74 }
75
76 outgoing_message_processor_->ProcessMessage(std::move(blimp_message),
77 net::CompletionCallback());
78 }
79
80 void EngineGeolocationFeature::StopListenState() {
81 CHECK(false);
82 GeolocationMessage* geolocation_message;
83 std::unique_ptr<BlimpMessage> blimp_message =
84 CreateBlimpMessage(&geolocation_message);
85
86 UpdateListenStateMessage* details =
87 geolocation_message->mutable_update_listen_state();
88 details->set_listen_state(UpdateListenStateMessage::STOPPED);
89
90 outgoing_message_processor_->ProcessMessage(std::move(blimp_message),
91 net::CompletionCallback());
92 }
93
94 void EngineGeolocationFeature::RequestRefresh() {
95 GeolocationMessage* geolocation_message;
96 std::unique_ptr<BlimpMessage> blimp_message =
97 CreateBlimpMessage(&geolocation_message);
98
99 geolocation_message->mutable_request_refresh();
100
101 outgoing_message_processor_->ProcessMessage(std::move(blimp_message),
102 net::CompletionCallback());
103 }
104
105 void SetUpdateCallback(const LocationProviderUpdateCallback& callback) {
106 DCHECK(!callback.is_null());
107
108 callback_ = callback;
109 }
110
111
112 void EngineGeolocationFeature::NotifyCallback(
113 const content::Geoposition& position) {
114 callback_.Run(this, position);
115 }
116
117 void EngineGeolocationFeature::ProcessMessage(
118 std::unique_ptr<BlimpMessage> message,
119 const net::CompletionCallback& callback) {
120 DCHECK(!callback.is_null());
121 DCHECK_EQ(BlimpMessage::kGeolocation, message->feature_case());
122 DCHECK(location_provider_);
123
124 const GeolocationMessage& geolocation_message = message->geolocation();
125 content::Geoposition output;
126
127 switch (geolocation_message.type_case()) {
128 case GeolocationMessage::kLocation: {
129 const LocationMessage location = geolocation_message.location();
130 ConvertLocationMessage(&output, location);
131 location_provider_->NotifyCallback(output);
132 break;
133 }
134 case GeolocationMessage::kError: {
135 const ErrorMessage error_message = geolocation_message.error();
136 output.error_message = error_message.error_message();
137 output.error_code = GetErrorCode(error_message.error_code());
138 location_provider_->NotifyCallback(output);
139 break;
140 }
141 case GeolocationMessage::kUpdateListenState:
142 case GeolocationMessage::kRequestRefresh:
143 NOTREACHED() << "Engine received unexpected geolocation type.";
144 break;
145 case GeolocationMessage::TYPE_NOT_SET:
146 NOTREACHED();
147 break;
148 }
149 callback.Run(net::OK);
150 }
151
152 } // namespace engine
153 } // namespace blimp
OLDNEW
« no previous file with comments | « no previous file | blimp/common/create_blimp_message.h » ('j') | blimp/common/logging.cc » ('J')

Powered by Google App Engine
This is Rietveld 408576698