forked from chromium/chromium
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add an Android specific ChildAccountInfoFetcher that talks to the Acc…
…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
Showing
22 changed files
with
573 additions
and
230 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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
25
components/signin/core/browser/android/component_jni_registrar.cc
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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
18
components/signin/core/browser/android/component_jni_registrar.h
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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_ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
include_rules = [ | ||
"+sync/android/java/src/org/chromium/sync/signin", | ||
] |
67 changes: 67 additions & 0 deletions
67
...core/browser/android/java/src/org/chromium/components/signin/ChildAccountInfoFetcher.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
} |
Oops, something went wrong.