Commit 1533915c authored by Lei Zhang's avatar Lei Zhang Committed by Commit Bot

Convert time constants to base::TimeDelta in chrome/browser/extensions.

Change-Id: I89c98bdec12e657b7928b00082a5c6591596879e
Reviewed-on: https://chromium-review.googlesource.com/1168595
Commit-Queue: Lei Zhang <thestig@chromium.org>
Reviewed-by: default avatarDevlin <rdevlin.cronin@chromium.org>
Cr-Commit-Position: refs/heads/master@{#581912}
parent bfde49d0
...@@ -56,7 +56,7 @@ using extensions::Action; ...@@ -56,7 +56,7 @@ using extensions::Action;
// Delay between cleaning passes (to delete old action records) through the // Delay between cleaning passes (to delete old action records) through the
// database. // database.
const int kCleaningDelayInHours = 12; constexpr base::TimeDelta kCleaningDelay = base::TimeDelta::FromHours(12);
// We should log the arguments to these API calls. Be careful when // We should log the arguments to these API calls. Be careful when
// constructing this whitelist to not keep arguments that might compromise // constructing this whitelist to not keep arguments that might compromise
...@@ -244,8 +244,7 @@ bool CountingPolicy::FlushDatabase(sql::Database* db) { ...@@ -244,8 +244,7 @@ bool CountingPolicy::FlushDatabase(sql::Database* db) {
// always check on the first database flush (since there might be a large // always check on the first database flush (since there might be a large
// amount of data to clear). // amount of data to clear).
bool clean_database = (last_database_cleaning_time_.is_null() || bool clean_database = (last_database_cleaning_time_.is_null() ||
Now() - last_database_cleaning_time_ > Now() - last_database_cleaning_time_ > kCleaningDelay);
base::TimeDelta::FromHours(kCleaningDelayInHours));
if (queue.empty() && !clean_database) if (queue.empty() && !clean_database)
return true; return true;
......
...@@ -27,12 +27,17 @@ namespace api { ...@@ -27,12 +27,17 @@ namespace api {
namespace braille_display_private { namespace braille_display_private {
namespace { namespace {
// Delay between detecting a directory update and trying to connect // Delay between detecting a directory update and trying to connect
// to the brlapi. // to the brlapi.
const int64_t kConnectionDelayMs = 500; constexpr base::TimeDelta kConnectionDelay =
base::TimeDelta::FromMilliseconds(500);
// How long to periodically retry connecting after a brltty restart. // How long to periodically retry connecting after a brltty restart.
// Some displays are slow to connect. // Some displays are slow to connect.
const int64_t kConnectRetryTimeout = 20000; constexpr base::TimeDelta kConnectRetryTimeout =
base::TimeDelta::FromSeconds(20);
} // namespace } // namespace
BrailleController::BrailleController() { BrailleController::BrailleController() {
...@@ -248,19 +253,16 @@ void BrailleControllerImpl::TryToConnect() { ...@@ -248,19 +253,16 @@ void BrailleControllerImpl::TryToConnect() {
void BrailleControllerImpl::ResetRetryConnectHorizon() { void BrailleControllerImpl::ResetRetryConnectHorizon() {
DCHECK_CURRENTLY_ON(BrowserThread::IO); DCHECK_CURRENTLY_ON(BrowserThread::IO);
retry_connect_horizon_ = retry_connect_horizon_ = base::Time::Now() + kConnectRetryTimeout;
base::Time::Now() +
base::TimeDelta::FromMilliseconds(kConnectRetryTimeout);
} }
void BrailleControllerImpl::ScheduleTryToConnect() { void BrailleControllerImpl::ScheduleTryToConnect() {
DCHECK_CURRENTLY_ON(BrowserThread::IO); DCHECK_CURRENTLY_ON(BrowserThread::IO);
base::TimeDelta delay(base::TimeDelta::FromMilliseconds(kConnectionDelayMs));
// Don't reschedule if there's already a connect scheduled or // Don't reschedule if there's already a connect scheduled or
// the next attempt would fall outside of the retry limit. // the next attempt would fall outside of the retry limit.
if (connect_scheduled_) if (connect_scheduled_)
return; return;
if (base::Time::Now() + delay > retry_connect_horizon_) { if (base::Time::Now() + kConnectionDelay > retry_connect_horizon_) {
VLOG(1) << "Stopping to retry to connect to brlapi"; VLOG(1) << "Stopping to retry to connect to brlapi";
return; return;
} }
...@@ -270,7 +272,7 @@ void BrailleControllerImpl::ScheduleTryToConnect() { ...@@ -270,7 +272,7 @@ void BrailleControllerImpl::ScheduleTryToConnect() {
BrowserThread::IO, FROM_HERE, BrowserThread::IO, FROM_HERE,
base::BindOnce(&BrailleControllerImpl::TryToConnect, base::BindOnce(&BrailleControllerImpl::TryToConnect,
base::Unretained(this)), base::Unretained(this)),
delay); kConnectionDelay);
} }
void BrailleControllerImpl::Disconnect() { void BrailleControllerImpl::Disconnect() {
......
...@@ -34,8 +34,8 @@ const int kMaxOffscreenTabsPerExtension = 4; ...@@ -34,8 +34,8 @@ const int kMaxOffscreenTabsPerExtension = 4;
// Time intervals used by the logic that detects when the capture of an // Time intervals used by the logic that detects when the capture of an
// offscreen tab has stopped, to automatically tear it down and free resources. // offscreen tab has stopped, to automatically tear it down and free resources.
const int kMaxSecondsToWaitForCapture = 60; constexpr base::TimeDelta kMaxWaitForCapture = base::TimeDelta::FromMinutes(1);
const int kPollIntervalInSeconds = 1; constexpr base::TimeDelta kPollInterval = base::TimeDelta::FromSeconds(1);
} // namespace } // namespace
...@@ -392,8 +392,7 @@ void OffscreenTab::DieIfContentCaptureEnded() { ...@@ -392,8 +392,7 @@ void OffscreenTab::DieIfContentCaptureEnded() {
DVLOG(2) << "Capture of OffscreenTab content has started for start_url=" DVLOG(2) << "Capture of OffscreenTab content has started for start_url="
<< start_url_.spec(); << start_url_.spec();
content_capture_was_detected_ = true; content_capture_was_detected_ = true;
} else if (base::TimeTicks::Now() - start_time_ > } else if (base::TimeTicks::Now() - start_time_ > kMaxWaitForCapture) {
base::TimeDelta::FromSeconds(kMaxSecondsToWaitForCapture)) {
// More than a minute has elapsed since this OffscreenTab was started and // More than a minute has elapsed since this OffscreenTab was started and
// content capture still hasn't started. As a safety precaution, assume // content capture still hasn't started. As a safety precaution, assume
// that content capture is never going to start and die to free up // that content capture is never going to start and die to free up
...@@ -405,11 +404,9 @@ void OffscreenTab::DieIfContentCaptureEnded() { ...@@ -405,11 +404,9 @@ void OffscreenTab::DieIfContentCaptureEnded() {
} }
// Schedule the timer to check again in a second. // Schedule the timer to check again in a second.
capture_poll_timer_.Start( capture_poll_timer_.Start(FROM_HERE, kPollInterval,
FROM_HERE, base::Bind(&OffscreenTab::DieIfContentCaptureEnded,
base::TimeDelta::FromSeconds(kPollIntervalInSeconds), base::Unretained(this)));
base::Bind(&OffscreenTab::DieIfContentCaptureEnded,
base::Unretained(this)));
} }
void OffscreenTab::DieIfOriginalProfileDestroyed(Profile* profile) { void OffscreenTab::DieIfOriginalProfileDestroyed(Profile* profile) {
......
...@@ -42,12 +42,14 @@ namespace extensions { ...@@ -42,12 +42,14 @@ namespace extensions {
namespace { namespace {
// Wait this many seconds before trying to garbage collect extensions again. // Wait this long before trying to garbage collect extensions again.
const int kGarbageCollectRetryDelayInSeconds = 30; constexpr base::TimeDelta kGarbageCollectRetryDelay =
base::TimeDelta::FromSeconds(30);
// Wait this many seconds after startup to see if there are any extensions // Wait this long after startup to see if there are any extensions which can be
// which can be garbage collected. // garbage collected.
const int kGarbageCollectStartupDelay = 30; constexpr base::TimeDelta kGarbageCollectStartupDelay =
base::TimeDelta::FromSeconds(30);
typedef std::multimap<std::string, base::FilePath> ExtensionPathsMultimap; typedef std::multimap<std::string, base::FilePath> ExtensionPathsMultimap;
...@@ -117,7 +119,7 @@ ExtensionGarbageCollector::ExtensionGarbageCollector( ...@@ -117,7 +119,7 @@ ExtensionGarbageCollector::ExtensionGarbageCollector(
FROM_HERE, FROM_HERE,
base::Bind(&ExtensionGarbageCollector::GarbageCollectExtensions, base::Bind(&ExtensionGarbageCollector::GarbageCollectExtensions,
weak_factory_.GetWeakPtr()), weak_factory_.GetWeakPtr()),
base::TimeDelta::FromSeconds(kGarbageCollectStartupDelay)); kGarbageCollectStartupDelay);
extension_system->ready().Post( extension_system->ready().Post(
FROM_HERE, FROM_HERE,
...@@ -182,7 +184,7 @@ void ExtensionGarbageCollector::GarbageCollectExtensions() { ...@@ -182,7 +184,7 @@ void ExtensionGarbageCollector::GarbageCollectExtensions() {
FROM_HERE, FROM_HERE,
base::BindOnce(&ExtensionGarbageCollector::GarbageCollectExtensions, base::BindOnce(&ExtensionGarbageCollector::GarbageCollectExtensions,
weak_factory_.GetWeakPtr()), weak_factory_.GetWeakPtr()),
base::TimeDelta::FromSeconds(kGarbageCollectRetryDelayInSeconds)); kGarbageCollectRetryDelay);
return; return;
} }
......
...@@ -122,12 +122,12 @@ using LoadErrorBehavior = ExtensionRegistrar::LoadErrorBehavior; ...@@ -122,12 +122,12 @@ using LoadErrorBehavior = ExtensionRegistrar::LoadErrorBehavior;
namespace { namespace {
// Wait this many seconds after an extensions becomes idle before updating it. // Wait this long after an extensions becomes idle before updating it.
const int kUpdateIdleDelay = 5; constexpr base::TimeDelta kUpdateIdleDelay = base::TimeDelta::FromSeconds(5);
// IDs of extensions that have been replaced by component extensions and need to // IDs of extensions that have been replaced by component extensions and need to
// be uninstalled. // be uninstalled.
const char* kMigratedExtensionIds[] = { const char* const kMigratedExtensionIds[] = {
"boadgeojelhgndaghljhdicfkmllpafd", // Google Cast "boadgeojelhgndaghljhdicfkmllpafd", // Google Cast
"dliochdbjfkdbacpmhlcpmleaejidimm" // Google Cast (Beta) "dliochdbjfkdbacpmhlcpmleaejidimm" // Google Cast (Beta)
}; };
...@@ -1812,7 +1812,7 @@ void ExtensionService::Observe(int type, ...@@ -1812,7 +1812,7 @@ void ExtensionService::Observe(int type,
base::IgnoreResult( base::IgnoreResult(
&ExtensionService::FinishDelayedInstallationIfReady), &ExtensionService::FinishDelayedInstallationIfReady),
AsWeakPtr(), *it, false /*install_immediately*/), AsWeakPtr(), *it, false /*install_immediately*/),
base::TimeDelta::FromSeconds(kUpdateIdleDelay)); kUpdateIdleDelay);
} }
} }
} }
......
...@@ -5,32 +5,26 @@ ...@@ -5,32 +5,26 @@
#include "chrome/browser/extensions/updater/extension_cache_delegate.h" #include "chrome/browser/extensions/updater/extension_cache_delegate.h"
namespace extensions { namespace extensions {
namespace {
// Default maximum size of local cache on disk, in bytes.
const size_t kDefaultCacheSizeLimit = 256 * 1024 * 1024;
// Default minimum size of local cache on disk, in bytes.
const int kDefaultMinimumCacheSize = 1024 * 1024;
// Maximum age of unused extensions in the cache.
const int kMaxCacheAgeInDays = 30;
} // namespace
ExtensionCacheDelegate::~ExtensionCacheDelegate() { ExtensionCacheDelegate::~ExtensionCacheDelegate() {
} }
size_t ExtensionCacheDelegate::GetMinimumCacheSize() const { size_t ExtensionCacheDelegate::GetMinimumCacheSize() const {
// Default minimum size of local cache on disk, in bytes.
static constexpr int kDefaultMinimumCacheSize = 1024 * 1024;
return kDefaultMinimumCacheSize; return kDefaultMinimumCacheSize;
} }
size_t ExtensionCacheDelegate::GetMaximumCacheSize() const { size_t ExtensionCacheDelegate::GetMaximumCacheSize() const {
// Default maximum size of local cache on disk, in bytes.
static constexpr size_t kDefaultCacheSizeLimit = 256 * 1024 * 1024;
return kDefaultCacheSizeLimit; return kDefaultCacheSizeLimit;
} }
base::TimeDelta ExtensionCacheDelegate::GetMaximumCacheAge() const { base::TimeDelta ExtensionCacheDelegate::GetMaximumCacheAge() const {
return base::TimeDelta::FromDays(kMaxCacheAgeInDays); // Maximum age of unused extensions in the cache.
static constexpr base::TimeDelta kMaxCacheAge = base::TimeDelta::FromDays(30);
return kMaxCacheAge;
} }
} // namespace extensions } // namespace extensions
...@@ -23,7 +23,8 @@ const char kCRXFileExtension[] = ".crx"; ...@@ -23,7 +23,8 @@ const char kCRXFileExtension[] = ".crx";
// Delay between checks for flag file presence when waiting for the cache to // Delay between checks for flag file presence when waiting for the cache to
// become ready. // become ready.
const int64_t kCacheStatusPollingDelayMs = 1000; constexpr base::TimeDelta kCacheStatusPollingDelay =
base::TimeDelta::FromSeconds(1);
} // namespace } // namespace
...@@ -39,8 +40,7 @@ LocalExtensionCache::LocalExtensionCache( ...@@ -39,8 +40,7 @@ LocalExtensionCache::LocalExtensionCache(
min_cache_age_(base::Time::Now() - max_cache_age), min_cache_age_(base::Time::Now() - max_cache_age),
backend_task_runner_(backend_task_runner), backend_task_runner_(backend_task_runner),
state_(kUninitialized), state_(kUninitialized),
cache_status_polling_delay_( cache_status_polling_delay_(kCacheStatusPollingDelay),
base::TimeDelta::FromMilliseconds(kCacheStatusPollingDelayMs)),
weak_ptr_factory_(this) {} weak_ptr_factory_(this) {}
LocalExtensionCache::~LocalExtensionCache() { LocalExtensionCache::~LocalExtensionCache() {
......
...@@ -102,7 +102,8 @@ const char kAppLauncherInstallSource[] = "applauncher"; ...@@ -102,7 +102,8 @@ const char kAppLauncherInstallSource[] = "applauncher";
// See http://crbug.com/371398. // See http://crbug.com/371398.
const char kAuthUserQueryKey[] = "authuser"; const char kAuthUserQueryKey[] = "authuser";
const size_t kTimeRemainingMinutesThreshold = 1u; constexpr base::TimeDelta kTimeRemainingThreshold =
base::TimeDelta::FromSeconds(1);
// Folder for downloading crx files from the webstore. This is used so that the // Folder for downloading crx files from the webstore. This is used so that the
// crx files don't go via the usual downloads folder. // crx files don't go via the usual downloads folder.
...@@ -738,13 +739,9 @@ void WebstoreInstaller::UpdateDownloadProgress() { ...@@ -738,13 +739,9 @@ void WebstoreInstaller::UpdateDownloadProgress() {
// timer. // timer.
base::TimeDelta time_remaining; base::TimeDelta time_remaining;
if (download_item_->TimeRemaining(&time_remaining) && if (download_item_->TimeRemaining(&time_remaining) &&
time_remaining > time_remaining > kTimeRemainingThreshold) {
base::TimeDelta::FromSeconds(kTimeRemainingMinutesThreshold)) { download_progress_timer_.Start(FROM_HERE, kTimeRemainingThreshold, this,
download_progress_timer_.Start( &WebstoreInstaller::UpdateDownloadProgress);
FROM_HERE,
base::TimeDelta::FromSeconds(kTimeRemainingMinutesThreshold),
this,
&WebstoreInstaller::UpdateDownloadProgress);
} else { } else {
download_progress_timer_.Stop(); download_progress_timer_.Stop();
} }
......
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