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..24e808dc551a3164f752892cde25d5b65d3f95c5 |
| --- /dev/null |
| +++ b/chrome/browser/android/signin/account_tracker_service_android.cc |
| @@ -0,0 +1,61 @@ |
| +// 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()); |
| + |
| + AccountTrackerService* account_tracker_service_ = |
| + AccountTrackerServiceFactory::GetForProfile( |
| + 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
|
| + |
| + // Clear no longer existed accounts from AccountTrackerService first. |
| + std::vector<AccountTrackerService::AccountInfo> accounts_info = |
| + account_tracker_service_->GetAccounts(); |
| + for (std::vector<AccountTrackerService::AccountInfo>::iterator it = |
| + accounts_info.begin(); |
| + 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.
|
| + std::vector<std::string>::iterator it_inner = gaia_ids.begin(); |
| + for (; it_inner != gaia_ids.end(); ++it_inner) { |
| + if (*it_inner == (*it).gaia) |
| + break; |
| + } |
| + if (it_inner == gaia_ids.end()) |
| + account_tracker_service_->StopTrackingAccount((*it).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); |
| +} |