| OLD | NEW |
| 1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 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 <vector> | 5 #include <vector> |
| 6 | 6 |
| 7 #include "chrome/browser/android/signin/signin_manager_android.h" | 7 #include "chrome/browser/android/signin/signin_manager_android.h" |
| 8 | 8 |
| 9 #include "base/android/jni_android.h" | 9 #include "base/android/jni_android.h" |
| 10 #include "base/android/jni_array.h" | 10 #include "base/android/jni_array.h" |
| (...skipping 86 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 97 SigninManagerAndroid::~SigninManagerAndroid() {} | 97 SigninManagerAndroid::~SigninManagerAndroid() {} |
| 98 | 98 |
| 99 void SigninManagerAndroid::CheckPolicyBeforeSignIn(JNIEnv* env, | 99 void SigninManagerAndroid::CheckPolicyBeforeSignIn(JNIEnv* env, |
| 100 jobject obj, | 100 jobject obj, |
| 101 jstring username) { | 101 jstring username) { |
| 102 #if defined(ENABLE_CONFIGURATION_POLICY) | 102 #if defined(ENABLE_CONFIGURATION_POLICY) |
| 103 username_ = base::android::ConvertJavaStringToUTF8(env, username); | 103 username_ = base::android::ConvertJavaStringToUTF8(env, username); |
| 104 policy::UserPolicySigninService* service = | 104 policy::UserPolicySigninService* service = |
| 105 policy::UserPolicySigninServiceFactory::GetForProfile(profile_); | 105 policy::UserPolicySigninServiceFactory::GetForProfile(profile_); |
| 106 service->RegisterForPolicy( | 106 service->RegisterForPolicy( |
| 107 base::android::ConvertJavaStringToUTF8(env, username), | 107 username_, AccountTrackerServiceFactory::GetForProfile(profile_) |
| 108 ->FindAccountInfoByEmail(username_) |
| 109 .account_id, |
| 108 base::Bind(&SigninManagerAndroid::OnPolicyRegisterDone, | 110 base::Bind(&SigninManagerAndroid::OnPolicyRegisterDone, |
| 109 weak_factory_.GetWeakPtr())); | 111 weak_factory_.GetWeakPtr())); |
| 110 #else | 112 #else |
| 111 // This shouldn't be called when ShouldLoadPolicyForUser() is false. | 113 // This shouldn't be called when ShouldLoadPolicyForUser() is false. |
| 112 NOTREACHED(); | 114 NOTREACHED(); |
| 113 base::android::ScopedJavaLocalRef<jstring> domain; | 115 base::android::ScopedJavaLocalRef<jstring> domain; |
| 114 Java_SigninManager_onPolicyCheckedBeforeSignIn(env, | 116 Java_SigninManager_onPolicyCheckedBeforeSignIn(env, |
| 115 java_signin_manager_.obj(), | 117 java_signin_manager_.obj(), |
| 116 domain.obj()); | 118 domain.obj()); |
| 117 #endif | 119 #endif |
| (...skipping 18 matching lines...) Expand all Loading... |
| 136 #endif | 138 #endif |
| 137 // This shouldn't be called when ShouldLoadPolicyForUser() is false, or when | 139 // This shouldn't be called when ShouldLoadPolicyForUser() is false, or when |
| 138 // CheckPolicyBeforeSignIn() failed. | 140 // CheckPolicyBeforeSignIn() failed. |
| 139 NOTREACHED(); | 141 NOTREACHED(); |
| 140 Java_SigninManager_onPolicyFetchedBeforeSignIn(env, | 142 Java_SigninManager_onPolicyFetchedBeforeSignIn(env, |
| 141 java_signin_manager_.obj()); | 143 java_signin_manager_.obj()); |
| 142 } | 144 } |
| 143 | 145 |
| 144 void SigninManagerAndroid::OnSignInCompleted(JNIEnv* env, | 146 void SigninManagerAndroid::OnSignInCompleted(JNIEnv* env, |
| 145 jobject obj, | 147 jobject obj, |
| 146 jstring username, | 148 jstring username) { |
| 147 jobjectArray accountIds, | |
| 148 jobjectArray accountNames) { | |
| 149 DVLOG(1) << "SigninManagerAndroid::OnSignInCompleted"; | 149 DVLOG(1) << "SigninManagerAndroid::OnSignInCompleted"; |
| 150 // Seed the account tracker with id/email information if provided. | |
| 151 DCHECK(accountIds && accountNames); | |
| 152 std::vector<std::string> gaia_ids; | |
| 153 std::vector<std::string> emails; | |
| 154 base::android::AppendJavaStringArrayToStringVector(env, accountIds, | |
| 155 &gaia_ids); | |
| 156 base::android::AppendJavaStringArrayToStringVector(env, accountNames, | |
| 157 &emails); | |
| 158 DCHECK_EQ(emails.size(), gaia_ids.size()); | |
| 159 DVLOG(1) << "SigninManagerAndroid::OnSignInCompleted: seeding " | |
| 160 << emails.size() << " accounts"; | |
| 161 | |
| 162 AccountTrackerService* tracker = | |
| 163 AccountTrackerServiceFactory::GetForProfile(profile_); | |
| 164 for (size_t i = 0; i < emails.size(); ++i) { | |
| 165 DVLOG(1) << "SigninManagerAndroid::OnSignInCompleted: seeding" | |
| 166 << " gaia_id=" << gaia_ids[i] << " email=" << emails[i]; | |
| 167 if (!gaia_ids[i].empty() && !emails[i].empty()) | |
| 168 tracker->SeedAccountInfo(gaia_ids[i], emails[i]); | |
| 169 } | |
| 170 | |
| 171 SigninManagerFactory::GetForProfile(profile_)->OnExternalSigninCompleted( | 150 SigninManagerFactory::GetForProfile(profile_)->OnExternalSigninCompleted( |
| 172 base::android::ConvertJavaStringToUTF8(env, username)); | 151 base::android::ConvertJavaStringToUTF8(env, username)); |
| 173 } | 152 } |
| 174 | 153 |
| 175 void SigninManagerAndroid::SignOut(JNIEnv* env, jobject obj) { | 154 void SigninManagerAndroid::SignOut(JNIEnv* env, jobject obj) { |
| 176 SigninManagerFactory::GetForProfile(profile_)->SignOut( | 155 SigninManagerFactory::GetForProfile(profile_)->SignOut( |
| 177 signin_metrics::USER_CLICKED_SIGNOUT_SETTINGS); | 156 signin_metrics::USER_CLICKED_SIGNOUT_SETTINGS); |
| 178 } | 157 } |
| 179 | 158 |
| 180 base::android::ScopedJavaLocalRef<jstring> | 159 base::android::ScopedJavaLocalRef<jstring> |
| (...skipping 119 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 300 return !policy::BrowserPolicyConnector::IsNonEnterpriseUser(username); | 279 return !policy::BrowserPolicyConnector::IsNonEnterpriseUser(username); |
| 301 #else | 280 #else |
| 302 return false; | 281 return false; |
| 303 #endif | 282 #endif |
| 304 } | 283 } |
| 305 | 284 |
| 306 // static | 285 // static |
| 307 bool SigninManagerAndroid::Register(JNIEnv* env) { | 286 bool SigninManagerAndroid::Register(JNIEnv* env) { |
| 308 return RegisterNativesImpl(env); | 287 return RegisterNativesImpl(env); |
| 309 } | 288 } |
| OLD | NEW |