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

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

Issue 1417733008: Java code for fetching variations first run seed after receiving chrome.TOS_ACKED broadcast. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: 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: chrome/android/java/src/org/chromium/chrome/browser/firstrun/variations/VariationsSeedBridge.java
diff --git a/chrome/android/java/src/org/chromium/chrome/browser/firstrun/variations/VariationsSeedBridge.java b/chrome/android/java/src/org/chromium/chrome/browser/firstrun/variations/VariationsSeedBridge.java
new file mode 100644
index 0000000000000000000000000000000000000000..c68cd4dfb969d489a242134d17fae18a45f5c380
--- /dev/null
+++ b/chrome/android/java/src/org/chromium/chrome/browser/firstrun/variations/VariationsSeedBridge.java
@@ -0,0 +1,79 @@
+// 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.chrome.browser.firstrun.variations;
+
+import android.content.Context;
+import android.content.SharedPreferences;
+import android.preference.PreferenceManager;
+import android.util.Base64;
+
+import org.chromium.base.ThreadUtils;
+import org.chromium.base.annotations.CalledByNative;
+
+/**
+ * PrefServiceBridge is a singleton which provides access to some native preferences. Ideally
+ * preferences should be grouped with their relevant functionality but this is a grab-bag for other
+ * preferences.
+ */
+public final class VariationsSeedBridge {
+ private VariationsSeedBridge() {}
+
+ private static VariationsSeedBridge sInstance;
+
+ /**
+ * @return The singleton bridge object.
+ */
+ public static VariationsSeedBridge getInstance() {
+ ThreadUtils.assertOnUiThread();
+ if (sInstance == null) sInstance = new VariationsSeedBridge();
+ return sInstance;
+ }
+
+ /**
+ * @return Whether the preferences have been initialized.
+ */
+ public static boolean isInitialized() {
+ return sInstance != null;
+ }
+
+ // TODO(agulenko): Move this piece of code to a separate class.
+
+ private static final String VARIATIONS_FIRST_RUN_SEED_BASE64 = "variations_seed_base64";
+ private static final String VARIATIONS_FIRST_RUN_SEED_SIGNATURE = "variations_seed_signature";
+ private static final String VARIATIONS_FIRST_RUN_SEED_COUNTRY = "variations_seed_country";
+
+ private static String getVariationsFirstRunSeedPref(Context context, String prefName) {
+ SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(context);
+ return prefs.getString(prefName, "");
+ }
+
+ public static void setVariationsFirstRunSeed(
+ Context context, byte[] rawSeed, String signature, String country) {
+ SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(context);
+ prefs.edit()
+ .putString(VARIATIONS_FIRST_RUN_SEED_BASE64,
+ Base64.encodeToString(rawSeed, Base64.NO_WRAP))
+ .putString(VARIATIONS_FIRST_RUN_SEED_SIGNATURE, signature)
+ .putString(VARIATIONS_FIRST_RUN_SEED_COUNTRY, country)
+ .apply();
+ }
+
+ @CalledByNative
+ private static byte[] getVariationsFirstRunSeedData(Context context) {
+ return Base64.decode(
+ getVariationsFirstRunSeedPref(context, VARIATIONS_FIRST_RUN_SEED_BASE64),
+ Base64.NO_WRAP);
+ }
+
+ @CalledByNative
+ private static String getVariationsFirstRunSeedSignature(Context context) {
+ return getVariationsFirstRunSeedPref(context, VARIATIONS_FIRST_RUN_SEED_SIGNATURE);
+ }
+
+ @CalledByNative
+ private static String getVariationsFirstRunSeedCountry(Context context) {
+ return getVariationsFirstRunSeedPref(context, VARIATIONS_FIRST_RUN_SEED_COUNTRY);
+ }
+}

Powered by Google App Engine
This is Rietveld 408576698