| 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 "chrome/browser/android/signin/signin_manager_android.h" | 5 #include "chrome/browser/android/signin/signin_manager_android.h" |
| 6 | 6 |
| 7 #include <deque> |
| 8 |
| 7 #include "base/android/jni_android.h" | 9 #include "base/android/jni_android.h" |
| 8 #include "base/android/jni_string.h" | 10 #include "base/android/jni_string.h" |
| 9 #include "base/bind.h" | 11 #include "base/bind.h" |
| 10 #include "base/bind_helpers.h" | 12 #include "base/bind_helpers.h" |
| 11 #include "base/memory/ref_counted.h" | 13 #include "base/memory/ref_counted.h" |
| 12 #include "base/message_loop/message_loop_proxy.h" | 14 #include "base/message_loop/message_loop_proxy.h" |
| 13 #include "base/prefs/pref_service.h" | 15 #include "base/prefs/pref_service.h" |
| 14 #include "chrome/browser/bookmarks/bookmark_model.h" | 16 #include "chrome/browser/bookmarks/bookmark_model.h" |
| 15 #include "chrome/browser/bookmarks/bookmark_model_factory.h" | 17 #include "chrome/browser/bookmarks/bookmark_model_factory.h" |
| 16 #include "chrome/browser/browser_process.h" | 18 #include "chrome/browser/browser_process.h" |
| 17 #include "chrome/browser/browsing_data/browsing_data_helper.h" | 19 #include "chrome/browser/browsing_data/browsing_data_helper.h" |
| 18 #include "chrome/browser/browsing_data/browsing_data_remover.h" | 20 #include "chrome/browser/browsing_data/browsing_data_remover.h" |
| 19 #include "chrome/browser/profiles/profile_manager.h" | 21 #include "chrome/browser/profiles/profile_manager.h" |
| 22 #include "chrome/browser/profiles/profiles_state.h" |
| 20 #include "chrome/browser/signin/google_auto_login_helper.h" | 23 #include "chrome/browser/signin/google_auto_login_helper.h" |
| 24 #include "chrome/browser/signin/profile_oauth2_token_service.h" |
| 25 #include "chrome/browser/signin/profile_oauth2_token_service_factory.h" |
| 21 #include "chrome/browser/signin/signin_manager.h" | 26 #include "chrome/browser/signin/signin_manager.h" |
| 22 #include "chrome/browser/signin/signin_manager_factory.h" | 27 #include "chrome/browser/signin/signin_manager_factory.h" |
| 23 #include "chrome/common/pref_names.h" | 28 #include "chrome/common/pref_names.h" |
| 24 #include "jni/SigninManager_jni.h" | 29 #include "jni/SigninManager_jni.h" |
| 25 | 30 |
| 26 #if defined(ENABLE_CONFIGURATION_POLICY) | 31 #if defined(ENABLE_CONFIGURATION_POLICY) |
| 27 #include "chrome/browser/policy/browser_policy_connector.h" | 32 #include "chrome/browser/policy/browser_policy_connector.h" |
| 28 #include "chrome/browser/policy/cloud/cloud_policy_client.h" | 33 #include "chrome/browser/policy/cloud/cloud_policy_client.h" |
| 29 #include "chrome/browser/policy/cloud/cloud_policy_core.h" | 34 #include "chrome/browser/policy/cloud/cloud_policy_core.h" |
| 30 #include "chrome/browser/policy/cloud/cloud_policy_store.h" | 35 #include "chrome/browser/policy/cloud/cloud_policy_store.h" |
| (...skipping 163 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 194 | 199 |
| 195 // All the Profile data has been wiped. Clear the last signed in username as | 200 // All the Profile data has been wiped. Clear the last signed in username as |
| 196 // well, so that the next signin doesn't trigger the acount change dialog. | 201 // well, so that the next signin doesn't trigger the acount change dialog. |
| 197 profile_->GetPrefs()->ClearPref(prefs::kGoogleServicesLastUsername); | 202 profile_->GetPrefs()->ClearPref(prefs::kGoogleServicesLastUsername); |
| 198 | 203 |
| 199 Java_SigninManager_onProfileDataWiped(base::android::AttachCurrentThread(), | 204 Java_SigninManager_onProfileDataWiped(base::android::AttachCurrentThread(), |
| 200 java_signin_manager_.obj()); | 205 java_signin_manager_.obj()); |
| 201 } | 206 } |
| 202 | 207 |
| 203 void SigninManagerAndroid::LogInSignedInUser(JNIEnv* env, jobject obj) { | 208 void SigninManagerAndroid::LogInSignedInUser(JNIEnv* env, jobject obj) { |
| 204 // AutoLogin deletes itself. | 209 if (profiles::IsNewProfileManagementEnabled()) { |
| 205 GoogleAutoLoginHelper* autoLogin = new GoogleAutoLoginHelper(profile_); | 210 // New Mirror code path that just fires the events and let the |
| 206 autoLogin->LogIn(); | 211 // Account Reconcilor handles everything. |
| 212 |
| 213 AndroidProfileOAuth2TokenService* token_service = |
| 214 ProfileOAuth2TokenServiceFactory::GetForProfile(profile_); |
| 215 |
| 216 // The first account we merge should always be the primiary |
| 217 // account. The rest will just be whatever order the account manager |
| 218 // inform us. |
| 219 std::string primary_acct = token_service->GetPrimaryAccountId(); |
| 220 |
| 221 std::vector<std::string> ids = token_service->GetAccounts(); |
| 222 |
| 223 std::deque<std::string> ordered_accts; |
| 224 ordered_accts.push_back(primary_acct); |
| 225 |
| 226 for (std::vector<std::string>::iterator it = ids.begin(); |
| 227 it != ids.end(); it++) { |
| 228 if (*it != primary_acct) { |
| 229 ordered_accts.push_back(*it); |
| 230 } |
| 231 } |
| 232 token_service->FireRefreshTokenAvailable(ordered_accts); |
| 233 |
| 234 } else { |
| 235 // Old code path that doesn't depend on the new Account Reconcilor. |
| 236 // We manually login. |
| 237 |
| 238 // AutoLogin deletes itself. |
| 239 GoogleAutoLoginHelper* autoLogin = new GoogleAutoLoginHelper(profile_); |
| 240 autoLogin->LogIn(); |
| 241 } |
| 207 } | 242 } |
| 208 | 243 |
| 209 static int Init(JNIEnv* env, jobject obj) { | 244 static int Init(JNIEnv* env, jobject obj) { |
| 210 SigninManagerAndroid* signin_manager_android = | 245 SigninManagerAndroid* signin_manager_android = |
| 211 new SigninManagerAndroid(env, obj); | 246 new SigninManagerAndroid(env, obj); |
| 212 return reinterpret_cast<jint>(signin_manager_android); | 247 return reinterpret_cast<jint>(signin_manager_android); |
| 213 } | 248 } |
| 214 | 249 |
| 215 static jboolean ShouldLoadPolicyForUser(JNIEnv* env, | 250 static jboolean ShouldLoadPolicyForUser(JNIEnv* env, |
| 216 jobject obj, | 251 jobject obj, |
| 217 jstring j_username) { | 252 jstring j_username) { |
| 218 #if defined(ENABLE_CONFIGURATION_POLICY) | 253 #if defined(ENABLE_CONFIGURATION_POLICY) |
| 219 std::string username = | 254 std::string username = |
| 220 base::android::ConvertJavaStringToUTF8(env, j_username); | 255 base::android::ConvertJavaStringToUTF8(env, j_username); |
| 221 return !policy::BrowserPolicyConnector::IsNonEnterpriseUser(username); | 256 return !policy::BrowserPolicyConnector::IsNonEnterpriseUser(username); |
| 222 #else | 257 #else |
| 223 return false; | 258 return false; |
| 224 #endif | 259 #endif |
| 225 } | 260 } |
| 226 | 261 |
| 227 // static | 262 // static |
| 228 bool SigninManagerAndroid::Register(JNIEnv* env) { | 263 bool SigninManagerAndroid::Register(JNIEnv* env) { |
| 229 return RegisterNativesImpl(env); | 264 return RegisterNativesImpl(env); |
| 230 } | 265 } |
| OLD | NEW |