| 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 "device/geolocation/location_api_adapter_android.h" | 5 #include "device/geolocation/location_api_adapter_android.h" |
| 6 | 6 |
| 7 #include "base/android/context_utils.h" | 7 #include "base/android/context_utils.h" |
| 8 #include "base/android/jni_android.h" | 8 #include "base/android/jni_android.h" |
| 9 #include "base/android/jni_string.h" | 9 #include "base/android/jni_string.h" |
| 10 #include "base/bind.h" | 10 #include "base/bind.h" |
| (...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 69 } | 69 } |
| 70 } | 70 } |
| 71 // At this point we should have all our pre-conditions ready, and they'd only | 71 // At this point we should have all our pre-conditions ready, and they'd only |
| 72 // change in Stop() which must be called on the same thread as here. | 72 // change in Stop() which must be called on the same thread as here. |
| 73 CHECK(location_provider_); | 73 CHECK(location_provider_); |
| 74 CHECK(task_runner_.get()); | 74 CHECK(task_runner_.get()); |
| 75 CHECK(!java_location_provider_android_object_.is_null()); | 75 CHECK(!java_location_provider_android_object_.is_null()); |
| 76 // We'll start receiving notifications from java in the main thread looper | 76 // We'll start receiving notifications from java in the main thread looper |
| 77 // until Stop() is called. | 77 // until Stop() is called. |
| 78 return Java_LocationProviderAdapter_start( | 78 return Java_LocationProviderAdapter_start( |
| 79 env, java_location_provider_android_object_.obj(), high_accuracy); | 79 env, java_location_provider_android_object_, high_accuracy); |
| 80 } | 80 } |
| 81 | 81 |
| 82 void AndroidLocationApiAdapter::Stop() { | 82 void AndroidLocationApiAdapter::Stop() { |
| 83 if (!location_provider_) { | 83 if (!location_provider_) { |
| 84 CHECK(!task_runner_.get()); | 84 CHECK(!task_runner_.get()); |
| 85 CHECK(java_location_provider_android_object_.is_null()); | 85 CHECK(java_location_provider_android_object_.is_null()); |
| 86 return; | 86 return; |
| 87 } | 87 } |
| 88 | 88 |
| 89 { | 89 { |
| 90 base::AutoLock lock(lock_); | 90 base::AutoLock lock(lock_); |
| 91 task_runner_ = NULL; | 91 task_runner_ = NULL; |
| 92 } | 92 } |
| 93 | 93 |
| 94 location_provider_ = NULL; | 94 location_provider_ = NULL; |
| 95 | 95 |
| 96 JNIEnv* env = AttachCurrentThread(); | 96 JNIEnv* env = AttachCurrentThread(); |
| 97 Java_LocationProviderAdapter_stop( | 97 Java_LocationProviderAdapter_stop(env, |
| 98 env, java_location_provider_android_object_.obj()); | 98 java_location_provider_android_object_); |
| 99 java_location_provider_android_object_.Reset(); | 99 java_location_provider_android_object_.Reset(); |
| 100 } | 100 } |
| 101 | 101 |
| 102 // static | 102 // static |
| 103 void AndroidLocationApiAdapter::NotifyProviderNewGeoposition( | 103 void AndroidLocationApiAdapter::NotifyProviderNewGeoposition( |
| 104 const Geoposition& geoposition) { | 104 const Geoposition& geoposition) { |
| 105 // Called on the geolocation thread, safe to access location_provider_ here. | 105 // Called on the geolocation thread, safe to access location_provider_ here. |
| 106 if (GetInstance()->location_provider_) { | 106 if (GetInstance()->location_provider_) { |
| 107 CHECK(GetInstance()->task_runner_->BelongsToCurrentThread()); | 107 CHECK(GetInstance()->task_runner_->BelongsToCurrentThread()); |
| 108 GetInstance()->location_provider_->NotifyNewGeoposition(geoposition); | 108 GetInstance()->location_provider_->NotifyNewGeoposition(geoposition); |
| (...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 169 base::AutoLock lock(lock_); | 169 base::AutoLock lock(lock_); |
| 170 if (!task_runner_.get()) | 170 if (!task_runner_.get()) |
| 171 return; | 171 return; |
| 172 task_runner_->PostTask( | 172 task_runner_->PostTask( |
| 173 FROM_HERE, | 173 FROM_HERE, |
| 174 base::Bind(&AndroidLocationApiAdapter::NotifyProviderNewGeoposition, | 174 base::Bind(&AndroidLocationApiAdapter::NotifyProviderNewGeoposition, |
| 175 geoposition)); | 175 geoposition)); |
| 176 } | 176 } |
| 177 | 177 |
| 178 } // namespace device | 178 } // namespace device |
| OLD | NEW |