Skip to content

Commit

Permalink
Quota: Cleanup kPersistent in storage
Browse files Browse the repository at this point in the history
This change removes deprecated kPersistent from
/storage/browser/ except for data in QuotaDatabase
which will be done in a follow-up CL.

Bug: 1353228
Change-Id: Id78b63271e0cf1641524d9ac48717503e409c74b
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/3962473
Reviewed-by: Evan Stade <estade@chromium.org>
Reviewed-by: Mustafa Emre Acer <meacer@chromium.org>
Commit-Queue: Ayu Ishii <ayui@chromium.org>
Cr-Commit-Position: refs/heads/main@{#1067595}
  • Loading branch information
ayuishii authored and Chromium LUCI CQ committed Nov 4, 2022
1 parent fbc7e73 commit e0d51be
Show file tree
Hide file tree
Showing 12 changed files with 417 additions and 956 deletions.
2 changes: 0 additions & 2 deletions content/browser/resources/quota/quota_internals.html
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@ <h3>Disk Availability</h3>
<th>Total Space</th>
<th>Available Space</th>
<th>Temporary Storage Usage</th>
<th>Persistent Storage Usage</th>
<th>Syncable Storage Usage</th>
<th>Temp Pool Size</th>
</thead>
Expand Down Expand Up @@ -77,7 +76,6 @@ <h2>Bucket Usage Data</h2>
<td class="total-space"></td>
<td class="available-space"></td>
<td class="temporary-global-and-unlimited-usage"></td>
<td class="persistent-global-and-unlimited-usage"></td>
<td class="syncable-global-and-unlimited-usage"></td>
<td class="temp-pool-size"></td>
</tr>
Expand Down
2 changes: 1 addition & 1 deletion content/browser/resources/quota/quota_internals.ts
Original file line number Diff line number Diff line change
Expand Up @@ -251,7 +251,7 @@ async function renderUsageAndQuotaStats() {
usageAndQuotaRow.querySelector('.storage-key')!.remove();
}

/* If the current storage type (temporary, persistent, syncable) is not
/* If the current storage type (temporary, syncable) is not
* the first of its kind for a given storage key and storage type,
* remove the Storage Type cells from the row before
* appending the row to the table body.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import {QuotaInternalsHandler} from './quota_internals.mojom-webui.js';

export enum StorageType {
TEMPORARY = 0,
PERSISTENT = 1,
// PERSISTENT = 1, DEPRECATED
SYNCABLE = 2,
}

Expand Down
38 changes: 0 additions & 38 deletions storage/browser/quota/quota_callbacks.h
Original file line number Diff line number Diff line change
Expand Up @@ -77,44 +77,6 @@ class CallbackQueue {
std::vector<CallbackType> callbacks_;
};

template <typename CallbackType, typename Key, typename... Args>
class CallbackQueueMap {
public:
using CallbackQueueType = CallbackQueue<CallbackType, Args...>;
using CallbackMap = std::map<Key, CallbackQueueType>;
using iterator = typename CallbackMap::iterator;

bool Add(const Key& key, CallbackType callback) {
return callback_map_[key].Add(std::move(callback));
}

bool HasCallbacks(const Key& key) const {
return base::Contains(callback_map_, key);
}

bool HasAnyCallbacks() const { return !callback_map_.empty(); }

iterator Begin() { return callback_map_.begin(); }
iterator End() { return callback_map_.end(); }

void Clear() { callback_map_.clear(); }

// Runs the callbacks added for the given |key| and clears the key
// from the map.
template <typename... RunArgs>
void Run(const Key& key, RunArgs&&... args) {
if (!this->HasCallbacks(key))
return;
CallbackQueueType queue;
queue.Swap(&callback_map_[key]);
callback_map_.erase(key);
queue.Run(std::forward<RunArgs>(args)...);
}

private:
CallbackMap callback_map_;
};

} // namespace storage

#endif // STORAGE_BROWSER_QUOTA_QUOTA_CALLBACKS_H_
66 changes: 1 addition & 65 deletions storage/browser/quota/quota_database.cc
Original file line number Diff line number Diff line change
Expand Up @@ -160,6 +160,7 @@ std::set<BucketInfo> BucketInfosFromSqlStatement(sql::Statement& statement) {
} // anonymous namespace

const QuotaDatabase::TableSchema QuotaDatabase::kTables[] = {
// TODO(crbug.com/1175113): Cleanup kHostQuotaTable.
{kHostQuotaTable,
"(host TEXT NOT NULL,"
" type INTEGER NOT NULL,"
Expand Down Expand Up @@ -217,51 +218,6 @@ QuotaDatabase::~QuotaDatabase() {

constexpr char QuotaDatabase::kDatabaseName[];

QuotaErrorOr<int64_t> QuotaDatabase::GetHostQuota(const std::string& host,
StorageType type) {
DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_);
QuotaError open_error = EnsureOpened();
if (open_error != QuotaError::kNone)
return open_error;

static constexpr char kSql[] =
"SELECT quota FROM quota WHERE host = ? AND type = ?";
sql::Statement statement(db_->GetCachedStatement(SQL_FROM_HERE, kSql));
statement.BindString(0, host);
statement.BindInt(1, static_cast<int>(type));

if (!statement.Step()) {
return statement.Succeeded() ? QuotaError::kNotFound
: QuotaError::kDatabaseError;
}
return statement.ColumnInt64(0);
}

QuotaError QuotaDatabase::SetHostQuota(const std::string& host,
StorageType type,
int64_t quota) {
DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_);
DCHECK_GE(quota, 0);
QuotaError open_error = EnsureOpened();
if (open_error != QuotaError::kNone)
return open_error;

if (quota == 0)
return DeleteHostQuota(host, type);

static constexpr char kSql[] =
"INSERT OR REPLACE INTO quota(quota, host, type) VALUES (?, ?, ?)";
sql::Statement statement(db_->GetCachedStatement(SQL_FROM_HERE, kSql));
statement.BindInt64(0, quota);
statement.BindString(1, host);
statement.BindInt(2, static_cast<int>(type));
if (!statement.Run())
return QuotaError::kDatabaseError;

ScheduleCommit();
return QuotaError::kNone;
}

QuotaErrorOr<BucketInfo> QuotaDatabase::UpdateOrCreateBucket(
const BucketInitParams& params) {
DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_);
Expand Down Expand Up @@ -610,26 +566,6 @@ QuotaErrorOr<mojom::BucketTableEntryPtr> QuotaDatabase::GetBucketInfo(
return entry;
}

QuotaError QuotaDatabase::DeleteHostQuota(const std::string& host,
StorageType type) {
DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_);
QuotaError open_error = EnsureOpened();
if (open_error != QuotaError::kNone)
return open_error;

static constexpr char kSql[] =
"DELETE FROM quota WHERE host = ? AND type = ?";
sql::Statement statement(db_->GetCachedStatement(SQL_FROM_HERE, kSql));
statement.BindString(0, host);
statement.BindInt(1, static_cast<int>(type));

if (!statement.Run())
return QuotaError::kDatabaseError;

ScheduleCommit();
return QuotaError::kNone;
}

QuotaError QuotaDatabase::DeleteBucketData(const BucketLocator& bucket) {
DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_);
QuotaError open_error = EnsureOpened();
Expand Down
12 changes: 0 additions & 12 deletions storage/browser/quota/quota_database.h
Original file line number Diff line number Diff line change
Expand Up @@ -76,18 +76,6 @@ class COMPONENT_EXPORT(STORAGE_BROWSER) QuotaDatabase {

~QuotaDatabase();

// Returns quota if entry is found. Returns QuotaError::kNotFound no entry if
// found.
QuotaErrorOr<int64_t> GetHostQuota(const std::string& host,
blink::mojom::StorageType type);

// Returns whether the operation succeeded.
QuotaError SetHostQuota(const std::string& host,
blink::mojom::StorageType type,
int64_t quota);
QuotaError DeleteHostQuota(const std::string& host,
blink::mojom::StorageType type);

// Gets the bucket described by `params.storage_key` and `params.name`
// for StorageType kTemporary and returns the BucketInfo. If a bucket fitting
// the params doesn't exist, it creates a new bucket with the policies in
Expand Down

0 comments on commit e0d51be

Please sign in to comment.