Commit 352d5a2f authored by Victor Costan's avatar Victor Costan Committed by Chromium LUCI CQ

WebSQL: Remove OriginInfo::DBInfo.

DBInfo now holds a single member, the database size. This CL replaces
the OriginInfo::databases_info map holding DBInfo values with a
`database_sizes` map.

Change-Id: I62e1e56fec26a9d964190d918ccf917c42f1ddfc
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2634864
Commit-Queue: Victor Costan <pwnall@chromium.org>
Reviewed-by: default avatarJoshua Bell <jsbell@chromium.org>
Cr-Commit-Position: refs/heads/master@{#845083}
parent b7f75454
......@@ -11,6 +11,7 @@
#include "base/bind.h"
#include "base/callback_helpers.h"
#include "base/containers/contains.h"
#include "base/files/file_path.h"
#include "base/location.h"
#include "base/memory/scoped_refptr.h"
......@@ -107,8 +108,8 @@ class MockDatabaseTracker : public DatabaseTracker {
}
void AddMockDatabase(const base::string16& name, int size) {
EXPECT_TRUE(database_info_.find(name) == database_info_.end());
database_info_[name].size = size;
EXPECT_FALSE(base::Contains(database_sizes_, name));
database_sizes_[name] = size;
total_size_ += size;
}
};
......
......@@ -56,14 +56,14 @@ OriginInfo::~OriginInfo() = default;
void OriginInfo::GetAllDatabaseNames(
std::vector<base::string16>* databases) const {
for (const auto& pair : database_info_)
databases->push_back(pair.first);
for (const auto& name_and_size : database_sizes_)
databases->push_back(name_and_size.first);
}
int64_t OriginInfo::GetDatabaseSize(const base::string16& database_name) const {
auto it = database_info_.find(database_name);
if (it != database_info_.end())
return it->second.size;
auto it = database_sizes_.find(database_name);
if (it != database_sizes_.end())
return it->second;
return 0;
}
......
......@@ -59,15 +59,12 @@ class COMPONENT_EXPORT(STORAGE_BROWSER) OriginInfo {
int64_t GetDatabaseSize(const base::string16& database_name) const;
protected:
struct DBInfo {
int64_t size;
};
OriginInfo(const std::string& origin_identifier, int64_t total_size);
std::string origin_identifier_;
int64_t total_size_;
base::Time last_modified_;
std::map<base::string16, DBInfo> database_info_;
std::map<base::string16, int64_t> database_sizes_;
};
// This class manages the main database and keeps track of open databases.
......@@ -194,10 +191,14 @@ class COMPONENT_EXPORT(STORAGE_BROWSER) DatabaseTracker
}
void SetDatabaseSize(const base::string16& database_name,
int64_t new_size) {
int64_t old_size = 0;
if (database_info_.find(database_name) != database_info_.end())
old_size = database_info_[database_name].size;
database_info_[database_name].size = new_size;
// If the name does not exist in the map, operator[] creates a new entry
// with a default-constructed value. The default-constructed value for
// int64_t is zero (0), which is exactly what we want `old_size` to be set
// to in this case.
int64_t& database_size = database_sizes_[database_name];
int64_t old_size = database_size;
database_size = new_size;
if (new_size != old_size)
total_size_ += new_size - old_size;
}
......
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