Chromium Code Reviews| 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 AccountTrackerService* account_tracker_service_ = | |
| 29 AccountTrackerServiceFactory::GetForProfile( | |
| 30 ProfileManager::GetActiveUserProfile()); | |
|
Roger Tawa OOO till Jul 10th
2015/08/14 15:01:22
Should get profile from java code. Should pass it
gogerald1
2015/08/18 01:14:26
Java code get profile from C++ layer and there is
| |
| 31 | |
| 32 // Clear no longer existed accounts from AccountTrackerService first. | |
| 33 std::vector<AccountTrackerService::AccountInfo> accounts_info = | |
| 34 account_tracker_service_->GetAccounts(); | |
| 35 for (std::vector<AccountTrackerService::AccountInfo>::iterator it = | |
| 36 accounts_info.begin(); | |
| 37 it != accounts_info.end(); ++it) { | |
|
Roger Tawa OOO till Jul 10th
2015/08/14 15:01:22
Use:
for(auto info : accounts_info) {
gogerald1
2015/08/18 01:14:26
Done.
| |
| 38 std::vector<std::string>::iterator it_inner = gaia_ids.begin(); | |
| 39 for (; it_inner != gaia_ids.end(); ++it_inner) { | |
| 40 if (*it_inner == (*it).gaia) | |
| 41 break; | |
| 42 } | |
| 43 if (it_inner == gaia_ids.end()) | |
| 44 account_tracker_service_->StopTrackingAccount((*it).account_id); | |
| 45 } | |
| 46 | |
| 47 for (unsigned int i = 0; i < gaia_ids.size(); i++) { | |
| 48 account_tracker_service_->SeedAccountInfo(gaia_ids[i], account_names[i]); | |
| 49 } | |
| 50 } | |
| 51 | |
| 52 static jlong Init(JNIEnv* env, jobject obj) { | |
| 53 AccountTrackerServiceAndroid* account_tracker_service_android = | |
| 54 new AccountTrackerServiceAndroid(env, obj); | |
| 55 return reinterpret_cast<intptr_t>(account_tracker_service_android); | |
| 56 } | |
| 57 | |
| 58 // static | |
| 59 bool AccountTrackerServiceAndroid::Register(JNIEnv* env) { | |
| 60 return RegisterNativesImpl(env); | |
| 61 } | |
| OLD | NEW |