Skip to content

Commit

Permalink
Issue mozilla-mobile#2325: Address nits
Browse files Browse the repository at this point in the history
  • Loading branch information
dnarcese committed Jun 10, 2019
1 parent 1582c53 commit 6a80105
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 18 deletions.
17 changes: 7 additions & 10 deletions app/src/main/java/org/mozilla/tv/firefox/IntentValidator.kt
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,11 @@ import mozilla.components.browser.session.Session
import mozilla.components.service.fretboard.ExperimentDescriptor
import mozilla.components.support.utils.SafeIntent
import org.mozilla.tv.firefox.ext.serviceLocator
import org.mozilla.tv.firefox.pocket.PocketVideoFetchScheduler
import org.mozilla.tv.firefox.telemetry.TelemetryIntegration
import org.mozilla.tv.firefox.utils.UrlUtils

private const val EXTRA_ACTIVE_EXPERIMENTS = "qaActiveExperiments"
private const val EXTRA_FETCH_DELAY_KEY = "fetchDelay"
private const val EXTRA_FETCH_DELAY_KEY = "qaFetchDelaySeconds"

data class ValidatedIntentData(val url: String, val source: Session.Source)

Expand Down Expand Up @@ -57,16 +56,14 @@ object IntentValidator {

fun validate(context: Context, intent: SafeIntent): ValidatedIntentData? {
setExperimentOverrides(intent, context)
changeFetchDelaySecondsForQA(intent)
changeFetchDelaySecondsForQA(intent, context)

when (intent.action) {
Intent.ACTION_MAIN -> {
val extras = intent.extras ?: return null

if (extras.keySet().contains(DIAL_PARAMS_KEY)) {
val param = extras.getString(DIAL_PARAMS_KEY)
val dialParams = intent.extras?.getString(DIAL_PARAMS_KEY) ?: return null
if (dialParams.isNotEmpty()) {
TelemetryIntegration.INSTANCE.youtubeCastEvent()
return ValidatedIntentData(url = "https://www.youtube.com/tv?$param", source = Session.Source.ACTION_VIEW)
return ValidatedIntentData(url = "https://www.youtube.com/tv?$dialParams", source = Session.Source.ACTION_VIEW)
}
}
Intent.ACTION_VIEW -> {
Expand Down Expand Up @@ -101,9 +98,9 @@ object IntentValidator {
}
}

private fun changeFetchDelaySecondsForQA(intent: SafeIntent) {
private fun changeFetchDelaySecondsForQA(intent: SafeIntent, context: Context) {
intent.extras?.getLong(EXTRA_FETCH_DELAY_KEY)?.let { delay ->
PocketVideoFetchScheduler.setDelayForQA(delay)
context.serviceLocator.pocketVideoFetchScheduler.setDelayForQA(delay)
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -53,14 +53,15 @@ class PocketVideoFetchScheduler(
.setRequiredNetworkType(NetworkType.CONNECTED)
.build()

// This sets the custom fetch delay for testing purposes.
// The custom delay will only run once.
val delay: Long
val workPolicy: ExistingWorkPolicy

// This sets the custom fetch delay for testing purposes.
// The custom delay will only run once.
if (IS_QA_BUILD) {
delay = DELAY_TIME_FOR_QA_MILLIS
delay = checkNotNull(DELAY_TIME_FOR_QA_MILLIS) { "Fetch delay value must be set" }
workPolicy = ExistingWorkPolicy.REPLACE
// Only allow this value to be used once so we do not end up spamming the Pocket servers
IS_QA_BUILD = false
} else {
delay = getDelayUntilUpcomingNightFetchMillis(now, randLong)
Expand Down Expand Up @@ -110,6 +111,11 @@ class PocketVideoFetchScheduler(
return userFetchTime.timeInMillis - now.timeInMillis
}

fun setDelayForQA(seconds: Long) {
IS_QA_BUILD = true
DELAY_TIME_FOR_QA_MILLIS = TimeUnit.SECONDS.toMillis(seconds)
}

companion object {
@VisibleForTesting(otherwise = PRIVATE) const val FETCH_START_HOUR = 3 // am
@VisibleForTesting(otherwise = PRIVATE) const val FETCH_END_HOUR = 5L
Expand All @@ -120,12 +126,8 @@ class PocketVideoFetchScheduler(
@VisibleForTesting(otherwise = PRIVATE) val BACKOFF_DELAY_MIN_MILLIS = TimeUnit.SECONDS.toMillis(30)
@VisibleForTesting(otherwise = PRIVATE) val BACKOFF_DELAY_MAX_MILLIS = TimeUnit.SECONDS.toMillis(60)

private var DELAY_TIME_FOR_QA_MILLIS = TimeUnit.SECONDS.toMillis(5)
private var DELAY_TIME_FOR_QA_MILLIS: Long? = null
private var IS_QA_BUILD = false
fun setDelayForQA(seconds: Long) {
IS_QA_BUILD = true
DELAY_TIME_FOR_QA_MILLIS = TimeUnit.SECONDS.toMillis(seconds)
}
}
}

Expand Down

0 comments on commit 6a80105

Please sign in to comment.