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

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

Issue 1170623003: Revert "content: Remove use of MessageLoopProxy and deprecated MessageLoop APIs" (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 5 years, 6 months 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 "base/thread_task_runner_handle.h"
12 #include "content/browser/geolocation/location_provider_android.h" 11 #include "content/browser/geolocation/location_provider_android.h"
13 #include "jni/LocationProviderAdapter_jni.h" 12 #include "jni/LocationProviderAdapter_jni.h"
14 13
15 using base::android::AttachCurrentThread; 14 using base::android::AttachCurrentThread;
16 using base::android::CheckException; 15 using base::android::CheckException;
17 using base::android::ClearException; 16 using base::android::ClearException;
18 using content::AndroidLocationApiAdapter; 17 using content::AndroidLocationApiAdapter;
19 18
20 static void NewLocationAvailable(JNIEnv* env, jclass, 19 static void NewLocationAvailable(JNIEnv* env, jclass,
21 jdouble latitude, 20 jdouble latitude,
(...skipping 13 matching lines...) Expand all
35 } 34 }
36 35
37 namespace content { 36 namespace content {
38 37
39 AndroidLocationApiAdapter::AndroidLocationApiAdapter() 38 AndroidLocationApiAdapter::AndroidLocationApiAdapter()
40 : location_provider_(NULL) { 39 : location_provider_(NULL) {
41 } 40 }
42 41
43 AndroidLocationApiAdapter::~AndroidLocationApiAdapter() { 42 AndroidLocationApiAdapter::~AndroidLocationApiAdapter() {
44 CHECK(!location_provider_); 43 CHECK(!location_provider_);
45 CHECK(!task_runner_.get()); 44 CHECK(!message_loop_.get());
46 CHECK(java_location_provider_android_object_.is_null()); 45 CHECK(java_location_provider_android_object_.is_null());
47 } 46 }
48 47
49 bool AndroidLocationApiAdapter::Start( 48 bool AndroidLocationApiAdapter::Start(
50 LocationProviderAndroid* location_provider, bool high_accuracy) { 49 LocationProviderAndroid* location_provider, bool high_accuracy) {
51 JNIEnv* env = AttachCurrentThread(); 50 JNIEnv* env = AttachCurrentThread();
52 if (!location_provider_) { 51 if (!location_provider_) {
53 location_provider_ = location_provider; 52 location_provider_ = location_provider;
54 CHECK(java_location_provider_android_object_.is_null()); 53 CHECK(java_location_provider_android_object_.is_null());
55 CreateJavaObject(env); 54 CreateJavaObject(env);
56 { 55 {
57 base::AutoLock lock(lock_); 56 base::AutoLock lock(lock_);
58 CHECK(!task_runner_.get()); 57 CHECK(!message_loop_.get());
59 task_runner_ = base::ThreadTaskRunnerHandle::Get(); 58 message_loop_ = base::MessageLoopProxy::current();
60 } 59 }
61 } 60 }
62 // 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
63 // 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.
64 CHECK(location_provider_); 63 CHECK(location_provider_);
65 CHECK(task_runner_.get()); 64 CHECK(message_loop_.get());
66 CHECK(!java_location_provider_android_object_.is_null()); 65 CHECK(!java_location_provider_android_object_.is_null());
67 // 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
68 // until Stop() is called. 67 // until Stop() is called.
69 return Java_LocationProviderAdapter_start(env, 68 return Java_LocationProviderAdapter_start(env,
70 java_location_provider_android_object_.obj(), high_accuracy); 69 java_location_provider_android_object_.obj(), high_accuracy);
71 } 70 }
72 71
73 void AndroidLocationApiAdapter::Stop() { 72 void AndroidLocationApiAdapter::Stop() {
74 if (!location_provider_) { 73 if (!location_provider_) {
75 CHECK(!task_runner_.get()); 74 CHECK(!message_loop_.get());
76 CHECK(java_location_provider_android_object_.is_null()); 75 CHECK(java_location_provider_android_object_.is_null());
77 return; 76 return;
78 } 77 }
79 78
80 { 79 {
81 base::AutoLock lock(lock_); 80 base::AutoLock lock(lock_);
82 task_runner_ = NULL; 81 message_loop_ = NULL;
83 } 82 }
84 83
85 location_provider_ = NULL; 84 location_provider_ = NULL;
86 85
87 JNIEnv* env = AttachCurrentThread(); 86 JNIEnv* env = AttachCurrentThread();
88 Java_LocationProviderAdapter_stop( 87 Java_LocationProviderAdapter_stop(
89 env, java_location_provider_android_object_.obj()); 88 env, java_location_provider_android_object_.obj());
90 java_location_provider_android_object_.Reset(); 89 java_location_provider_android_object_.Reset();
91 } 90 }
92 91
93 // static 92 // static
94 void AndroidLocationApiAdapter::NotifyProviderNewGeoposition( 93 void AndroidLocationApiAdapter::NotifyProviderNewGeoposition(
95 const Geoposition& geoposition) { 94 const Geoposition& geoposition) {
96 // Called on the geolocation thread, safe to access location_provider_ here. 95 // Called on the geolocation thread, safe to access location_provider_ here.
97 if (GetInstance()->location_provider_) { 96 if (GetInstance()->location_provider_) {
98 CHECK(GetInstance()->task_runner_->BelongsToCurrentThread()); 97 CHECK(GetInstance()->message_loop_->BelongsToCurrentThread());
99 GetInstance()->location_provider_->NotifyNewGeoposition(geoposition); 98 GetInstance()->location_provider_->NotifyNewGeoposition(geoposition);
100 } 99 }
101 } 100 }
102 101
103 // static 102 // static
104 void AndroidLocationApiAdapter::OnNewLocationAvailable( 103 void AndroidLocationApiAdapter::OnNewLocationAvailable(
105 double latitude, double longitude, double time_stamp, 104 double latitude, double longitude, double time_stamp,
106 bool has_altitude, double altitude, 105 bool has_altitude, double altitude,
107 bool has_accuracy, double accuracy, 106 bool has_accuracy, double accuracy,
108 bool has_heading, double heading, 107 bool has_heading, double heading,
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after
146 // Create the Java AndroidLocationProvider object. 145 // Create the Java AndroidLocationProvider object.
147 java_location_provider_android_object_.Reset( 146 java_location_provider_android_object_.Reset(
148 Java_LocationProviderAdapter_create(env, 147 Java_LocationProviderAdapter_create(env,
149 base::android::GetApplicationContext())); 148 base::android::GetApplicationContext()));
150 CHECK(!java_location_provider_android_object_.is_null()); 149 CHECK(!java_location_provider_android_object_.is_null());
151 } 150 }
152 151
153 void AndroidLocationApiAdapter::OnNewGeopositionInternal( 152 void AndroidLocationApiAdapter::OnNewGeopositionInternal(
154 const Geoposition& geoposition) { 153 const Geoposition& geoposition) {
155 base::AutoLock lock(lock_); 154 base::AutoLock lock(lock_);
156 if (!task_runner_.get()) 155 if (!message_loop_.get())
157 return; 156 return;
158 task_runner_->PostTask( 157 message_loop_->PostTask(
159 FROM_HERE, 158 FROM_HERE,
160 base::Bind(&AndroidLocationApiAdapter::NotifyProviderNewGeoposition, 159 base::Bind(
161 geoposition)); 160 &AndroidLocationApiAdapter::NotifyProviderNewGeoposition,
161 geoposition));
162 } 162 }
163 163
164 } // namespace content 164 } // namespace content
OLDNEW
« no previous file with comments | « content/browser/geolocation/location_api_adapter_android.h ('k') | content/browser/geolocation/mock_location_provider.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698