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 org.chromium.base.ContextUtils; |
8 | |
9 import org.chromium.base.VisibleForTesting; | 8 import org.chromium.base.VisibleForTesting; |
10 | 9 |
11 /** | 10 /** |
12 * Factory to create a LocationProvider to allow us to inject a mock for tests. | 11 * Factory to create a LocationProvider to allow us to inject a mock for tests. |
13 */ | 12 */ |
14 public class LocationProviderFactory { | 13 public class LocationProviderFactory { |
15 private static LocationProviderFactory.LocationProvider sProviderImpl; | 14 private static LocationProviderFactory.LocationProvider sProviderImpl; |
16 private static boolean sUseGmsCoreLocationProvider; | 15 private static boolean sUseGmsCoreLocationProvider; |
17 | 16 |
18 /** | 17 /** |
(...skipping 22 matching lines...) Expand all Loading... |
41 | 40 |
42 @VisibleForTesting | 41 @VisibleForTesting |
43 public static void setLocationProviderImpl(LocationProviderFactory.LocationP
rovider provider) { | 42 public static void setLocationProviderImpl(LocationProviderFactory.LocationP
rovider provider) { |
44 sProviderImpl = provider; | 43 sProviderImpl = provider; |
45 } | 44 } |
46 | 45 |
47 public static void useGmsCoreLocationProvider() { | 46 public static void useGmsCoreLocationProvider() { |
48 sUseGmsCoreLocationProvider = true; | 47 sUseGmsCoreLocationProvider = true; |
49 } | 48 } |
50 | 49 |
51 public static LocationProvider create(Context context) { | 50 public static LocationProvider create() { |
52 if (sProviderImpl != null) return sProviderImpl; | 51 if (sProviderImpl != null) return sProviderImpl; |
53 | 52 |
54 if (sUseGmsCoreLocationProvider | 53 if (sUseGmsCoreLocationProvider |
55 && LocationProviderGmsCore.isGooglePlayServicesAvailable(context
)) { | 54 && LocationProviderGmsCore.isGooglePlayServicesAvailable( |
56 sProviderImpl = new LocationProviderGmsCore(context); | 55 ContextUtils.getApplicationContext())) { |
| 56 sProviderImpl = new LocationProviderGmsCore(ContextUtils.getApplicat
ionContext()); |
57 } else { | 57 } else { |
58 sProviderImpl = new LocationProviderAndroid(context); | 58 sProviderImpl = new LocationProviderAndroid(); |
59 } | 59 } |
60 return sProviderImpl; | 60 return sProviderImpl; |
61 } | 61 } |
62 } | 62 } |
OLD | NEW |