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:
@@ -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();
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user