Commit 478434db authored by Jarryd's avatar Jarryd Committed by Commit Bot

Quota: Hide storage pressure trigger on Android.

Currently, quota internals exposes a button that is used to test the
storage pressure notification, which is not yet available on Android.
This change hides that section on quota internals to prevent users
from crashing the browser when testing this unavailable feature.

Bug: 1076794
Change-Id: I1b25cb52856be9cb419185b74b8bfd89e50f5f13
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2207772
Commit-Queue: Jarryd Goodman <jarrydg@chromium.org>
Reviewed-by: default avatarVictor Costan <pwnall@chromium.org>
Cr-Commit-Position: refs/heads/master@{#773977}
parent 76574e7d
...@@ -390,6 +390,22 @@ function handleStatistics(event) { ...@@ -390,6 +390,22 @@ function handleStatistics(event) {
} }
} }
/**
* Event Handler for |cr.quota.onStoragePressureFlagUpdated|.
* |event.detail| contains a boolean representing whether or not to show
* the storage pressure UI.
* @param {!CustomEvent<!Object>} event StoragePressureFlagUpdated event.
*/
function handleStoragePressureFlagInfo(event) {
const data = event.detail;
$('storage-pressure-loading').hidden = true;
if (data.isStoragePressureEnabled) {
$('storage-pressure-outer').hidden = false;
} else {
$('storage-pressure-disabled').hidden = false;
}
}
/** /**
* Update description on 'tree-item-description' field with * Update description on 'tree-item-description' field with
* selected item in tree view. * selected item in tree view.
...@@ -490,6 +506,8 @@ function onLoad() { ...@@ -490,6 +506,8 @@ function onLoad() {
cr.quota.onPerOriginInfoUpdated.addEventListener( cr.quota.onPerOriginInfoUpdated.addEventListener(
'update', handlePerOriginInfo); 'update', handlePerOriginInfo);
cr.quota.onStatisticsUpdated.addEventListener('update', handleStatistics); cr.quota.onStatisticsUpdated.addEventListener('update', handleStatistics);
cr.quota.onStoragePressureFlagUpdated.addEventListener(
'update', handleStoragePressureFlagInfo);
cr.quota.requestInfo(); cr.quota.requestInfo();
$('refresh-button').addEventListener('click', cr.quota.requestInfo, false); $('refresh-button').addEventListener('click', cr.quota.requestInfo, false);
......
...@@ -56,7 +56,12 @@ found in the LICENSE file. ...@@ -56,7 +56,12 @@ found in the LICENSE file.
<table> <table>
<tbody id="stat-entries" class="entries"></tbody> <tbody id="stat-entries" class="entries"></tbody>
</table> </table>
<div id="storage-pressure-section">
<h2>Test Storage Pressure Behavior</h2> <h2>Test Storage Pressure Behavior</h2>
<div id="storage-pressure-loading">
Loading...
</div>
<div id="storage-pressure-outer" hidden>
<div class="pressure"> <div class="pressure">
Origin to test: Origin to test:
<input id="storage-pressure-origin" <input id="storage-pressure-origin"
...@@ -67,6 +72,11 @@ found in the LICENSE file. ...@@ -67,6 +72,11 @@ found in the LICENSE file.
Trigger Storage Pressure Notification Trigger Storage Pressure Notification
</button> </button>
</div> </div>
</div>
<div id="storage-pressure-disabled" hidden>
Storage Pressure feature disabled.
</div>
</div>
</tabpanel> </tabpanel>
<tabpanel> <tabpanel>
......
...@@ -38,13 +38,15 @@ cr.define('cr.quota', function() { ...@@ -38,13 +38,15 @@ cr.define('cr.quota', function() {
* * onGlobalInfoUpdated, * * onGlobalInfoUpdated,
* * onPerHostInfoUpdated, * * onPerHostInfoUpdated,
* * onPerOriginInfoUpdated, * * onPerOriginInfoUpdated,
* * onStatisticsUpdated. * * onStatisticsUpdated,
* * onStoragePressureFlagUpdated.
* @param {string} message Message label. Possible Values are: * @param {string} message Message label. Possible Values are:
* * 'AvailableSpaceUpdated', * * 'AvailableSpaceUpdated',
* * 'GlobalInfoUpdated', * * 'GlobalInfoUpdated',
* * 'PerHostInfoUpdated', * * 'PerHostInfoUpdated',
* * 'PerOriginInfoUpdated', * * 'PerOriginInfoUpdated',
* * 'StatisticsUpdated'. * * 'StatisticsUpdated',
* * 'StoragePressureFlagUpdated'.
* @param {Object} detail Message specific additional data. * @param {Object} detail Message specific additional data.
*/ */
function messageHandler(message, detail) { function messageHandler(message, detail) {
...@@ -65,6 +67,9 @@ cr.define('cr.quota', function() { ...@@ -65,6 +67,9 @@ cr.define('cr.quota', function() {
case 'StatisticsUpdated': case 'StatisticsUpdated':
target = cr.quota.onStatisticsUpdated; target = cr.quota.onStatisticsUpdated;
break; break;
case 'StoragePressureFlagUpdated':
target = cr.quota.onStoragePressureFlagUpdated;
break;
default: default:
console.error('Unknown Message'); console.error('Unknown Message');
break; break;
...@@ -82,6 +87,7 @@ cr.define('cr.quota', function() { ...@@ -82,6 +87,7 @@ cr.define('cr.quota', function() {
onPerHostInfoUpdated: new cr.EventTarget(), onPerHostInfoUpdated: new cr.EventTarget(),
onPerOriginInfoUpdated: new cr.EventTarget(), onPerOriginInfoUpdated: new cr.EventTarget(),
onStatisticsUpdated: new cr.EventTarget(), onStatisticsUpdated: new cr.EventTarget(),
onStoragePressureFlagUpdated: new cr.EventTarget(),
requestInfo: requestInfo, requestInfo: requestInfo,
triggerStoragePressure: triggerStoragePressure, triggerStoragePressure: triggerStoragePressure,
......
...@@ -7,16 +7,30 @@ ...@@ -7,16 +7,30 @@
#include <string> #include <string>
#include "base/bind.h" #include "base/bind.h"
#include "base/bind_helpers.h" #include "base/feature_list.h"
#include "base/values.h" #include "base/values.h"
#include "build/build_config.h"
#include "chrome/browser/profiles/profile.h" #include "chrome/browser/profiles/profile.h"
#include "chrome/browser/ui/webui/quota_internals/quota_internals_proxy.h" #include "chrome/browser/ui/webui/quota_internals/quota_internals_proxy.h"
#include "chrome/browser/ui/webui/quota_internals/quota_internals_types.h" #include "chrome/browser/ui/webui/quota_internals/quota_internals_types.h"
#include "content/public/browser/storage_partition.h" #include "content/public/browser/storage_partition.h"
#include "content/public/browser/web_ui.h" #include "content/public/browser/web_ui.h"
#include "content/public/common/content_features.h"
using content::BrowserContext; using content::BrowserContext;
namespace {
bool IsStoragePressureEnabled() {
#if defined(OS_ANDROID)
return false;
#else
return base::FeatureList::IsEnabled(features::kStoragePressureUI);
#endif
}
} // namespace
namespace quota_internals { namespace quota_internals {
QuotaInternalsHandler::QuotaInternalsHandler() {} QuotaInternalsHandler::QuotaInternalsHandler() {}
...@@ -75,6 +89,13 @@ void QuotaInternalsHandler::ReportStatistics(const Statistics& stats) { ...@@ -75,6 +89,13 @@ void QuotaInternalsHandler::ReportStatistics(const Statistics& stats) {
SendMessage("StatisticsUpdated", dict); SendMessage("StatisticsUpdated", dict);
} }
void QuotaInternalsHandler::ReportStoragePressureFlag() {
base::DictionaryValue flag_enabled;
flag_enabled.SetBoolean("isStoragePressureEnabled",
IsStoragePressureEnabled());
SendMessage("StoragePressureFlagUpdated", flag_enabled);
}
void QuotaInternalsHandler::SendMessage(const std::string& message, void QuotaInternalsHandler::SendMessage(const std::string& message,
const base::Value& value) { const base::Value& value) {
web_ui()->CallJavascriptFunctionUnsafe("cr.quota.messageHandler", web_ui()->CallJavascriptFunctionUnsafe("cr.quota.messageHandler",
...@@ -84,6 +105,7 @@ void QuotaInternalsHandler::SendMessage(const std::string& message, ...@@ -84,6 +105,7 @@ void QuotaInternalsHandler::SendMessage(const std::string& message,
void QuotaInternalsHandler::OnRequestInfo(const base::ListValue*) { void QuotaInternalsHandler::OnRequestInfo(const base::ListValue*) {
if (!proxy_.get()) if (!proxy_.get())
proxy_ = new QuotaInternalsProxy(this); proxy_ = new QuotaInternalsProxy(this);
ReportStoragePressureFlag();
proxy_->RequestInfo( proxy_->RequestInfo(
BrowserContext::GetDefaultStoragePartition( BrowserContext::GetDefaultStoragePartition(
Profile::FromWebUI(web_ui()))->GetQuotaManager()); Profile::FromWebUI(web_ui()))->GetQuotaManager());
......
...@@ -42,6 +42,7 @@ class QuotaInternalsHandler : public content::WebUIMessageHandler { ...@@ -42,6 +42,7 @@ class QuotaInternalsHandler : public content::WebUIMessageHandler {
void ReportPerHostInfo(const std::vector<PerHostStorageInfo>& hosts); void ReportPerHostInfo(const std::vector<PerHostStorageInfo>& hosts);
void ReportPerOriginInfo(const std::vector<PerOriginStorageInfo>& origins); void ReportPerOriginInfo(const std::vector<PerOriginStorageInfo>& origins);
void ReportStatistics(const Statistics& stats); void ReportStatistics(const Statistics& stats);
void ReportStoragePressureFlag();
private: private:
void OnRequestInfo(const base::ListValue*); void OnRequestInfo(const base::ListValue*);
......
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