Quota: Add button to test storage pressure notification.
Add a button to the quota-internals page that will trigger the storage pressure notification and ignore any rate limiting. This is useful for folks to test the storage pressure behavior without having to actually put the device under storage pressure. Bug: 997258 Change-Id: I4ced3f9a37f8d731570cb1bcb1528e8d8e758905 Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2116934 Commit-Queue: Victor Costan <pwnall@chromium.org> Reviewed-by: Victor Costan <pwnall@chromium.org> Reviewed-by: Kinuko Yasuda <kinuko@chromium.org> Cr-Commit-Position: refs/heads/master@{#755726}
This commit is contained in:
chrome
browser
resources
quota_internals
storage
ui
common
storage/browser/quota
@ -491,6 +491,10 @@ function onLoad() {
|
||||
|
||||
$('refresh-button').addEventListener('click', cr.quota.requestInfo, false);
|
||||
$('dump-button').addEventListener('click', dump, false);
|
||||
$('trigger-notification').addEventListener('click', () => {
|
||||
const origin = $('storage-pressure-origin').value;
|
||||
cr.quota.triggerStoragePressure(origin);
|
||||
}, false);
|
||||
}
|
||||
|
||||
document.addEventListener('DOMContentLoaded', onLoad, false);
|
||||
|
@ -22,3 +22,10 @@ tr:nth-child(odd) {
|
||||
.tree-item:not([may-have-children]) > .tree-row > .tree-label-icon {
|
||||
background-image: url(../../../../ui/webui/resources/images/icon_file.png);
|
||||
}
|
||||
|
||||
.pressure {
|
||||
margin: 10px 0;
|
||||
}
|
||||
#storage-pressure-origin {
|
||||
min-width: 20em;
|
||||
}
|
||||
|
@ -48,6 +48,17 @@ found in the LICENSE file.
|
||||
<table>
|
||||
<tbody id="stat-entries" class="entries"></tbody>
|
||||
</table>
|
||||
<h2>Test Storage Pressure Behavior</h2>
|
||||
<div class="pressure">
|
||||
Origin to test:
|
||||
<input id="storage-pressure-origin"
|
||||
value="https://www.example.com">
|
||||
</div>
|
||||
<div class="pressure">
|
||||
<button id="trigger-notification">
|
||||
Trigger Storage Pressure Notification
|
||||
</button>
|
||||
</div>
|
||||
</tabpanel>
|
||||
|
||||
<tabpanel>
|
||||
|
@ -24,6 +24,13 @@ cr.define('cr.quota', function() {
|
||||
chrome.send('requestInfo');
|
||||
}
|
||||
|
||||
/**
|
||||
* Post triggerStoragePressure message to Browser.
|
||||
*/
|
||||
function triggerStoragePressure(origin) {
|
||||
chrome.send('triggerStoragePressure', [origin]);
|
||||
}
|
||||
|
||||
/**
|
||||
* Callback entry point from Browser.
|
||||
* Messages are Dispatched as Event to:
|
||||
@ -77,6 +84,7 @@ cr.define('cr.quota', function() {
|
||||
onStatisticsUpdated: new cr.EventTarget(),
|
||||
|
||||
requestInfo: requestInfo,
|
||||
triggerStoragePressure: triggerStoragePressure,
|
||||
messageHandler: messageHandler
|
||||
};
|
||||
});
|
||||
|
@ -4,23 +4,44 @@
|
||||
|
||||
#include "chrome/browser/storage/storage_notification_service_impl.h"
|
||||
|
||||
#include "base/command_line.h"
|
||||
#include "base/strings/string_number_conversions.h"
|
||||
#include "base/time/time.h"
|
||||
#include "build/build_config.h"
|
||||
#include "chrome/browser/profiles/profile.h"
|
||||
#include "chrome/common/chrome_switches.h"
|
||||
|
||||
#if !defined(OS_ANDROID)
|
||||
#include "chrome/browser/ui/storage_pressure_bubble.h"
|
||||
#endif
|
||||
|
||||
namespace {
|
||||
|
||||
// Minimum interval between consecutive storage pressure notifications.
|
||||
const base::TimeDelta kDiskPressureNotificationInterval =
|
||||
base::TimeDelta::FromDays(1);
|
||||
|
||||
const base::TimeDelta GetThrottlingInterval() {
|
||||
base::CommandLine* command_line = base::CommandLine::ForCurrentProcess();
|
||||
int int_value;
|
||||
if (command_line->HasSwitch(switches::kStoragePressureNotificationInterval)) {
|
||||
const std::string string_value = command_line->GetSwitchValueASCII(
|
||||
switches::kStoragePressureNotificationInterval);
|
||||
if (base::StringToInt(string_value, &int_value) && int_value >= 0) {
|
||||
return base::TimeDelta::FromMinutes(int_value);
|
||||
}
|
||||
}
|
||||
return kDiskPressureNotificationInterval;
|
||||
}
|
||||
|
||||
} // namespace
|
||||
|
||||
void StorageNotificationServiceImpl::MaybeShowStoragePressureNotification(
|
||||
const url::Origin origin) {
|
||||
if (base::TimeTicks::Now() - disk_pressure_notification_last_sent_at_ <
|
||||
kDiskPressureNotificationInterval)
|
||||
GetThrottlingInterval()) {
|
||||
return;
|
||||
}
|
||||
|
||||
chrome::ShowStoragePressureBubble(origin);
|
||||
disk_pressure_notification_last_sent_at_ = base::TimeTicks::Now();
|
||||
|
@ -30,6 +30,10 @@ void QuotaInternalsHandler::RegisterMessages() {
|
||||
web_ui()->RegisterMessageCallback(
|
||||
"requestInfo", base::BindRepeating(&QuotaInternalsHandler::OnRequestInfo,
|
||||
base::Unretained(this)));
|
||||
web_ui()->RegisterMessageCallback(
|
||||
"triggerStoragePressure",
|
||||
base::BindRepeating(&QuotaInternalsHandler::OnTriggerStoragePressure,
|
||||
base::Unretained(this)));
|
||||
}
|
||||
|
||||
void QuotaInternalsHandler::ReportAvailableSpace(int64_t available_space) {
|
||||
@ -85,4 +89,19 @@ void QuotaInternalsHandler::OnRequestInfo(const base::ListValue*) {
|
||||
Profile::FromWebUI(web_ui()))->GetQuotaManager());
|
||||
}
|
||||
|
||||
void QuotaInternalsHandler::OnTriggerStoragePressure(
|
||||
const base::ListValue* args) {
|
||||
CHECK_EQ(1U, args->GetSize());
|
||||
std::string origin_string;
|
||||
CHECK(args->GetString(0, &origin_string));
|
||||
GURL url(origin_string);
|
||||
|
||||
if (!proxy_.get())
|
||||
proxy_ = new QuotaInternalsProxy(this);
|
||||
proxy_->TriggerStoragePressure(
|
||||
url::Origin::Create(url),
|
||||
BrowserContext::GetDefaultStoragePartition(Profile::FromWebUI(web_ui()))
|
||||
->GetQuotaManager());
|
||||
}
|
||||
|
||||
} // namespace quota_internals
|
||||
|
@ -45,6 +45,7 @@ class QuotaInternalsHandler : public content::WebUIMessageHandler {
|
||||
|
||||
private:
|
||||
void OnRequestInfo(const base::ListValue*);
|
||||
void OnTriggerStoragePressure(const base::ListValue*);
|
||||
void SendMessage(const std::string& message, const base::Value& value);
|
||||
|
||||
scoped_refptr<QuotaInternalsProxy> proxy_;
|
||||
|
@ -67,6 +67,19 @@ void QuotaInternalsProxy::RequestInfo(
|
||||
ReportStatistics(stats);
|
||||
}
|
||||
|
||||
void QuotaInternalsProxy::TriggerStoragePressure(
|
||||
url::Origin origin,
|
||||
scoped_refptr<storage::QuotaManager> quota_manager) {
|
||||
DCHECK(quota_manager.get());
|
||||
if (!BrowserThread::CurrentlyOn(BrowserThread::IO)) {
|
||||
base::PostTask(FROM_HERE, {BrowserThread::IO},
|
||||
base::BindOnce(&QuotaInternalsProxy::TriggerStoragePressure,
|
||||
this, origin, quota_manager));
|
||||
return;
|
||||
}
|
||||
quota_manager->SimulateStoragePressure(origin);
|
||||
}
|
||||
|
||||
QuotaInternalsProxy::~QuotaInternalsProxy() = default;
|
||||
|
||||
#define RELAY_TO_HANDLER(func, arg_t) \
|
||||
|
@ -39,6 +39,9 @@ class QuotaInternalsProxy
|
||||
explicit QuotaInternalsProxy(QuotaInternalsHandler* handler);
|
||||
|
||||
void RequestInfo(scoped_refptr<storage::QuotaManager> quota_manager);
|
||||
void TriggerStoragePressure(
|
||||
url::Origin origin,
|
||||
scoped_refptr<storage::QuotaManager> quota_manager);
|
||||
|
||||
private:
|
||||
friend class base::DeleteHelper<QuotaInternalsProxy>;
|
||||
|
@ -575,6 +575,12 @@ const char kStartStackProfiler[] = "start-stack-profiler";
|
||||
// durations to be significantly less than the test timeout.
|
||||
const char kStartStackProfilerBrowserTest[] = "browser-test";
|
||||
|
||||
// Interval, in minutes, used for storage pressure notification throttling.
|
||||
// Useful for developers testing applications that might use non-trivial
|
||||
// amounts of disk space.
|
||||
const char kStoragePressureNotificationInterval[] =
|
||||
"storage-pressure-notification-interval";
|
||||
|
||||
// Sets the supervised user ID for any loaded or newly created profile to the
|
||||
// given value. Pass an empty string to mark the profile as non-supervised.
|
||||
// Used for testing.
|
||||
|
@ -169,6 +169,7 @@ extern const char kSSLVersionTLSv13[];
|
||||
extern const char kStartMaximized[];
|
||||
extern const char kStartStackProfiler[];
|
||||
extern const char kStartStackProfilerBrowserTest[];
|
||||
extern const char kStoragePressureNotificationInterval[];
|
||||
extern const char kSupervisedUserId[];
|
||||
extern const char kSystemLogUploadFrequency[];
|
||||
extern const char kTaskManagerShowExtraRenderers[];
|
||||
|
@ -1508,6 +1508,10 @@ void QuotaManager::MaybeRunStoragePressureCallback(const url::Origin& origin,
|
||||
}
|
||||
}
|
||||
|
||||
void QuotaManager::SimulateStoragePressure(const url::Origin origin) {
|
||||
storage_pressure_callback_.Run(origin);
|
||||
}
|
||||
|
||||
void QuotaManager::SetStoragePressureCallback(
|
||||
base::RepeatingCallback<void(url::Origin)> storage_pressure_callback) {
|
||||
storage_pressure_callback_ = storage_pressure_callback;
|
||||
|
@ -418,6 +418,9 @@ class COMPONENT_EXPORT(STORAGE_BROWSER) QuotaManager
|
||||
void MaybeRunStoragePressureCallback(const url::Origin& origin,
|
||||
int64_t total_space,
|
||||
int64_t available_space);
|
||||
// Used from quota-internals page to test behavior of the storage pressure
|
||||
// callback.
|
||||
void SimulateStoragePressure(const url::Origin origin);
|
||||
|
||||
void PostTaskAndReplyWithResultForDBThread(
|
||||
const base::Location& from_here,
|
||||
|
Reference in New Issue
Block a user