Commit 1c98fd42 authored by Mikel Astiz's avatar Mikel Astiz Committed by Commit Bot

Broadcast changes in sync trusted vault backend keys on Android

With this patch TrustedVaultClient.Backend has the ability to notify
native code that the keys in the vault may have changed. This
notification makes its way via TrustedVaultClientAndroid to ultimately
SyncServiceCrypto, where refetching logic is triggered.

This is expected to be an effective means for resolving encryption
issues transparently without user action and without having to restart
the browser.

The very same method is also used upon relevant user action such as
triggering the retrieval flow, in case the keys within the vault have
changed since the last fetch (e.g. if the backend failed to or does not
support broadcasting change notifications).

Bug: 1012659
Change-Id: I985db773fe5b18f107a8c8731d31dbd80aaf599c
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1978005Reviewed-by: default avatarBoris Sazonov <bsazonov@chromium.org>
Commit-Queue: Mikel Astiz <mastiz@chromium.org>
Cr-Commit-Position: refs/heads/master@{#730147}
parent 4dff7197
...@@ -105,9 +105,6 @@ public class TrustedVaultClient { ...@@ -105,9 +105,6 @@ public class TrustedVaultClient {
* Displays a UI that allows the user to reauthenticate and retrieve the sync encryption keys. * Displays a UI that allows the user to reauthenticate and retrieve the sync encryption keys.
*/ */
public void displayKeyRetrievalDialog(Context context) { public void displayKeyRetrievalDialog(Context context) {
// TODO(crbug.com/1012659): Before starting the intent, one last attempt
// should be made to read the currently-available keys.
Intent intent = createKeyRetrievalIntent(); Intent intent = createKeyRetrievalIntent();
if (intent == null) return; if (intent == null) return;
...@@ -128,6 +125,16 @@ public class TrustedVaultClient { ...@@ -128,6 +125,16 @@ public class TrustedVaultClient {
return mBackend.createKeyRetrievalIntent(); return mBackend.createKeyRetrievalIntent();
} }
/**
* Notifies all registered native clients (in practice, exactly one) that keys in the backend
* may have changed, which usually leads to refetching the keys from the backend.
*/
public void notifyKeysChanged() {
for (long nativeTrustedVaultClientAndroid : mNativeTrustedVaultClientAndroidSet) {
TrustedVaultClientJni.get().notifyKeysChanged(nativeTrustedVaultClientAndroid);
}
}
/** /**
* Registers a C++ client, which is a prerequisite before interacting with Java. * Registers a C++ client, which is a prerequisite before interacting with Java.
*/ */
...@@ -207,5 +214,6 @@ public class TrustedVaultClient { ...@@ -207,5 +214,6 @@ public class TrustedVaultClient {
interface Natives { interface Natives {
void fetchKeysCompleted(long nativeTrustedVaultClientAndroid, String gaiaId, byte[][] keys); void fetchKeysCompleted(long nativeTrustedVaultClientAndroid, String gaiaId, byte[][] keys);
void markKeysAsStaleCompleted(long nativeTrustedVaultClientAndroid, boolean result); void markKeysAsStaleCompleted(long nativeTrustedVaultClientAndroid, boolean result);
void notifyKeysChanged(long nativeTrustedVaultClientAndroid);
} }
} }
...@@ -62,6 +62,10 @@ void TrustedVaultClientAndroid::MarkKeysAsStaleCompleted(JNIEnv* env, ...@@ -62,6 +62,10 @@ void TrustedVaultClientAndroid::MarkKeysAsStaleCompleted(JNIEnv* env,
std::move(cb).Run(!!result); std::move(cb).Run(!!result);
} }
void TrustedVaultClientAndroid::NotifyKeysChanged(JNIEnv* env) {
observer_list_.Notify();
}
std::unique_ptr<TrustedVaultClientAndroid::Subscription> std::unique_ptr<TrustedVaultClientAndroid::Subscription>
TrustedVaultClientAndroid::AddKeysChangedObserver( TrustedVaultClientAndroid::AddKeysChangedObserver(
const base::RepeatingClosure& cb) { const base::RepeatingClosure& cb) {
......
...@@ -41,6 +41,9 @@ class TrustedVaultClientAndroid : public syncer::TrustedVaultClient { ...@@ -41,6 +41,9 @@ class TrustedVaultClientAndroid : public syncer::TrustedVaultClient {
// ongoing MarkKeysAsStale() request. // ongoing MarkKeysAsStale() request.
void MarkKeysAsStaleCompleted(JNIEnv* env, jboolean result); void MarkKeysAsStaleCompleted(JNIEnv* env, jboolean result);
// Called from Java to notify that the keys in the vault may have changed.
void NotifyKeysChanged(JNIEnv* env);
// TrustedVaultClient implementation. // TrustedVaultClient implementation.
std::unique_ptr<Subscription> AddKeysChangedObserver( std::unique_ptr<Subscription> AddKeysChangedObserver(
const base::RepeatingClosure& cb) override; const base::RepeatingClosure& cb) override;
......
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