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

Side by Side Diff: content/public/android/java/src/org/chromium/content/browser/LocationProviderAdapter.java

Issue 65273002: Add a mechanism to pause and resume geolocation requests. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 7 years 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
(Empty)
1 // Copyright 2012 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 package org.chromium.content.browser;
6
7 import android.content.Context;
8
9 import com.google.common.annotations.VisibleForTesting;
10
11 import org.chromium.base.CalledByNative;
12 import org.chromium.base.ThreadUtils;
13
14 import java.util.concurrent.FutureTask;
15
16 /**
17 * Implements the Java side of LocationProviderAndroid.
18 * Delegates all real functionality to the implementation
19 * returned from LocationProviderFactory.
20 * See detailed documentation on
21 * content/browser/geolocation/android_location_api_adapter.h.
22 * Based on android.webkit.GeolocationService.java
23 */
24 @VisibleForTesting
25 public class LocationProviderAdapter {
26
27 // Delegate handling the real work in the main thread.
28 private LocationProviderFactory.LocationProvider mImpl;
29
30 private LocationProviderAdapter(Context context) {
31 mImpl = LocationProviderFactory.get(context);
32 }
33
34 @CalledByNative
35 static LocationProviderAdapter create(Context context) {
36 return new LocationProviderAdapter(context);
37 }
38
39 /**
40 * Start listening for location updates until we're told to quit. May be
41 * called in any thread.
42 * @param gpsEnabled Whether or not we're interested in high accuracy GPS.
43 */
44 @CalledByNative
45 public boolean start(final boolean gpsEnabled) {
46 FutureTask<Void> task = new FutureTask<Void>(new Runnable() {
47 @Override
48 public void run() {
49 mImpl.start(gpsEnabled);
50 }
51 }, null);
52 ThreadUtils.runOnUiThread(task);
53 return true;
54 }
55
56 /**
57 * Stop listening for location updates. May be called in any thread.
58 */
59 @CalledByNative
60 public void stop() {
61 FutureTask<Void> task = new FutureTask<Void>(new Runnable() {
62 @Override
63 public void run() {
64 mImpl.stop();
65 }
66 }, null);
67 ThreadUtils.runOnUiThread(task);
68 }
69
70 /**
71 * Returns true if we are currently listening for location updates, false if not.
72 * Must be called only in the UI thread.
73 */
74 public boolean isRunning() {
75 assert ThreadUtils.runningOnUiThread();
76 return mImpl.isRunning();
77 }
78
79 public static void newLocationAvailable(double latitude, double longitude, d ouble timestamp,
80 boolean hasAltitude, double altitude,
81 boolean hasAccuracy, double accuracy,
82 boolean hasHeading, double heading,
83 boolean hasSpeed, double speed) {
84 nativeNewLocationAvailable(latitude, longitude, timestamp, hasAltitude, altitude,
85 hasAccuracy, accuracy, hasHeading, heading, hasSpeed, speed);
86 }
87
88 public static void newErrorAvailable(String message) {
89 nativeNewErrorAvailable(message);
90 }
91
92 // Native functions
93 private static native void nativeNewLocationAvailable(
94 double latitude, double longitude, double timeStamp,
95 boolean hasAltitude, double altitude,
96 boolean hasAccuracy, double accuracy,
97 boolean hasHeading, double heading,
98 boolean hasSpeed, double speed);
99 private static native void nativeNewErrorAvailable(String message);
100 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698