| 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 "net/android/http_auth_negotiate_android.h" | 5 #include "net/android/http_auth_negotiate_android.h" |
| 6 | 6 |
| 7 #include "base/android/jni_string.h" | 7 #include "base/android/jni_string.h" |
| 8 #include "base/android/scoped_java_ref.h" | 8 #include "base/android/scoped_java_ref.h" |
| 9 #include "base/bind.h" | 9 #include "base/bind.h" |
| 10 #include "base/callback_helpers.h" | 10 #include "base/callback_helpers.h" |
| (...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 58 HttpAuthNegotiateAndroid::HttpAuthNegotiateAndroid( | 58 HttpAuthNegotiateAndroid::HttpAuthNegotiateAndroid( |
| 59 const HttpAuthPreferences* prefs) | 59 const HttpAuthPreferences* prefs) |
| 60 : prefs_(prefs), | 60 : prefs_(prefs), |
| 61 can_delegate_(false), | 61 can_delegate_(false), |
| 62 first_challenge_(true), | 62 first_challenge_(true), |
| 63 auth_token_(nullptr), | 63 auth_token_(nullptr), |
| 64 weak_factory_(this) { | 64 weak_factory_(this) { |
| 65 JNIEnv* env = AttachCurrentThread(); | 65 JNIEnv* env = AttachCurrentThread(); |
| 66 java_authenticator_.Reset(Java_HttpNegotiateAuthenticator_create( | 66 java_authenticator_.Reset(Java_HttpNegotiateAuthenticator_create( |
| 67 env, | 67 env, |
| 68 ConvertUTF8ToJavaString(env, prefs->AuthAndroidNegotiateAccountType()) | 68 ConvertUTF8ToJavaString(env, prefs->AuthAndroidNegotiateAccountType()))); |
| 69 .obj())); | |
| 70 } | 69 } |
| 71 | 70 |
| 72 HttpAuthNegotiateAndroid::~HttpAuthNegotiateAndroid() { | 71 HttpAuthNegotiateAndroid::~HttpAuthNegotiateAndroid() { |
| 73 } | 72 } |
| 74 | 73 |
| 75 bool HttpAuthNegotiateAndroid::Register(JNIEnv* env) { | 74 bool HttpAuthNegotiateAndroid::Register(JNIEnv* env) { |
| 76 return RegisterNativesImpl(env); | 75 return RegisterNativesImpl(env); |
| 77 } | 76 } |
| 78 | 77 |
| 79 bool HttpAuthNegotiateAndroid::Init() { | 78 bool HttpAuthNegotiateAndroid::Init() { |
| (...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 133 // asynchronously on a different thread, and needs an object to call it on. As | 132 // asynchronously on a different thread, and needs an object to call it on. As |
| 134 // such, the callback_wrapper must not be deleted until the callback has been | 133 // such, the callback_wrapper must not be deleted until the callback has been |
| 135 // called, whatever happens to the HttpAuthNegotiateAndroid object. | 134 // called, whatever happens to the HttpAuthNegotiateAndroid object. |
| 136 // | 135 // |
| 137 // Unfortunately we have no automated way of managing C++ objects owned by | 136 // Unfortunately we have no automated way of managing C++ objects owned by |
| 138 // Java, so the Java code must simply be written to guarantee that the | 137 // Java, so the Java code must simply be written to guarantee that the |
| 139 // callback is, in the end, called. | 138 // callback is, in the end, called. |
| 140 JavaNegotiateResultWrapper* callback_wrapper = new JavaNegotiateResultWrapper( | 139 JavaNegotiateResultWrapper* callback_wrapper = new JavaNegotiateResultWrapper( |
| 141 callback_task_runner, thread_safe_callback); | 140 callback_task_runner, thread_safe_callback); |
| 142 Java_HttpNegotiateAuthenticator_getNextAuthToken( | 141 Java_HttpNegotiateAuthenticator_getNextAuthToken( |
| 143 env, java_authenticator_.obj(), | 142 env, java_authenticator_, reinterpret_cast<intptr_t>(callback_wrapper), |
| 144 reinterpret_cast<intptr_t>(callback_wrapper), java_spn.obj(), | 143 java_spn, java_server_auth_token, can_delegate_); |
| 145 java_server_auth_token.obj(), can_delegate_); | |
| 146 return ERR_IO_PENDING; | 144 return ERR_IO_PENDING; |
| 147 } | 145 } |
| 148 | 146 |
| 149 void HttpAuthNegotiateAndroid::Delegate() { | 147 void HttpAuthNegotiateAndroid::Delegate() { |
| 150 can_delegate_ = true; | 148 can_delegate_ = true; |
| 151 } | 149 } |
| 152 | 150 |
| 153 void HttpAuthNegotiateAndroid::SetResultInternal(int result, | 151 void HttpAuthNegotiateAndroid::SetResultInternal(int result, |
| 154 const std::string& raw_token) { | 152 const std::string& raw_token) { |
| 155 DCHECK(auth_token_); | 153 DCHECK(auth_token_); |
| 156 DCHECK(!completion_callback_.is_null()); | 154 DCHECK(!completion_callback_.is_null()); |
| 157 if (result == OK) | 155 if (result == OK) |
| 158 *auth_token_ = "Negotiate " + raw_token; | 156 *auth_token_ = "Negotiate " + raw_token; |
| 159 base::ResetAndReturn(&completion_callback_).Run(result); | 157 base::ResetAndReturn(&completion_callback_).Run(result); |
| 160 } | 158 } |
| 161 | 159 |
| 162 } // namespace android | 160 } // namespace android |
| 163 } // namespace net | 161 } // namespace net |
| OLD | NEW |