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 ...@@ -150,8 +150,9 @@ public final class FeedActionUploadRequestManager implements ActionUploadRequest
@HttpMethod @HttpMethod
String httpMethod = mConfiguration.getValueOrDefault( String httpMethod = mConfiguration.getValueOrDefault(
ConfigKey.FEED_ACTION_SERVER_METHOD, HttpMethod.POST); ConfigKey.FEED_ACTION_SERVER_METHOD, HttpMethod.POST);
HttpRequest httpRequest = RequestHelper.buildHttpRequest( HttpRequest httpRequest =
httpMethod, requestBuilder.build().toByteArray(), endpoint, /* locale= */ ""); RequestHelper.buildHttpRequest(httpMethod, requestBuilder.build().toByteArray(),
endpoint, /* locale= */ "", /* priorityParamValue= */ "");
Logger.i(TAG, "Making Request: %s", httpRequest.getUri().getPath()); Logger.i(TAG, "Making Request: %s", httpRequest.getUri().getPath());
mNetworkClient.send(httpRequest, input -> { mNetworkClient.send(httpRequest, input -> {
......
...@@ -204,16 +204,23 @@ public final class FeedRequestManagerImpl implements FeedRequestManager { ...@@ -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) { private void sendRequest(RequestBuilder requestBuilder, Consumer<Result<Model>> consumer) {
mThreadUtils.checkNotMainThread(); mThreadUtils.checkNotMainThread();
String endpoint = mConfiguration.getValueOrDefault(ConfigKey.FEED_SERVER_ENDPOINT, ""); String endpoint = mConfiguration.getValueOrDefault(ConfigKey.FEED_SERVER_ENDPOINT, "");
@HttpMethod @HttpMethod
String httpMethod = String httpMethod =
mConfiguration.getValueOrDefault(ConfigKey.FEED_SERVER_METHOD, HttpMethod.GET); mConfiguration.getValueOrDefault(ConfigKey.FEED_SERVER_METHOD, HttpMethod.GET);
HttpRequest httpRequest = HttpRequest httpRequest =
RequestHelper.buildHttpRequest(httpMethod, requestBuilder.build().toByteArray(), 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()); Logger.i(TAG, "Making Request: %s", httpRequest.getUri().getPath());
mNetworkClient.send(httpRequest, input -> { mNetworkClient.send(httpRequest, input -> {
...@@ -267,7 +274,7 @@ public final class FeedRequestManagerImpl implements FeedRequestManager { ...@@ -267,7 +274,7 @@ public final class FeedRequestManagerImpl implements FeedRequestManager {
private final Context mContext; private final Context mContext;
private final ApplicationInfo mApplicationInfo; private final ApplicationInfo mApplicationInfo;
private final Configuration mConfiguration; private final Configuration mConfiguration;
private final FeedQuery.RequestReason mRequestReason; public final FeedQuery.RequestReason mRequestReason;
@RequestReason @RequestReason
private final int mClientLoggingRequestReason; private final int mClientLoggingRequestReason;
private boolean mCardMenuTooltipWouldTrigger; private boolean mCardMenuTooltipWouldTrigger;
......
...@@ -21,6 +21,9 @@ public final class RequestHelper { ...@@ -21,6 +21,9 @@ public final class RequestHelper {
public static final String LOCALE_PARAM = "hl"; public static final String LOCALE_PARAM = "hl";
private static final String MOTHERSHIP_PARAM_FORMAT = "fmt"; private static final String MOTHERSHIP_PARAM_FORMAT = "fmt";
private static final String MOTHERSHIP_VALUE_BINARY = "bin"; 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() {} private RequestHelper() {}
...@@ -41,8 +44,8 @@ public final class RequestHelper { ...@@ -41,8 +44,8 @@ public final class RequestHelper {
} }
} }
static HttpRequest buildHttpRequest( static HttpRequest buildHttpRequest(String httpMethod, byte[] bytes, String endpoint,
String httpMethod, byte[] bytes, String endpoint, String locale) { String locale, String priorityParamValue) {
boolean isPostMethod = HttpMethod.POST.equals(httpMethod); boolean isPostMethod = HttpMethod.POST.equals(httpMethod);
Uri.Builder uriBuilder = Uri.parse(endpoint).buildUpon(); Uri.Builder uriBuilder = Uri.parse(endpoint).buildUpon();
if (!isPostMethod) { if (!isPostMethod) {
...@@ -54,6 +57,9 @@ public final class RequestHelper { ...@@ -54,6 +57,9 @@ public final class RequestHelper {
if (!locale.isEmpty()) { if (!locale.isEmpty()) {
uriBuilder.appendQueryParameter(LOCALE_PARAM, locale); uriBuilder.appendQueryParameter(LOCALE_PARAM, locale);
} }
if (!priorityParamValue.isEmpty()) {
uriBuilder.appendQueryParameter(PRIORITY_PARAM, priorityParamValue);
}
return new HttpRequest(uriBuilder.build(), httpMethod, Collections.emptyList(), return new HttpRequest(uriBuilder.build(), httpMethod, Collections.emptyList(),
isPostMethod ? bytes : new byte[] {}); isPostMethod ? bytes : new byte[] {});
......
...@@ -170,6 +170,8 @@ public class FeedRequestManagerImplTest { ...@@ -170,6 +170,8 @@ public class FeedRequestManagerImplTest {
HttpRequest httpRequest = mFakeNetworkClient.getLatestRequest(); HttpRequest httpRequest = mFakeNetworkClient.getLatestRequest();
assertHttpRequestFormattedCorrectly(httpRequest, mContext); assertHttpRequestFormattedCorrectly(httpRequest, mContext);
assertThat(httpRequest.getUri().getQueryParameter(RequestHelper.PRIORITY_PARAM))
.isEqualTo(RequestHelper.PRIORITY_VALUE_BACKGROUND);
Request request = getRequestFromHttpRequest(httpRequest); Request request = getRequestFromHttpRequest(httpRequest);
Request expectedRequest = Request expectedRequest =
...@@ -673,42 +675,50 @@ public class FeedRequestManagerImplTest { ...@@ -673,42 +675,50 @@ public class FeedRequestManagerImplTest {
@Test @Test
public void testGetWireRequestResponse_unknown() throws Exception { 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 @Test
public void testGetWireRequestResponse_zeroState() throws Exception { 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 @Test
public void testGetWireRequestResponse_hostRequested() throws Exception { 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 @Test
public void testGetWireRequestResponse_openWithContent() throws Exception { 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 @Test
public void testGetWireRequestResponse_manualContinuation() throws Exception { 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 @Test
public void testGetWireRequestResponse_automaticContinuation() throws Exception { 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 @Test
public void testGetWireRequestResponse_openWithoutContent() throws Exception { 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 @Test
public void testGetWireRequestResponse_clearAll() throws Exception { 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 @Test
...@@ -780,8 +790,8 @@ public class FeedRequestManagerImplTest { ...@@ -780,8 +790,8 @@ public class FeedRequestManagerImplTest {
assertThat(request).isEqualTo(expectedRequest); assertThat(request).isEqualTo(expectedRequest);
} }
private void testReason(@RequestReason int reason, FeedQuery.RequestReason expectedReason) private void testReason(@RequestReason int reason, FeedQuery.RequestReason expectedReason,
throws Exception { String expectedPriority) throws Exception {
mFakeNetworkClient.addResponse(mFailingResponse); mFakeNetworkClient.addResponse(mFailingResponse);
mRequestManager.triggerRefresh(reason, input -> {}); mRequestManager.triggerRefresh(reason, input -> {});
...@@ -790,6 +800,8 @@ public class FeedRequestManagerImplTest { ...@@ -790,6 +800,8 @@ public class FeedRequestManagerImplTest {
assertThat(request.getExtension(FeedRequest.feedRequest).getFeedQuery().getReason()) assertThat(request.getExtension(FeedRequest.feedRequest).getFeedQuery().getReason())
.isEqualTo(expectedReason); .isEqualTo(expectedReason);
assertThat(mFakeBasicLoggingApi.serverRequestReason).isEqualTo(reason); assertThat(mFakeBasicLoggingApi.serverRequestReason).isEqualTo(reason);
assertThat(httpRequest.getUri().getQueryParameter(RequestHelper.PRIORITY_PARAM))
.isEqualTo(expectedPriority);
} }
private static void assertHttpRequestFormattedCorrectly( 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