Chromium Code Reviews| OLD | NEW |
|---|---|
| (Empty) | |
| 1 // Copyright (c) 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 #ifndef CONTENT_BROWSER_GEOLOCATION_ANDROID_LOCATION_API_ADAPTER_H_ | |
| 6 #define CONTENT_BROWSER_GEOLOCATION_ANDROID_LOCATION_API_ADAPTER_H_ | |
| 7 #pragma once | |
| 8 | |
| 9 #include "base/android/scoped_java_ref.h" | |
| 10 #include "base/synchronization/lock.h" | |
| 11 #include "base/memory/scoped_ptr.h" | |
| 12 #include "base/memory/singleton.h" | |
| 13 #include "base/message_loop_proxy.h" | |
| 14 #include "base/android/jni_helper.h" | |
| 15 | |
| 16 namespace content { | |
| 17 struct Geoposition; | |
| 18 } | |
| 19 | |
| 20 class LocationProviderAndroid; | |
|
bulach
2012/05/08 09:11:05
nit: add a \n
John Knottenbelt
2012/05/08 13:43:16
Done.
| |
| 21 // Interacts with JNI and reports back to AndroidLocationProvider. | |
| 22 // This class creates a LocationProvider java object and listens for | |
| 23 // updates. | |
| 24 // The simplified flow is: | |
| 25 // GeolocationProvider runs in a Geolocation Thread and fetches geolocation data | |
| 26 // from a LocationProvider. | |
| 27 // AndroidLocationProvider access a singleton AndroidLocationApiAdapter | |
| 28 // AndroidLocationApiAdapter calls via JNI and uses the main thread Looper | |
| 29 // in the java side to listen for location updates. We then bounce these updates | |
| 30 // to the Geolocation thread. | |
| 31 // Note that AndroidLocationApiAdapter is a singleton and there's at most only | |
| 32 // one AndroidLocationProvider that has called Start(). | |
| 33 class AndroidLocationApiAdapter { | |
| 34 public: | |
| 35 // Starts the underlying location provider, returns true if successful. | |
| 36 // Called on the Geolocation thread. | |
| 37 bool Start(LocationProviderAndroid* location_provider, bool high_accuracy); | |
| 38 // Stops the underlying location provider. | |
| 39 // Called on the Geolocation thread. | |
| 40 void Stop(); | |
| 41 | |
| 42 // Returns our singleton. | |
| 43 static AndroidLocationApiAdapter* GetInstance(); | |
| 44 | |
| 45 // Called when initializing chrome_view to obtain a pointer to the java class. | |
| 46 static bool RegisterGeolocationService(JNIEnv* env); | |
| 47 | |
| 48 // Called by JNI on main thread looper. | |
| 49 static void OnNewLocationAvailable(double latitude, | |
| 50 double longitude, | |
| 51 long time_stamp, | |
| 52 bool has_altitude, double altitude, | |
| 53 bool has_accuracy, double accuracy, | |
| 54 bool has_heading, double heading, | |
| 55 bool has_speed, double speed); | |
| 56 static void OnNewErrorAvailable(JNIEnv* env, jstring message); | |
| 57 | |
| 58 private: | |
| 59 friend struct DefaultSingletonTraits<AndroidLocationApiAdapter>; | |
| 60 AndroidLocationApiAdapter(); | |
| 61 ~AndroidLocationApiAdapter(); | |
| 62 | |
| 63 void CreateJavaObject(JNIEnv* env); | |
| 64 | |
| 65 // Called on the JNI main thread looper. | |
| 66 void OnNewGeopositionInternal(const content::Geoposition& geoposition); | |
| 67 | |
| 68 /// Called on the Geolocation thread. | |
| 69 static void NotifyProviderNewGeoposition( | |
| 70 const content::Geoposition& geoposition); | |
| 71 | |
| 72 base::android::ScopedJavaGlobalRef<jobject> | |
| 73 java_location_provider_android_object_; | |
| 74 LocationProviderAndroid* location_provider_; | |
| 75 | |
| 76 // Guards against the following member which is accessed on Geolocation | |
| 77 // thread and the JNI main thread looper. | |
| 78 base::Lock lock_; | |
| 79 scoped_refptr<base::MessageLoopProxy> message_loop_; | |
| 80 }; | |
| 81 | |
| 82 #endif // CONTENT_BROWSER_GEOLOCATION_ANDROID_LOCATION_API_ADAPTER_H_ | |
| OLD | NEW |