| 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..e47cc2f7c10af795e4e7f6631a81010cd85962b6
|
| --- /dev/null
|
| +++ b/chrome/browser/android/signin/account_tracker_service_android.cc
|
| @@ -0,0 +1,62 @@
|
| +// 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 "components/signin/core/browser/account_info.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());
|
| +
|
| + DVLOG(1) << "AccountTrackerServiceAndroid::SeedAccountsInfo: "
|
| + << " number of accounts " << gaia_ids.size();
|
| + Profile* profile = ProfileManager::GetActiveUserProfile();
|
| + AccountTrackerService* account_tracker_service_ =
|
| + AccountTrackerServiceFactory::GetForProfile(profile);
|
| +
|
| + // Clear accounts no longer exist from AccountTrackerService first.
|
| + std::vector<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, const JavaParamRef<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);
|
| +}
|
|
|