Chromium Code Reviews| 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; | 7 import android.content.Context; |
| 8 | 8 |
| 9 import org.chromium.base.VisibleForTesting; | 9 import org.chromium.base.VisibleForTesting; |
| 10 | 10 |
| 11 /** | 11 /** |
| 12 * Factory to create a LocationProvider to allow us to inject | 12 * Factory to create a LocationProvider to allow us to inject a mock for tests. |
| 13 * a mock for tests. | |
| 14 */ | 13 */ |
| 15 public class LocationProviderFactory { | 14 public class LocationProviderFactory { |
| 16 private static LocationProviderFactory.LocationProvider sProviderImpl; | 15 private static LocationProviderFactory.LocationProvider sProviderImpl; |
| 17 | 16 |
| 18 /** | 17 /** |
| 19 * LocationProviderFactory.create() returns an instance of this interface. | 18 * LocationProviderFactory.create() returns an instance of this interface. |
| 20 */ | 19 */ |
| 21 public interface LocationProvider { | 20 public interface LocationProvider { |
| 22 /** | 21 /** |
| 23 * Start listening for location updates. | 22 * Start listening for location updates. Calling several times before st op() is interpreted |
| 24 * @param enableHighAccuracy Whether or not to enable high accuracy loca tion providers. | 23 * as restart. |
| 24 * @param enableHighAccuracy Whether or not to enable high accuracy loca tion. | |
| 25 */ | 25 */ |
| 26 public void start(boolean enableHighAccuracy); | 26 public void start(boolean enableHighAccuracy); |
| 27 | 27 |
| 28 /** | 28 /** |
| 29 * Stop listening for location updates. | 29 * Stop listening for location updates. |
| 30 */ | 30 */ |
| 31 public void stop(); | 31 public void stop(); |
| 32 | 32 |
| 33 /** | 33 /** |
| 34 * Returns true if we are currently listening for location updates, fals e if not. | 34 * Returns true if we are currently listening for location updates, fals e if not. |
| 35 */ | 35 */ |
| 36 public boolean isRunning(); | 36 public boolean isRunning(); |
| 37 } | 37 } |
| 38 | 38 |
| 39 private LocationProviderFactory() {} | 39 private LocationProviderFactory() {} |
| 40 | 40 |
| 41 @VisibleForTesting | 41 @VisibleForTesting |
| 42 public static void setLocationProviderImpl(LocationProviderFactory.LocationP rovider provider) { | 42 public static void setLocationProviderImpl(LocationProviderFactory.LocationP rovider provider) { |
| 43 assert sProviderImpl == null; | |
| 44 sProviderImpl = provider; | 43 sProviderImpl = provider; |
| 45 } | 44 } |
| 46 | 45 |
| 47 public static LocationProvider create(Context context) { | 46 public static LocationProvider create(Context context) { |
| 48 if (sProviderImpl == null) { | 47 if (sProviderImpl != null) return sProviderImpl; |
| 48 | |
| 49 if (LocationProviderGmsCore.isGooglePlayServicesAvailable(context)) { | |
| 50 sProviderImpl = new LocationProviderGmsCore(context); | |
|
sgurun-gerrit only
2017/04/26 22:22:54
instead of doing this, can you set sProviderImpl f
| |
| 51 } else { | |
| 49 sProviderImpl = new LocationProviderAndroid(context); | 52 sProviderImpl = new LocationProviderAndroid(context); |
| 50 } | 53 } |
| 51 return sProviderImpl; | 54 return sProviderImpl; |
| 52 } | 55 } |
| 53 } | 56 } |
| OLD | NEW |