Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(681)

Unified Diff: components/variations/android/java/src/org/chromium/components/variations/firstrun/VariationsSeedBridge.java

Issue 1437833004: Implemented clearing Java prefs after pulling variations first run seed from Java to C++ side (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Fixed unit tests failure Created 5 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: components/variations/android/java/src/org/chromium/components/variations/firstrun/VariationsSeedBridge.java
diff --git a/components/variations/android/java/src/org/chromium/components/variations/firstrun/VariationsSeedBridge.java b/components/variations/android/java/src/org/chromium/components/variations/firstrun/VariationsSeedBridge.java
index 3af546bf3bf62115b4ff37c4ff207f4c58f6a54d..4916b72bcbd7c8252031ee9acb176be9cdad8c74 100644
--- a/components/variations/android/java/src/org/chromium/components/variations/firstrun/VariationsSeedBridge.java
+++ b/components/variations/android/java/src/org/chromium/components/variations/firstrun/VariationsSeedBridge.java
@@ -5,7 +5,6 @@
package org.chromium.components.variations.firstrun;
import android.content.Context;
-import android.content.SharedPreferences;
import android.preference.PreferenceManager;
import android.util.Base64;
@@ -22,9 +21,13 @@ public final class VariationsSeedBridge {
private static final String VARIATIONS_FIRST_RUN_SEED_SIGNATURE = "variations_seed_signature";
private static final String VARIATIONS_FIRST_RUN_SEED_COUNTRY = "variations_seed_country";
+ // This pref is used to store information about successful seed storing on the C++ side, in
+ // order to not fetch the seed again.
+ private static final String VARIATIONS_FIRST_RUN_SEED_NATIVE_STORED =
+ "variations_seed_native_stored";
+
private static String getVariationsFirstRunSeedPref(Context context, String prefName) {
- SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(context);
- return prefs.getString(prefName, "");
+ return PreferenceManager.getDefaultSharedPreferences(context).getString(prefName, "");
}
/**
@@ -32,8 +35,8 @@ public final class VariationsSeedBridge {
*/
public static void setVariationsFirstRunSeed(
Context context, byte[] rawSeed, String signature, String country) {
- SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(context);
- prefs.edit()
+ PreferenceManager.getDefaultSharedPreferences(context)
+ .edit()
.putString(VARIATIONS_FIRST_RUN_SEED_BASE64,
Base64.encodeToString(rawSeed, Base64.NO_WRAP))
.putString(VARIATIONS_FIRST_RUN_SEED_SIGNATURE, signature)
@@ -42,6 +45,41 @@ public final class VariationsSeedBridge {
}
@CalledByNative
+ private static void clearFirstRunPrefs(Context context) {
+ PreferenceManager.getDefaultSharedPreferences(context)
+ .edit()
+ .remove(VARIATIONS_FIRST_RUN_SEED_BASE64)
+ .remove(VARIATIONS_FIRST_RUN_SEED_SIGNATURE)
+ .remove(VARIATIONS_FIRST_RUN_SEED_COUNTRY)
+ .apply();
+ }
+
+ /**
+ * Returns the status of the variations first run fetch: was it successful or not.
+ */
+ public static boolean hasJavaPref(Context context) {
+ return !PreferenceManager.getDefaultSharedPreferences(context)
+ .getString(VARIATIONS_FIRST_RUN_SEED_BASE64, "")
+ .isEmpty();
+ }
+
+ /**
+ * Returns the status of the variations seed storing on the C++ side: was it successful or not.
+ */
+ public static boolean hasNativePref(Context context) {
+ return PreferenceManager.getDefaultSharedPreferences(context).getBoolean(
+ VARIATIONS_FIRST_RUN_SEED_NATIVE_STORED, false);
+ }
+
+ @CalledByNative
+ private static void markVariationsSeedAsStored(Context context) {
+ PreferenceManager.getDefaultSharedPreferences(context)
+ .edit()
+ .putBoolean(VARIATIONS_FIRST_RUN_SEED_NATIVE_STORED, true)
+ .apply();
+ }
+
+ @CalledByNative
private static byte[] getVariationsFirstRunSeedData(Context context) {
return Base64.decode(
getVariationsFirstRunSeedPref(context, VARIATIONS_FIRST_RUN_SEED_BASE64),

Powered by Google App Engine
This is Rietveld 408576698