Chromium Code Reviews| Index: chrome/browser/android/signin/account_tracker_service_android.cc |
| diff --git a/chrome/browser/android/signin/account_tracker_service_android.cc b/chrome/browser/android/signin/account_tracker_service_android.cc |
| new file mode 100644 |
| index 0000000000000000000000000000000000000000..b19e90fe113ac4c91547e670f4804ff89e40777c |
| --- /dev/null |
| +++ b/chrome/browser/android/signin/account_tracker_service_android.cc |
| @@ -0,0 +1,59 @@ |
| +// Copyright 2015 The Chromium Authors. All rights reserved. |
| +// Use of this source code is governed by a BSD-style license that can be |
| +// found in the LICENSE file. |
| + |
| +#include "chrome/browser/android/signin/account_tracker_service_android.h" |
| + |
| +#include "base/android/jni_array.h" |
| +#include "chrome/browser/profiles/profile_manager.h" |
| +#include "chrome/browser/signin/account_tracker_service_factory.h" |
| +#include "jni/AccountTrackerService_jni.h" |
| + |
| +AccountTrackerServiceAndroid::AccountTrackerServiceAndroid(JNIEnv* env, |
| + jobject obj) { |
| + java_account_tracker_service_.Reset(env, obj); |
| +} |
| + |
| +void AccountTrackerServiceAndroid::SeedAccountsInfo(JNIEnv* env, |
| + jobject obj, |
| + jobjectArray gaiaIds, |
| + jobjectArray accountNames) { |
| + std::vector<std::string> gaia_ids; |
| + std::vector<std::string> account_names; |
| + base::android::AppendJavaStringArrayToStringVector(env, gaiaIds, &gaia_ids); |
| + base::android::AppendJavaStringArrayToStringVector(env, accountNames, |
| + &account_names); |
| + DCHECK_EQ(gaia_ids.size(), account_names.size()); |
| + |
| + Profile* profile = ProfileManager::GetActiveUserProfile(); |
| + AccountTrackerService* account_tracker_service_ = |
| + AccountTrackerServiceFactory::GetForProfile(profile); |
| + |
| + // Clear no longer existed accounts from AccountTrackerService first. |
|
nyquist
2015/08/28 19:18:26
Nit: Clear accounts no longer existing from ...
gogerald1
2015/08/28 21:38:47
Done.
|
| + std::vector<AccountTrackerService::AccountInfo> accounts_info = |
| + account_tracker_service_->GetAccounts(); |
| + for (auto info : accounts_info) { |
| + auto it = gaia_ids.begin(); |
| + for (; it != gaia_ids.end(); ++it) { |
| + if (*it == info.gaia) |
| + break; |
| + } |
| + if (it == gaia_ids.end()) |
| + account_tracker_service_->RemoveAccount(info.account_id); |
| + } |
| + |
| + for (unsigned int i = 0; i < gaia_ids.size(); i++) { |
| + account_tracker_service_->SeedAccountInfo(gaia_ids[i], account_names[i]); |
| + } |
| +} |
| + |
| +static jlong Init(JNIEnv* env, jobject obj) { |
| + AccountTrackerServiceAndroid* account_tracker_service_android = |
| + new AccountTrackerServiceAndroid(env, obj); |
| + return reinterpret_cast<intptr_t>(account_tracker_service_android); |
| +} |
| + |
| +// static |
| +bool AccountTrackerServiceAndroid::Register(JNIEnv* env) { |
| + return RegisterNativesImpl(env); |
| +} |