Commit f78d3a82 authored by Sigurdur Asgeirsson's avatar Sigurdur Asgeirsson Committed by Commit Bot

RC: Plumb the DB size to the chrome://discards page.

Bug: 874968
Change-Id: If8dbe441b02baf0910dbf2b1b89fd7cd9c67e5eb
Reviewed-on: https://chromium-review.googlesource.com/1240200
Commit-Queue: Sigurður Ásgeirsson <siggi@chromium.org>
Reviewed-by: default avatarDemetrios Papadopoulos <dpapad@chromium.org>
Reviewed-by: default avatarFrançois Doray <fdoray@chromium.org>
Reviewed-by: default avatarWill Harris <wfh@chromium.org>
Cr-Commit-Position: refs/heads/master@{#593917}
parent 33ef01da
......@@ -89,8 +89,7 @@ LocalSiteCharacteristicsDataStore::GetAllInMemoryOrigins() {
void LocalSiteCharacteristicsDataStore::GetDatabaseSize(
DatabaseSizeCallback on_have_data) {
// TODO(siggi): implement me.
std::move(on_have_data).Run(base::nullopt, base::nullopt);
database_->GetDatabaseSize(std::move(on_have_data));
}
bool LocalSiteCharacteristicsDataStore::GetDataForOrigin(
......
......@@ -59,6 +59,10 @@ general use and is not localized.
opacity: 1;
}
</style>
<div>
<div>Database Rows: [[optionalIntegerToString_(size_.numRows)]]</div>
<div>Database Size: [[kilobytesToString_(size_.onDiskSizeKb)]]</div>
</div>
<table>
<thead>
<tr>
......
......@@ -175,8 +175,9 @@ cr.define('database_tab', function() {
}
return {
getSortFunctionForKey: getSortFunctionForKey,
formatLoadTimeEstimate: formatLoadTimeEstimate,
getSortFunctionForKey: getSortFunctionForKey,
kilobytesToString: kilobytesToString,
};
});
......@@ -193,10 +194,22 @@ Polymer({
rows_: {
type: Array,
},
/**
* The database size response.
* @private {!mojom.SiteCharacteristicsDatabaseSize}
*/
size_: {
type: Object,
value: {numRows: -1, onDiskSizeKb: -1},
},
},
/** @private {number} */
updateTimer_: 0,
updateTableTimer_: 0,
/** @private {number} */
updateSizesTimer_: 0,
/** @private {!Object} */
requestedOrigins_: {},
......@@ -215,10 +228,25 @@ Polymer({
// Update immediately.
this.updateDbRows_();
this.updateDbSizes_();
// Set an interval timer to update periodically.
this.updateTimer_ =
// Set an interval timer to update the database periodically.
this.updateTableTimer_ =
setInterval(this.updateDbRows_.bind(this), UPDATE_INTERVAL_MS);
// Set another interval timer to update the database sizes, but much less
// frequently, as this requires iterating the entire database.
this.updateSizesTimer_ =
setInterval(this.updateDbSizes_.bind(this), UPDATE_INTERVAL_MS * 30);
},
/** @override */
detached: function() {
// Clear the update timers to avoid memory leaks.
clearInterval(this.updateTableTimer_);
this.updateTableTimer_ = 0;
clearInterval(this.updateSizesTimer_);
this.updateSizesTimer_ = 0;
},
/**
......@@ -242,6 +270,19 @@ Polymer({
});
},
/**
* Issues a request for the database sizes and renders on response.
* @private
*/
updateDbSizes_: function() {
this.uiHandler_.getSiteCharacteristicsDatabaseSize().then(response => {
// Bail if the SiteCharacteristicsDatabase is turned off.
if (!response.dbSize)
return;
this.size_ = response.dbSize;
});
},
/**
* Returns a sort function to compare tab infos based on the provided sort key
* and a boolean reverse flag.
......@@ -319,4 +360,23 @@ Polymer({
getLoadTimeEstimate_: function(item, propertyName) {
return database_tab.formatLoadTimeEstimate(item, propertyName);
},
/**
* @param {number} value A value in units of kilobytes, or -1 indicating not
* available.
* @return {string} A human readable string representing value.
* @private
*/
kilobytesToString_: function(value) {
return value == -1 ? 'N/A' : database_tab.kilobytesToString(value);
},
/**
* @param {number} value A numeric value or -1, indicating not available.
* @return {string} A human readable string representing value.
* @private
*/
optionalIntegerToString_: function(value) {
return value == -1 ? 'N/A' : value.toString();
},
});
......@@ -32,6 +32,16 @@ struct SiteCharacteristicsPerformanceMeasurement {
float avg_load_duration_us;
};
struct SiteCharacteristicsDatabaseSize {
// The total number of rows in the database, or -1 if the value is not
// available.
int64 num_rows;
// The total size of the database on disk in kilobytes, or -1 if the value
// is not available.
int64 on_disk_size_kb;
};
// The data stored for a given origin, this should mirror the
// SiteCharacteristicsProto structure in site_characteristics.proto.
struct SiteCharacteristicsDatabaseValue {
......@@ -65,14 +75,6 @@ struct SiteCharacteristicsDatabaseEntry {
// Contains information about a specific DB instance.
struct SiteCharacteristicsDatabase {
// The total number of rows in the database, or -1 if the value is not (yet)
// available.
int64 num_rows;
// The total size of the database on disk in kilobytes, or -1 if the value
// is not (yet) available.
int64 on_disk_size_kb;
// Contains the entries requested.
array<SiteCharacteristicsDatabaseEntry> db_rows;
};
......@@ -142,6 +144,12 @@ interface DiscardsDetailsProvider {
array<string> explicitly_requested_origins) =>
(SiteCharacteristicsDatabase? result);
// Returns the size of the database in number of rows and kilobytes.
// Note that this may be fairly expensive to acquire, and so shouldn't be
// called frequently.
GetSiteCharacteristicsDatabaseSize() =>
(SiteCharacteristicsDatabaseSize? db_size);
// Sets the auto-discardable state of a tab, as specified by its stable
// |tab_id|, earlier returned by GetTabDiscardsInfo. Invokes a callback when
// the change has been made.
......
......@@ -238,6 +238,8 @@ class DiscardsDetailsProviderImpl : public mojom::DiscardsDetailsProvider {
void GetSiteCharacteristicsDatabase(
const std::vector<std::string>& explicitly_requested_origins,
GetSiteCharacteristicsDatabaseCallback callback) override;
void GetSiteCharacteristicsDatabaseSize(
GetSiteCharacteristicsDatabaseSizeCallback callback) override;
void SetAutoDiscardable(int32_t id,
bool is_auto_discardable,
......@@ -354,6 +356,32 @@ void DiscardsDetailsProviderImpl::GetSiteCharacteristicsDatabase(
std::move(callback).Run(std::move(result));
}
void DiscardsDetailsProviderImpl::GetSiteCharacteristicsDatabaseSize(
GetSiteCharacteristicsDatabaseSizeCallback callback) {
if (!data_store_inspector_) {
// Early return with a nullptr if there's no inspector.
std::move(callback).Run(nullptr);
return;
}
// Adapt the inspector callback to the mojom callback with this lambda.
auto inspector_callback = base::BindOnce(
[](GetSiteCharacteristicsDatabaseSizeCallback callback,
base::Optional<int64_t> num_rows,
base::Optional<int64_t> on_disk_size_kb) {
mojom::SiteCharacteristicsDatabaseSizePtr result =
mojom::SiteCharacteristicsDatabaseSize::New();
result->num_rows = num_rows.has_value() ? num_rows.value() : -1;
result->on_disk_size_kb =
on_disk_size_kb.has_value() ? on_disk_size_kb.value() : -1;
std::move(callback).Run(std::move(result));
},
std::move(callback));
data_store_inspector_->GetDatabaseSize(std::move(inspector_callback));
}
} // namespace
DiscardsUI::DiscardsUI(content::WebUI* web_ui)
......
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