OLD | NEW |
(Empty) | |
| 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 |
| 3 // found in the LICENSE file. |
| 4 |
| 5 #ifndef BLIMP_CLIENT_FEATURE_GEOLOCATION_FEATURE_H_ |
| 6 #define BLIMP_CLIENT_FEATURE_GEOLOCATION_FEATURE_H_ |
| 7 |
| 8 #include <memory> |
| 9 #include <string> |
| 10 |
| 11 #include "blimp/common/proto/geolocation.pb.h" |
| 12 #include "blimp/net/blimp_message_processor.h" |
| 13 #include "device/geolocation/geoposition.h" |
| 14 #include "device/geolocation/location_provider.h" |
| 15 |
| 16 namespace blimp { |
| 17 namespace client { |
| 18 |
| 19 // Client-side feature handling geolocation messages. |
| 20 class GeolocationFeature : public BlimpMessageProcessor { |
| 21 public: |
| 22 // The location_provider passed in will be the only location_provider the |
| 23 // GeolocationFeature will gather information from. |
| 24 explicit GeolocationFeature( |
| 25 std::unique_ptr<device::LocationProvider> location_provider); |
| 26 ~GeolocationFeature() override; |
| 27 |
| 28 // Sets the BlimpMessageProcessor that will be used to send |
| 29 // BlimpMessage::GEOLOCATION messages to the engine. |
| 30 void set_outgoing_message_processor( |
| 31 std::unique_ptr<BlimpMessageProcessor> processor); |
| 32 |
| 33 // BlimpMessageProcessor implementation. |
| 34 void ProcessMessage(std::unique_ptr<BlimpMessage> message, |
| 35 const net::CompletionCallback& callback) override; |
| 36 |
| 37 private: |
| 38 // Sends engine an update of the client's geoposition. |
| 39 void OnLocationUpdate(const device::LocationProvider* location_provider, |
| 40 const device::Geoposition& position); |
| 41 |
| 42 // Communicates to the client a change of interest level from the engine. |
| 43 void SetInterestLevel(GeolocationSetInterestLevelMessage::Level level); |
| 44 |
| 45 // Creates a GeolocationPositionMessage that reflects the given |
| 46 // geoposition and sends it to the engine. |
| 47 void SendGeolocationPositionMessage(const device::Geoposition& position); |
| 48 |
| 49 // Creates a GeolocationErrorMessage that reflects the error defined |
| 50 // in the given geoposition and sends it. |
| 51 void SendGeolocationErrorMessage( |
| 52 const GeolocationErrorMessage::ErrorCode& error_code, |
| 53 const std::string& error_message); |
| 54 |
| 55 // Callback function when message finishes sending. |
| 56 void OnSendComplete(int result); |
| 57 |
| 58 // Used to obtain the client's location. |
| 59 std::unique_ptr<device::LocationProvider> location_provider_; |
| 60 |
| 61 // Used to send BlimpMessage::GEOLOCATION message to the engine. |
| 62 std::unique_ptr<BlimpMessageProcessor> outgoing_message_processor_; |
| 63 |
| 64 // Run when message is finished sending. |
| 65 net::CompletionCallback completion_callback_; |
| 66 |
| 67 // True if a message is not in the process of being sent. |
| 68 bool can_send_message_ = true; |
| 69 |
| 70 DISALLOW_COPY_AND_ASSIGN(GeolocationFeature); |
| 71 }; |
| 72 |
| 73 } // namespace client |
| 74 } // namespace blimp |
| 75 |
| 76 #endif // BLIMP_CLIENT_FEATURE_GEOLOCATION_FEATURE_H_ |
OLD | NEW |