Commit 3c6fb0c0 authored by Daniel Murphy's avatar Daniel Murphy Committed by Commit Bot

[WebManifest] Add switch for disabling manifest update throttling

This change also cleans up the logic a bit to correctly use the optional
type.

R=alancutter@chromium.org, phillis@chromium.org

Bug: 1116059d
Change-Id: Ie467ce69f8fbf4900ca89be49f4de83d32db3f55
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2354453Reviewed-by: default avatarAlan Cutter <alancutter@chromium.org>
Commit-Queue: Daniel Murphy <dmurph@chromium.org>
Cr-Commit-Position: refs/heads/master@{#799683}
parent 75c52710
...@@ -4,6 +4,7 @@ ...@@ -4,6 +4,7 @@
#include "chrome/browser/web_applications/manifest_update_manager.h" #include "chrome/browser/web_applications/manifest_update_manager.h"
#include "base/command_line.h"
#include "base/metrics/histogram_macros.h" #include "base/metrics/histogram_macros.h"
#include "base/util/values/values_util.h" #include "base/util/values/values_util.h"
#include "chrome/browser/content_settings/host_content_settings_map_factory.h" #include "chrome/browser/content_settings/host_content_settings_map_factory.h"
...@@ -17,6 +18,9 @@ ...@@ -17,6 +18,9 @@
namespace web_app { namespace web_app {
constexpr const char kDisableManifestUpdateThrottle[] =
"disable-manifest-update-throttle";
ManifestUpdateManager::ManifestUpdateManager() = default; ManifestUpdateManager::ManifestUpdateManager() = default;
ManifestUpdateManager::~ManifestUpdateManager() = default; ManifestUpdateManager::~ManifestUpdateManager() = default;
...@@ -103,18 +107,19 @@ void ManifestUpdateManager::OnWebAppUninstalled(const AppId& app_id) { ...@@ -103,18 +107,19 @@ void ManifestUpdateManager::OnWebAppUninstalled(const AppId& app_id) {
bool ManifestUpdateManager::MaybeConsumeUpdateCheck(const GURL& origin, bool ManifestUpdateManager::MaybeConsumeUpdateCheck(const GURL& origin,
const AppId& app_id) { const AppId& app_id) {
constexpr base::TimeDelta kDelayBetweenChecks = base::TimeDelta::FromDays(1);
base::Optional<base::Time> last_check_time = base::Optional<base::Time> last_check_time =
GetLastUpdateCheckTime(origin, app_id); GetLastUpdateCheckTime(origin, app_id);
if (!last_check_time)
return false;
base::Time now = time_override_for_testing_.value_or(base::Time::Now()); base::Time now = time_override_for_testing_.value_or(base::Time::Now());
// Throttling updates to at most once per day is consistent with Android. // Throttling updates to at most once per day is consistent with Android.
// See |UPDATE_INTERVAL| in WebappDataStorage.java. // See |UPDATE_INTERVAL| in WebappDataStorage.java.
constexpr base::TimeDelta kDelayBetweenChecks = base::TimeDelta::FromDays(1); if (last_check_time.has_value() &&
if (now < *last_check_time + kDelayBetweenChecks) now < *last_check_time + kDelayBetweenChecks &&
!base::CommandLine::ForCurrentProcess()->HasSwitch(
kDisableManifestUpdateThrottle)) {
return false; return false;
}
SetLastUpdateCheckTime(origin, app_id, now); SetLastUpdateCheckTime(origin, app_id, now);
return true; return true;
} }
...@@ -123,7 +128,8 @@ base::Optional<base::Time> ManifestUpdateManager::GetLastUpdateCheckTime( ...@@ -123,7 +128,8 @@ base::Optional<base::Time> ManifestUpdateManager::GetLastUpdateCheckTime(
const GURL& origin, const GURL& origin,
const AppId& app_id) const { const AppId& app_id) const {
auto it = last_update_check_.find(app_id); auto it = last_update_check_.find(app_id);
return it != last_update_check_.end() ? it->second : base::Time(); return it != last_update_check_.end() ? base::Optional<base::Time>(it->second)
: base::nullopt;
} }
void ManifestUpdateManager::SetLastUpdateCheckTime(const GURL& origin, void ManifestUpdateManager::SetLastUpdateCheckTime(const GURL& origin,
......
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