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

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

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