OLD | NEW |
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; | |
8 import android.location.Location; | 7 import android.location.Location; |
9 | 8 |
10 import org.chromium.base.Log; | 9 import org.chromium.base.Log; |
11 import org.chromium.base.ThreadUtils; | 10 import org.chromium.base.ThreadUtils; |
12 import org.chromium.base.VisibleForTesting; | 11 import org.chromium.base.VisibleForTesting; |
13 import org.chromium.base.annotations.CalledByNative; | 12 import org.chromium.base.annotations.CalledByNative; |
14 import org.chromium.base.annotations.MainDex; | 13 import org.chromium.base.annotations.MainDex; |
15 | 14 |
16 import java.util.concurrent.FutureTask; | 15 import java.util.concurrent.FutureTask; |
17 | 16 |
18 /** | 17 /** |
19 * Implements the Java side of LocationProviderAndroid. | 18 * Implements the Java side of LocationProviderAndroid. |
20 * Delegates all real functionality to the implementation | 19 * Delegates all real functionality to the implementation |
21 * returned from LocationProviderFactory. | 20 * returned from LocationProviderFactory. |
22 * See detailed documentation on | 21 * See detailed documentation on |
23 * content/browser/geolocation/location_api_adapter_android.h. | 22 * content/browser/geolocation/location_api_adapter_android.h. |
24 * Based on android.webkit.GeolocationService.java | 23 * Based on android.webkit.GeolocationService.java |
25 */ | 24 */ |
26 @MainDex | 25 @MainDex |
27 @VisibleForTesting | 26 @VisibleForTesting |
28 public class LocationProviderAdapter { | 27 public class LocationProviderAdapter { |
29 private static final String TAG = "cr_LocationProvider"; | 28 private static final String TAG = "cr_LocationProvider"; |
30 | 29 |
31 // Delegate handling the real work in the main thread. | 30 // Delegate handling the real work in the main thread. |
32 private LocationProviderFactory.LocationProvider mImpl; | 31 private LocationProviderFactory.LocationProvider mImpl; |
33 | 32 |
34 private LocationProviderAdapter(Context context) { | 33 private LocationProviderAdapter() { |
35 mImpl = LocationProviderFactory.create(context); | 34 mImpl = LocationProviderFactory.create(); |
36 } | 35 } |
37 | 36 |
38 @CalledByNative | 37 @CalledByNative |
39 public static LocationProviderAdapter create(Context context) { | 38 public static LocationProviderAdapter create() { |
40 return new LocationProviderAdapter(context); | 39 return new LocationProviderAdapter(); |
41 } | 40 } |
42 | 41 |
43 /** | 42 /** |
44 * Start listening for location updates until we're told to quit. May be cal
led in any thread. | 43 * Start listening for location updates until we're told to quit. May be cal
led in any thread. |
45 * @param enableHighAccuracy Whether or not to enable high accuracy location
providers. | 44 * @param enableHighAccuracy Whether or not to enable high accuracy location
providers. |
46 */ | 45 */ |
47 @CalledByNative | 46 @CalledByNative |
48 public boolean start(final boolean enableHighAccuracy) { | 47 public boolean start(final boolean enableHighAccuracy) { |
49 FutureTask<Void> task = new FutureTask<Void>(new Runnable() { | 48 FutureTask<Void> task = new FutureTask<Void>(new Runnable() { |
50 @Override | 49 @Override |
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
90 Log.e(TAG, "newErrorAvailable %s", message); | 89 Log.e(TAG, "newErrorAvailable %s", message); |
91 nativeNewErrorAvailable(message); | 90 nativeNewErrorAvailable(message); |
92 } | 91 } |
93 | 92 |
94 // Native functions | 93 // Native functions |
95 private static native void nativeNewLocationAvailable(double latitude, doubl
e longitude, | 94 private static native void nativeNewLocationAvailable(double latitude, doubl
e longitude, |
96 double timeStamp, boolean hasAltitude, double altitude, boolean hasA
ccuracy, | 95 double timeStamp, boolean hasAltitude, double altitude, boolean hasA
ccuracy, |
97 double accuracy, boolean hasHeading, double heading, boolean hasSpee
d, double speed); | 96 double accuracy, boolean hasHeading, double heading, boolean hasSpee
d, double speed); |
98 private static native void nativeNewErrorAvailable(String message); | 97 private static native void nativeNewErrorAvailable(String message); |
99 } | 98 } |
OLD | NEW |