Skip to content

Commit

Permalink
Add an Android specific ChildAccountInfoFetcher that talks to the Acc…
Browse files Browse the repository at this point in the history
…ountManager.

Based on http://crrev.com/1224643007

BUG=508054

Review URL: https://codereview.chromium.org/1231653007

Cr-Commit-Position: refs/heads/master@{#340774}
  • Loading branch information
knn authored and Commit bot committed Jul 28, 2015
1 parent 2341b80 commit 2d7f8e7
Show file tree
Hide file tree
Showing 22 changed files with 573 additions and 230 deletions.
5 changes: 3 additions & 2 deletions chrome/android/BUILD.gn
Original file line number Diff line number Diff line change
Expand Up @@ -126,10 +126,11 @@ android_library("chrome_java") {
"//components/gcm_driver/android:gcm_driver_java",
"//components/invalidation/impl:java",
"//components/navigation_interception/android:navigation_interception_java",
"//components/safe_json/android:safe_json_java",
"//components/service_tab_launcher:service_tab_launcher_java",
"//components/policy/android:policy_java",
"//components/precache/android:precache_java",
"//components/safe_json/android:safe_json_java",
"//components/service_tab_launcher:service_tab_launcher_java",
"//components/signin/core/browser/android:java",
"//components/variations/android:variations_java",
"//components/web_contents_delegate_android:web_contents_delegate_android_java",
"//content/public/android:content_java",
Expand Down
10 changes: 5 additions & 5 deletions chrome/browser/android/chrome_jni_registrar.cc
Original file line number Diff line number Diff line change
Expand Up @@ -134,6 +134,7 @@
#include "components/policy/core/browser/android/component_jni_registrar.h"
#include "components/safe_json/android/component_jni_registrar.h"
#include "components/service_tab_launcher/component_jni_registrar.h"
#include "components/signin/core/browser/android/component_jni_registrar.h"
#include "components/variations/android/component_jni_registrar.h"
#include "components/web_contents_delegate_android/component_jni_registrar.h"

Expand All @@ -156,6 +157,7 @@ static base::android::RegistrationMethod kChromeRegisteredMethods[] = {
navigation_interception::RegisterNavigationInterceptionJni},
{"Policy", policy::android::RegisterPolicy},
{"SafeJson", safe_json::android::RegisterSafeJsonJni},
{"Signin", signin::android::RegisterSigninJni},
{"WebContentsDelegateAndroid",
web_contents_delegate_android::RegisterWebContentsDelegateAndroidJni},
// Register JNI for chrome classes.
Expand All @@ -174,9 +176,8 @@ static base::android::RegistrationMethod kChromeRegisteredMethods[] = {
RegisterAutofillDialogControllerAndroid},
{"AutofillDialogResult",
autofill::AutofillDialogResult::RegisterAutofillDialogResult},
{"AutofillKeyboardAccessory",
autofill::AutofillKeyboardAccessoryView::
RegisterAutofillKeyboardAccessoryView},
{"AutofillKeyboardAccessory", autofill::AutofillKeyboardAccessoryView::
RegisterAutofillKeyboardAccessoryView},
{"AutofillLoggerAndroid", autofill::AutofillLoggerAndroid::Register},
{"AutofillPopup",
autofill::AutofillPopupViewAndroid::RegisterAutofillPopupViewAndroid},
Expand Down Expand Up @@ -252,8 +253,7 @@ static base::android::RegistrationMethod kChromeRegisteredMethods[] = {
NotificationUIManagerAndroid::RegisterNotificationUIManager},
{"OAuth2TokenServiceDelegateAndroid",
OAuth2TokenServiceDelegateAndroid::Register},
{"OfflinePageBridge",
offline_pages::android::RegisterOfflinePageBridge},
{"OfflinePageBridge", offline_pages::android::RegisterOfflinePageBridge},
{"OmniboxPrerender", RegisterOmniboxPrerender},
{"OmniboxUrlEmphasizer",
OmniboxUrlEmphasizer::RegisterOmniboxUrlEmphasizer},
Expand Down
1 change: 1 addition & 0 deletions chrome/chrome.gyp
Original file line number Diff line number Diff line change
Expand Up @@ -603,6 +603,7 @@
'../components/components.gyp:precache_java',
'../components/components.gyp:safe_json_java',
'../components/components.gyp:service_tab_launcher_java',
'../components/components.gyp:signin_core_browser_java',
'../components/components.gyp:variations_java',
'../components/components.gyp:web_contents_delegate_android_java',
'../content/content.gyp:content_java',
Expand Down
1 change: 1 addition & 0 deletions components/components_tests.gyp
Original file line number Diff line number Diff line change
Expand Up @@ -1554,6 +1554,7 @@
'dependencies': [
'components_unittests',
'components.gyp:invalidation_java',
'components.gyp:signin_core_browser_java',
],
'variables': {
'test_suite_name': 'components_unittests',
Expand Down
44 changes: 44 additions & 0 deletions components/signin.gypi
Original file line number Diff line number Diff line change
Expand Up @@ -59,8 +59,14 @@
'signin/core/browser/account_reconcilor.h',
'signin/core/browser/account_tracker_service.cc',
'signin/core/browser/account_tracker_service.h',
'signin/core/browser/android/component_jni_registrar.cc',
'signin/core/browser/android/component_jni_registrar.h',
'signin/core/browser/child_account_info_fetcher.cc',
'signin/core/browser/child_account_info_fetcher.h',
'signin/core/browser/child_account_info_fetcher_android.cc',
'signin/core/browser/child_account_info_fetcher_android.h',
'signin/core/browser/child_account_info_fetcher_impl.cc',
'signin/core/browser/child_account_info_fetcher_impl.h',
'signin/core/browser/device_activity_fetcher.cc',
'signin/core/browser/device_activity_fetcher.h',
'signin/core/browser/gaia_cookie_manager_service.cc',
Expand Down Expand Up @@ -97,6 +103,15 @@
'signin/core/browser/webdata/token_web_data.h',
],
'conditions': [
['OS=="android"', {
'dependencies': [
'signin_core_browser_jni_headers',
],
'sources!': [
'signin/core/browser/child_account_info_fetcher_impl.cc',
'signin/core/browser/child_account_info_fetcher_impl.h',
],
}],
['chromeos==1', {
'sources!': [
'signin/core/browser/signin_manager.cc',
Expand Down Expand Up @@ -131,6 +146,35 @@
},
],
'conditions': [
['OS == "android"', {
'targets': [
{
# GN version: //components/signin/core/browser/android:java
'target_name': 'signin_core_browser_java',
'type': 'none',
'dependencies': [
'../base/base.gyp:base',
'../sync/sync.gyp:sync_java',
],
'variables': {
'java_in_dir': 'signin/core/browser/android/java',
},
'includes': [ '../build/java.gypi' ],
},
{
# GN version: //components/signin/core/browser/android:jni_headers
'target_name': 'signin_core_browser_jni_headers',
'type': 'none',
'sources': [
'signin/core/browser/android/java/src/org/chromium/components/signin/ChildAccountInfoFetcher.java',
],
'variables': {
'jni_gen_package': 'components/signin',
},
'includes': [ '../build/jni_generator.gypi' ],
},
],
}],
['OS == "ios"', {
# GN version: //components/signin/core/browser:ios
'targets': [
Expand Down
14 changes: 14 additions & 0 deletions components/signin/core/browser/BUILD.gn
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,14 @@ static_library("browser") {
"account_reconcilor.h",
"account_tracker_service.cc",
"account_tracker_service.h",
"android/component_jni_registrar.cc",
"android/component_jni_registrar.h",
"child_account_info_fetcher.cc",
"child_account_info_fetcher.h",
"child_account_info_fetcher_android.cc",
"child_account_info_fetcher_android.h",
"child_account_info_fetcher_impl.cc",
"child_account_info_fetcher_impl.h",
"device_activity_fetcher.cc",
"device_activity_fetcher.h",
"gaia_cookie_manager_service.cc",
Expand Down Expand Up @@ -73,6 +79,14 @@ static_library("browser") {
if (is_chromeos) {
sources -= [ "signin_manager.cc" ]
}

if (is_android) {
sources -= [
"child_account_info_fetcher_impl.cc",
"child_account_info_fetcher_impl.h",
]
deps += [ "android:jni_headers" ]
}
}

static_library("test_support") {
Expand Down
1 change: 1 addition & 0 deletions components/signin/core/browser/DEPS
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,5 @@ specific_include_rules = {
include_rules = [
"+components/invalidation/public",
"+google/cacheinvalidation",
"+jni",
]
11 changes: 6 additions & 5 deletions components/signin/core/browser/account_fetcher_service.cc
Original file line number Diff line number Diff line change
Expand Up @@ -185,9 +185,9 @@ void AccountFetcherService::StartFetchingChildInfo(
if (!AccountSupportsUserInfo(account_id))
return;
child_request_account_id_ = account_id;
child_info_request_.reset(new ChildAccountInfoFetcher(
token_service_, signin_client_->GetURLRequestContext(), this,
invalidation_service_, child_request_account_id_));
child_info_request_.reset(ChildAccountInfoFetcher::CreateFrom(
child_request_account_id_, this, token_service_,
signin_client_->GetURLRequestContext(), invalidation_service_));
}

void AccountFetcherService::ResetChildInfo() {
Expand Down Expand Up @@ -267,7 +267,8 @@ void AccountFetcherService::OnUserInfoFetchSuccess(

void AccountFetcherService::SetIsChildAccount(const std::string& account_id,
bool is_child_account) {
account_tracker_service_->SetIsChildAccount(account_id, is_child_account);
if (child_request_account_id_ == account_id)
account_tracker_service_->SetIsChildAccount(account_id, is_child_account);
}

void AccountFetcherService::OnUserInfoFetchFailure(
Expand All @@ -283,8 +284,8 @@ void AccountFetcherService::OnRefreshTokenAvailable(
// (such as fetching the signin token "handle" in order to look for password
// changes) once everything is initialized and the refresh token is present.
signin_client_->DoFinalInit();
UpdateChildInfo();
RefreshAccountInfo(account_id, true);
UpdateChildInfo();
}

void AccountFetcherService::OnRefreshTokenRevoked(
Expand Down
3 changes: 2 additions & 1 deletion components/signin/core/browser/account_fetcher_service.h
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,8 @@ class AccountFetcherService : public KeyedService,

private:
friend class AccountInfoFetcher;
friend class ChildAccountInfoFetcher;
friend class ChildAccountInfoFetcherImpl;
friend class ChildAccountInfoFetcherAndroid;

void RefreshAllAccountInfo(bool only_fetch_if_invalid);
void RefreshAllAccountsAndScheduleNext();
Expand Down
23 changes: 23 additions & 0 deletions components/signin/core/browser/android/BUILD.gn
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
# 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.

import("//build/config/android/rules.gni")

# GYP version: components/signin.gypi:signin_core_browser_jni_headers
generate_jni("jni_headers") {
sources = [
"java/src/org/chromium/components/signin/ChildAccountInfoFetcher.java",
]
jni_package = "components/signin"
}

# GYP version: components/signin.gypi:signin_core_browser_java
android_library("java") {
deps = [
"//base:base_java",
"//sync/android:sync_java",
]

DEPRECATED_java_in_dir = "java/src"
}
25 changes: 25 additions & 0 deletions components/signin/core/browser/android/component_jni_registrar.cc
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
// 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 "components/signin/core/browser/android/component_jni_registrar.h"

#include "base/android/jni_android.h"
#include "base/android/jni_registrar.h"
#include "base/basictypes.h"
#include "components/signin/core/browser/child_account_info_fetcher_android.h"

namespace signin {
namespace android {

static base::android::RegistrationMethod kSigninRegisteredMethods[] = {
{"ChildAccountInfoFetcher", ChildAccountInfoFetcherAndroid::Register},
};

bool RegisterSigninJni(JNIEnv* env) {
return base::android::RegisterNativeMethods(
env, kSigninRegisteredMethods, arraysize(kSigninRegisteredMethods));
}

} // namespace android
} // namespace signin
18 changes: 18 additions & 0 deletions components/signin/core/browser/android/component_jni_registrar.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
// 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.

#ifndef COMPONENTS_SIGNIN_CORE_BROWSER_ANDROID_COMPONENT_JNI_REGISTRAR_H_
#define COMPONENTS_SIGNIN_CORE_BROWSER_ANDROID_COMPONENT_JNI_REGISTRAR_H_

#include <jni.h>

namespace signin {
namespace android {

bool RegisterSigninJni(JNIEnv* env);

} // namespace android
} // namespace signin

#endif // COMPONENTS_SIGNIN_CORE_BROWSER_ANDROID_COMPONENT_JNI_REGISTRAR_H_
3 changes: 3 additions & 0 deletions components/signin/core/browser/android/java/DEPS
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
include_rules = [
"+sync/android/java/src/org/chromium/sync/signin",
]
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
// 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.

package org.chromium.components.signin;

import android.accounts.Account;
import android.accounts.AccountManagerCallback;
import android.accounts.AccountManagerFuture;
import android.accounts.AuthenticatorException;
import android.accounts.OperationCanceledException;
import android.content.Context;

import org.chromium.base.ApplicationStatus;
import org.chromium.base.CalledByNative;
import org.chromium.base.Log;
import org.chromium.sync.signin.AccountManagerHelper;

import java.io.IOException;

/**
* ChildAccountInfoFetcher for the Android platform.
* Checks whether an account is a child account from the AccountManager.
*/
public final class ChildAccountInfoFetcher {
private static final String TAG = "cr.signin";

private ChildAccountInfoFetcher() {
// For static use only.
}

@CalledByNative
private static void fetch(final long nativeAccountFetcherService, final String accountId) {
Context app = ApplicationStatus.getApplicationContext();
assert app != null;
AccountManagerHelper helper = AccountManagerHelper.get(app);
Account[] accounts = helper.getGoogleAccounts();
Account candidate_account = null;
for (Account account : accounts) {
if (account.name.equals(accountId)) {
candidate_account = account;
break;
}
}
if (candidate_account == null) {
nativeSetIsChildAccount(nativeAccountFetcherService, accountId, false);
return;
}
helper.checkChildAccount(candidate_account, new AccountManagerCallback<Boolean>() {
@Override
public void run(AccountManagerFuture<Boolean> future) {
assert future.isDone();
try {
boolean isChildAccount = future.getResult();
nativeSetIsChildAccount(nativeAccountFetcherService, accountId, isChildAccount);
} catch (AuthenticatorException | IOException e) {
Log.e(TAG, "Error while fetching child account info: ", e);
} catch (OperationCanceledException e) {
Log.e(TAG, "Child account info fetch was cancelled. This should not happen.");
}
}
});
}

private static native void nativeSetIsChildAccount(
long ptrAccountFetcherService, final String accountId, boolean isChildAccount);
}
Loading

0 comments on commit 2d7f8e7

Please sign in to comment.