Skip to content

Commit

Permalink
Adds EngineGeolocationFeature for Blimp Geolocation project.
Browse files Browse the repository at this point in the history
This change provides the engine-side classes needed to receive and send
geolocation messages from the client. EngineGeolocationFeature sends
messages from the engine that can either indicate the client-side to start
sending location messages of the specified accuracy, request a refresh of
the location, or indicate that the engine side no longer is listening for
updates. The EngineGeolocationFeature also receives messages from the
client, which can either provide a location or indicate an error.

Other changes:
*Moves EmptyMessage out of tab_control.proto to common.proto

BUG=614486

Review-Url: https://codereview.chromium.org/2091023006
Cr-Commit-Position: refs/heads/master@{#407934}
  • Loading branch information
lethalantidote authored and Commit bot committed Jul 26, 2016
1 parent 997739a commit 695c494
Show file tree
Hide file tree
Showing 20 changed files with 842 additions and 57 deletions.
8 changes: 8 additions & 0 deletions blimp/common/create_blimp_message.cc
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
#include "blimp/common/proto/blimp_message.pb.h"
#include "blimp/common/proto/blob_channel.pb.h"
#include "blimp/common/proto/compositor.pb.h"
#include "blimp/common/proto/geolocation.pb.h"
#include "blimp/common/proto/input.pb.h"
#include "blimp/common/proto/render_widget.pb.h"
#include "blimp/common/proto/settings.pb.h"
Expand Down Expand Up @@ -87,6 +88,13 @@ std::unique_ptr<BlimpMessage> CreateBlimpMessage(
return output;
}

std::unique_ptr<BlimpMessage> CreateBlimpMessage(
GeolocationMessage** geolocation_message) {
std::unique_ptr<BlimpMessage> output(new BlimpMessage);
*geolocation_message = output->mutable_geolocation();
return output;
}

std::unique_ptr<BlimpMessage> CreateStartConnectionMessage(
const std::string& client_token,
int protocol_version) {
Expand Down
4 changes: 4 additions & 0 deletions blimp/common/create_blimp_message.h
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ class BlimpMessage;
class BlobChannelMessage;
class CompositorMessage;
class EngineSettingsMessage;
class GeolocationMessage;
class ImeMessage;
class InputMessage;
class NavigationMessage;
Expand Down Expand Up @@ -70,6 +71,9 @@ BLIMP_COMMON_EXPORT std::unique_ptr<BlimpMessage> CreateBlimpMessage(
BLIMP_COMMON_EXPORT std::unique_ptr<BlimpMessage> CreateBlimpMessage(
BlobChannelMessage** blob_channel_message);

BLIMP_COMMON_EXPORT std::unique_ptr<BlimpMessage> CreateBlimpMessage(
GeolocationMessage** geolocation_message);

BLIMP_COMMON_EXPORT std::unique_ptr<BlimpMessage> CreateStartConnectionMessage(
const std::string& client_token,
int protocol_version);
Expand Down
41 changes: 41 additions & 0 deletions blimp/common/logging.cc
Original file line number Diff line number Diff line change
Expand Up @@ -300,6 +300,43 @@ void ExtractBlobChannelMessageFields(const BlimpMessage& message,
}
}

// Logs fields from GEOLOCATION messages.
void ExtractGeolocationMessageFields(const BlimpMessage& message,
LogFields* output) {
switch (message.geolocation().type_case()) {
case GeolocationMessage::TypeCase::kSetInterestLevel:
AddField("subtype", "SET_INTEREST_LEVEL", output);
AddField("level", message.geolocation().set_interest_level().level(),
output);
break;
case GeolocationMessage::TypeCase::kRequestRefresh:
AddField("subtype", "REQUEST_REFRESH", output);
break;
case GeolocationMessage::TypeCase::kCoordinates: {
const GeolocationCoordinatesMessage& coordinates =
message.geolocation().coordinates();
AddField("subtype", "COORDINATES", output);
AddField("latitude", coordinates.latitude(), output);
AddField("longitude", coordinates.longitude(), output);
AddField("altitude", coordinates.altitude(), output);
AddField("accuracy", coordinates.accuracy(), output);
AddField("altitude_accuracy", coordinates.altitude_accuracy(), output);
AddField("heading", coordinates.heading(), output);
AddField("speed", coordinates.speed(), output);
break;
}
case GeolocationMessage::TypeCase::kError:
AddField("subtype", "ERROR", output);
AddField("error_code", message.geolocation().error().error_code(),
output);
AddField("error_message", message.geolocation().error().error_message(),
output);
break;
case GeolocationMessage::TypeCase::TYPE_NOT_SET:
break;
}
}

} // namespace

std::ostream& operator<<(std::ostream& out, const BlimpMessage& message) {
Expand Down Expand Up @@ -342,6 +379,10 @@ std::ostream& operator<<(std::ostream& out, const BlimpMessage& message) {
AddField("type", "IME", &fields);
ExtractImeMessageFields(message, &fields);
break;
case BlimpMessage::kGeolocation:
AddField("type", "GEOLOCATION", &fields);
ExtractGeolocationMessageFields(message, &fields);
break;
case BlimpMessage::FEATURE_NOT_SET:
AddField("type", "<UNKNOWN>", &fields);
break;
Expand Down
2 changes: 2 additions & 0 deletions blimp/common/proto/BUILD.gn
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,9 @@ proto_library("proto_internal") {
"blimp_message.proto",
"blob_cache.proto",
"blob_channel.proto",
"common.proto",
"compositor.proto",
"geolocation.proto",
"ime.proto",
"input.proto",
"navigation.proto",
Expand Down
2 changes: 2 additions & 0 deletions blimp/common/proto/blimp_message.proto
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ import "blob_channel.proto";
import "compositor.proto";
import "ime.proto";
import "input.proto";
import "geolocation.proto";
import "navigation.proto";
import "render_widget.proto";
import "protocol_control.proto";
Expand Down Expand Up @@ -63,6 +64,7 @@ message BlimpMessage {
ImeMessage ime = 46;
SettingsMessage settings = 47;
BlobChannelMessage blob_channel = 48;
GeolocationMessage geolocation = 49;
}
}

13 changes: 13 additions & 0 deletions blimp/common/proto/common.proto
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
// 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.
//
// Message definitions shared across proto files.

syntax = "proto2";

option optimize_for = LITE_RUNTIME;

package blimp;

message EmptyMessage {}
59 changes: 59 additions & 0 deletions blimp/common/proto/geolocation.proto
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
// 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.

syntax = "proto2";

option optimize_for = LITE_RUNTIME;

import "common.proto";

package blimp;

message GeolocationErrorMessage {
enum ErrorCode {
PERMISSION_DENIED = 1;
POSITION_UNAVAILABLE = 2;
TIMEOUT = 3;
}

optional ErrorCode error_code = 1;
optional string error_message = 2;
}

message GeolocationCoordinatesMessage {
optional double latitude = 1;
optional double longitude = 2;
optional double altitude = 3;
optional double accuracy = 4;
optional double altitude_accuracy = 5;
optional double heading = 6;
optional double speed = 7;
}

message GeolocationSetInterestLevelMessage {
// These values represent the various listening states the server can have.
// A Level containing an accuracy level indicates that the server is
// waiting for either high or low accuracy position updates from the client.
// If a NO_INTEREST level is sent, the server is no longer listening
// for updates.
enum Level {
NO_INTEREST = 0;
HIGH_ACCURACY = 1;
LOW_ACCURACY = 2;
}

optional Level level = 1;
}

message GeolocationMessage {
oneof type {
// Server => Client types.
GeolocationSetInterestLevelMessage set_interest_level = 1;
EmptyMessage request_refresh = 2;

// Client => Server types.
GeolocationCoordinatesMessage coordinates = 3;
GeolocationErrorMessage error = 4;
}
}
4 changes: 2 additions & 2 deletions blimp/common/proto/tab_control.proto
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@ syntax = "proto2";

option optimize_for = LITE_RUNTIME;

import "common.proto";

package blimp;

// Contains display information that represents resize events coming from the
Expand All @@ -18,8 +20,6 @@ message SizeMessage {
optional float device_pixel_ratio = 3;
}

message EmptyMessage {}

message TabControlMessage {
// Feature-specific messages follow.
oneof tab_control {
Expand Down
9 changes: 9 additions & 0 deletions blimp/engine/BUILD.gn
Original file line number Diff line number Diff line change
Expand Up @@ -266,6 +266,8 @@ source_set("feature") {
"feature/engine_settings_feature.h",
"feature/geolocation/blimp_location_provider.cc",
"feature/geolocation/blimp_location_provider.h",
"feature/geolocation/engine_geolocation_feature.cc",
"feature/geolocation/engine_geolocation_feature.h",
]

deps = [
Expand Down Expand Up @@ -372,11 +374,15 @@ source_set("test_support") {
sources = [
"app/test_content_main_delegate.cc",
"app/test_content_main_delegate.h",
"feature/geolocation/mock_blimp_location_provider_delegate.cc",
"feature/geolocation/mock_blimp_location_provider_delegate.h",
]

deps = [
":app",
":feature",
"//base",
"//testing/gmock",
]
}

Expand Down Expand Up @@ -442,10 +448,13 @@ source_set("feature_unit_tests") {
sources = [
"feature/engine_render_widget_feature_unittest.cc",
"feature/engine_settings_feature_unittest.cc",
"feature/geolocation/blimp_location_provider_unittest.cc",
"feature/geolocation/engine_geolocation_feature_unittest.cc",
]

deps = [
":feature",
":test_support",
"//base",
"//base/test:test_support",
"//blimp/common",
Expand Down
25 changes: 2 additions & 23 deletions blimp/engine/app/blimp_browser_main_parts.cc
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@

#include "blimp/engine/app/blimp_browser_main_parts.h"

#include <utility>

#include "base/command_line.h"
#include "base/memory/ptr_util.h"
#include "base/threading/thread_restrictions.h"
Expand All @@ -15,34 +17,13 @@
#include "blimp/engine/session/blimp_engine_session.h"
#include "blimp/net/blimp_connection.h"
#include "content/public/browser/browser_thread.h"
#include "content/public/browser/geolocation_delegate.h"
#include "content/public/browser/geolocation_provider.h"
#include "content/public/common/main_function_params.h"
#include "net/base/net_module.h"
#include "net/log/net_log.h"

namespace blimp {
namespace engine {

namespace {
// A provider of services needed by Geolocation.
class BlimpGeolocationDelegate : public content::GeolocationDelegate {
public:
BlimpGeolocationDelegate() = default;

bool UseNetworkLocationProviders() final { return false; }

std::unique_ptr<content::LocationProvider> OverrideSystemLocationProvider()
final {
return base::WrapUnique(new BlimpLocationProvider());
}

private:
DISALLOW_COPY_AND_ASSIGN(BlimpGeolocationDelegate);
};

} // anonymous namespace

BlimpBrowserMainParts::BlimpBrowserMainParts(
const content::MainFunctionParams& parameters) {}

Expand All @@ -65,8 +46,6 @@ void BlimpBrowserMainParts::PreMainMessageLoopRun() {
settings_manager_.reset(new SettingsManager);
std::unique_ptr<BlimpBrowserContext> browser_context(
new BlimpBrowserContext(false, net_log_.get()));
content::GeolocationProvider::SetGeolocationDelegate(
new BlimpGeolocationDelegate());
engine_session_.reset(
new BlimpEngineSession(std::move(browser_context), net_log_.get(),
engine_config_.get(), settings_manager_.get()));
Expand Down
58 changes: 33 additions & 25 deletions blimp/engine/feature/geolocation/blimp_location_provider.cc
Original file line number Diff line number Diff line change
Expand Up @@ -4,58 +4,66 @@

#include "blimp/engine/feature/geolocation/blimp_location_provider.h"

#include "base/bind.h"
#include "base/bind_helpers.h"
#include "base/memory/weak_ptr.h"
#include "content/public/common/geoposition.h"

namespace blimp {
namespace engine {

BlimpLocationProvider::BlimpLocationProvider() {}
BlimpLocationProvider::BlimpLocationProvider(
base::WeakPtr<BlimpLocationProvider::Delegate> delegate)
: delegate_(delegate), is_started_(false) {}

BlimpLocationProvider::~BlimpLocationProvider() {
StopProvider();
if (is_started_) {
StopProvider();
}
}

bool BlimpLocationProvider::StartProvider(bool high_accuracy) {
NOTIMPLEMENTED();
return true;
if (delegate_) {
if (high_accuracy) {
delegate_->RequestAccuracy(
GeolocationSetInterestLevelMessage::HIGH_ACCURACY);
} else {
delegate_->RequestAccuracy(
GeolocationSetInterestLevelMessage::LOW_ACCURACY);
}
is_started_ = true;
}
return is_started_;
}

void BlimpLocationProvider::StopProvider() {
DCHECK(is_started_);
if (delegate_) {
delegate_->RequestAccuracy(GeolocationSetInterestLevelMessage::NO_INTEREST);
is_started_ = false;
}
}

void BlimpLocationProvider::GetPosition(content::Geoposition* position) {
DCHECK(position);

*position = position_;
*position = cached_position_;
}

void BlimpLocationProvider::RequestRefresh() {
NOTIMPLEMENTED();
DCHECK(is_started_);
if (delegate_) {
delegate_->RequestRefresh();
}
}

void BlimpLocationProvider::OnPermissionGranted() {
RequestRefresh();
NOTIMPLEMENTED();
}

void BlimpLocationProvider::NotifyCallback(
const content::Geoposition& position) {
DCHECK(!callback_.is_null());

callback_.Run(this, position);
}

void BlimpLocationProvider::OnLocationResponse(
const content::Geoposition& position) {
NotifyCallback(position);
NOTIMPLEMENTED();
}

void BlimpLocationProvider::SetUpdateCallback(
const LocationProviderUpdateCallback& callback) {
DCHECK(!callback.is_null());

callback_ = callback;
if (delegate_) {
delegate_->SetUpdateCallback(base::Bind(callback, base::Unretained(this)));
}
}

} // namespace engine
Expand Down
Loading

0 comments on commit 695c494

Please sign in to comment.