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

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

Issue 2810863003: Android: Remove GetApplicationContext: components/ (Closed)
Patch Set: Fix tests Created 3 years, 8 months 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 unified diff | Download patch
OLDNEW
1 // Copyright 2015 The Chromium Authors. All rights reserved. 1 // Copyright 2015 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 package org.chromium.components.variations.firstrun; 5 package org.chromium.components.variations.firstrun;
6 6
7 import android.content.Context;
8 import android.util.Base64; 7 import android.util.Base64;
9 8
10 import org.chromium.base.ContextUtils; 9 import org.chromium.base.ContextUtils;
11 import org.chromium.base.annotations.CalledByNative; 10 import org.chromium.base.annotations.CalledByNative;
12 11
13 /** 12 /**
14 * VariationsSeedBridge is a class which is used to pass variations first run se ed that was fetched 13 * VariationsSeedBridge is a class which is used to pass variations first run se ed that was fetched
15 * before the actual Chrome first run to Chromium core. Class provides methods t o store the seed 14 * before the actual Chrome first run to Chromium core. Class provides methods t o store the seed
16 * in SharedPreferences and to get the seed from there. To store raw seed data c lass serializes 15 * in SharedPreferences and to get the seed from there. To store raw seed data c lass serializes
17 * byte[] to Base64 encoded string and decodes this string before passing to C++ side. 16 * byte[] to Base64 encoded string and decodes this string before passing to C++ side.
18 */ 17 */
19 public class VariationsSeedBridge { 18 public class VariationsSeedBridge {
20 protected static final String VARIATIONS_FIRST_RUN_SEED_BASE64 = "variations _seed_base64"; 19 protected static final String VARIATIONS_FIRST_RUN_SEED_BASE64 = "variations _seed_base64";
21 protected static final String VARIATIONS_FIRST_RUN_SEED_SIGNATURE = "variati ons_seed_signature"; 20 protected static final String VARIATIONS_FIRST_RUN_SEED_SIGNATURE = "variati ons_seed_signature";
22 protected static final String VARIATIONS_FIRST_RUN_SEED_COUNTRY = "variation s_seed_country"; 21 protected static final String VARIATIONS_FIRST_RUN_SEED_COUNTRY = "variation s_seed_country";
23 protected static final String VARIATIONS_FIRST_RUN_SEED_DATE = "variations_s eed_date"; 22 protected static final String VARIATIONS_FIRST_RUN_SEED_DATE = "variations_s eed_date";
24 protected static final String VARIATIONS_FIRST_RUN_SEED_IS_GZIP_COMPRESSED = 23 protected static final String VARIATIONS_FIRST_RUN_SEED_IS_GZIP_COMPRESSED =
25 "variations_seed_is_gzip_compressed"; 24 "variations_seed_is_gzip_compressed";
26 25
27 // This pref is used to store information about successful seed storing on t he C++ side, in 26 // This pref is used to store information about successful seed storing on t he C++ side, in
28 // order to not fetch the seed again. 27 // order to not fetch the seed again.
29 protected static final String VARIATIONS_FIRST_RUN_SEED_NATIVE_STORED = 28 protected static final String VARIATIONS_FIRST_RUN_SEED_NATIVE_STORED =
30 "variations_seed_native_stored"; 29 "variations_seed_native_stored";
31 30
32 protected static String getVariationsFirstRunSeedPref(Context context, Strin g prefName) { 31 protected static String getVariationsFirstRunSeedPref(String prefName) {
33 return ContextUtils.getAppSharedPreferences().getString(prefName, ""); 32 return ContextUtils.getAppSharedPreferences().getString(prefName, "");
34 } 33 }
35 34
36 /** 35 /**
37 * Stores variations seed data (raw data, seed signature and country code) i n SharedPreferences. 36 * Stores variations seed data (raw data, seed signature and country code) i n SharedPreferences.
38 * CalledByNative attribute is used by unit tests code to set test data. 37 * CalledByNative attribute is used by unit tests code to set test data.
39 */ 38 */
40 @CalledByNative 39 @CalledByNative
41 public static void setVariationsFirstRunSeed(Context context, byte[] rawSeed , String signature, 40 public static void setVariationsFirstRunSeed(byte[] rawSeed, String signatur e, String country,
42 String country, String date, boolean isGzipCompressed) { 41 String date, boolean isGzipCompressed) {
43 ContextUtils.getAppSharedPreferences() 42 ContextUtils.getAppSharedPreferences()
44 .edit() 43 .edit()
45 .putString(VARIATIONS_FIRST_RUN_SEED_BASE64, 44 .putString(VARIATIONS_FIRST_RUN_SEED_BASE64,
46 Base64.encodeToString(rawSeed, Base64.NO_WRAP)) 45 Base64.encodeToString(rawSeed, Base64.NO_WRAP))
47 .putString(VARIATIONS_FIRST_RUN_SEED_SIGNATURE, signature) 46 .putString(VARIATIONS_FIRST_RUN_SEED_SIGNATURE, signature)
48 .putString(VARIATIONS_FIRST_RUN_SEED_COUNTRY, country) 47 .putString(VARIATIONS_FIRST_RUN_SEED_COUNTRY, country)
49 .putString(VARIATIONS_FIRST_RUN_SEED_DATE, date) 48 .putString(VARIATIONS_FIRST_RUN_SEED_DATE, date)
50 .putBoolean(VARIATIONS_FIRST_RUN_SEED_IS_GZIP_COMPRESSED, isGzip Compressed) 49 .putBoolean(VARIATIONS_FIRST_RUN_SEED_IS_GZIP_COMPRESSED, isGzip Compressed)
51 .apply(); 50 .apply();
52 } 51 }
53 52
54 @CalledByNative 53 @CalledByNative
55 private static void clearFirstRunPrefs(Context context) { 54 private static void clearFirstRunPrefs() {
56 ContextUtils.getAppSharedPreferences() 55 ContextUtils.getAppSharedPreferences()
57 .edit() 56 .edit()
58 .remove(VARIATIONS_FIRST_RUN_SEED_BASE64) 57 .remove(VARIATIONS_FIRST_RUN_SEED_BASE64)
59 .remove(VARIATIONS_FIRST_RUN_SEED_SIGNATURE) 58 .remove(VARIATIONS_FIRST_RUN_SEED_SIGNATURE)
60 .remove(VARIATIONS_FIRST_RUN_SEED_COUNTRY) 59 .remove(VARIATIONS_FIRST_RUN_SEED_COUNTRY)
61 .remove(VARIATIONS_FIRST_RUN_SEED_DATE) 60 .remove(VARIATIONS_FIRST_RUN_SEED_DATE)
62 .remove(VARIATIONS_FIRST_RUN_SEED_IS_GZIP_COMPRESSED) 61 .remove(VARIATIONS_FIRST_RUN_SEED_IS_GZIP_COMPRESSED)
63 .apply(); 62 .apply();
64 } 63 }
65 64
66 /** 65 /**
67 * Returns the status of the variations first run fetch: was it successful o r not. 66 * Returns the status of the variations first run fetch: was it successful o r not.
68 */ 67 */
69 public static boolean hasJavaPref(Context context) { 68 public static boolean hasJavaPref() {
70 return !ContextUtils.getAppSharedPreferences() 69 return !ContextUtils.getAppSharedPreferences()
71 .getString(VARIATIONS_FIRST_RUN_SEED_BASE64, "") 70 .getString(VARIATIONS_FIRST_RUN_SEED_BASE64, "")
72 .isEmpty(); 71 .isEmpty();
73 } 72 }
74 73
75 /** 74 /**
76 * Returns the status of the variations seed storing on the C++ side: was it successful or not. 75 * Returns the status of the variations seed storing on the C++ side: was it successful or not.
77 */ 76 */
78 public static boolean hasNativePref(Context context) { 77 public static boolean hasNativePref() {
79 return ContextUtils.getAppSharedPreferences().getBoolean( 78 return ContextUtils.getAppSharedPreferences().getBoolean(
80 VARIATIONS_FIRST_RUN_SEED_NATIVE_STORED, false); 79 VARIATIONS_FIRST_RUN_SEED_NATIVE_STORED, false);
81 } 80 }
82 81
83 @CalledByNative 82 @CalledByNative
84 private static void markVariationsSeedAsStored(Context context) { 83 private static void markVariationsSeedAsStored() {
85 ContextUtils.getAppSharedPreferences() 84 ContextUtils.getAppSharedPreferences()
86 .edit() 85 .edit()
87 .putBoolean(VARIATIONS_FIRST_RUN_SEED_NATIVE_STORED, true) 86 .putBoolean(VARIATIONS_FIRST_RUN_SEED_NATIVE_STORED, true)
88 .apply(); 87 .apply();
89 } 88 }
90 89
91 @CalledByNative 90 @CalledByNative
92 private static byte[] getVariationsFirstRunSeedData(Context context) { 91 private static byte[] getVariationsFirstRunSeedData() {
93 return Base64.decode( 92 return Base64.decode(
94 getVariationsFirstRunSeedPref(context, VARIATIONS_FIRST_RUN_SEED _BASE64), 93 getVariationsFirstRunSeedPref(VARIATIONS_FIRST_RUN_SEED_BASE64), Base64.NO_WRAP);
95 Base64.NO_WRAP);
96 } 94 }
97 95
98 @CalledByNative 96 @CalledByNative
99 private static String getVariationsFirstRunSeedSignature(Context context) { 97 private static String getVariationsFirstRunSeedSignature() {
100 return getVariationsFirstRunSeedPref(context, VARIATIONS_FIRST_RUN_SEED_ SIGNATURE); 98 return getVariationsFirstRunSeedPref(VARIATIONS_FIRST_RUN_SEED_SIGNATURE );
101 } 99 }
102 100
103 @CalledByNative 101 @CalledByNative
104 private static String getVariationsFirstRunSeedCountry(Context context) { 102 private static String getVariationsFirstRunSeedCountry() {
105 return getVariationsFirstRunSeedPref(context, VARIATIONS_FIRST_RUN_SEED_ COUNTRY); 103 return getVariationsFirstRunSeedPref(VARIATIONS_FIRST_RUN_SEED_COUNTRY);
106 } 104 }
107 105
108 @CalledByNative 106 @CalledByNative
109 private static String getVariationsFirstRunSeedDate(Context context) { 107 private static String getVariationsFirstRunSeedDate() {
110 return getVariationsFirstRunSeedPref(context, VARIATIONS_FIRST_RUN_SEED_ DATE); 108 return getVariationsFirstRunSeedPref(VARIATIONS_FIRST_RUN_SEED_DATE);
111 } 109 }
112 110
113 @CalledByNative 111 @CalledByNative
114 private static boolean getVariationsFirstRunSeedIsGzipCompressed(Context con text) { 112 private static boolean getVariationsFirstRunSeedIsGzipCompressed() {
115 return ContextUtils.getAppSharedPreferences().getBoolean( 113 return ContextUtils.getAppSharedPreferences().getBoolean(
116 VARIATIONS_FIRST_RUN_SEED_IS_GZIP_COMPRESSED, false); 114 VARIATIONS_FIRST_RUN_SEED_IS_GZIP_COMPRESSED, false);
117 } 115 }
118 } 116 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698