[M108 Migration] Bring up Geolocation 29/286929/8
authorayush.k123 <ayush.k123@samsung.com>
Mon, 16 Jan 2023 12:45:08 +0000 (18:15 +0530)
committerBot Blink <blinkbot@samsung.com>
Wed, 18 Jan 2023 12:32:39 +0000 (12:32 +0000)
This patch brings up Geolocation feature to M108.

Reference: https://review.tizen.org/gerrit/274261/

Change-Id: I004a61ee5b1800c97c5ca97f3714e5fce16a8a59
Signed-off-by: Ayush Kumar <ayush.k123@samsung.com>
services/device/geolocation/location_arbitrator.cc
third_party/blink/renderer/modules/geolocation/geolocation_coordinates.cc
tizen_src/ewk/efl_integration/BUILD.gn
tizen_src/ewk/efl_integration/browser/geolocation/location_provider_efl.cc
tizen_src/ewk/efl_integration/browser/geolocation/location_provider_efl.h
tizen_src/ewk/efl_integration/content_browser_client_efl.cc
tizen_src/ewk/efl_integration/private/ewk_geolocation_private.cc
tizen_src/ewk/efl_integration/private/ewk_geolocation_private.h

index 723328e..f875edf 100644 (file)
 #include "services/device/public/cpp/geolocation/geoposition.h"
 #include "services/network/public/cpp/shared_url_loader_factory.h"
 
+#if BUILDFLAG(IS_TIZEN)
+#include "base/base_switches.h"
+#include "base/command_line.h"
+#endif
+
 namespace device {
 
 // To avoid oscillations, set this to twice the expected update interval of a
@@ -149,8 +154,8 @@ LocationArbitrator::NewNetworkLocationProvider(
     scoped_refptr<network::SharedURLLoaderFactory> url_loader_factory,
     const std::string& api_key) {
   DCHECK(url_loader_factory);
-#if BUILDFLAG(IS_ANDROID)
-  // Android uses its own SystemLocationProvider.
+#if BUILDFLAG(IS_ANDROID) || BUILDFLAG(IS_TIZEN)
+  // Android/Tizen uses its own SystemLocationProvider.
   return nullptr;
 #else
   return std::make_unique<NetworkLocationProvider>(
@@ -161,6 +166,14 @@ LocationArbitrator::NewNetworkLocationProvider(
 
 std::unique_ptr<LocationProvider>
 LocationArbitrator::NewSystemLocationProvider() {
+#if BUILDFLAG(IS_TIZEN)
+  if (base::CommandLine::ForCurrentProcess()->HasSwitch(
+          switches::kEnableOffscreenRendering)) {
+    return device::NewSystemLocationProvider(main_task_runner_,
+                                             geolocation_manager_);
+  }
+#endif
+
 #if BUILDFLAG(IS_LINUX) || BUILDFLAG(IS_CHROMEOS) || BUILDFLAG(IS_FUCHSIA)
   return nullptr;
 #else
index fb01ad3..54930be 100644 (file)
 
 #include "third_party/blink/renderer/modules/geolocation/geolocation_coordinates.h"
 
+#if BUILDFLAG(IS_TIZEN)
+#include <limits>
+#endif
+
 namespace blink {
 
 absl::optional<double> GeolocationCoordinates::altitude() const {
@@ -40,8 +44,13 @@ absl::optional<double> GeolocationCoordinates::altitudeAccuracy() const {
 }
 
 absl::optional<double> GeolocationCoordinates::heading() const {
-  if (can_provide_heading_)
+  if (can_provide_heading_) {
+#if BUILDFLAG(IS_TIZEN)
+    if (can_provide_speed_ && speed_ == 0.0)
+      return std::numeric_limits<double>::quiet_NaN();
+#endif
     return heading_;
+  }
   return absl::nullopt;
 }
 
index e9d015b..da0da33 100644 (file)
@@ -143,13 +143,6 @@ shared_library("chromium-ewk") {
       "browser/geolocation/location_provider_efl.cc",
       "browser/geolocation/location_provider_efl.h",
     ]
-    if (ewk_bringup) {
-      # FIXME: EWK_BRINGUP
-      exclude_source_set -= [
-        "browser/geolocation/location_provider_efl.cc",
-        "browser/geolocation/location_provider_efl.h",
-      ]
-    }
   }
 
   # TODO : Below dependency is set in chromium/device/battery_tizen.gypi,
@@ -605,8 +598,6 @@ shared_library("chromium-ewk") {
   # FIXME: Followings are guarded just for bringup.
   if (ewk_bringup) {
     sources -= [
-      "browser/geolocation/location_provider_efl.cc",
-      "browser/geolocation/location_provider_efl.h",
       "browser/vibration/vibration_provider_client.cc",
       "browser/vibration/vibration_provider_client.h",
       "permission_popup_manager.cc",
index 13bb051..2b8b815 100644 (file)
@@ -3,74 +3,98 @@
 // found in the LICENSE file.
 
 #include "browser/geolocation/location_provider_efl.h"
-
 #include "base/bind.h"
 #include "base/logging.h"
 #include "base/time/time.h"
-#include "base/message_loop/message_loop.h"
-#include "content/public/common/geoposition.h"
 
-namespace content {
+#include "services/device/public/cpp/geolocation/geolocation_manager.h"
 
-LocationProviderEfl::LocationProviderEfl()
-  : LocationProviderBase()
-  , location_manager_(NULL)
-  , geolocation_message_loop_(base::MessageLoop::current()) {
+namespace device {
+
+static double KilometerPerHourToMeterPerSecond(double kilometer_per_hour) {
+  return kilometer_per_hour * 5 / 18;
 }
 
+LocationProviderEfl::LocationProviderEfl()
+    : location_manager_(nullptr),
+      task_runner_(base::ThreadTaskRunnerHandle::Get()) {}
+
 LocationProviderEfl::~LocationProviderEfl() {
   StopProvider();
 }
 
 // static
-void LocationProviderEfl::GeoPositionChangedCb(
-      double latitude, double longitude, double altitude,
-      time_t timestamp, void* user_data) {
+void LocationProviderEfl::GeoPositionChangedCb(double latitude,
+                                               double longitude,
+                                               double altitude,
+                                               double speed,
+                                               double direction,
+                                               double horizontal_accuracy,
+                                               time_t timestamp,
+                                               void* user_data) {
   LocationProviderEfl* location_provider =
       static_cast<LocationProviderEfl*>(user_data);
   DCHECK(location_provider);
-  location_provider->NotifyPositionChanged(
-      latitude, longitude, altitude, timestamp);
+  location_provider->NotifyPositionChanged(latitude, longitude, altitude, speed,
+                                           direction, horizontal_accuracy,
+                                           timestamp);
+}
+void LocationProviderEfl::NotifyCallback(const mojom::Geoposition& position) {
+  if (!callback_.is_null())
+    callback_.Run(this, position);
 }
 
-void LocationProviderEfl::NotifyPositionChanged(
-      double latitude, double longitude, double altitude, time_t timestamp) {
-  location_accuracy_level_e level;
+void LocationProviderEfl::SetUpdateCallback(
+    const LocationProviderUpdateCallback& callback) {
+  callback_ = callback;
+}
 
+void LocationProviderEfl::NotifyPositionChanged(double latitude,
+                                                double longitude,
+                                                double altitude,
+                                                double speed,
+                                                double direction,
+                                                double horizontal_accuracy,
+                                                time_t timestamp) {
   DCHECK(location_manager_);
-  DCHECK(geolocation_message_loop_);
+  DCHECK(task_runner_);
 
   last_position_.latitude = latitude;
   last_position_.longitude = longitude;
+  last_position_.altitude = altitude;
   last_position_.timestamp = base::Time::FromTimeT(timestamp);
+  last_position_.speed = KilometerPerHourToMeterPerSecond(speed);
+  last_position_.heading = direction;
 
+  location_accuracy_level_e level;
   location_manager_get_last_accuracy(location_manager_,
       &level, &last_position_.accuracy, &last_position_.altitude_accuracy);
 
-  base::Closure task = base::BindOnce(&LocationProviderEfl::NotifyCallback,
-                                      base::Unretained(this), last_position_);
-  geolocation_message_loop_->PostTask(FROM_HERE, task);
+  base::OnceClosure task =
+      base::BindOnce(&LocationProviderEfl::NotifyCallback,
+                     base::Unretained(this), last_position_);
+  task_runner_->PostTask(FROM_HERE, std::move(task));
 }
 
-bool LocationProviderEfl::StartProvider(bool high_accuracy) {
+void LocationProviderEfl::StartProvider(bool high_accuracy) {
   if (location_manager_) {
     // already started!
-    return false;
+    return;
   }
 
   int ret = location_manager_create(LOCATIONS_METHOD_HYBRID, &location_manager_);
   if (ret != LOCATIONS_ERROR_NONE) {
     LOG(ERROR) << "Failed to create location manager!";
-    return false;
+    return;
   }
 
-  ret = location_manager_set_position_updated_cb(
-      location_manager_, GeoPositionChangedCb, 1, this);
+  ret = location_manager_set_location_changed_cb(location_manager_,
+                                                 GeoPositionChangedCb, 1, this);
   if (ret != LOCATIONS_ERROR_NONE) {
     LOG(ERROR) << "Failed to register position changed callback!";
     location_manager_destroy(location_manager_);
-    location_manager_ = NULL;
-    return false;
+    location_manager_ = nullptr;
+    return;
   }
 
   ret = static_cast<location_error_e>(location_manager_start(location_manager_));
@@ -78,40 +102,34 @@ bool LocationProviderEfl::StartProvider(bool high_accuracy) {
     LOG(ERROR) << "Failed to start location manager: " << ret;
     location_manager_unset_position_updated_cb(location_manager_);
     location_manager_destroy(location_manager_);
-    location_manager_ = NULL;
-    return false;
+    location_manager_ = nullptr;
   }
-
-  return true;
 }
 
 void LocationProviderEfl::StopProvider() {
-  if (location_manager_) {
-    int ret = location_manager_stop(location_manager_);
-    if (ret == LOCATIONS_ERROR_NONE) {
-      location_manager_unset_position_updated_cb(location_manager_);
-    }
+  if (!location_manager_)
+    return;
 
-    // TODO: didn't stop but destroy?
-    location_manager_destroy(location_manager_);
-    location_manager_ = NULL;
-  }
-}
+  int ret = location_manager_stop(location_manager_);
+  if (ret == LOCATIONS_ERROR_NONE)
+    location_manager_unset_position_updated_cb(location_manager_);
 
-void LocationProviderEfl::GetPosition(Geoposition* position) {
-   DCHECK(position);
-  *position = last_position_;
+  // TODO: didn't stop but destroy?
+  location_manager_destroy(location_manager_);
+  location_manager_ = nullptr;
 }
 
-void LocationProviderEfl::RequestRefresh() {
+const mojom::Geoposition& LocationProviderEfl::GetPosition() {
+  return last_position_;
 }
 
 void LocationProviderEfl::OnPermissionGranted() {
 }
 
-//static
-LocationProvider* LocationProviderEfl::Create() {
-  return new LocationProviderEfl();
+std::unique_ptr<LocationProvider> NewSystemLocationProvider(
+    scoped_refptr<base::SingleThreadTaskRunner> main_task_runner,
+    GeolocationManager* geolocation_manager) {
+  return base::WrapUnique(new LocationProviderEfl());
 }
 
-}  // namespace content
+}  // namespace device
index b47d447..5616c1b 100644 (file)
@@ -6,43 +6,50 @@
 #define LOCATION_PROVIDER_EFL_H_
 
 #include "base/compiler_specific.h"
-#include "content/browser/geolocation/location_provider_base.h"
-#include "content/public/common/geoposition.h"
+#include "base/memory/ptr_util.h"
+#include "services/device/geolocation/geolocation_provider.h"
+#include "services/device/public/cpp/geolocation/geoposition.h"
+#include "services/device/public/cpp/geolocation/location_provider.h"
 
 #include <location/locations.h>
 
-namespace base {
-class MessageLoop;
-}
+namespace device {
 
-namespace content {
-
-class LocationProviderEfl : public LocationProviderBase {
+class LocationProviderEfl : public LocationProvider {
  public:
-  virtual ~LocationProviderEfl();
+  LocationProviderEfl();
+  ~LocationProviderEfl() override;
 
-  static LocationProvider* Create();
+  void SetUpdateCallback(
+      const LocationProviderUpdateCallback& callback) override;
+  void StartProvider(bool high_accuracy) override;
+  void StopProvider() override;
+  const mojom::Geoposition& GetPosition() override;
 
-  virtual bool StartProvider(bool high_accuracy) override;
-  virtual void StopProvider() override;
-  virtual void GetPosition(Geoposition* position) override;
-  virtual void RequestRefresh() override;
-  virtual void OnPermissionGranted() override;
+  void OnPermissionGranted() override;
 
  private:
-  LocationProviderEfl();
-
   LocationProviderEfl(const LocationProviderEfl&) = delete;
   LocationProviderEfl& operator=(const LocationProviderEfl&) = delete;
 
-  static void GeoPositionChangedCb(double, double, double, time_t, void*);
-  void NotifyPositionChanged(double, double, double, time_t);
-
-  Geoposition last_position_;
+  static void GeoPositionChangedCb(double,
+                                   double,
+                                   double,
+                                   double,
+                                   double,
+                                   double,
+                                   time_t,
+                                   void*);
+  void
+  NotifyPositionChanged(double, double, double, double, double, double, time_t);
+  void NotifyCallback(const mojom::Geoposition&);
+
+  mojom::Geoposition last_position_;
   location_manager_h location_manager_;
-  base::MessageLoop* geolocation_message_loop_;
+  scoped_refptr<base::SingleThreadTaskRunner> task_runner_;
+  LocationProviderUpdateCallback callback_;
 };
 
-}  // namespace content
+}  // namespace device
 
 #endif  // LOCATION_PROVIDER_EFL_H_
index 878d02a..7b36d0f 100644 (file)
@@ -35,9 +35,6 @@
 #include "web_contents_view_delegate_ewk.h"
 
 #if BUILDFLAG(IS_TIZEN)
-#if !defined(EWK_BRINGUP)
-#include "browser/geolocation/location_provider_efl.h"
-#endif
 #include <vconf.h>
 #include "content/browser/speech/tts_message_filter_efl.h"
 #endif
index a705b07..4091a6d 100644 (file)
@@ -3,9 +3,9 @@
 // found in the LICENSE file.
 
 #include "ewk_geolocation_private.h"
+#include "content/public/browser/browser_thread.h"
 #include "private/ewk_security_origin_private.h"
-
-#include <content/public/browser/browser_thread.h>
+#include "services/device/geolocation/geolocation_provider_impl.h"
 
 using content::BrowserThread;
 using namespace blink::mojom;
@@ -22,6 +22,11 @@ _Ewk_Geolocation_Permission_Request::~_Ewk_Geolocation_Permission_Request() {
 }
 
 void _Ewk_Geolocation_Permission_Request::runCallback(bool allowed) {
+  if (allowed) {
+    device::GeolocationProviderImpl::GetInstance()
+        ->UserDidOptIntoLocationServices();
+  }
+
   std::move(callback_).Run(allowed ? PermissionStatus::GRANTED
                                    : PermissionStatus::DENIED);
 }
index e3619d0..ab83c11 100644 (file)
@@ -20,7 +20,7 @@ class _Ewk_Geolocation_Permission_Request : public Ewk_Suspendable_Object{
   _Ewk_Geolocation_Permission_Request(
       const GURL& origin_url,
       base::OnceCallback<void(blink::mojom::PermissionStatus)> callback);
-  ~_Ewk_Geolocation_Permission_Request();
+  ~_Ewk_Geolocation_Permission_Request() override;
 
   _Ewk_Security_Origin* GetOrigin() const { return origin_; }