OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 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 | 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 #include "content/browser/geolocation/location_api_adapter_android.h" | 5 #include "content/browser/geolocation/location_api_adapter_android.h" |
6 | 6 |
7 #include "base/android/jni_android.h" | 7 #include "base/android/jni_android.h" |
8 #include "base/android/jni_string.h" | 8 #include "base/android/jni_string.h" |
9 #include "base/bind.h" | 9 #include "base/bind.h" |
10 #include "base/location.h" | 10 #include "base/location.h" |
11 #include "content/browser/geolocation/location_provider_android.h" | 11 #include "content/browser/geolocation/location_provider_android.h" |
12 #include "jni/location_provider_jni.h" | 12 #include "jni/location_provider_jni.h" |
13 | 13 |
14 using base::android::AttachCurrentThread; | 14 using base::android::AttachCurrentThread; |
15 using base::android::CheckException; | 15 using base::android::CheckException; |
16 using base::android::ClearException; | 16 using base::android::ClearException; |
17 using base::android::GetMethodID; | 17 using base::android::GetMethodID; |
18 | 18 |
19 static void NewLocationAvailable(JNIEnv* env, jclass, | 19 static void NewLocationAvailable(JNIEnv* env, jclass, |
20 jdouble latitude, | 20 jdouble latitude, |
21 jdouble longitude, | 21 jdouble longitude, |
22 jlong time_stamp, | 22 jdouble time_stamp, |
23 jboolean has_altitude, jdouble altitude, | 23 jboolean has_altitude, jdouble altitude, |
24 jboolean has_accuracy, jdouble accuracy, | 24 jboolean has_accuracy, jdouble accuracy, |
25 jboolean has_heading, jdouble heading, | 25 jboolean has_heading, jdouble heading, |
26 jboolean has_speed, jdouble speed) { | 26 jboolean has_speed, jdouble speed) { |
27 AndroidLocationApiAdapter::OnNewLocationAvailable(latitude, longitude, | 27 AndroidLocationApiAdapter::OnNewLocationAvailable(latitude, longitude, |
28 time_stamp, has_altitude, altitude, has_accuracy, accuracy, | 28 time_stamp, has_altitude, altitude, has_accuracy, accuracy, |
29 has_heading, heading, has_speed, speed); | 29 has_heading, heading, has_speed, speed); |
30 } | 30 } |
31 | 31 |
32 static void NewErrorAvailable(JNIEnv* env, jclass, jstring message) { | 32 static void NewErrorAvailable(JNIEnv* env, jclass, jstring message) { |
(...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
91 const content::Geoposition& geoposition) { | 91 const content::Geoposition& geoposition) { |
92 // Called on the geolocation thread, safe to access location_provider_ here. | 92 // Called on the geolocation thread, safe to access location_provider_ here. |
93 if (GetInstance()->location_provider_) { | 93 if (GetInstance()->location_provider_) { |
94 CHECK(GetInstance()->message_loop_->BelongsToCurrentThread()); | 94 CHECK(GetInstance()->message_loop_->BelongsToCurrentThread()); |
95 GetInstance()->location_provider_->NotifyNewGeoposition(geoposition); | 95 GetInstance()->location_provider_->NotifyNewGeoposition(geoposition); |
96 } | 96 } |
97 } | 97 } |
98 | 98 |
99 // static | 99 // static |
100 void AndroidLocationApiAdapter::OnNewLocationAvailable( | 100 void AndroidLocationApiAdapter::OnNewLocationAvailable( |
101 double latitude, double longitude, long time_stamp, | 101 double latitude, double longitude, double time_stamp, |
102 bool has_altitude, double altitude, | 102 bool has_altitude, double altitude, |
103 bool has_accuracy, double accuracy, | 103 bool has_accuracy, double accuracy, |
104 bool has_heading, double heading, | 104 bool has_heading, double heading, |
105 bool has_speed, double speed) { | 105 bool has_speed, double speed) { |
106 content::Geoposition position; | 106 content::Geoposition position; |
107 position.latitude = latitude; | 107 position.latitude = latitude; |
108 position.longitude = longitude; | 108 position.longitude = longitude; |
109 position.timestamp = base::Time::FromDoubleT(time_stamp / 1000.0); | 109 position.timestamp = base::Time::FromDoubleT(time_stamp); |
110 if (has_altitude) | 110 if (has_altitude) |
111 position.altitude = altitude; | 111 position.altitude = altitude; |
112 if (has_accuracy) | 112 if (has_accuracy) |
113 position.accuracy = accuracy; | 113 position.accuracy = accuracy; |
114 if (has_heading) | 114 if (has_heading) |
115 position.heading = heading; | 115 position.heading = heading; |
116 if (has_speed) | 116 if (has_speed) |
117 position.speed = speed; | 117 position.speed = speed; |
118 GetInstance()->OnNewGeopositionInternal(position); | 118 GetInstance()->OnNewGeopositionInternal(position); |
119 } | 119 } |
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
151 const content::Geoposition& geoposition) { | 151 const content::Geoposition& geoposition) { |
152 base::AutoLock lock(lock_); | 152 base::AutoLock lock(lock_); |
153 if (!message_loop_) | 153 if (!message_loop_) |
154 return; | 154 return; |
155 message_loop_->PostTask( | 155 message_loop_->PostTask( |
156 FROM_HERE, | 156 FROM_HERE, |
157 base::Bind( | 157 base::Bind( |
158 &AndroidLocationApiAdapter::NotifyProviderNewGeoposition, | 158 &AndroidLocationApiAdapter::NotifyProviderNewGeoposition, |
159 geoposition)); | 159 geoposition)); |
160 } | 160 } |
OLD | NEW |