Changed UsageTableHeader::Shrink to tolerate over shrinking.

[ Merge of http://go/wvgerrit/83804 ]

There is a private helper method in `UsageTableHeader` which is used by
other methods to shrink the table by removing a specified number of
entries.

Prior to this change, if `Shrink` was called to remove more entries
than there are, it would: 1) do nothing and 2) return `NO_ERROR`.
Obviously, at least one of those action should change.

Instead of doing nothing, it will simply remove all the entries from
the table and return `NO_ERROR`.  A warning will be logged that it was
requested to shrink by more entries than there are.

Four (4) new tests have been created to ensure that `Shrink()` works as
expected.

Test: Linux unit tests
Bug: 138242127
Change-Id: Idedd922bd883d7ae1b84ce8ec1255fdce00c0948
This commit is contained in:
Alex Dale
2019-07-31 12:06:58 -07:00
parent 0b3edf73a8
commit 79a28e5ddb
3 changed files with 83 additions and 5 deletions

View File

@@ -508,10 +508,10 @@ CdmResponseType UsageTableHeader::Shrink(
if (usage_entry_info_.size() < number_of_usage_entries_to_delete) {
LOGW(
"UsageTableHeader::Shrink: cannot delete %d entries when usage entry "
"table size is %d",
number_of_usage_entries_to_delete, usage_entry_info_.size());
return NO_ERROR;
"Cannot delete more entries than the table size, reducing to current "
"table size: table_size = %zu, number_to_delete = %u",
usage_entry_info_.size(), number_of_usage_entries_to_delete);
number_of_usage_entries_to_delete = usage_entry_info_.size();
}
if (number_of_usage_entries_to_delete == 0) return NO_ERROR;
@@ -524,7 +524,7 @@ CdmResponseType UsageTableHeader::Shrink(
std::unique_ptr<CryptoSession> scoped_crypto_session;
CryptoSession* crypto_session = test_crypto_session_.get();
if (crypto_session == NULL) {
scoped_crypto_session.reset((CryptoSession::MakeCryptoSession(metrics)));
scoped_crypto_session.reset(CryptoSession::MakeCryptoSession(metrics));
crypto_session = scoped_crypto_session.get();
}