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

Unified Diff: blimp/engine/feature/geolocation/engine_geolocation_feature.cc

Issue 2091023006: Adds EngineGeolocationFeature for Blimp Geolocation project. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Addresses kmarshall's #10 Created 4 years, 6 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 side-by-side diff with in-line comments
Download patch
Index: blimp/engine/feature/geolocation/engine_geolocation_feature.cc
diff --git a/blimp/engine/feature/geolocation/engine_geolocation_feature.cc b/blimp/engine/feature/geolocation/engine_geolocation_feature.cc
new file mode 100644
index 0000000000000000000000000000000000000000..f2a0f4e5d8fcce69c0cd659800c820d10f38fb8c
--- /dev/null
+++ b/blimp/engine/feature/geolocation/engine_geolocation_feature.cc
@@ -0,0 +1,132 @@
+// Copyright 2016 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#include "blimp/common/create_blimp_message.h"
+#include "blimp/common/proto/blimp_message.pb.h"
+#include "blimp/common/proto/geolocation.pb.h"
+#include "blimp/engine/feature/geolocation/engine_geolocation_feature.h"
+#include "content/public/common/geoposition.h"
+
+namespace blimp {
+namespace engine {
+namespace {
+
+content::Geoposition::ErrorCode GetErrorCode(
+ const ErrorMessage::ErrorCode& error_code) {
+ switch (error_code) {
+ case ErrorMessage::ERROR_CODE_NONE:
+ return content::Geoposition::ErrorCode::ERROR_CODE_NONE;
+ case ErrorMessage::ERROR_CODE_PERMISSION_DENIED:
+ return content::Geoposition::ErrorCode::ERROR_CODE_PERMISSION_DENIED;
+ case ErrorMessage::ERROR_CODE_POSITION_UNAVAILABLE:
+ return content::Geoposition::ErrorCode::ERROR_CODE_POSITION_UNAVAILABLE;
+ case ErrorMessage::ERROR_CODE_TIMEOUT:
+ return content::Geoposition::ErrorCode::ERROR_CODE_TIMEOUT;
+ }
+}
+
+void ConvertLocationMessage(content::Geoposition* output,
+ const LocationMessage& location) {
+ output->latitude = location.latitude();
+ output->longitude = location.longitude();
+ output->altitude = location.altitude();
+ output->accuracy = location.accuracy();
+ output->altitude_accuracy = location.altitude_accuracy();
+ output->heading = location.heading();
+ output->speed = location.speed();
+ output->timestamp = base::Time::FromJsTime(location.timestamp_millis());
+}
+
+} // namespace
+
+EngineGeolocationFeature::EngineGeolocationFeature() {}
+EngineGeolocationFeature::~EngineGeolocationFeature() {}
+
+void EngineGeolocationFeature::set_outgoing_message_processor(
+ std::unique_ptr<BlimpMessageProcessor> message_processor) {
+ DCHECK(message_processor);
+ outgoing_message_processor_ = std::move(message_processor);
+}
+
+void EngineGeolocationFeature::SendUpdateListenStateMessage(
+ bool enable_high_accuracy) {
+ GeolocationMessage* geolocation_message;
+ std::unique_ptr<BlimpMessage> blimp_message =
+ CreateBlimpMessage(&geolocation_message);
+
+ UpdateListenStateMessage* details =
+ geolocation_message->mutable_update_listen_state();
+ if (enable_high_accuracy) {
+ details->set_listen_state(UpdateListenStateMessage::ACCURACY_HIGH);
+ } else {
+ details->set_listen_state(UpdateListenStateMessage::ACCURACY_LOW);
+ }
+
+ outgoing_message_processor_->ProcessMessage(std::move(blimp_message),
+ net::CompletionCallback());
+}
+
+void EngineGeolocationFeature::SendStopListenStateMessage() {
+ GeolocationMessage* geolocation_message;
+ std::unique_ptr<BlimpMessage> blimp_message =
+ CreateBlimpMessage(&geolocation_message);
+
+ UpdateListenStateMessage* details =
+ geolocation_message->mutable_update_listen_state();
+ details->set_listen_state(UpdateListenStateMessage::STOPPED);
+
+ outgoing_message_processor_->ProcessMessage(std::move(blimp_message),
+ net::CompletionCallback());
+}
+
+void EngineGeolocationFeature::SendRequestRefreshMessage() {
+ GeolocationMessage* geolocation_message;
+ std::unique_ptr<BlimpMessage> blimp_message =
+ CreateBlimpMessage(&geolocation_message);
+
+ geolocation_message->mutable_request_refresh();
+
+ outgoing_message_processor_->ProcessMessage(std::move(blimp_message),
+ net::CompletionCallback());
+}
+
+void EngineGeolocationFeature::ProcessMessage(
+ std::unique_ptr<BlimpMessage> message,
+ const net::CompletionCallback& callback) {
+ DCHECK(!callback.is_null());
+ DCHECK_EQ(BlimpMessage::kGeolocation, message->feature_case());
+ DCHECK(location_provider_);
+
+ const GeolocationMessage& geolocation_message = message->geolocation();
+ content::Geoposition output;
+
+ switch (geolocation_message.type_case()) {
+ case GeolocationMessage::kLocation: {
+ const LocationMessage location = geolocation_message.location();
+
Kevin M 2016/06/29 17:52:56 remove these blank lines - they're part of the sam
CJ 2016/07/11 23:21:07 Done.
+ ConvertLocationMessage(&output, location);
+
+ location_provider_->OnLocationResponse(output);
+ break;
+ }
+ case GeolocationMessage::kError: {
+ const ErrorMessage error_message = geolocation_message.error();
+ output.error_message = error_message.error_message();
+
Kevin M 2016/06/29 17:52:56 ditto
CJ 2016/07/11 23:21:07 Done.
+ output.error_code = GetErrorCode(error_message.error_code());
+
+ location_provider_->OnLocationResponse(output);
+ break;
+ }
+ case GeolocationMessage::kUpdateListenState:
+ case GeolocationMessage::kRequestRefresh:
+ NOTREACHED() << "Engine received unexpected geolocation type.";
Kevin M 2016/06/29 17:52:56 break;
CJ 2016/07/11 23:21:07 Done.
+ case GeolocationMessage::TYPE_NOT_SET:
+ NOTREACHED();
+ break;
+ }
+}
+
+} // namespace engine
+} // namespace blimp

Powered by Google App Engine
This is Rietveld 408576698