Commit 0b470c09 authored by Dan Harrington's avatar Dan Harrington Committed by Commit Bot

Add 'bq' query parameter for feed request

This indicates how important the request is.

Bug: b/149323794
Change-Id: I23bd7177a89fa1122c9365268e1cffc45a4c9b7e
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2055025Reviewed-by: default avatarIan Wells <iwells@chromium.org>
Commit-Queue: Dan H <harringtond@chromium.org>
Cr-Commit-Position: refs/heads/master@{#741216}
parent e71d7d88
......@@ -150,8 +150,9 @@ public final class FeedActionUploadRequestManager implements ActionUploadRequest
@HttpMethod
String httpMethod = mConfiguration.getValueOrDefault(
ConfigKey.FEED_ACTION_SERVER_METHOD, HttpMethod.POST);
HttpRequest httpRequest = RequestHelper.buildHttpRequest(
httpMethod, requestBuilder.build().toByteArray(), endpoint, /* locale= */ "");
HttpRequest httpRequest =
RequestHelper.buildHttpRequest(httpMethod, requestBuilder.build().toByteArray(),
endpoint, /* locale= */ "", /* priorityParamValue= */ "");
Logger.i(TAG, "Making Request: %s", httpRequest.getUri().getPath());
mNetworkClient.send(httpRequest, input -> {
......
......@@ -204,16 +204,23 @@ public final class FeedRequestManagerImpl implements FeedRequestManager {
}
}
private static boolean isRequestInteractive(FeedQuery.RequestReason reason) {
return !(reason == FeedQuery.RequestReason.SCHEDULED_REFRESH
|| reason == FeedQuery.RequestReason.WITH_CONTENT);
}
private void sendRequest(RequestBuilder requestBuilder, Consumer<Result<Model>> consumer) {
mThreadUtils.checkNotMainThread();
String endpoint = mConfiguration.getValueOrDefault(ConfigKey.FEED_SERVER_ENDPOINT, "");
@HttpMethod
String httpMethod =
mConfiguration.getValueOrDefault(ConfigKey.FEED_SERVER_METHOD, HttpMethod.GET);
HttpRequest httpRequest =
RequestHelper.buildHttpRequest(httpMethod, requestBuilder.build().toByteArray(),
endpoint, LocaleUtils.getLanguageTag(mContext));
endpoint, LocaleUtils.getLanguageTag(mContext),
isRequestInteractive(requestBuilder.mRequestReason)
? RequestHelper.PRIORITY_VALUE_INTERACTIVE
: RequestHelper.PRIORITY_VALUE_BACKGROUND);
Logger.i(TAG, "Making Request: %s", httpRequest.getUri().getPath());
mNetworkClient.send(httpRequest, input -> {
......@@ -267,7 +274,7 @@ public final class FeedRequestManagerImpl implements FeedRequestManager {
private final Context mContext;
private final ApplicationInfo mApplicationInfo;
private final Configuration mConfiguration;
private final FeedQuery.RequestReason mRequestReason;
public final FeedQuery.RequestReason mRequestReason;
@RequestReason
private final int mClientLoggingRequestReason;
private boolean mCardMenuTooltipWouldTrigger;
......
......@@ -21,6 +21,9 @@ public final class RequestHelper {
public static final String LOCALE_PARAM = "hl";
private static final String MOTHERSHIP_PARAM_FORMAT = "fmt";
private static final String MOTHERSHIP_VALUE_BINARY = "bin";
public static final String PRIORITY_PARAM = "bq";
public static final String PRIORITY_VALUE_BACKGROUND = "1";
public static final String PRIORITY_VALUE_INTERACTIVE = "0";
private RequestHelper() {}
......@@ -41,8 +44,8 @@ public final class RequestHelper {
}
}
static HttpRequest buildHttpRequest(
String httpMethod, byte[] bytes, String endpoint, String locale) {
static HttpRequest buildHttpRequest(String httpMethod, byte[] bytes, String endpoint,
String locale, String priorityParamValue) {
boolean isPostMethod = HttpMethod.POST.equals(httpMethod);
Uri.Builder uriBuilder = Uri.parse(endpoint).buildUpon();
if (!isPostMethod) {
......@@ -54,6 +57,9 @@ public final class RequestHelper {
if (!locale.isEmpty()) {
uriBuilder.appendQueryParameter(LOCALE_PARAM, locale);
}
if (!priorityParamValue.isEmpty()) {
uriBuilder.appendQueryParameter(PRIORITY_PARAM, priorityParamValue);
}
return new HttpRequest(uriBuilder.build(), httpMethod, Collections.emptyList(),
isPostMethod ? bytes : new byte[] {});
......
......@@ -170,6 +170,8 @@ public class FeedRequestManagerImplTest {
HttpRequest httpRequest = mFakeNetworkClient.getLatestRequest();
assertHttpRequestFormattedCorrectly(httpRequest, mContext);
assertThat(httpRequest.getUri().getQueryParameter(RequestHelper.PRIORITY_PARAM))
.isEqualTo(RequestHelper.PRIORITY_VALUE_BACKGROUND);
Request request = getRequestFromHttpRequest(httpRequest);
Request expectedRequest =
......@@ -673,42 +675,50 @@ public class FeedRequestManagerImplTest {
@Test
public void testGetWireRequestResponse_unknown() throws Exception {
testReason(RequestReason.UNKNOWN, FeedQuery.RequestReason.UNKNOWN_REQUEST_REASON);
testReason(RequestReason.UNKNOWN, FeedQuery.RequestReason.UNKNOWN_REQUEST_REASON,
RequestHelper.PRIORITY_VALUE_INTERACTIVE);
}
@Test
public void testGetWireRequestResponse_zeroState() throws Exception {
testReason(RequestReason.ZERO_STATE, FeedQuery.RequestReason.ZERO_STATE_REFRESH);
testReason(RequestReason.ZERO_STATE, FeedQuery.RequestReason.ZERO_STATE_REFRESH,
RequestHelper.PRIORITY_VALUE_INTERACTIVE);
}
@Test
public void testGetWireRequestResponse_hostRequested() throws Exception {
testReason(RequestReason.HOST_REQUESTED, FeedQuery.RequestReason.SCHEDULED_REFRESH);
testReason(RequestReason.HOST_REQUESTED, FeedQuery.RequestReason.SCHEDULED_REFRESH,
RequestHelper.PRIORITY_VALUE_BACKGROUND);
}
@Test
public void testGetWireRequestResponse_openWithContent() throws Exception {
testReason(RequestReason.OPEN_WITH_CONTENT, FeedQuery.RequestReason.WITH_CONTENT);
testReason(RequestReason.OPEN_WITH_CONTENT, FeedQuery.RequestReason.WITH_CONTENT,
RequestHelper.PRIORITY_VALUE_BACKGROUND);
}
@Test
public void testGetWireRequestResponse_manualContinuation() throws Exception {
testReason(RequestReason.MANUAL_CONTINUATION, FeedQuery.RequestReason.NEXT_PAGE_SCROLL);
testReason(RequestReason.MANUAL_CONTINUATION, FeedQuery.RequestReason.NEXT_PAGE_SCROLL,
RequestHelper.PRIORITY_VALUE_INTERACTIVE);
}
@Test
public void testGetWireRequestResponse_automaticContinuation() throws Exception {
testReason(RequestReason.AUTOMATIC_CONTINUATION, FeedQuery.RequestReason.NEXT_PAGE_SCROLL);
testReason(RequestReason.AUTOMATIC_CONTINUATION, FeedQuery.RequestReason.NEXT_PAGE_SCROLL,
RequestHelper.PRIORITY_VALUE_INTERACTIVE);
}
@Test
public void testGetWireRequestResponse_openWithoutContent() throws Exception {
testReason(RequestReason.OPEN_WITHOUT_CONTENT, FeedQuery.RequestReason.INITIAL_LOAD);
testReason(RequestReason.OPEN_WITHOUT_CONTENT, FeedQuery.RequestReason.INITIAL_LOAD,
RequestHelper.PRIORITY_VALUE_INTERACTIVE);
}
@Test
public void testGetWireRequestResponse_clearAll() throws Exception {
testReason(RequestReason.CLEAR_ALL, FeedQuery.RequestReason.CLEAR_ALL);
testReason(RequestReason.CLEAR_ALL, FeedQuery.RequestReason.CLEAR_ALL,
RequestHelper.PRIORITY_VALUE_INTERACTIVE);
}
@Test
......@@ -780,8 +790,8 @@ public class FeedRequestManagerImplTest {
assertThat(request).isEqualTo(expectedRequest);
}
private void testReason(@RequestReason int reason, FeedQuery.RequestReason expectedReason)
throws Exception {
private void testReason(@RequestReason int reason, FeedQuery.RequestReason expectedReason,
String expectedPriority) throws Exception {
mFakeNetworkClient.addResponse(mFailingResponse);
mRequestManager.triggerRefresh(reason, input -> {});
......@@ -790,6 +800,8 @@ public class FeedRequestManagerImplTest {
assertThat(request.getExtension(FeedRequest.feedRequest).getFeedQuery().getReason())
.isEqualTo(expectedReason);
assertThat(mFakeBasicLoggingApi.serverRequestReason).isEqualTo(reason);
assertThat(httpRequest.getUri().getQueryParameter(RequestHelper.PRIORITY_PARAM))
.isEqualTo(expectedPriority);
}
private static void assertHttpRequestFormattedCorrectly(
......
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