Commit c512b0b0 authored by Henrique Nakashima's avatar Henrique Nakashima Committed by Commit Bot

KeyPrefix#createKey(int) to generate dynamic SharedPrefs key with ints.

This will be used in at least two places: OmniboxSuggestion and
CtrSuppression.

Bug: 1022108
Change-Id: I627aae9bd0bc3c9f260371b2a4ac0ecf5f3dc992
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2019940Reviewed-by: default avatarNatalie Chouinard <chouinard@chromium.org>
Commit-Queue: Henrique Nakashima <hnakashima@chromium.org>
Cr-Commit-Position: refs/heads/master@{#735525}
parent daec5894
...@@ -19,11 +19,18 @@ public class KeyPrefix { ...@@ -19,11 +19,18 @@ public class KeyPrefix {
} }
/** /**
* @param suffix A non-empty string. The '*' character is reserved. * @param stem A non-empty string. The '*' character is reserved.
* @return The complete SharedPreferences key to be passed to {@link SharedPreferencesManager}. * @return The complete SharedPreferences key to be passed to {@link SharedPreferencesManager}.
*/ */
public String createKey(String suffix) { public String createKey(String stem) {
return mPrefix + suffix; return mPrefix + stem;
}
/**
* @param index An int to generate a unique key.
* @return The complete SharedPreferences key to be passed to {@link SharedPreferencesManager}.
*/
public String createKey(int index) {
return mPrefix + index;
} }
String pattern() { String pattern() {
......
...@@ -29,9 +29,11 @@ public class KeyPrefixTest { ...@@ -29,9 +29,11 @@ public class KeyPrefixTest {
assertEquals(prefix.createKey("DynamicKey"), "Chrome.Feature.KP.DynamicKey"); assertEquals(prefix.createKey("DynamicKey"), "Chrome.Feature.KP.DynamicKey");
assertEquals(prefix.createKey("Level.DynamicKey"), "Chrome.Feature.KP.Level.DynamicKey"); assertEquals(prefix.createKey("Level.DynamicKey"), "Chrome.Feature.KP.Level.DynamicKey");
assertEquals(prefix.createKey(42), "Chrome.Feature.KP.42");
assertTrue(prefix.hasGenerated("Chrome.Feature.KP.DynamicKey")); assertTrue(prefix.hasGenerated("Chrome.Feature.KP.DynamicKey"));
assertTrue(prefix.hasGenerated("Chrome.Feature.KP.Level.DynamicKey")); assertTrue(prefix.hasGenerated("Chrome.Feature.KP.Level.DynamicKey"));
assertTrue(prefix.hasGenerated("Chrome.Feature.KP.42"));
assertFalse(prefix.hasGenerated("OtherKey")); assertFalse(prefix.hasGenerated("OtherKey"));
} }
......
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