OLD | NEW |
---|---|
1 // Copyright 2015 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "chrome/browser/android/signin/account_tracker_service_android.h" | 5 #include "chrome/browser/android/signin/account_tracker_service_android.h" |
6 | 6 |
7 #include "base/android/jni_array.h" | 7 #include "base/android/jni_array.h" |
8 #include "chrome/browser/profiles/profile_manager.h" | 8 #include "chrome/browser/profiles/profile_manager.h" |
9 #include "chrome/browser/signin/account_fetcher_service_factory.h" | |
9 #include "chrome/browser/signin/account_tracker_service_factory.h" | 10 #include "chrome/browser/signin/account_tracker_service_factory.h" |
11 #include "components/signin/core/browser/account_fetcher_service.h" | |
10 #include "components/signin/core/browser/account_info.h" | 12 #include "components/signin/core/browser/account_info.h" |
11 #include "jni/AccountTrackerService_jni.h" | 13 #include "jni/AccountTrackerService_jni.h" |
12 | 14 |
13 AccountTrackerServiceAndroid::AccountTrackerServiceAndroid(JNIEnv* env, | 15 AccountTrackerServiceAndroid::AccountTrackerServiceAndroid(JNIEnv* env, |
14 jobject obj) { | 16 jobject obj) |
17 : seeded_accounts_info_(false) { | |
15 java_account_tracker_service_.Reset(env, obj); | 18 java_account_tracker_service_.Reset(env, obj); |
16 } | 19 } |
17 | 20 |
18 void AccountTrackerServiceAndroid::SeedAccountsInfo(JNIEnv* env, | 21 void AccountTrackerServiceAndroid::SeedAccountsInfo(JNIEnv* env, |
19 jobject obj, | 22 jobject obj, |
20 jobjectArray gaiaIds, | 23 jobjectArray gaiaIds, |
21 jobjectArray accountNames) { | 24 jobjectArray accountNames) { |
22 std::vector<std::string> gaia_ids; | 25 std::vector<std::string> gaia_ids; |
23 std::vector<std::string> account_names; | 26 std::vector<std::string> account_names; |
24 base::android::AppendJavaStringArrayToStringVector(env, gaiaIds, &gaia_ids); | 27 base::android::AppendJavaStringArrayToStringVector(env, gaiaIds, &gaia_ids); |
25 base::android::AppendJavaStringArrayToStringVector(env, accountNames, | 28 base::android::AppendJavaStringArrayToStringVector(env, accountNames, |
26 &account_names); | 29 &account_names); |
27 DCHECK_EQ(gaia_ids.size(), account_names.size()); | 30 DCHECK_EQ(gaia_ids.size(), account_names.size()); |
28 | 31 |
29 DVLOG(1) << "AccountTrackerServiceAndroid::SeedAccountsInfo: " | 32 DVLOG(1) << "AccountTrackerServiceAndroid::SeedAccountsInfo: " |
30 << " number of accounts " << gaia_ids.size(); | 33 << " number of accounts " << gaia_ids.size(); |
31 Profile* profile = ProfileManager::GetActiveUserProfile(); | 34 Profile* profile = ProfileManager::GetActiveUserProfile(); |
32 AccountTrackerService* account_tracker_service_ = | 35 AccountTrackerService* account_tracker_service = |
33 AccountTrackerServiceFactory::GetForProfile(profile); | 36 AccountTrackerServiceFactory::GetForProfile(profile); |
34 | 37 |
35 for (unsigned int i = 0; i < gaia_ids.size(); i++) { | 38 for (unsigned int i = 0; i < gaia_ids.size(); i++) { |
36 account_tracker_service_->SeedAccountInfo(gaia_ids[i], account_names[i]); | 39 account_tracker_service->SeedAccountInfo(gaia_ids[i], account_names[i]); |
37 } | 40 } |
41 if (!seeded_accounts_info_) | |
42 AccountFetcherServiceFactory::GetForProfile(profile) | |
Mike Lerman
2015/10/01 13:54:44
nit: add { and } for multi-line statement.
| |
43 ->EnableNetworkFetches(); | |
44 seeded_accounts_info_ = true; | |
38 } | 45 } |
Roger Tawa OOO till Jul 10th
2015/10/01 14:17:38
I suspect this could come up in other situations t
anthonyvd
2015/10/01 14:33:20
Agreed that EnableNetworkFetches should be idempot
| |
39 | 46 |
40 static jlong Init(JNIEnv* env, const JavaParamRef<jobject>& obj) { | 47 static jlong Init(JNIEnv* env, const JavaParamRef<jobject>& obj) { |
41 AccountTrackerServiceAndroid* account_tracker_service_android = | 48 AccountTrackerServiceAndroid* account_tracker_service_android = |
42 new AccountTrackerServiceAndroid(env, obj); | 49 new AccountTrackerServiceAndroid(env, obj); |
43 return reinterpret_cast<intptr_t>(account_tracker_service_android); | 50 return reinterpret_cast<intptr_t>(account_tracker_service_android); |
44 } | 51 } |
45 | 52 |
46 // static | 53 // static |
47 bool AccountTrackerServiceAndroid::Register(JNIEnv* env) { | 54 bool AccountTrackerServiceAndroid::Register(JNIEnv* env) { |
48 return RegisterNativesImpl(env); | 55 return RegisterNativesImpl(env); |
49 } | 56 } |
OLD | NEW |