| OLD | NEW |
| (Empty) | |
| 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 |
| 3 // found in the LICENSE file. |
| 4 |
| 5 #include "chrome/browser/android/signin/account_tracker_service_android.h" |
| 6 |
| 7 #include "base/android/jni_array.h" |
| 8 #include "chrome/browser/profiles/profile_manager.h" |
| 9 #include "chrome/browser/signin/account_tracker_service_factory.h" |
| 10 #include "jni/AccountTrackerService_jni.h" |
| 11 |
| 12 AccountTrackerServiceAndroid::AccountTrackerServiceAndroid(JNIEnv* env, |
| 13 jobject obj) { |
| 14 java_account_tracker_service_.Reset(env, obj); |
| 15 } |
| 16 |
| 17 void AccountTrackerServiceAndroid::SeedAccountsInfo(JNIEnv* env, |
| 18 jobject obj, |
| 19 jobjectArray gaiaIds, |
| 20 jobjectArray accountNames) { |
| 21 std::vector<std::string> gaia_ids; |
| 22 std::vector<std::string> account_names; |
| 23 base::android::AppendJavaStringArrayToStringVector(env, gaiaIds, &gaia_ids); |
| 24 base::android::AppendJavaStringArrayToStringVector(env, accountNames, |
| 25 &account_names); |
| 26 DCHECK_EQ(gaia_ids.size(), account_names.size()); |
| 27 |
| 28 Profile* profile = ProfileManager::GetActiveUserProfile(); |
| 29 AccountTrackerService* account_tracker_service_ = |
| 30 AccountTrackerServiceFactory::GetForProfile(profile); |
| 31 |
| 32 // Clear no longer existed accounts from AccountTrackerService first. |
| 33 std::vector<AccountTrackerService::AccountInfo> accounts_info = |
| 34 account_tracker_service_->GetAccounts(); |
| 35 for (auto info : accounts_info) { |
| 36 auto it = gaia_ids.begin(); |
| 37 for (; it != gaia_ids.end(); ++it) { |
| 38 if (*it == info.gaia) |
| 39 break; |
| 40 } |
| 41 if (it == gaia_ids.end()) |
| 42 account_tracker_service_->RemoveAccount(info.account_id); |
| 43 } |
| 44 |
| 45 for (unsigned int i = 0; i < gaia_ids.size(); i++) { |
| 46 account_tracker_service_->SeedAccountInfo(gaia_ids[i], account_names[i]); |
| 47 } |
| 48 } |
| 49 |
| 50 static jlong Init(JNIEnv* env, jobject obj) { |
| 51 AccountTrackerServiceAndroid* account_tracker_service_android = |
| 52 new AccountTrackerServiceAndroid(env, obj); |
| 53 return reinterpret_cast<intptr_t>(account_tracker_service_android); |
| 54 } |
| 55 |
| 56 // static |
| 57 bool AccountTrackerServiceAndroid::Register(JNIEnv* env) { |
| 58 return RegisterNativesImpl(env); |
| 59 } |
| OLD | NEW |