1 // Copyright 2019 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4 
5 package org.chromium.chrome.browser.contextualsearch;
6 
7 import java.util.Map;
8 
9 /**
10  * Persists user-interaction outcomes and the associated EventID used to track them.
11  * This allows recording a user's interaction with the feature and sending that to
12  * the server to facilitate offline quality analysis.
13  */
14 interface ContextualSearchInteractionPersister {
15     /** An EventID of 0 means no event ID is available.  Don't persist. */
16     public static final long NO_EVENT_ID = 0;
17 
18     /** An interaction value of 0 means no interaction. */
19     public static final int NO_INTERACTION = 0;
20 
21     /**
22      * Gets the current persisted interaction and returns it, after clearing the persisted state.
23      * After this call {@link #persistInteractions} must be called to store a non-empty interaction.
24      * @return A new {@link PersistedInteraction} that is often empty due to the server not
25      *         providing any EventID.
26      */
getAndClearPersistedInteraction()27     PersistedInteraction getAndClearPersistedInteraction();
28 
29     /**
30      * Persists the given ID and outcomes to local storage.
31      * The outcomes Map keys should contain @Feature int values only. The Objects that are values in
32      * this map must be Booleans, but could some day be Integers.
33      * @param eventId A non-zero event ID to store.
34      * @param outcomesMap A map of outcome features and associated values.
35      */
persistInteractions( long eventId, Map< Integer, Object> outcomesMap)36     void persistInteractions(
37             long eventId, Map</* @Feature */ Integer, /* Boolean */ Object> outcomesMap);
38 
39     /** Provides access to a {@link PersistedInteraction} through getters. */
40     interface PersistedInteraction {
41         /** Gets the Event ID previously sent by the server during a resolve request. */
getEventId()42         long getEventId();
43 
44         /** Gets the bit-encoded user interactions associated with that event. */
getEncodedUserInteractions()45         int getEncodedUserInteractions();
46 
47         /** Gets the time stamp of this user interaction in milliseconds. */
getTimestampMs()48         long getTimestampMs();
49     }
50 }
51