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

Side by Side Diff: device/geolocation/android/java/src/org/chromium/device/geolocation/LocationProviderAdapter.java

Issue 2809813002: GeoLocation: add support for GmsCore location provider (Closed)
Patch Set: reillyg@ nit Created 3 years, 8 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
OLDNEW
1 // Copyright 2013 The Chromium Authors. All rights reserved. 1 // Copyright 2013 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 package org.chromium.device.geolocation; 5 package org.chromium.device.geolocation;
6 6
7 import android.content.Context; 7 import android.content.Context;
8 import android.location.Location;
8 9
10 import org.chromium.base.Log;
9 import org.chromium.base.ThreadUtils; 11 import org.chromium.base.ThreadUtils;
10 import org.chromium.base.VisibleForTesting; 12 import org.chromium.base.VisibleForTesting;
11 import org.chromium.base.annotations.CalledByNative; 13 import org.chromium.base.annotations.CalledByNative;
12 import org.chromium.base.annotations.MainDex; 14 import org.chromium.base.annotations.MainDex;
13 15
14 import java.util.concurrent.FutureTask; 16 import java.util.concurrent.FutureTask;
15 17
16 /** 18 /**
17 * Implements the Java side of LocationProviderAndroid. 19 * Implements the Java side of LocationProviderAndroid.
18 * Delegates all real functionality to the implementation 20 * Delegates all real functionality to the implementation
19 * returned from LocationProviderFactory. 21 * returned from LocationProviderFactory.
20 * See detailed documentation on 22 * See detailed documentation on
21 * content/browser/geolocation/location_api_adapter_android.h. 23 * content/browser/geolocation/location_api_adapter_android.h.
22 * Based on android.webkit.GeolocationService.java 24 * Based on android.webkit.GeolocationService.java
23 */ 25 */
24 @MainDex 26 @MainDex
25 @VisibleForTesting 27 @VisibleForTesting
26 public class LocationProviderAdapter { 28 public class LocationProviderAdapter {
29 private static final String TAG = "cr_LocationProvider";
30
27 // Delegate handling the real work in the main thread. 31 // Delegate handling the real work in the main thread.
28 private LocationProviderFactory.LocationProvider mImpl; 32 private LocationProviderFactory.LocationProvider mImpl;
29 33
30 private LocationProviderAdapter(Context context) { 34 private LocationProviderAdapter(Context context) {
31 mImpl = LocationProviderFactory.create(context); 35 mImpl = LocationProviderFactory.create(context);
32 } 36 }
33 37
34 @CalledByNative 38 @CalledByNative
35 public static LocationProviderAdapter create(Context context) { 39 public static LocationProviderAdapter create(Context context) {
36 return new LocationProviderAdapter(context); 40 return new LocationProviderAdapter(context);
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after
68 72
69 /** 73 /**
70 * Returns true if we are currently listening for location updates, false if not. 74 * Returns true if we are currently listening for location updates, false if not.
71 * Must be called only in the UI thread. 75 * Must be called only in the UI thread.
72 */ 76 */
73 public boolean isRunning() { 77 public boolean isRunning() {
74 assert ThreadUtils.runningOnUiThread(); 78 assert ThreadUtils.runningOnUiThread();
75 return mImpl.isRunning(); 79 return mImpl.isRunning();
76 } 80 }
77 81
78 public static void newLocationAvailable(double latitude, double longitude, d ouble timestamp, 82 public static void onNewLocationAvailable(Location location) {
79 boolean hasAltitude, double altitude, boolean hasAccuracy, double ac curacy, 83 nativeNewLocationAvailable(location.getLatitude(), location.getLongitude (),
80 boolean hasHeading, double heading, boolean hasSpeed, double speed) { 84 location.getTime() / 1000.0, location.hasAltitude(), location.ge tAltitude(),
81 nativeNewLocationAvailable(latitude, longitude, timestamp, hasAltitude, altitude, 85 location.hasAccuracy(), location.getAccuracy(), location.hasBear ing(),
82 hasAccuracy, accuracy, hasHeading, heading, hasSpeed, speed); 86 location.getBearing(), location.hasSpeed(), location.getSpeed()) ;
83 } 87 }
84 88
85 public static void newErrorAvailable(String message) { 89 public static void newErrorAvailable(String message) {
90 Log.e(TAG, "newErrorAvailable %s", message);
86 nativeNewErrorAvailable(message); 91 nativeNewErrorAvailable(message);
87 } 92 }
88 93
89 // Native functions 94 // Native functions
90 private static native void nativeNewLocationAvailable(double latitude, doubl e longitude, 95 private static native void nativeNewLocationAvailable(double latitude, doubl e longitude,
91 double timeStamp, boolean hasAltitude, double altitude, boolean hasA ccuracy, 96 double timeStamp, boolean hasAltitude, double altitude, boolean hasA ccuracy,
92 double accuracy, boolean hasHeading, double heading, boolean hasSpee d, double speed); 97 double accuracy, boolean hasHeading, double heading, boolean hasSpee d, double speed);
93 private static native void nativeNewErrorAvailable(String message); 98 private static native void nativeNewErrorAvailable(String message);
94 } 99 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698