Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(326)

Side by Side Diff: content/browser/geolocation/location_api_adapter_android.cc

Issue 65273002: Add a mechanism to pause and resume geolocation requests. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 7 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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/LocationProvider_jni.h" 12 #include "jni/LocationProviderAdapter_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 content::AndroidLocationApiAdapter; 17 using content::AndroidLocationApiAdapter;
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 jdouble time_stamp, 22 jdouble time_stamp,
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after
58 message_loop_ = base::MessageLoopProxy::current(); 58 message_loop_ = base::MessageLoopProxy::current();
59 } 59 }
60 } 60 }
61 // At this point we should have all our pre-conditions ready, and they'd only 61 // At this point we should have all our pre-conditions ready, and they'd only
62 // change in Stop() which must be called on the same thread as here. 62 // change in Stop() which must be called on the same thread as here.
63 CHECK(location_provider_); 63 CHECK(location_provider_);
64 CHECK(message_loop_.get()); 64 CHECK(message_loop_.get());
65 CHECK(!java_location_provider_android_object_.is_null()); 65 CHECK(!java_location_provider_android_object_.is_null());
66 // We'll start receiving notifications from java in the main thread looper 66 // We'll start receiving notifications from java in the main thread looper
67 // until Stop() is called. 67 // until Stop() is called.
68 return Java_LocationProvider_start(env, 68 return Java_LocationProviderAdapter_start(env,
69 java_location_provider_android_object_.obj(), high_accuracy); 69 java_location_provider_android_object_.obj(), high_accuracy);
70 } 70 }
71 71
72 void AndroidLocationApiAdapter::Stop() { 72 void AndroidLocationApiAdapter::Stop() {
73 if (!location_provider_) { 73 if (!location_provider_) {
74 CHECK(!message_loop_.get()); 74 CHECK(!message_loop_.get());
75 CHECK(java_location_provider_android_object_.is_null()); 75 CHECK(java_location_provider_android_object_.is_null());
76 return; 76 return;
77 } 77 }
78 78
79 { 79 {
80 base::AutoLock lock(lock_); 80 base::AutoLock lock(lock_);
81 message_loop_ = NULL; 81 message_loop_ = NULL;
82 } 82 }
83 83
84 location_provider_ = NULL; 84 location_provider_ = NULL;
85 85
86 JNIEnv* env = AttachCurrentThread(); 86 JNIEnv* env = AttachCurrentThread();
87 Java_LocationProvider_stop(env, java_location_provider_android_object_.obj()); 87 Java_LocationProviderAdapter_stop(
88 env, java_location_provider_android_object_.obj());
88 java_location_provider_android_object_.Reset(); 89 java_location_provider_android_object_.Reset();
89 } 90 }
90 91
91 // static 92 // static
92 void AndroidLocationApiAdapter::NotifyProviderNewGeoposition( 93 void AndroidLocationApiAdapter::NotifyProviderNewGeoposition(
93 const Geoposition& geoposition) { 94 const Geoposition& geoposition) {
94 // Called on the geolocation thread, safe to access location_provider_ here. 95 // Called on the geolocation thread, safe to access location_provider_ here.
95 if (GetInstance()->location_provider_) { 96 if (GetInstance()->location_provider_) {
96 CHECK(GetInstance()->message_loop_->BelongsToCurrentThread()); 97 CHECK(GetInstance()->message_loop_->BelongsToCurrentThread());
97 GetInstance()->location_provider_->NotifyNewGeoposition(geoposition); 98 GetInstance()->location_provider_->NotifyNewGeoposition(geoposition);
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after
136 } 137 }
137 138
138 // static 139 // static
139 bool AndroidLocationApiAdapter::RegisterGeolocationService(JNIEnv* env) { 140 bool AndroidLocationApiAdapter::RegisterGeolocationService(JNIEnv* env) {
140 return RegisterNativesImpl(env); 141 return RegisterNativesImpl(env);
141 } 142 }
142 143
143 void AndroidLocationApiAdapter::CreateJavaObject(JNIEnv* env) { 144 void AndroidLocationApiAdapter::CreateJavaObject(JNIEnv* env) {
144 // Create the Java AndroidLocationProvider object. 145 // Create the Java AndroidLocationProvider object.
145 java_location_provider_android_object_.Reset( 146 java_location_provider_android_object_.Reset(
146 Java_LocationProvider_create(env, 147 Java_LocationProviderAdapter_create(env,
147 base::android::GetApplicationContext())); 148 base::android::GetApplicationContext()));
148 CHECK(!java_location_provider_android_object_.is_null()); 149 CHECK(!java_location_provider_android_object_.is_null());
149 } 150 }
150 151
151 void AndroidLocationApiAdapter::OnNewGeopositionInternal( 152 void AndroidLocationApiAdapter::OnNewGeopositionInternal(
152 const Geoposition& geoposition) { 153 const Geoposition& geoposition) {
153 base::AutoLock lock(lock_); 154 base::AutoLock lock(lock_);
154 if (!message_loop_.get()) 155 if (!message_loop_.get())
155 return; 156 return;
156 message_loop_->PostTask( 157 message_loop_->PostTask(
157 FROM_HERE, 158 FROM_HERE,
158 base::Bind( 159 base::Bind(
159 &AndroidLocationApiAdapter::NotifyProviderNewGeoposition, 160 &AndroidLocationApiAdapter::NotifyProviderNewGeoposition,
160 geoposition)); 161 geoposition));
161 } 162 }
162 163
163 } // namespace content 164 } // namespace content
OLDNEW
« no previous file with comments | « content/browser/geolocation/geolocation_dispatcher_host.cc ('k') | content/browser/renderer_host/render_process_host_impl.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698