Commit 3f5890f1 authored by Pâris MEULEMAN's avatar Pâris MEULEMAN Committed by Commit Bot

Rename OAuth2TokenService to ProfileOAuth2TokenServiceDelegate

Align ProfileOAuth2TokenServiceDelegate's name for Android with other
implementations: in Java this changes OAuth2TokenService to
ProfileOAuth2TokenServiceDelegate and in C++ this change
OAuth2TokenServiceDelegateAndroid to
ProfileOAuth2TokenServiceDelegateAndroid.

Also mark ProfileOAuth2TokenServiceDelegate ctor package private. The
whole class could not be made package private due to
ProfileOAuth2TokenServiceDelegate.STORED_ACCOUNTS_KEY  which is accessed
from other packages. The constructor is not private as used in tests.

This change was partially performed automatically with the following
commands:
  git grep -l oauth2_token_service_delegate_android| xargs sed s/oauth2_token_service_delegate_android/profile_oauth2_token_service_delegate_android/g   -i
  git grep -l OAuth2TokenService *.java | xargs sed s/OAuth2TokenService/ProfileOAuth2TokenServiceDelegate/g -i
  git grep -l OAuth2TokenService.java | xargs sed s/OAuth2TokenService.java/ProfileOAuth2TokenServiceDelegate.java/g -i
  git grep -l OAuth2TokenServiceTest.java | xargs sed s/OAuth2TokenServiceTest.java/ProfileOAuth2TokenServiceDelegateTest.java/g -i


Bug: 934688
Change-Id: I903d82d00ee9f64532f988e02758870481f7d1dc
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1780831
Commit-Queue: Pâris Meuleman <pmeuleman@chromium.org>
Reviewed-by: default avatarBoris Sazonov <bsazonov@chromium.org>
Reviewed-by: default avatarSylvain Defresne <sdefresne@chromium.org>
Cr-Commit-Position: refs/heads/master@{#722981}
parent 03abd70e
...@@ -15,7 +15,7 @@ import org.chromium.chrome.browser.signin.SigninHelper; ...@@ -15,7 +15,7 @@ import org.chromium.chrome.browser.signin.SigninHelper;
import org.chromium.components.signin.AccountIdProvider; import org.chromium.components.signin.AccountIdProvider;
import org.chromium.components.signin.AccountManagerFacade; import org.chromium.components.signin.AccountManagerFacade;
import org.chromium.components.signin.ChromeSigninController; import org.chromium.components.signin.ChromeSigninController;
import org.chromium.components.signin.identitymanager.OAuth2TokenService; import org.chromium.components.signin.identitymanager.ProfileOAuth2TokenServiceDelegate;
import org.chromium.components.signin.test.util.AccountHolder; import org.chromium.components.signin.test.util.AccountHolder;
import org.chromium.components.signin.test.util.FakeAccountManagerDelegate; import org.chromium.components.signin.test.util.FakeAccountManagerDelegate;
import org.chromium.content_public.browser.test.util.TestThreadUtils; import org.chromium.content_public.browser.test.util.TestThreadUtils;
...@@ -141,7 +141,8 @@ public final class SigninTestUtil { ...@@ -141,7 +141,8 @@ public final class SigninTestUtil {
ChromeSigninController.get().setSignedInAccountName(null); ChromeSigninController.get().setSignedInAccountName(null);
ContextUtils.getAppSharedPreferences() ContextUtils.getAppSharedPreferences()
.edit() .edit()
.putStringSet(OAuth2TokenService.STORED_ACCOUNTS_KEY, new HashSet<>()) .putStringSet(
ProfileOAuth2TokenServiceDelegate.STORED_ACCOUNTS_KEY, new HashSet<>())
.apply(); .apply();
} }
......
...@@ -24,8 +24,6 @@ source_set("identity_manager") { ...@@ -24,8 +24,6 @@ source_set("identity_manager") {
"diagnostics_provider_impl.h", "diagnostics_provider_impl.h",
"gaia_cookie_manager_service.cc", "gaia_cookie_manager_service.cc",
"gaia_cookie_manager_service.h", "gaia_cookie_manager_service.h",
"oauth2_token_service_delegate_android.cc",
"oauth2_token_service_delegate_android.h",
"oauth_multilogin_helper.cc", "oauth_multilogin_helper.cc",
"oauth_multilogin_helper.h", "oauth_multilogin_helper.h",
"oauth_multilogin_token_fetcher.cc", "oauth_multilogin_token_fetcher.cc",
...@@ -41,6 +39,8 @@ source_set("identity_manager") { ...@@ -41,6 +39,8 @@ source_set("identity_manager") {
"profile_oauth2_token_service_builder.h", "profile_oauth2_token_service_builder.h",
"profile_oauth2_token_service_delegate.cc", "profile_oauth2_token_service_delegate.cc",
"profile_oauth2_token_service_delegate.h", "profile_oauth2_token_service_delegate.h",
"profile_oauth2_token_service_delegate_android.cc",
"profile_oauth2_token_service_delegate_android.h",
"profile_oauth2_token_service_delegate_chromeos.cc", "profile_oauth2_token_service_delegate_chromeos.cc",
"profile_oauth2_token_service_delegate_chromeos.h", "profile_oauth2_token_service_delegate_chromeos.h",
"profile_oauth2_token_service_delegate_ios.h", "profile_oauth2_token_service_delegate_ios.h",
...@@ -130,11 +130,11 @@ source_set("unit_tests") { ...@@ -130,11 +130,11 @@ source_set("unit_tests") {
"account_info_util_unittest.cc", "account_info_util_unittest.cc",
"account_tracker_service_unittest.cc", "account_tracker_service_unittest.cc",
"gaia_cookie_manager_service_unittest.cc", "gaia_cookie_manager_service_unittest.cc",
"oauth2_token_service_delegate_android_unittest.cc",
"oauth_multilogin_helper_unittest.cc", "oauth_multilogin_helper_unittest.cc",
"oauth_multilogin_token_fetcher_unittest.cc", "oauth_multilogin_token_fetcher_unittest.cc",
"primary_account_manager_unittest.cc", "primary_account_manager_unittest.cc",
"primary_account_policy_manager_impl_unittest.cc", "primary_account_policy_manager_impl_unittest.cc",
"profile_oauth2_token_service_delegate_android_unittest.cc",
"profile_oauth2_token_service_delegate_chromeos_unittest.cc", "profile_oauth2_token_service_delegate_chromeos_unittest.cc",
"profile_oauth2_token_service_delegate_ios_unittest.mm", "profile_oauth2_token_service_delegate_ios_unittest.mm",
"profile_oauth2_token_service_delegate_unittest.cc", "profile_oauth2_token_service_delegate_unittest.cc",
......
...@@ -7,6 +7,6 @@ generate_jni("jni_headers") { ...@@ -7,6 +7,6 @@ generate_jni("jni_headers") {
"//components/signin/public/identity_manager/android/java/src/org/chromium/components/signin/identitymanager/CoreAccountInfo.java", "//components/signin/public/identity_manager/android/java/src/org/chromium/components/signin/identitymanager/CoreAccountInfo.java",
"//components/signin/public/identity_manager/android/java/src/org/chromium/components/signin/identitymanager/IdentityManager.java", "//components/signin/public/identity_manager/android/java/src/org/chromium/components/signin/identitymanager/IdentityManager.java",
"//components/signin/public/identity_manager/android/java/src/org/chromium/components/signin/identitymanager/IdentityMutator.java", "//components/signin/public/identity_manager/android/java/src/org/chromium/components/signin/identitymanager/IdentityMutator.java",
"//components/signin/public/identity_manager/android/java/src/org/chromium/components/signin/identitymanager/OAuth2TokenService.java", "//components/signin/public/identity_manager/android/java/src/org/chromium/components/signin/identitymanager/ProfileOAuth2TokenServiceDelegate.java",
] ]
} }
...@@ -17,7 +17,7 @@ ...@@ -17,7 +17,7 @@
#if defined(OS_ANDROID) #if defined(OS_ANDROID)
#include "components/signin/internal/base/account_manager_facade_android.h" #include "components/signin/internal/base/account_manager_facade_android.h"
#include "components/signin/internal/identity_manager/oauth2_token_service_delegate_android.h" #include "components/signin/internal/identity_manager/profile_oauth2_token_service_delegate_android.h"
#else #else
#include "components/signin/internal/identity_manager/mutable_profile_oauth2_token_service_delegate.h" #include "components/signin/internal/identity_manager/mutable_profile_oauth2_token_service_delegate.h"
#include "components/signin/public/webdata/token_web_data.h" #include "components/signin/public/webdata/token_web_data.h"
...@@ -39,14 +39,14 @@ namespace { ...@@ -39,14 +39,14 @@ namespace {
#if defined(OS_ANDROID) #if defined(OS_ANDROID)
// TODO(crbug.com/986435) Provide AccountManagerFacade as a parameter once // TODO(crbug.com/986435) Provide AccountManagerFacade as a parameter once
// IdentityServicesProvider owns its instance management. // IdentityServicesProvider owns its instance management.
std::unique_ptr<OAuth2TokenServiceDelegateAndroid> CreateAndroidOAuthDelegate( std::unique_ptr<ProfileOAuth2TokenServiceDelegateAndroid>
AccountTrackerService* account_tracker_service) { CreateAndroidOAuthDelegate(AccountTrackerService* account_tracker_service) {
auto account_manager_facade = auto account_manager_facade =
OAuth2TokenServiceDelegateAndroid:: ProfileOAuth2TokenServiceDelegateAndroid::
get_disable_interaction_with_system_accounts() get_disable_interaction_with_system_accounts()
? nullptr ? nullptr
: AccountManagerFacadeAndroid::GetJavaObject(); : AccountManagerFacadeAndroid::GetJavaObject();
return std::make_unique<OAuth2TokenServiceDelegateAndroid>( return std::make_unique<ProfileOAuth2TokenServiceDelegateAndroid>(
account_tracker_service, account_manager_facade); account_tracker_service, account_manager_facade);
} }
#elif defined(OS_IOS) #elif defined(OS_IOS)
......
...@@ -2,8 +2,8 @@ ...@@ -2,8 +2,8 @@
// Use of this source code is governed by a BSD-style license that can be // Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file. // found in the LICENSE file.
#ifndef COMPONENTS_SIGNIN_INTERNAL_IDENTITY_MANAGER_OAUTH2_TOKEN_SERVICE_DELEGATE_ANDROID_H_ #ifndef COMPONENTS_SIGNIN_INTERNAL_IDENTITY_MANAGER_PROFILE_OAUTH2_TOKEN_SERVICE_DELEGATE_ANDROID_H_
#define COMPONENTS_SIGNIN_INTERNAL_IDENTITY_MANAGER_OAUTH2_TOKEN_SERVICE_DELEGATE_ANDROID_H_ #define COMPONENTS_SIGNIN_INTERNAL_IDENTITY_MANAGER_PROFILE_OAUTH2_TOKEN_SERVICE_DELEGATE_ANDROID_H_
#include <map> #include <map>
#include <memory> #include <memory>
...@@ -27,16 +27,16 @@ ...@@ -27,16 +27,16 @@
// See |ProfileOAuth2TokenServiceDelegate| for usage details. // See |ProfileOAuth2TokenServiceDelegate| for usage details.
// //
// Note: requests should be started from the UI thread. // Note: requests should be started from the UI thread.
class OAuth2TokenServiceDelegateAndroid class ProfileOAuth2TokenServiceDelegateAndroid
: public ProfileOAuth2TokenServiceDelegate { : public ProfileOAuth2TokenServiceDelegate {
public: public:
OAuth2TokenServiceDelegateAndroid( ProfileOAuth2TokenServiceDelegateAndroid(
AccountTrackerService* account_tracker_service, AccountTrackerService* account_tracker_service,
const base::android::JavaRef<jobject>& account_manager_facade); const base::android::JavaRef<jobject>& account_manager_facade);
~OAuth2TokenServiceDelegateAndroid() override; ~ProfileOAuth2TokenServiceDelegateAndroid() override;
// Creates a new instance of the OAuth2TokenServiceDelegateAndroid. // Creates a new instance of the ProfileOAuth2TokenServiceDelegateAndroid.
static OAuth2TokenServiceDelegateAndroid* Create(); static ProfileOAuth2TokenServiceDelegateAndroid* Create();
// Returns a reference to the corresponding Java OAuth2TokenService object. // Returns a reference to the corresponding Java OAuth2TokenService object.
base::android::ScopedJavaLocalRef<jobject> GetJavaObject() override; base::android::ScopedJavaLocalRef<jobject> GetJavaObject() override;
...@@ -45,7 +45,7 @@ class OAuth2TokenServiceDelegateAndroid ...@@ -45,7 +45,7 @@ class OAuth2TokenServiceDelegateAndroid
// tests. This prevents the token service from building the java objects // tests. This prevents the token service from building the java objects
// which require prior initialization (AccountManagerFacade) // which require prior initialization (AccountManagerFacade)
// TODO(crbug.com/1009957) Remove disable_interation_with_system_accounts_ // TODO(crbug.com/1009957) Remove disable_interation_with_system_accounts_
// from OAuth2TokenServiceDelegateAndroid // from ProfileOAuth2TokenServiceDelegateAndroid
static void set_disable_interaction_with_system_accounts() { static void set_disable_interaction_with_system_accounts() {
disable_interaction_with_system_accounts_ = true; disable_interaction_with_system_accounts_ = true;
} }
...@@ -145,10 +145,10 @@ class OAuth2TokenServiceDelegateAndroid ...@@ -145,10 +145,10 @@ class OAuth2TokenServiceDelegateAndroid
// For testing, disables the creation of the java counterpart, see // For testing, disables the creation of the java counterpart, see
// set_disable_interaction_with_system_accounts(). // set_disable_interaction_with_system_accounts().
// TODO(crbug.com/1009957) Remove disable_interation_with_system_accounts_ // TODO(crbug.com/1009957) Remove disable_interation_with_system_accounts_
// from OAuth2TokenServiceDelegateAndroid // from ProfileOAuth2TokenServiceDelegateAndroid
static bool disable_interaction_with_system_accounts_; static bool disable_interaction_with_system_accounts_;
DISALLOW_COPY_AND_ASSIGN(OAuth2TokenServiceDelegateAndroid); DISALLOW_COPY_AND_ASSIGN(ProfileOAuth2TokenServiceDelegateAndroid);
}; };
#endif // COMPONENTS_SIGNIN_INTERNAL_IDENTITY_MANAGER_OAUTH2_TOKEN_SERVICE_DELEGATE_ANDROID_H_ #endif // COMPONENTS_SIGNIN_INTERNAL_IDENTITY_MANAGER_PROFILE_OAUTH2_TOKEN_SERVICE_DELEGATE_ANDROID_H_
...@@ -2,7 +2,7 @@ ...@@ -2,7 +2,7 @@
// Use of this source code is governed by a BSD-style license that can be // Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file. // found in the LICENSE file.
#include "components/signin/internal/identity_manager/oauth2_token_service_delegate_android.h" #include "components/signin/internal/identity_manager/profile_oauth2_token_service_delegate_android.h"
#include "components/sync_preferences/testing_pref_service_syncable.h" #include "components/sync_preferences/testing_pref_service_syncable.h"
#include "testing/gmock/include/gmock/gmock.h" #include "testing/gmock/include/gmock/gmock.h"
...@@ -19,11 +19,12 @@ namespace signin { ...@@ -19,11 +19,12 @@ namespace signin {
namespace { namespace {
const std::vector<CoreAccountId> kEmptyVector; const std::vector<CoreAccountId> kEmptyVector;
class OAuth2TokenServiceDelegateAndroidForTest class OAuth2TokenServiceDelegateAndroidForTest
: public OAuth2TokenServiceDelegateAndroid { : public ProfileOAuth2TokenServiceDelegateAndroid {
public: public:
OAuth2TokenServiceDelegateAndroidForTest( OAuth2TokenServiceDelegateAndroidForTest(
AccountTrackerService* account_tracker_service) AccountTrackerService* account_tracker_service)
: OAuth2TokenServiceDelegateAndroid(account_tracker_service, nullptr) {} : ProfileOAuth2TokenServiceDelegateAndroid(account_tracker_service,
nullptr) {}
MOCK_METHOD1(SetAccounts, void(const std::vector<CoreAccountId>&)); MOCK_METHOD1(SetAccounts, void(const std::vector<CoreAccountId>&));
}; };
......
...@@ -20,7 +20,7 @@ android_library("java") { ...@@ -20,7 +20,7 @@ android_library("java") {
"java/src/org/chromium/components/signin/identitymanager/CoreAccountInfo.java", "java/src/org/chromium/components/signin/identitymanager/CoreAccountInfo.java",
"java/src/org/chromium/components/signin/identitymanager/IdentityManager.java", "java/src/org/chromium/components/signin/identitymanager/IdentityManager.java",
"java/src/org/chromium/components/signin/identitymanager/IdentityMutator.java", "java/src/org/chromium/components/signin/identitymanager/IdentityMutator.java",
"java/src/org/chromium/components/signin/identitymanager/OAuth2TokenService.java", "java/src/org/chromium/components/signin/identitymanager/ProfileOAuth2TokenServiceDelegate.java",
] ]
annotation_processor_deps = [ "//base/android/jni_generator:jni_processor" ] annotation_processor_deps = [ "//base/android/jni_generator:jni_processor" ]
...@@ -41,5 +41,5 @@ android_library("javatests") { ...@@ -41,5 +41,5 @@ android_library("javatests") {
"//third_party/junit", "//third_party/junit",
] ]
java_files = [ "javatests/src/org/chromium/components/signin/identitymanager/OAuth2TokenServiceTest.java" ] java_files = [ "javatests/src/org/chromium/components/signin/identitymanager/ProfileOAuth2TokenServiceDelegateTest.java" ]
} }
...@@ -5,13 +5,13 @@ specific_include_rules = { ...@@ -5,13 +5,13 @@ specific_include_rules = {
"IdentityManager.java": [ "IdentityManager.java": [
"+components/signin/core/browser/android/java/src/org/chromium/components/signin/AccountManagerFacade.java", "+components/signin/core/browser/android/java/src/org/chromium/components/signin/AccountManagerFacade.java",
], ],
"OAuth2TokenService.java": [ "ProfileOAuth2TokenServiceDelegate.java": [
"+components/signin/core/browser/android/java/src/org/chromium/components/signin/AccountManagerFacade.java", "+components/signin/core/browser/android/java/src/org/chromium/components/signin/AccountManagerFacade.java",
"+components/signin/core/browser/android/java/src/org/chromium/components/signin/AccountTrackerService.java", "+components/signin/core/browser/android/java/src/org/chromium/components/signin/AccountTrackerService.java",
"+components/signin/core/browser/android/java/src/org/chromium/components/signin/ChromeSigninController.java", "+components/signin/core/browser/android/java/src/org/chromium/components/signin/ChromeSigninController.java",
"+components/signin/core/browser/android/java/src/org/chromium/components/signin/AuthException.java", "+components/signin/core/browser/android/java/src/org/chromium/components/signin/AuthException.java",
], ],
"OAuth2TokenServiceTest.java": [ "ProfileOAuth2TokenServiceDelegateTest.java": [
"+components/signin/core/browser/android/java/src/org/chromium/components/signin/AccountManagerFacade.java", "+components/signin/core/browser/android/java/src/org/chromium/components/signin/AccountManagerFacade.java",
"+components/signin/core/browser/android/javatests/src/org/chromium/components/signin/test/util/AccountHolder.java", "+components/signin/core/browser/android/javatests/src/org/chromium/components/signin/test/util/AccountHolder.java",
"+components/signin/core/browser/android/javatests/src/org/chromium/components/signin/test/util/AccountManagerTestRule.java", "+components/signin/core/browser/android/javatests/src/org/chromium/components/signin/test/util/AccountManagerTestRule.java",
......
...@@ -42,10 +42,11 @@ public class IdentityManager { ...@@ -42,10 +42,11 @@ public class IdentityManager {
/** /**
* A simple callback for getAccessToken. * A simple callback for getAccessToken.
*/ */
public interface GetAccessTokenCallback extends OAuth2TokenService.GetAccessTokenCallback {} public interface GetAccessTokenCallback
extends ProfileOAuth2TokenServiceDelegate.GetAccessTokenCallback {}
private long mNativeIdentityManager; private long mNativeIdentityManager;
private OAuth2TokenService mOAuth2TokenService; private ProfileOAuth2TokenServiceDelegate mProfileOAuth2TokenServiceDelegate;
private final ObserverList<Observer> mObservers = new ObserverList<>(); private final ObserverList<Observer> mObservers = new ObserverList<>();
...@@ -53,16 +54,17 @@ public class IdentityManager { ...@@ -53,16 +54,17 @@ public class IdentityManager {
* Called by native to create an instance of IdentityManager. * Called by native to create an instance of IdentityManager.
*/ */
@CalledByNative @CalledByNative
private static IdentityManager create( private static IdentityManager create(long nativeIdentityManager,
long nativeIdentityManager, OAuth2TokenService oAuth2TokenService) { ProfileOAuth2TokenServiceDelegate profileOAuth2TokenServiceDelegate) {
assert nativeIdentityManager != 0; assert nativeIdentityManager != 0;
return new IdentityManager(nativeIdentityManager, oAuth2TokenService); return new IdentityManager(nativeIdentityManager, profileOAuth2TokenServiceDelegate);
} }
@VisibleForTesting @VisibleForTesting
public IdentityManager(long nativeIdentityManager, OAuth2TokenService oAuth2TokenService) { public IdentityManager(long nativeIdentityManager,
ProfileOAuth2TokenServiceDelegate profileOAuth2TokenServiceDelegate) {
mNativeIdentityManager = nativeIdentityManager; mNativeIdentityManager = nativeIdentityManager;
mOAuth2TokenService = oAuth2TokenService; mProfileOAuth2TokenServiceDelegate = profileOAuth2TokenServiceDelegate;
} }
/** /**
...@@ -160,9 +162,9 @@ public class IdentityManager { ...@@ -160,9 +162,9 @@ public class IdentityManager {
*/ */
@MainThread @MainThread
public void getAccessToken(Account account, String scope, GetAccessTokenCallback callback) { public void getAccessToken(Account account, String scope, GetAccessTokenCallback callback) {
assert mOAuth2TokenService != null; assert mProfileOAuth2TokenServiceDelegate != null;
// TODO(crbug.com/934688) The following should call a JNI method instead. // TODO(crbug.com/934688) The following should call a JNI method instead.
mOAuth2TokenService.getAccessToken(account, scope, callback); mProfileOAuth2TokenServiceDelegate.getAccessToken(account, scope, callback);
} }
/** /**
...@@ -182,7 +184,8 @@ public class IdentityManager { ...@@ -182,7 +184,8 @@ public class IdentityManager {
public static void getAccessTokenWithFacade(AccountManagerFacade accountManagerFacade, public static void getAccessTokenWithFacade(AccountManagerFacade accountManagerFacade,
Account account, String scope, GetAccessTokenCallback callback) { Account account, String scope, GetAccessTokenCallback callback) {
// TODO(crbug.com/934688) The following should call a JNI method instead. // TODO(crbug.com/934688) The following should call a JNI method instead.
OAuth2TokenService.getAccessTokenWithFacade(accountManagerFacade, account, scope, callback); ProfileOAuth2TokenServiceDelegate.getAccessTokenWithFacade(
accountManagerFacade, account, scope, callback);
} }
/** /**
...@@ -191,10 +194,10 @@ public class IdentityManager { ...@@ -191,10 +194,10 @@ public class IdentityManager {
*/ */
@MainThread @MainThread
public void invalidateAccessToken(String accessToken) { public void invalidateAccessToken(String accessToken) {
assert mOAuth2TokenService != null; assert mProfileOAuth2TokenServiceDelegate != null;
// TODO(crbug.com/934688) The following should call a JNI method instead. // TODO(crbug.com/934688) The following should call a JNI method instead.
mOAuth2TokenService.invalidateAccessToken(accessToken); mProfileOAuth2TokenServiceDelegate.invalidateAccessToken(accessToken);
} }
/** /**
...@@ -213,7 +216,7 @@ public class IdentityManager { ...@@ -213,7 +216,7 @@ public class IdentityManager {
public static void getNewAccessTokenWithFacade(AccountManagerFacade accountManagerFacade, public static void getNewAccessTokenWithFacade(AccountManagerFacade accountManagerFacade,
Account account, @Nullable String oldToken, String scope, Account account, @Nullable String oldToken, String scope,
GetAccessTokenCallback callback) { GetAccessTokenCallback callback) {
OAuth2TokenService.getNewAccessTokenWithFacade( ProfileOAuth2TokenServiceDelegate.getNewAccessTokenWithFacade(
accountManagerFacade, account, oldToken, scope, callback); accountManagerFacade, account, oldToken, scope, callback);
} }
......
...@@ -31,14 +31,14 @@ import java.util.concurrent.atomic.AtomicBoolean; ...@@ -31,14 +31,14 @@ import java.util.concurrent.atomic.AtomicBoolean;
import java.util.concurrent.atomic.AtomicInteger; import java.util.concurrent.atomic.AtomicInteger;
/** /**
* Java instance for the native OAuth2TokenService. * Java instance for the native ProfileOAuth2TokenServiceDelegate.
* <p/> * <p/>
* This class forwards calls to request or invalidate access tokens made by native code to * This class forwards calls to request or invalidate access tokens made by native code to
* AccountManagerFacade and forwards callbacks to native code. * AccountManagerFacade and forwards callbacks to native code.
* <p/> * <p/>
*/ */
@VisibleForTesting(otherwise = VisibleForTesting.PACKAGE_PRIVATE) @VisibleForTesting(otherwise = VisibleForTesting.PACKAGE_PRIVATE)
public final class OAuth2TokenService public final class ProfileOAuth2TokenServiceDelegate
implements AccountTrackerService.OnSystemAccountsSeededListener { implements AccountTrackerService.OnSystemAccountsSeededListener {
private static final String TAG = "OAuth2TokenService"; private static final String TAG = "OAuth2TokenService";
...@@ -66,7 +66,7 @@ public final class OAuth2TokenService ...@@ -66,7 +66,7 @@ public final class OAuth2TokenService
private static final String OAUTH2_SCOPE_PREFIX = "oauth2:"; private static final String OAUTH2_SCOPE_PREFIX = "oauth2:";
private final long mNativeOAuth2TokenServiceDelegate; private final long mNativeProfileOAuth2TokenServiceDelegate;
private final AccountTrackerService mAccountTrackerService; private final AccountTrackerService mAccountTrackerService;
private final AccountManagerFacade mAccountManagerFacade; private final AccountManagerFacade mAccountManagerFacade;
...@@ -76,10 +76,10 @@ public final class OAuth2TokenService ...@@ -76,10 +76,10 @@ public final class OAuth2TokenService
private String mPendingUpdateAccountId; private String mPendingUpdateAccountId;
@VisibleForTesting @VisibleForTesting
public OAuth2TokenService(long nativeOAuth2TokenServiceDelegate, ProfileOAuth2TokenServiceDelegate(long nativeProfileOAuth2TokenServiceDelegateDelegate,
AccountTrackerService accountTrackerService, AccountTrackerService accountTrackerService,
AccountManagerFacade accountManagerFacade) { AccountManagerFacade accountManagerFacade) {
mNativeOAuth2TokenServiceDelegate = nativeOAuth2TokenServiceDelegate; mNativeProfileOAuth2TokenServiceDelegate = nativeProfileOAuth2TokenServiceDelegateDelegate;
mAccountTrackerService = accountTrackerService; mAccountTrackerService = accountTrackerService;
mAccountManagerFacade = accountManagerFacade; mAccountManagerFacade = accountManagerFacade;
...@@ -90,12 +90,14 @@ public final class OAuth2TokenService ...@@ -90,12 +90,14 @@ public final class OAuth2TokenService
} }
@CalledByNative @CalledByNative
private static OAuth2TokenService create(long nativeOAuth2TokenServiceDelegate, private static ProfileOAuth2TokenServiceDelegate create(
long nativeProfileOAuth2TokenServiceDelegateDelegate,
AccountTrackerService accountTrackerService, AccountTrackerService accountTrackerService,
AccountManagerFacade accountManagerFacade) { AccountManagerFacade accountManagerFacade) {
assert nativeOAuth2TokenServiceDelegate != 0; assert nativeProfileOAuth2TokenServiceDelegateDelegate != 0;
return new OAuth2TokenService( return new ProfileOAuth2TokenServiceDelegate(
nativeOAuth2TokenServiceDelegate, accountTrackerService, accountManagerFacade); nativeProfileOAuth2TokenServiceDelegateDelegate, accountTrackerService,
accountManagerFacade);
} }
private Account getAccountOrNullFromUsername(String username) { private Account getAccountOrNullFromUsername(String username) {
...@@ -118,8 +120,8 @@ public final class OAuth2TokenService ...@@ -118,8 +120,8 @@ public final class OAuth2TokenService
@CalledByNative @CalledByNative
@VisibleForTesting @VisibleForTesting
String[] getSystemAccountNames() { String[] getSystemAccountNames() {
// TODO(https://crbug.com/768366): Remove this after adding cache to account manager facade. // TODO(https://crbug.com/768366): Remove this after adding cache to account manager
// This function is called by native code on UI thread. // facade. This function is called by native code on UI thread.
try (StrictModeContext ignored = StrictModeContext.allowDiskReads()) { try (StrictModeContext ignored = StrictModeContext.allowDiskReads()) {
List<String> accountNames = mAccountManagerFacade.tryGetGoogleAccountNames(); List<String> accountNames = mAccountManagerFacade.tryGetGoogleAccountNames();
return accountNames.toArray(new String[accountNames.size()]); return accountNames.toArray(new String[accountNames.size()]);
...@@ -142,7 +144,8 @@ public final class OAuth2TokenService ...@@ -142,7 +144,8 @@ public final class OAuth2TokenService
* Called by native to retrieve OAuth2 tokens. * Called by native to retrieve OAuth2 tokens.
* @param username The native username (email address). * @param username The native username (email address).
* @param scope The scope to get an auth token for (without Android-style 'oauth2:' prefix). * @param scope The scope to get an auth token for (without Android-style 'oauth2:' prefix).
* @param nativeCallback The pointer to the native callback that should be run upon completion. * @param nativeCallback The pointer to the native callback that should be run upon
* completion.
*/ */
@MainThread @MainThread
@CalledByNative @CalledByNative
...@@ -151,7 +154,8 @@ public final class OAuth2TokenService ...@@ -151,7 +154,8 @@ public final class OAuth2TokenService
Account account = getAccountOrNullFromUsername(username); Account account = getAccountOrNullFromUsername(username);
if (account == null) { if (account == null) {
ThreadUtils.postOnUiThread(() -> { ThreadUtils.postOnUiThread(() -> {
OAuth2TokenServiceJni.get().onOAuth2TokenFetched(null, false, nativeCallback); ProfileOAuth2TokenServiceDelegateJni.get().onOAuth2TokenFetched(
null, false, nativeCallback);
}); });
return; return;
} }
...@@ -159,20 +163,21 @@ public final class OAuth2TokenService ...@@ -159,20 +163,21 @@ public final class OAuth2TokenService
getAccessToken(account, oauth2Scope, new GetAccessTokenCallback() { getAccessToken(account, oauth2Scope, new GetAccessTokenCallback() {
@Override @Override
public void onGetTokenSuccess(String token) { public void onGetTokenSuccess(String token) {
OAuth2TokenServiceJni.get().onOAuth2TokenFetched(token, false, nativeCallback); ProfileOAuth2TokenServiceDelegateJni.get().onOAuth2TokenFetched(
token, false, nativeCallback);
} }
@Override @Override
public void onGetTokenFailure(boolean isTransientError) { public void onGetTokenFailure(boolean isTransientError) {
OAuth2TokenServiceJni.get().onOAuth2TokenFetched( ProfileOAuth2TokenServiceDelegateJni.get().onOAuth2TokenFetched(
null, isTransientError, nativeCallback); null, isTransientError, nativeCallback);
} }
}); });
} }
/** /**
* Call this method to retrieve an OAuth2 access token for the given account and scope. Please * Call this method to retrieve an OAuth2 access token for the given account and scope.
* note that this method expects a scope with 'oauth2:' prefix. * Please note that this method expects a scope with 'oauth2:' prefix.
* @param account the account to get the access token for. * @param account the account to get the access token for.
* @param scope The scope to get an auth token for (with Android-style 'oauth2:' prefix). * @param scope The scope to get an auth token for (with Android-style 'oauth2:' prefix).
* @param callback called on successful and unsuccessful fetching of auth token. * @param callback called on successful and unsuccessful fetching of auth token.
...@@ -283,8 +288,9 @@ public final class OAuth2TokenService ...@@ -283,8 +288,9 @@ public final class OAuth2TokenService
} }
// Temporarily allowing disk read while fixing. TODO: http://crbug.com/618096. // Temporarily allowing disk read while fixing. TODO: http://crbug.com/618096.
// This function is called in RefreshTokenIsAvailable of OAuth2TokenService which is // This function is called in RefreshTokenIsAvailable of
// expected to be called in the UI thread synchronously. // ProfileOAuth2TokenServiceDelegate which is expected to be called in the UI thread
// synchronously.
try (StrictModeContext ignored = StrictModeContext.allowDiskReads()) { try (StrictModeContext ignored = StrictModeContext.allowDiskReads()) {
return AccountManagerFacade.get().hasAccountForName(accountName); return AccountManagerFacade.get().hasAccountForName(accountName);
} }
...@@ -317,8 +323,8 @@ public final class OAuth2TokenService ...@@ -317,8 +323,8 @@ public final class OAuth2TokenService
} }
private void reloadAllAccountsWithPrimaryAccountAfterSeeding(@Nullable String accountId) { private void reloadAllAccountsWithPrimaryAccountAfterSeeding(@Nullable String accountId) {
OAuth2TokenServiceJni.get().reloadAllAccountsWithPrimaryAccountAfterSeeding( ProfileOAuth2TokenServiceDelegateJni.get().reloadAllAccountsWithPrimaryAccountAfterSeeding(
mNativeOAuth2TokenServiceDelegate, accountId); mNativeProfileOAuth2TokenServiceDelegate, accountId);
} }
private static String[] getStoredAccounts() { private static String[] getStoredAccounts() {
...@@ -350,8 +356,8 @@ public final class OAuth2TokenService ...@@ -350,8 +356,8 @@ public final class OAuth2TokenService
/** /**
* A helper class to encapsulate network connection retry logic for AuthTasks. * A helper class to encapsulate network connection retry logic for AuthTasks.
* *
* The task will be run on the background thread. If it encounters a transient error, it will * The task will be run on the background thread. If it encounters a transient error, it
* wait for a network change and retry up to MAX_TRIES times. * will wait for a network change and retry up to MAX_TRIES times.
*/ */
private static class ConnectionRetry<T> private static class ConnectionRetry<T>
implements NetworkChangeNotifier.ConnectionTypeObserver { implements NetworkChangeNotifier.ConnectionTypeObserver {
...@@ -423,6 +429,6 @@ public final class OAuth2TokenService ...@@ -423,6 +429,6 @@ public final class OAuth2TokenService
interface Natives { interface Natives {
void onOAuth2TokenFetched(String authToken, boolean isTransientError, long nativeCallback); void onOAuth2TokenFetched(String authToken, boolean isTransientError, long nativeCallback);
void reloadAllAccountsWithPrimaryAccountAfterSeeding( void reloadAllAccountsWithPrimaryAccountAfterSeeding(
long nativeOAuth2TokenServiceDelegateAndroid, @Nullable String accountId); long nativeProfileOAuth2TokenServiceDelegateAndroid, @Nullable String accountId);
} }
} }
...@@ -26,20 +26,21 @@ import org.chromium.components.signin.test.util.AccountManagerTestRule; ...@@ -26,20 +26,21 @@ import org.chromium.components.signin.test.util.AccountManagerTestRule;
import java.util.Arrays; import java.util.Arrays;
import java.util.concurrent.CountDownLatch; import java.util.concurrent.CountDownLatch;
/** Tests for OAuth2TokenService. */ /** Tests for ProfileOAuth2TokenServiceDelegate. */
@RunWith(BaseJUnit4ClassRunner.class) @RunWith(BaseJUnit4ClassRunner.class)
public class OAuth2TokenServiceTest { public class ProfileOAuth2TokenServiceDelegateTest {
private AdvancedMockContext mContext; private AdvancedMockContext mContext;
@Rule @Rule
public AccountManagerTestRule mAccountManagerTestRule = new AccountManagerTestRule(); public AccountManagerTestRule mAccountManagerTestRule = new AccountManagerTestRule();
private OAuth2TokenService mOAuth2TokenService; private ProfileOAuth2TokenServiceDelegate mProfileOAuth2TokenServiceDelegate;
/** /**
* Class handling GetAccessToken callbacks and providing a blocking {@link * Class handling GetAccessToken callbacks and providing a blocking {@link
* #getToken()}. * #getToken()}.
*/ */
class GetAccessTokenCallbackForTest implements OAuth2TokenService.GetAccessTokenCallback { class GetAccessTokenCallbackForTest
implements ProfileOAuth2TokenServiceDelegate.GetAccessTokenCallback {
private String mToken; private String mToken;
final CountDownLatch mTokenRetrievedCountDown = new CountDownLatch(1); final CountDownLatch mTokenRetrievedCountDown = new CountDownLatch(1);
...@@ -72,7 +73,8 @@ public class OAuth2TokenServiceTest { ...@@ -72,7 +73,8 @@ public class OAuth2TokenServiceTest {
@Before @Before
public void setUp() { public void setUp() {
mContext = new AdvancedMockContext(InstrumentationRegistry.getTargetContext()); mContext = new AdvancedMockContext(InstrumentationRegistry.getTargetContext());
mOAuth2TokenService = new OAuth2TokenService(0 /*nativeOAuth2TokenServiceDelegate*/, mProfileOAuth2TokenServiceDelegate = new ProfileOAuth2TokenServiceDelegate(
0 /*nativeProfileOAuth2TokenServiceDelegateDelegate*/,
null /* AccountTrackerService */, AccountManagerFacade.get()); null /* AccountTrackerService */, AccountManagerFacade.get());
} }
...@@ -85,7 +87,7 @@ public class OAuth2TokenServiceTest { ...@@ -85,7 +87,7 @@ public class OAuth2TokenServiceTest {
@SmallTest @SmallTest
@Feature({"Sync"}) @Feature({"Sync"})
public void testGetAccountsNoAccountsRegistered() { public void testGetAccountsNoAccountsRegistered() {
String[] accounts = OAuth2TokenService.getAccounts(); String[] accounts = ProfileOAuth2TokenServiceDelegate.getAccounts();
Assert.assertEquals("There should be no accounts registered", 0, accounts.length); Assert.assertEquals("There should be no accounts registered", 0, accounts.length);
} }
...@@ -97,11 +99,11 @@ public class OAuth2TokenServiceTest { ...@@ -97,11 +99,11 @@ public class OAuth2TokenServiceTest {
AccountHolder accountHolder1 = AccountHolder.builder(account1).build(); AccountHolder accountHolder1 = AccountHolder.builder(account1).build();
mAccountManagerTestRule.addAccount(accountHolder1); mAccountManagerTestRule.addAccount(accountHolder1);
String[] sysAccounts = mOAuth2TokenService.getSystemAccountNames(); String[] sysAccounts = mProfileOAuth2TokenServiceDelegate.getSystemAccountNames();
Assert.assertEquals("There should be one registered account", 1, sysAccounts.length); Assert.assertEquals("There should be one registered account", 1, sysAccounts.length);
Assert.assertEquals("The account should be " + account1, account1.name, sysAccounts[0]); Assert.assertEquals("The account should be " + account1, account1.name, sysAccounts[0]);
String[] accounts = OAuth2TokenService.getAccounts(); String[] accounts = ProfileOAuth2TokenServiceDelegate.getAccounts();
Assert.assertEquals("There should be zero registered account", 0, accounts.length); Assert.assertEquals("There should be zero registered account", 0, accounts.length);
} }
...@@ -116,14 +118,14 @@ public class OAuth2TokenServiceTest { ...@@ -116,14 +118,14 @@ public class OAuth2TokenServiceTest {
AccountHolder accountHolder2 = AccountHolder.builder(account2).build(); AccountHolder accountHolder2 = AccountHolder.builder(account2).build();
mAccountManagerTestRule.addAccount(accountHolder2); mAccountManagerTestRule.addAccount(accountHolder2);
String[] sysAccounts = mOAuth2TokenService.getSystemAccountNames(); String[] sysAccounts = mProfileOAuth2TokenServiceDelegate.getSystemAccountNames();
Assert.assertEquals("There should be one registered account", 2, sysAccounts.length); Assert.assertEquals("There should be one registered account", 2, sysAccounts.length);
Assert.assertTrue("The list should contain " + account1, Assert.assertTrue("The list should contain " + account1,
Arrays.asList(sysAccounts).contains(account1.name)); Arrays.asList(sysAccounts).contains(account1.name));
Assert.assertTrue("The list should contain " + account2, Assert.assertTrue("The list should contain " + account2,
Arrays.asList(sysAccounts).contains(account2.name)); Arrays.asList(sysAccounts).contains(account2.name));
String[] accounts = OAuth2TokenService.getAccounts(); String[] accounts = ProfileOAuth2TokenServiceDelegate.getAccounts();
Assert.assertEquals("There should be zero registered account", 0, accounts.length); Assert.assertEquals("There should be zero registered account", 0, accounts.length);
} }
...@@ -157,8 +159,9 @@ public class OAuth2TokenServiceTest { ...@@ -157,8 +159,9 @@ public class OAuth2TokenServiceTest {
mAccountManagerTestRule.addAccount(accountHolder); mAccountManagerTestRule.addAccount(accountHolder);
GetAccessTokenCallbackForTest callback = new GetAccessTokenCallbackForTest(); GetAccessTokenCallbackForTest callback = new GetAccessTokenCallbackForTest();
ThreadUtils.runOnUiThreadBlocking( ThreadUtils.runOnUiThreadBlocking(() -> {
() -> { mOAuth2TokenService.getAccessToken(account, scope, callback); }); mProfileOAuth2TokenServiceDelegate.getAccessToken(account, scope, callback);
});
Assert.assertEquals(expectedToken, callback.getToken()); Assert.assertEquals(expectedToken, callback.getToken());
} }
......
...@@ -20,7 +20,7 @@ ...@@ -20,7 +20,7 @@
#include "google_apis/gaia/gaia_constants.h" #include "google_apis/gaia/gaia_constants.h"
#if defined(OS_ANDROID) #if defined(OS_ANDROID)
#include "components/signin/internal/identity_manager/oauth2_token_service_delegate_android.h" #include "components/signin/internal/identity_manager/profile_oauth2_token_service_delegate_android.h"
#endif #endif
namespace signin { namespace signin {
...@@ -351,7 +351,7 @@ void DisableAccessTokenFetchRetries(IdentityManager* identity_manager) { ...@@ -351,7 +351,7 @@ void DisableAccessTokenFetchRetries(IdentityManager* identity_manager) {
#if defined(OS_ANDROID) #if defined(OS_ANDROID)
void DisableInteractionWithSystemAccounts() { void DisableInteractionWithSystemAccounts() {
OAuth2TokenServiceDelegateAndroid:: ProfileOAuth2TokenServiceDelegateAndroid::
set_disable_interaction_with_system_accounts(); set_disable_interaction_with_system_accounts();
} }
#endif #endif
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment