Commit 6efb4dae authored by Gyuyoung Kim's avatar Gyuyoung Kim Committed by Commit Bot

AppCache: Add command-line flags for default quota and disk size.

This CL introduces the following command-line switches:
- max-appcache-disk-cache-size-mb - limits the size of the HTTP disk
  cache used by AppCache for all origins
- max-appcache-origin-cache-size-mb - limits the per-origin AppCache
  quota when no QuotaManager is present

The CL is heavily based on the following reverted commits:
1. https://crrev.com/c/974804 - Set the maximum cache size per an origin
    in the command line for application cache
2. https://crrev.com/c/979877 - Pass the maximium disk cache size of
    appcache in the command line to appcache thread

Bug: 824619, 895825
Change-Id: I4fb424fa740ef9875d0584def4e9390aef366916
Reviewed-on: https://chromium-review.googlesource.com/c/1282685Reviewed-by: default avatarAntoine Labour <piman@chromium.org>
Reviewed-by: default avatarVictor Costan <pwnall@chromium.org>
Commit-Queue: Gyuyoung Kim <gyuyoung.kim@lge.com>
Cr-Commit-Position: refs/heads/master@{#605118}
parent 093f35ab
......@@ -14,11 +14,13 @@
#include "base/bind.h"
#include "base/bind_helpers.h"
#include "base/command_line.h"
#include "base/files/file_util.h"
#include "base/location.h"
#include "base/logging.h"
#include "base/single_thread_task_runner.h"
#include "base/stl_util.h"
#include "base/strings/string_number_conversions.h"
#include "base/strings/string_util.h"
#include "base/threading/sequenced_task_runner_handle.h"
#include "base/trace_event/trace_event.h"
......@@ -30,6 +32,7 @@
#include "content/browser/appcache/appcache_quota_client.h"
#include "content/browser/appcache/appcache_response.h"
#include "content/browser/appcache/appcache_service_impl.h"
#include "content/public/common/content_switches.h"
#include "net/base/cache_type.h"
#include "net/base/net_errors.h"
#include "sql/database.h"
......@@ -43,11 +46,13 @@ namespace content {
namespace {
constexpr const int kMB = 1024 * 1024;
// Hard coded default when not using quota management.
constexpr const int kDefaultQuota = 5 * 1024 * 1024;
constexpr const int kDefaultQuota = 5 * kMB;
constexpr const int kMaxAppCacheDiskCacheSize = 250 * 1024 * 1024;
constexpr const int kMaxAppCacheMemDiskCacheSize = 10 * 1024 * 1024;
constexpr const int kMaxAppCacheDiskCacheSize = 250 * kMB;
constexpr const int kMaxAppCacheMemDiskCacheSize = 10 * kMB;
constexpr base::FilePath::CharType kDiskCacheDirectoryName[] =
FILE_PATH_LITERAL("Cache");
......@@ -615,14 +620,24 @@ class AppCacheStorageImpl::StoreGroupAndCacheTask : public StoreOrLoadTask {
bool would_exceed_quota_;
int64_t space_available_;
int64_t new_origin_usage_;
int64_t max_appcache_origin_cache_size_;
std::vector<int64_t> newly_deletable_response_ids_;
};
AppCacheStorageImpl::StoreGroupAndCacheTask::StoreGroupAndCacheTask(
AppCacheStorageImpl* storage, AppCacheGroup* group, AppCache* newest_cache)
: StoreOrLoadTask(storage), group_(group), cache_(newest_cache),
success_(false), would_exceed_quota_(false),
space_available_(-1), new_origin_usage_(-1) {
AppCacheStorageImpl* storage,
AppCacheGroup* group,
AppCache* newest_cache)
: StoreOrLoadTask(storage),
group_(group),
cache_(newest_cache),
success_(false),
would_exceed_quota_(false),
space_available_(-1),
new_origin_usage_(-1),
// TODO(crbug.com/895825): Remove max_appcache_origin_cache_size_ in Feb
// 2019.
max_appcache_origin_cache_size_(kDefaultQuota) {
group_record_.group_id = group->group_id();
group_record_.manifest_url = group->manifest_url();
group_record_.origin = url::Origin::Create(group_record_.manifest_url);
......@@ -636,6 +651,15 @@ AppCacheStorageImpl::StoreGroupAndCacheTask::StoreGroupAndCacheTask(
&intercept_namespace_records_,
&fallback_namespace_records_,
&online_whitelist_records_);
base::CommandLine& command_line = *base::CommandLine::ForCurrentProcess();
if (command_line.HasSwitch(switches::kMaxAppCacheOriginCacheSizeMb)) {
if (base::StringToInt64(command_line.GetSwitchValueASCII(
switches::kMaxAppCacheOriginCacheSizeMb),
&max_appcache_origin_cache_size_)) {
max_appcache_origin_cache_size_ *= kMB;
}
}
}
void AppCacheStorageImpl::StoreGroupAndCacheTask::GetQuotaThenSchedule() {
......@@ -757,9 +781,10 @@ void AppCacheStorageImpl::StoreGroupAndCacheTask::Run() {
return;
}
// Use a simple hard-coded value when not using quota management.
// Use the value in --max-appcache-disk-cache-size-mb (or a hard-coded
// default) when no QuotaManager is wired in.
if (space_available_ == -1) {
if (new_origin_usage_ > kDefaultQuota) {
if (new_origin_usage_ > max_appcache_origin_cache_size_) {
would_exceed_quota_ = true;
success_ = false;
return;
......@@ -1874,9 +1899,21 @@ AppCacheDiskCache* AppCacheStorageImpl::disk_cache() {
base::Unretained(this)));
} else {
expecting_cleanup_complete_on_disable_ = true;
const base::CommandLine& command_line =
*base::CommandLine::ForCurrentProcess();
int64_t max_appcache_disk_cache_size = kMaxAppCacheDiskCacheSize;
if (command_line.HasSwitch(switches::kMaxAppCacheDiskCacheSizeMb)) {
if (base::StringToInt64(command_line.GetSwitchValueASCII(
switches::kMaxAppCacheDiskCacheSizeMb),
&max_appcache_disk_cache_size)) {
max_appcache_disk_cache_size *= kMB;
}
}
rv = disk_cache_->InitWithDiskBackend(
cache_directory_.Append(kDiskCacheDirectoryName),
kMaxAppCacheDiskCacheSize, false,
max_appcache_disk_cache_size, false,
base::BindOnce(&AppCacheStorageImpl::OnDiskCacheCleanupComplete,
weak_factory_.GetWeakPtr()),
base::BindOnce(&AppCacheStorageImpl::OnDiskCacheInitialized,
......
......@@ -579,6 +579,17 @@ const char kLogFile[] = "log-file";
const char kMainFrameResizesAreOrientationChanges[] =
"main-frame-resizes-are-orientation-changes";
// Specifies the maximum disk cache size for the ApplicationCache. The default
// value is 250MB.
// TODO(crbug.com/895825): Remove this flag in Feb 2019.
const char kMaxAppCacheDiskCacheSizeMb[] = "max-appcache-disk-cache-size-mb";
// Specifies the maximum cache size per an origin for the ApplicationCache.
// The default value is 5MB.
// TODO(crbug.com/895825): Remove this flag in Feb 2019.
const char kMaxAppCacheOriginCacheSizeMb[] =
"max-appcache-origin-cache-size-mb";
// Sets the maximium decoded image size limitation.
const char kMaxDecodedImageSizeMb[] = "max-decoded-image-size-mb";
......
......@@ -174,6 +174,8 @@ CONTENT_EXPORT extern const char kLogGpuControlListDecisions[];
CONTENT_EXPORT extern const char kLoggingLevel[];
CONTENT_EXPORT extern const char kLogFile[];
CONTENT_EXPORT extern const char kMainFrameResizesAreOrientationChanges[];
extern const char kMaxAppCacheDiskCacheSizeMb[];
extern const char kMaxAppCacheOriginCacheSizeMb[];
extern const char kMaxDecodedImageSizeMb[];
extern const char kMaxUntiledLayerHeight[];
extern const char kMaxUntiledLayerWidth[];
......
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