OLD | NEW |
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/message_loop/message_loop.h" |
(...skipping 82 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
93 // Holds the Java object which will get the callback with the result. | 93 // Holds the Java object which will get the callback with the result. |
94 base::android::ScopedJavaGlobalRef<jobject> java_callback_; | 94 base::android::ScopedJavaGlobalRef<jobject> java_callback_; |
95 | 95 |
96 // The URLFetcher that executes the connectivity check. | 96 // The URLFetcher that executes the connectivity check. |
97 scoped_ptr<net::URLFetcher> url_fetcher_; | 97 scoped_ptr<net::URLFetcher> url_fetcher_; |
98 | 98 |
99 // Whether |this| is already being destroyed, at which point the callback | 99 // Whether |this| is already being destroyed, at which point the callback |
100 // has already happened, and no further action should be taken. | 100 // has already happened, and no further action should be taken. |
101 bool is_being_destroyed_; | 101 bool is_being_destroyed_; |
102 | 102 |
103 scoped_ptr<base::OneShotTimer<ConnectivityChecker>> expiration_timer_; | 103 scoped_ptr<base::OneShotTimer> expiration_timer_; |
104 }; | 104 }; |
105 | 105 |
106 void ConnectivityChecker::OnURLFetchComplete(const net::URLFetcher* source) { | 106 void ConnectivityChecker::OnURLFetchComplete(const net::URLFetcher* source) { |
107 if (is_being_destroyed_) | 107 if (is_being_destroyed_) |
108 return; | 108 return; |
109 is_being_destroyed_ = true; | 109 is_being_destroyed_ = true; |
110 | 110 |
111 DCHECK_EQ(url_fetcher_.get(), source); | 111 DCHECK_EQ(url_fetcher_.get(), source); |
112 net::URLRequestStatus status = source->GetStatus(); | 112 net::URLRequestStatus status = source->GetStatus(); |
113 int response_code = source->GetResponseCode(); | 113 int response_code = source->GetResponseCode(); |
(...skipping 26 matching lines...) Expand all Loading... |
140 net::URLFetcher::Create(url_, net::URLFetcher::GET, this).Pass(); | 140 net::URLFetcher::Create(url_, net::URLFetcher::GET, this).Pass(); |
141 url_fetcher_->SetRequestContext(request_context_); | 141 url_fetcher_->SetRequestContext(request_context_); |
142 url_fetcher_->SetStopOnRedirect(true); | 142 url_fetcher_->SetStopOnRedirect(true); |
143 url_fetcher_->SetAutomaticallyRetryOn5xx(false); | 143 url_fetcher_->SetAutomaticallyRetryOn5xx(false); |
144 url_fetcher_->SetAutomaticallyRetryOnNetworkChanges(0); | 144 url_fetcher_->SetAutomaticallyRetryOnNetworkChanges(0); |
145 url_fetcher_->SetLoadFlags(net::LOAD_BYPASS_CACHE | net::LOAD_DISABLE_CACHE | | 145 url_fetcher_->SetLoadFlags(net::LOAD_BYPASS_CACHE | net::LOAD_DISABLE_CACHE | |
146 net::LOAD_DO_NOT_SAVE_COOKIES | | 146 net::LOAD_DO_NOT_SAVE_COOKIES | |
147 net::LOAD_DO_NOT_SEND_COOKIES | | 147 net::LOAD_DO_NOT_SEND_COOKIES | |
148 net::LOAD_DO_NOT_SEND_AUTH_DATA); | 148 net::LOAD_DO_NOT_SEND_AUTH_DATA); |
149 url_fetcher_->Start(); | 149 url_fetcher_->Start(); |
150 expiration_timer_.reset(new base::OneShotTimer<ConnectivityChecker>()); | 150 expiration_timer_.reset(new base::OneShotTimer()); |
151 expiration_timer_->Start(FROM_HERE, timeout_, this, | 151 expiration_timer_->Start(FROM_HERE, timeout_, this, |
152 &ConnectivityChecker::OnTimeout); | 152 &ConnectivityChecker::OnTimeout); |
153 } | 153 } |
154 | 154 |
155 void ConnectivityChecker::OnTimeout() { | 155 void ConnectivityChecker::OnTimeout() { |
156 if (is_being_destroyed_) | 156 if (is_being_destroyed_) |
157 return; | 157 return; |
158 is_being_destroyed_ = true; | 158 is_being_destroyed_ = true; |
159 url_fetcher_.reset(); | 159 url_fetcher_.reset(); |
160 ExecuteCallback(java_callback_.obj(), CONNECTIVITY_CHECK_RESULT_TIMEOUT); | 160 ExecuteCallback(java_callback_.obj(), CONNECTIVITY_CHECK_RESULT_TIMEOUT); |
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
193 GURL url(base::android::ConvertJavaStringToUTF8(env, j_url)); | 193 GURL url(base::android::ConvertJavaStringToUTF8(env, j_url)); |
194 return url.is_valid(); | 194 return url.is_valid(); |
195 } | 195 } |
196 | 196 |
197 bool RegisterConnectivityChecker(JNIEnv* env) { | 197 bool RegisterConnectivityChecker(JNIEnv* env) { |
198 return RegisterNativesImpl(env); | 198 return RegisterNativesImpl(env); |
199 } | 199 } |
200 | 200 |
201 } // namespace android | 201 } // namespace android |
202 } // namespace chrome | 202 } // namespace chrome |
OLD | NEW |