Commit e97c4683 authored by Sky Malice's avatar Sky Malice Committed by Commit Bot

Move Configuration construction to FeedConfiguration.

Also fixes the configuration of the endpoint.

Bug: 886972
Change-Id: Ia80e98ee0498af82c1b59832e7e7a68655c3a605
Reviewed-on: https://chromium-review.googlesource.com/c/1259805Reviewed-by: default avatarFilip Gorski <fgorski@chromium.org>
Commit-Queue: Sky Malice <skym@chromium.org>
Cr-Commit-Position: refs/heads/master@{#596415}
parent e179a324
......@@ -6,9 +6,19 @@ package org.chromium.chrome.browser.feed;
import android.text.TextUtils;
import com.google.android.libraries.feed.host.config.Configuration;
import com.google.android.libraries.feed.host.config.Configuration.ConfigKey;
import org.chromium.chrome.browser.ChromeFeatureList;
class FeedConfiguration {
/**
* Collection of configurable parameters and default values given to the Feed. Every getter passes
* checks to see if it has been overridden by a field trail param.
* */
final class FeedConfiguration {
/** Do not allow construction */
private FeedConfiguration() {}
private static final String FEED_SERVER_ENDPOINT = "feed_server_endpoint";
/** Default value for server endpoint. */
public static final String FEED_SERVER_ENDPOINT_DEFAULT =
......@@ -95,4 +105,22 @@ class FeedConfiguration {
ChromeFeatureList.INTEREST_FEED_CONTENT_SUGGESTIONS, VIEW_LOG_THRESHOLD,
VIEW_LOG_THRESHOLD_DEFAULT);
}
/**
* @return A fully built {@link Configuration}, ready to be given to the Feed.
*/
public static Configuration createConfiguration() {
return new Configuration.Builder()
.put(ConfigKey.FEED_SERVER_ENDPOINT, FeedConfiguration.getFeedServerEndpoint())
.put(ConfigKey.FEED_SERVER_METHOD, FeedConfiguration.getFeedServerMethod())
.put(ConfigKey.FEED_SERVER_RESPONSE_LENGTH_PREFIXED,
FeedConfiguration.getFeedServerReponseLengthPrefixed())
.put(ConfigKey.LOGGING_IMMEDIATE_CONTENT_THRESHOLD_MS,
FeedConfiguration.getLoggingImmediateContentThresholdMs())
.put(ConfigKey.SESSION_LIFETIME_MS, FeedConfiguration.getSessionLifetimeMs())
.put(ConfigKey.TRIGGER_IMMEDIATE_PAGINATION,
FeedConfiguration.getTriggerImmedatePagination())
.put(ConfigKey.VIEW_LOG_THRESHOLD, FeedConfiguration.getViewLogThreshold())
.build();
}
}
......@@ -10,7 +10,6 @@ import com.google.android.libraries.feed.api.common.ThreadUtils;
import com.google.android.libraries.feed.api.scope.FeedProcessScope;
import com.google.android.libraries.feed.feedapplifecyclelistener.FeedAppLifecycleListener;
import com.google.android.libraries.feed.host.config.Configuration;
import com.google.android.libraries.feed.host.config.Configuration.ConfigKey;
import com.google.android.libraries.feed.host.config.DebugBehavior;
import com.google.android.libraries.feed.host.network.NetworkClient;
import com.google.android.libraries.feed.hostimpl.logging.LoggingApiImpl;
......@@ -92,7 +91,7 @@ public class FeedProcessScopeFactory {
FeedProcessScopeFactory::articlesEnabledPrefChange);
Profile profile = Profile.getLastUsedProfile().getOriginalProfile();
Configuration configHostApi = createConfiguration();
Configuration configHostApi = FeedConfiguration.createConfiguration();
FeedSchedulerBridge schedulerBridge = new FeedSchedulerBridge(profile);
sFeedScheduler = schedulerBridge;
......@@ -121,21 +120,6 @@ public class FeedProcessScopeFactory {
new FeedLifecycleBridge(profile), sFeedScheduler);
}
private static Configuration createConfiguration() {
return new Configuration.Builder()
.put(ConfigKey.FEED_SERVER_ENDPOINT, FeedConfiguration.getFeedServerEndpoint())
.put(ConfigKey.FEED_SERVER_METHOD, FeedConfiguration.getFeedServerEndpoint())
.put(ConfigKey.FEED_SERVER_RESPONSE_LENGTH_PREFIXED,
FeedConfiguration.getFeedServerReponseLengthPrefixed())
.put(ConfigKey.SESSION_LIFETIME_MS, FeedConfiguration.getSessionLifetimeMs())
.put(ConfigKey.VIEW_LOG_THRESHOLD, FeedConfiguration.getViewLogThreshold())
.put(ConfigKey.LOGGING_IMMEDIATE_CONTENT_THRESHOLD_MS,
FeedConfiguration.getLoggingImmediateContentThresholdMs())
.put(ConfigKey.TRIGGER_IMMEDIATE_PAGINATION,
FeedConfiguration.getTriggerImmedatePagination())
.build();
}
/**
* Creates a {@link FeedProcessScope} using the provided host implementations. Call {@link
* #clearFeedProcessScopeForTesting()} to reset the FeedProcessScope after testing is complete.
......@@ -148,7 +132,7 @@ public class FeedProcessScopeFactory {
static void createFeedProcessScopeForTesting(FeedScheduler feedScheduler,
NetworkClient networkClient, FeedOfflineIndicator feedOfflineIndicator,
FeedAppLifecycle feedAppLifecycle, FeedAppLifecycleListener lifecycleListener) {
Configuration configHostApi = createConfiguration();
Configuration configHostApi = FeedConfiguration.createConfiguration();
sFeedScheduler = feedScheduler;
sFeedProcessScope = new FeedProcessScope
.Builder(configHostApi, Executors.newSingleThreadExecutor(),
......
......@@ -6,6 +6,9 @@ package org.chromium.chrome.browser.feed;
import android.support.test.filters.SmallTest;
import com.google.android.libraries.feed.host.config.Configuration;
import com.google.android.libraries.feed.host.config.Configuration.ConfigKey;
import org.junit.Assert;
import org.junit.Rule;
import org.junit.Test;
......@@ -25,6 +28,8 @@ public class FeedConfigurationTest {
@Rule
public final ChromeBrowserTestRule mRule = new ChromeBrowserTestRule();
private static final double ASSERT_EQUALS_DOUBLE_DELTA = 0.001d;
@Test
@Feature({"Feed"})
@Features.EnableFeatures({ChromeFeatureList.INTEREST_FEED_CONTENT_SUGGESTIONS})
......@@ -41,7 +46,7 @@ public class FeedConfigurationTest {
FeedConfiguration.getSessionLifetimeMs());
Assert.assertFalse(FeedConfiguration.getTriggerImmedatePagination());
Assert.assertEquals(FeedConfiguration.VIEW_LOG_THRESHOLD_DEFAULT,
FeedConfiguration.getViewLogThreshold(), 0.001d);
FeedConfiguration.getViewLogThreshold(), ASSERT_EQUALS_DOUBLE_DELTA);
}
@Test
......@@ -106,6 +111,31 @@ public class FeedConfigurationTest {
Add({"enable-features=InterestFeedContentSuggestions<Trial", "force-fieldtrials=Trial/Group",
"force-fieldtrial-params=Trial.Group:view_log_threshold/0.33"})
public void testViewLogThreshold() {
Assert.assertEquals(0.33d, FeedConfiguration.getViewLogThreshold(), 0.001d);
Assert.assertEquals(
0.33d, FeedConfiguration.getViewLogThreshold(), ASSERT_EQUALS_DOUBLE_DELTA);
}
@Test
@Feature({"Feed"})
@Features.EnableFeatures({ChromeFeatureList.INTEREST_FEED_CONTENT_SUGGESTIONS})
public void testCreateConfiguration() {
Configuration configuration = FeedConfiguration.createConfiguration();
Assert.assertEquals(FeedConfiguration.FEED_SERVER_ENDPOINT_DEFAULT,
configuration.getValueOrDefault(ConfigKey.FEED_SERVER_ENDPOINT, ""));
Assert.assertEquals(FeedConfiguration.FEED_SERVER_METHOD_DEFAULT,
configuration.getValueOrDefault(ConfigKey.FEED_SERVER_METHOD, ""));
Assert.assertEquals(FeedConfiguration.FEED_SERVER_RESPONSE_LENGTH_PREFIXED_DEFAULT,
configuration.getValueOrDefault(ConfigKey.FEED_SERVER_RESPONSE_LENGTH_PREFIXED, 0));
Assert.assertEquals(
Long.valueOf(FeedConfiguration.LOGGING_IMMEDIATE_CONTENT_THRESHOLD_MS_DEFAULT),
configuration.getValueOrDefault(
ConfigKey.LOGGING_IMMEDIATE_CONTENT_THRESHOLD_MS, 0l));
Assert.assertEquals(Long.valueOf(FeedConfiguration.SESSION_LIFETIME_MS_DEFAULT),
configuration.getValueOrDefault(ConfigKey.SESSION_LIFETIME_MS, 0l));
Assert.assertFalse(
configuration.getValueOrDefault(ConfigKey.TRIGGER_IMMEDIATE_PAGINATION, true));
Assert.assertEquals(Double.valueOf(FeedConfiguration.VIEW_LOG_THRESHOLD_DEFAULT),
configuration.getValueOrDefault(ConfigKey.VIEW_LOG_THRESHOLD, 0d),
ASSERT_EQUALS_DOUBLE_DELTA);
}
}
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