Commit 20f3bc42 authored by Marcin Wiącek's avatar Marcin Wiącek Committed by Commit Bot

Remove MAP from ContextualSearchInteractionPersisterImpl.java

BUG=948866

Change-Id: I5606e5c7195b4ed59f0a943ae5f73d53f7d1c2f8
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1610761Reviewed-by: default avatarDonn Denman <donnd@chromium.org>
Commit-Queue: Marcin Wiącek <marcin@mwiacek.com>
Cr-Commit-Position: refs/heads/master@{#659333}
parent 54c27942
...@@ -4,11 +4,11 @@ ...@@ -4,11 +4,11 @@
package org.chromium.chrome.browser.contextualsearch; package org.chromium.chrome.browser.contextualsearch;
import android.support.annotation.Nullable;
import org.chromium.chrome.browser.contextualsearch.ContextualSearchInteractionRecorder.Feature; import org.chromium.chrome.browser.contextualsearch.ContextualSearchInteractionRecorder.Feature;
import org.chromium.chrome.browser.preferences.ChromePreferenceManager; import org.chromium.chrome.browser.preferences.ChromePreferenceManager;
import java.util.Collections;
import java.util.HashMap;
import java.util.Map; import java.util.Map;
/** /**
...@@ -20,23 +20,18 @@ import java.util.Map; ...@@ -20,23 +20,18 @@ import java.util.Map;
* persisted value. * persisted value.
*/ */
class ContextualSearchInteractionPersisterImpl implements ContextualSearchInteractionPersister { class ContextualSearchInteractionPersisterImpl implements ContextualSearchInteractionPersister {
static final int BITMASK_PANEL_OPENED = 1 << 0; private static final @Nullable Integer getOutcomeBitMask(@Feature int feature) {
static final int BITMASK_QUICK_ACTION_CLICKED = 1 << 1; switch (feature) {
static final int BITMASK_QUICK_ANSWER_SEEN = 1 << 2; case Feature.OUTCOME_WAS_PANEL_OPENED:
static final int BITMASK_CARDS_DATA_SHOWN = 1 << 3; return 1 << 0;
static final Map<Integer, Integer> OUTCOME_ENCODING_BIT_MAP; case Feature.OUTCOME_WAS_QUICK_ACTION_CLICKED:
static { return 1 << 1;
// Map keys should contain @Feature int values only. case Feature.OUTCOME_WAS_QUICK_ANSWER_SEEN:
// Map values should be int powers of 2 only. return 1 << 2;
Map<Integer, Integer> outcome_encoding_bit_map = new HashMap<Integer, Integer>(); case Feature.OUTCOME_WAS_CARDS_DATA_SHOWN:
outcome_encoding_bit_map.put(Feature.OUTCOME_WAS_PANEL_OPENED, BITMASK_PANEL_OPENED); return 1 << 3;
outcome_encoding_bit_map.put( }
Feature.OUTCOME_WAS_QUICK_ACTION_CLICKED, BITMASK_QUICK_ACTION_CLICKED); return null;
outcome_encoding_bit_map.put(
Feature.OUTCOME_WAS_QUICK_ANSWER_SEEN, BITMASK_QUICK_ANSWER_SEEN);
outcome_encoding_bit_map.put(
Feature.OUTCOME_WAS_CARDS_DATA_SHOWN, BITMASK_CARDS_DATA_SHOWN);
OUTCOME_ENCODING_BIT_MAP = Collections.unmodifiableMap(outcome_encoding_bit_map);
} }
@Override @Override
...@@ -64,7 +59,7 @@ class ContextualSearchInteractionPersisterImpl implements ContextualSearchIntera ...@@ -64,7 +59,7 @@ class ContextualSearchInteractionPersisterImpl implements ContextualSearchIntera
for (Map.Entry<Integer, Object> entry : outcomesMap.entrySet()) { for (Map.Entry<Integer, Object> entry : outcomesMap.entrySet()) {
// Bit-wise encode into an int with all the boolean outcomes. // Bit-wise encode into an int with all the boolean outcomes.
if ((boolean) entry.getValue()) { if ((boolean) entry.getValue()) {
encodedInteractionResults |= OUTCOME_ENCODING_BIT_MAP.get(entry.getKey()); encodedInteractionResults |= getOutcomeBitMask(entry.getKey());
} }
} }
writeOutcomesToPersistantStorage(encodedInteractionResults); writeOutcomesToPersistantStorage(encodedInteractionResults);
......
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