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

Side by Side Diff: chrome/browser/android/feedback/connectivity_checker.cc

Issue 2033753002: Remove use of deprecated MessageLoop methods in chrome/. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: manual change Created 4 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 2015 The Chromium Authors. All rights reserved. 1 // Copyright 2015 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 "chrome/browser/android/feedback/connectivity_checker.h" 5 #include "chrome/browser/android/feedback/connectivity_checker.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/android/scoped_java_ref.h" 9 #include "base/android/scoped_java_ref.h"
10 #include "base/message_loop/message_loop.h" 10 #include "base/location.h"
11 #include "base/single_thread_task_runner.h"
12 #include "base/threading/thread_task_runner_handle.h"
11 #include "base/time/time.h" 13 #include "base/time/time.h"
12 #include "base/timer/timer.h" 14 #include "base/timer/timer.h"
13 #include "chrome/browser/profiles/profile.h" 15 #include "chrome/browser/profiles/profile.h"
14 #include "chrome/browser/profiles/profile_android.h" 16 #include "chrome/browser/profiles/profile_android.h"
15 #include "jni/ConnectivityChecker_jni.h" 17 #include "jni/ConnectivityChecker_jni.h"
16 #include "net/base/load_flags.h" 18 #include "net/base/load_flags.h"
17 #include "net/http/http_status_code.h" 19 #include "net/http/http_status_code.h"
18 #include "net/url_request/url_fetcher.h" 20 #include "net/url_request/url_fetcher.h"
19 #include "net/url_request/url_fetcher_delegate.h" 21 #include "net/url_request/url_fetcher_delegate.h"
20 #include "net/url_request/url_request_context_getter.h" 22 #include "net/url_request/url_request_context_getter.h"
(...skipping 24 matching lines...) Expand all
45 47
46 void ExecuteCallbackFromRef( 48 void ExecuteCallbackFromRef(
47 base::android::ScopedJavaGlobalRef<jobject>* callback, 49 base::android::ScopedJavaGlobalRef<jobject>* callback,
48 ConnectivityCheckResult result) { 50 ConnectivityCheckResult result) {
49 ExecuteCallback(callback->obj(), result); 51 ExecuteCallback(callback->obj(), result);
50 } 52 }
51 53
52 void PostCallback(JNIEnv* env, 54 void PostCallback(JNIEnv* env,
53 jobject j_callback, 55 jobject j_callback,
54 ConnectivityCheckResult result) { 56 ConnectivityCheckResult result) {
55 base::MessageLoop::current()->PostTask( 57 base::ThreadTaskRunnerHandle::Get()->PostTask(
56 FROM_HERE, 58 FROM_HERE,
57 base::Bind(&ExecuteCallbackFromRef, 59 base::Bind(&ExecuteCallbackFromRef,
58 base::Owned(new base::android::ScopedJavaGlobalRef<jobject>( 60 base::Owned(new base::android::ScopedJavaGlobalRef<jobject>(
59 env, j_callback)), 61 env, j_callback)),
60 result)); 62 result));
61 } 63 }
62 64
63 // A utility class for checking if the device is currently connected to the 65 // A utility class for checking if the device is currently connected to the
64 // Internet. 66 // Internet.
65 class ConnectivityChecker : public net::URLFetcherDelegate { 67 class ConnectivityChecker : public net::URLFetcherDelegate {
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after
113 int response_code = source->GetResponseCode(); 115 int response_code = source->GetResponseCode();
114 116
115 bool connected = status.is_success() && response_code == net::HTTP_NO_CONTENT; 117 bool connected = status.is_success() && response_code == net::HTTP_NO_CONTENT;
116 if (connected) { 118 if (connected) {
117 ExecuteCallback(java_callback_.obj(), CONNECTIVITY_CHECK_RESULT_CONNECTED); 119 ExecuteCallback(java_callback_.obj(), CONNECTIVITY_CHECK_RESULT_CONNECTED);
118 } else { 120 } else {
119 ExecuteCallback(java_callback_.obj(), 121 ExecuteCallback(java_callback_.obj(),
120 CONNECTIVITY_CHECK_RESULT_NOT_CONNECTED); 122 CONNECTIVITY_CHECK_RESULT_NOT_CONNECTED);
121 } 123 }
122 124
123 base::MessageLoop::current()->DeleteSoon(FROM_HERE, this); 125 base::ThreadTaskRunnerHandle::Get()->DeleteSoon(FROM_HERE, this);
124 } 126 }
125 127
126 ConnectivityChecker::ConnectivityChecker( 128 ConnectivityChecker::ConnectivityChecker(
127 Profile* profile, 129 Profile* profile,
128 const GURL& url, 130 const GURL& url,
129 const base::TimeDelta& timeout, 131 const base::TimeDelta& timeout,
130 const base::android::JavaRef<jobject>& java_callback) 132 const base::android::JavaRef<jobject>& java_callback)
131 : request_context_(profile->GetRequestContext()), 133 : request_context_(profile->GetRequestContext()),
132 url_(url), 134 url_(url),
133 timeout_(timeout), 135 timeout_(timeout),
(...skipping 16 matching lines...) Expand all
150 expiration_timer_->Start(FROM_HERE, timeout_, this, 152 expiration_timer_->Start(FROM_HERE, timeout_, this,
151 &ConnectivityChecker::OnTimeout); 153 &ConnectivityChecker::OnTimeout);
152 } 154 }
153 155
154 void ConnectivityChecker::OnTimeout() { 156 void ConnectivityChecker::OnTimeout() {
155 if (is_being_destroyed_) 157 if (is_being_destroyed_)
156 return; 158 return;
157 is_being_destroyed_ = true; 159 is_being_destroyed_ = true;
158 url_fetcher_.reset(); 160 url_fetcher_.reset();
159 ExecuteCallback(java_callback_.obj(), CONNECTIVITY_CHECK_RESULT_TIMEOUT); 161 ExecuteCallback(java_callback_.obj(), CONNECTIVITY_CHECK_RESULT_TIMEOUT);
160 base::MessageLoop::current()->DeleteSoon(FROM_HERE, this); 162 base::ThreadTaskRunnerHandle::Get()->DeleteSoon(FROM_HERE, this);
161 } 163 }
162 164
163 } // namespace 165 } // namespace
164 166
165 void CheckConnectivity(JNIEnv* env, 167 void CheckConnectivity(JNIEnv* env,
166 const JavaParamRef<jclass>& clazz, 168 const JavaParamRef<jclass>& clazz,
167 const JavaParamRef<jobject>& j_profile, 169 const JavaParamRef<jobject>& j_profile,
168 const JavaParamRef<jstring>& j_url, 170 const JavaParamRef<jstring>& j_url,
169 jlong j_timeout_ms, 171 jlong j_timeout_ms,
170 const JavaParamRef<jobject>& j_callback) { 172 const JavaParamRef<jobject>& j_callback) {
(...skipping 21 matching lines...) Expand all
192 GURL url(base::android::ConvertJavaStringToUTF8(env, j_url)); 194 GURL url(base::android::ConvertJavaStringToUTF8(env, j_url));
193 return url.is_valid(); 195 return url.is_valid();
194 } 196 }
195 197
196 bool RegisterConnectivityChecker(JNIEnv* env) { 198 bool RegisterConnectivityChecker(JNIEnv* env) {
197 return RegisterNativesImpl(env); 199 return RegisterNativesImpl(env);
198 } 200 }
199 201
200 } // namespace android 202 } // namespace android
201 } // namespace chrome 203 } // namespace chrome
OLDNEW
« no previous file with comments | « chrome/browser/android/download/download_manager_service.cc ('k') | chrome/browser/apps/app_launch_for_metro_restart_win.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698