Avoid transient std::string construction when deserializing from database
Various base APIs accept a std::string_view and do not need ownership of a std::string, so sql::Statement::ColumnStringView can be used instead. Examples of affected callsites include UUID/JSON/proto parsing, string splitting, and literal string comparisons. Bug: 403218784 Change-Id: I9d5a25065958f7536e76e6b0333b90ef1e1f5f9a Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/6362935 Owners-Override: Daniel Cheng <dcheng@chromium.org> Reviewed-by: Daniel Cheng <dcheng@chromium.org> Commit-Queue: Daniel Cheng <dcheng@chromium.org> Cr-Commit-Position: refs/heads/main@{#1433834}
This commit is contained in:
parent
5aed270e6d
commit
204a4c089d
chrome
browser
ash/app_list/search/local_image_search
diagnostics
extensions/activity_log
utility/importer
components
affiliations/core/browser
autofill/core/browser/webdata
history/core/browser
download_database.cchistory_database.cc
sync
url_database.ccvisit_annotations_database.ccvisit_annotations_database.hvisit_database.ccvisitsegment_database.ccmedia_device_salt
offline_pages/core/background
password_manager/core/browser/password_store
plus_addresses/webdata
power_bookmarks/storage
power_bookmark_database_impl.ccpower_bookmark_database_impl.hpower_bookmark_sync_metadata_database.cc
search_engines
segmentation_platform/internal/database
services/storage/shared_storage
content/browser
first_party_sets/database
interest_group
media
tracing/trace_report
net/extras/sqlite
sql
storage/browser/quota
@ -278,8 +278,8 @@ std::vector<ImageInfo> AnnotationStorage::GetAllAnnotationsForTest() {
|
||||
std::vector<ImageInfo> matched_paths;
|
||||
while (statement->Step()) {
|
||||
const std::string annotation = statement->ColumnString(0);
|
||||
base::FilePath file_path(statement->ColumnString(1));
|
||||
file_path = file_path.Append(statement->ColumnString(2));
|
||||
base::FilePath file_path(statement->ColumnStringView(1));
|
||||
file_path = file_path.Append(statement->ColumnStringView(2));
|
||||
const base::Time time = statement->ColumnTime(3);
|
||||
const int64_t file_size = statement->ColumnInt64(4);
|
||||
DVLOG(1) << "Select find: " << annotation << ", " << file_path << ", "
|
||||
@ -454,22 +454,22 @@ std::vector<FileSearchResult> AnnotationStorage::PrefixSearch(
|
||||
while (statement->Step()) {
|
||||
double relevance = FuzzyTokenizedStringMatch::TokenSetRatio(
|
||||
tokenized_query,
|
||||
TokenizedString(base::UTF8ToUTF16(statement->ColumnString(0)),
|
||||
TokenizedString(base::UTF8ToUTF16(statement->ColumnStringView(0)),
|
||||
Mode::kWords),
|
||||
/*partial=*/false);
|
||||
if (relevance < GetRelevanceThreshold()) {
|
||||
continue;
|
||||
}
|
||||
|
||||
base::FilePath file_path(statement->ColumnString(1));
|
||||
file_path = file_path.Append(statement->ColumnString(2));
|
||||
base::FilePath file_path(statement->ColumnStringView(1));
|
||||
file_path = file_path.Append(statement->ColumnStringView(2));
|
||||
const base::Time time = statement->ColumnTime(3);
|
||||
// Updates the relevance as a weighted average of the query-term relevance
|
||||
// and the image annotation relevance score.
|
||||
relevance = kRelevanceWeight * relevance +
|
||||
(1 - kRelevanceWeight) * statement->ColumnDouble(4);
|
||||
DVLOG(1) << "Select: " << statement->ColumnString(0) << ", " << file_path
|
||||
<< ", " << time << " rl: " << relevance;
|
||||
DVLOG(1) << "Select: " << statement->ColumnStringView(0) << ", "
|
||||
<< file_path << ", " << time << " rl: " << relevance;
|
||||
|
||||
if (matched_paths.empty() || matched_paths.back().file_path != file_path) {
|
||||
matched_paths.emplace_back(file_path, std::move(time), relevance);
|
||||
|
@ -162,8 +162,8 @@ bool DocumentsTable::GetAllFiles(SqlDatabase* db,
|
||||
}
|
||||
|
||||
while (statement->Step()) {
|
||||
base::FilePath file_path(statement->ColumnString(0));
|
||||
file_path = file_path.Append(statement->ColumnString(1));
|
||||
base::FilePath file_path(statement->ColumnStringView(0));
|
||||
file_path = file_path.Append(statement->ColumnStringView(1));
|
||||
|
||||
DVLOG(1) << "GetAll : " << file_path;
|
||||
documents.emplace_back(base::FilePath(std::move(file_path)));
|
||||
@ -192,8 +192,8 @@ bool DocumentsTable::SearchByDirectory(
|
||||
statement->BindString(0, base::StrCat({directory.value(), "%"}));
|
||||
|
||||
while (statement->Step()) {
|
||||
base::FilePath file_path(statement->ColumnString(0));
|
||||
file_path = file_path.Append(statement->ColumnString(1));
|
||||
base::FilePath file_path(statement->ColumnStringView(0));
|
||||
file_path = file_path.Append(statement->ColumnStringView(1));
|
||||
matched_paths.emplace_back(file_path);
|
||||
}
|
||||
|
||||
|
@ -144,7 +144,7 @@ class SqliteIntegrityTest : public DiagnosticsTest {
|
||||
}
|
||||
|
||||
while (statement.Step()) {
|
||||
std::string result(statement.ColumnString(0));
|
||||
std::string_view result = statement.ColumnStringView(0);
|
||||
if ("ok" != result)
|
||||
++errors;
|
||||
}
|
||||
|
@ -500,7 +500,7 @@ std::unique_ptr<Action::ActionVector> CountingPolicy::DoReadFilteredData(
|
||||
|
||||
if (query.GetColumnType(4) != sql::ColumnType::kNull) {
|
||||
std::optional<base::Value> parsed_value =
|
||||
base::JSONReader::Read(query.ColumnString(4));
|
||||
base::JSONReader::Read(query.ColumnStringView(4));
|
||||
if (parsed_value && parsed_value->is_list()) {
|
||||
action->set_args(std::move(*parsed_value).TakeList());
|
||||
}
|
||||
@ -512,7 +512,7 @@ std::unique_ptr<Action::ActionVector> CountingPolicy::DoReadFilteredData(
|
||||
|
||||
if (query.GetColumnType(8) != sql::ColumnType::kNull) {
|
||||
std::optional<base::Value> parsed_value =
|
||||
base::JSONReader::Read(query.ColumnString(8));
|
||||
base::JSONReader::Read(query.ColumnStringView(8));
|
||||
if (parsed_value && parsed_value->is_dict()) {
|
||||
action->set_other(std::move(*parsed_value).TakeDict());
|
||||
}
|
||||
|
@ -193,7 +193,7 @@ std::unique_ptr<Action::ActionVector> FullStreamUIPolicy::DoReadFilteredData(
|
||||
|
||||
if (query.GetColumnType(4) != sql::ColumnType::kNull) {
|
||||
std::optional<base::Value> parsed_value =
|
||||
base::JSONReader::Read(query.ColumnString(4));
|
||||
base::JSONReader::Read(query.ColumnStringView(4));
|
||||
if (parsed_value && parsed_value->is_list()) {
|
||||
action->set_args(std::move(*parsed_value).TakeList());
|
||||
}
|
||||
@ -205,7 +205,7 @@ std::unique_ptr<Action::ActionVector> FullStreamUIPolicy::DoReadFilteredData(
|
||||
|
||||
if (query.GetColumnType(8) != sql::ColumnType::kNull) {
|
||||
std::optional<base::Value> parsed_value =
|
||||
base::JSONReader::Read(query.ColumnString(8));
|
||||
base::JSONReader::Read(query.ColumnStringView(8));
|
||||
if (parsed_value && parsed_value->is_dict()) {
|
||||
action->set_other(std::move(*parsed_value).TakeDict());
|
||||
}
|
||||
|
@ -83,7 +83,7 @@ bool CanImportURL(const GURL& url) {
|
||||
|
||||
// Initializes |favicon_url| and |png_data| members of given FaviconUsageData
|
||||
// structure with provided favicon data. Returns true if data is valid.
|
||||
bool SetFaviconData(const std::string& icon_url,
|
||||
bool SetFaviconData(std::string_view icon_url,
|
||||
const std::vector<unsigned char>& icon_data,
|
||||
favicon_base::FaviconUsageData* usage_data) {
|
||||
usage_data->favicon_url = GURL(icon_url);
|
||||
@ -583,8 +583,9 @@ void FirefoxImporter::LoadFavicons(
|
||||
continue;
|
||||
|
||||
favicon_base::FaviconUsageData usage_data;
|
||||
if (!SetFaviconData(s.ColumnString(0), data, &usage_data))
|
||||
if (!SetFaviconData(s.ColumnStringView(0), data, &usage_data)) {
|
||||
continue;
|
||||
}
|
||||
|
||||
usage_data.urls = i.second;
|
||||
favicons->push_back(usage_data);
|
||||
@ -637,8 +638,9 @@ void FirefoxImporter::LoadFavicons(
|
||||
continue;
|
||||
|
||||
favicon_base::FaviconUsageData usage_data;
|
||||
if (!SetFaviconData(s.ColumnString(1), data, &usage_data))
|
||||
if (!SetFaviconData(s.ColumnStringView(1), data, &usage_data)) {
|
||||
continue;
|
||||
}
|
||||
|
||||
usage_data.urls.insert(entry.url);
|
||||
favicons->push_back(usage_data);
|
||||
|
@ -40,9 +40,9 @@ bool CheckForeignKeyConstraints(sql::Database& db) {
|
||||
bool ret = true;
|
||||
while (stmt.Step()) {
|
||||
ret = false;
|
||||
LOG(ERROR) << "Foreign key violation "
|
||||
<< stmt.ColumnString(0) + ", " + stmt.ColumnString(1) + ", " +
|
||||
stmt.ColumnString(2) + ", " + stmt.ColumnString(3);
|
||||
LOG(ERROR) << "Foreign key violation " << stmt.ColumnStringView(0) << ", "
|
||||
<< stmt.ColumnStringView(1) << ", " << stmt.ColumnStringView(2)
|
||||
<< ", " << stmt.ColumnStringView(3);
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
@ -183,7 +183,7 @@ bool AddLegacyAutofillProfileNamesToProfile(sql::Database* db,
|
||||
kConjunctionLastNameStatus, kSecondLastName, kSecondLastNameStatus,
|
||||
kLastName, kLastNameStatus, kFullName, kFullNameStatus},
|
||||
profile->guid())) {
|
||||
DCHECK_EQ(profile->guid(), s.ColumnString(0));
|
||||
DCHECK_EQ(profile->guid(), s.ColumnStringView(0));
|
||||
|
||||
int index = 1;
|
||||
for (FieldType type :
|
||||
@ -230,7 +230,7 @@ bool AddLegacyAutofillProfileAddressesToProfile(sql::Database* db,
|
||||
kFloor,
|
||||
kFloorStatus},
|
||||
profile->guid())) {
|
||||
DCHECK_EQ(profile->guid(), s.ColumnString(0));
|
||||
DCHECK_EQ(profile->guid(), s.ColumnStringView(0));
|
||||
std::u16string street_address = s.ColumnString16(1);
|
||||
std::u16string dependent_locality = s.ColumnString16(13);
|
||||
std::u16string city = s.ColumnString16(15);
|
||||
@ -292,7 +292,7 @@ bool AddLegacyAutofillProfileEmailsToProfile(sql::Database* db,
|
||||
sql::Statement s;
|
||||
if (SelectByGuid(db, s, kAutofillProfileEmailsTable, {kGuid, kEmail},
|
||||
profile->guid())) {
|
||||
DCHECK_EQ(profile->guid(), s.ColumnString(0));
|
||||
DCHECK_EQ(profile->guid(), s.ColumnStringView(0));
|
||||
profile->SetRawInfo(EMAIL_ADDRESS, s.ColumnString16(1));
|
||||
}
|
||||
return s.Succeeded();
|
||||
@ -309,7 +309,7 @@ bool AddLegacyAutofillProfilePhonesToProfile(sql::Database* db,
|
||||
sql::Statement s;
|
||||
if (SelectByGuid(db, s, kAutofillProfilePhonesTable, {kGuid, kNumber},
|
||||
profile->guid())) {
|
||||
DCHECK_EQ(profile->guid(), s.ColumnString(0));
|
||||
DCHECK_EQ(profile->guid(), s.ColumnStringView(0));
|
||||
profile->SetRawInfo(PHONE_HOME_WHOLE_NUMBER, s.ColumnString16(1));
|
||||
}
|
||||
return s.Succeeded();
|
||||
|
@ -310,7 +310,7 @@ bool EntityTable::RemoveEntityInstancesModifiedBetween(base::Time delete_begin,
|
||||
s.BindInt64(1, delete_end.ToTimeT());
|
||||
std::vector<base::Uuid> guids;
|
||||
while (s.Step()) {
|
||||
base::Uuid guid = base::Uuid::ParseLowercase(s.ColumnString(0));
|
||||
base::Uuid guid = base::Uuid::ParseLowercase(s.ColumnStringView(0));
|
||||
if (!guid.is_valid()) {
|
||||
continue;
|
||||
}
|
||||
@ -340,7 +340,7 @@ EntityTable::LoadAttributes() const {
|
||||
attributes::kFieldType, attributes::kValueEncrypted,
|
||||
attributes::kVerificationStatus});
|
||||
while (s.Step()) {
|
||||
base::Uuid entity_guid = base::Uuid::ParseLowercase(s.ColumnString(0));
|
||||
base::Uuid entity_guid = base::Uuid::ParseLowercase(s.ColumnStringView(0));
|
||||
std::string attribute_type_name = s.ColumnString(1);
|
||||
std::underlying_type_t<FieldType> underlying_field_type = s.ColumnInt(2);
|
||||
std::u16string decrypted_value;
|
||||
@ -377,7 +377,7 @@ std::vector<EntityInstance> EntityTable::GetEntityInstances() const {
|
||||
{entities::kGuid, entities::kEntityType, entities::kNickname,
|
||||
entities::kDateModified});
|
||||
while (s.Step()) {
|
||||
base::Uuid guid = base::Uuid::ParseLowercase(s.ColumnString(0));
|
||||
base::Uuid guid = base::Uuid::ParseLowercase(s.ColumnStringView(0));
|
||||
std::string type_name = s.ColumnString(1);
|
||||
std::string nickname = s.ColumnString(2);
|
||||
base::Time date_modified = base::Time::FromTimeT(s.ColumnInt64(3));
|
||||
|
@ -184,7 +184,7 @@ bool AutofillSyncMetadataTable::GetAllSyncEntityMetadata(
|
||||
|
||||
while (s.Step()) {
|
||||
std::string storage_key = s.ColumnString(0);
|
||||
std::string serialized_metadata = s.ColumnString(1);
|
||||
std::string_view serialized_metadata = s.ColumnStringView(1);
|
||||
auto entity_metadata = std::make_unique<sync_pb::EntityMetadata>();
|
||||
if (entity_metadata->ParseFromString(serialized_metadata)) {
|
||||
metadata_batch->AddMetadata(storage_key, std::move(entity_metadata));
|
||||
@ -212,7 +212,7 @@ bool AutofillSyncMetadataTable::GetDataTypeState(
|
||||
return true;
|
||||
}
|
||||
|
||||
std::string serialized_state = s.ColumnString(0);
|
||||
std::string_view serialized_state = s.ColumnStringView(0);
|
||||
return state->ParseFromString(serialized_state);
|
||||
}
|
||||
|
||||
|
@ -1308,7 +1308,7 @@ bool PaymentsAutofillTable::GetServerIbans(std::vector<std::unique_ptr<Iban>>& i
|
||||
while (s.Step()) {
|
||||
int index = 0;
|
||||
int64_t instrument_id = 0;
|
||||
if (!base::StringToInt64(s.ColumnString(index++), &instrument_id)) {
|
||||
if (!base::StringToInt64(s.ColumnStringView(index++), &instrument_id)) {
|
||||
continue;
|
||||
}
|
||||
std::unique_ptr<Iban> iban =
|
||||
|
@ -52,7 +52,7 @@ void BindFilePath(sql::Statement& statement,
|
||||
statement.BindString(col, path.value());
|
||||
}
|
||||
base::FilePath ColumnFilePath(sql::Statement& statement, int col) {
|
||||
return base::FilePath(statement.ColumnString(col));
|
||||
return base::FilePath(statement.ColumnStringView(col));
|
||||
}
|
||||
|
||||
#else
|
||||
@ -64,7 +64,7 @@ void BindFilePath(sql::Statement& statement,
|
||||
statement.BindString(col, path.AsUTF8Unsafe());
|
||||
}
|
||||
base::FilePath ColumnFilePath(sql::Statement& statement, int col) {
|
||||
return base::FilePath::FromUTF8Unsafe(statement.ColumnString(col));
|
||||
return base::FilePath::FromUTF8Unsafe(statement.ColumnStringView(col));
|
||||
}
|
||||
|
||||
#endif
|
||||
|
@ -278,7 +278,7 @@ void HistoryDatabase::ComputeDatabaseMetrics(
|
||||
std::set<std::string> month_hosts;
|
||||
base::Time one_week_ago = base::Time::Now() - base::Days(7);
|
||||
while (url_sql.Step()) {
|
||||
GURL url(url_sql.ColumnString(0));
|
||||
GURL url(url_sql.ColumnStringView(0));
|
||||
base::Time visit_time = url_sql.ColumnTime(1);
|
||||
++month_url_count;
|
||||
month_hosts.insert(url.host());
|
||||
@ -311,7 +311,7 @@ int HistoryDatabase::CountUniqueHostsVisitedLastMonth() {
|
||||
|
||||
std::set<std::string> hosts;
|
||||
while (url_sql.Step()) {
|
||||
GURL url(url_sql.ColumnString(0));
|
||||
GURL url(url_sql.ColumnStringView(0));
|
||||
hosts.insert(url.host());
|
||||
}
|
||||
|
||||
@ -349,7 +349,7 @@ DomainsVisitedResult HistoryDatabase::GetUniqueDomainsVisited(
|
||||
std::set<std::string> locally_visited_domains_set;
|
||||
|
||||
while (url_sql.Step()) {
|
||||
GURL url(url_sql.ColumnString(0));
|
||||
GURL url(url_sql.ColumnStringView(0));
|
||||
std::string domain = net::registry_controlled_domains::GetDomainAndRegistry(
|
||||
url, net::registry_controlled_domains::EXCLUDE_PRIVATE_REGISTRIES);
|
||||
|
||||
@ -364,7 +364,7 @@ DomainsVisitedResult HistoryDatabase::GetUniqueDomainsVisited(
|
||||
result.all_visited_domains.push_back(domain);
|
||||
}
|
||||
|
||||
bool is_local = url_sql.ColumnString(1).empty() &&
|
||||
bool is_local = url_sql.ColumnStringView(1).empty() &&
|
||||
url_sql.ColumnInt(2) == VisitSource::SOURCE_BROWSED;
|
||||
|
||||
if (is_local && !locally_visited_domains_set.contains(domain)) {
|
||||
|
@ -168,7 +168,7 @@ bool HistorySyncMetadataDatabase::GetAllEntityMetadata(
|
||||
while (s.Step()) {
|
||||
std::string storage_key =
|
||||
StorageKeyFromMicrosSinceWindowsEpoch(s.ColumnInt64(0));
|
||||
std::string serialized_metadata = s.ColumnString(1);
|
||||
std::string_view serialized_metadata = s.ColumnStringView(1);
|
||||
auto entity_metadata = std::make_unique<sync_pb::EntityMetadata>();
|
||||
if (!entity_metadata->ParseFromString(serialized_metadata)) {
|
||||
DLOG(WARNING) << "Failed to deserialize HISTORY data type "
|
||||
|
@ -55,7 +55,7 @@ URLDatabase::~URLDatabase() = default;
|
||||
bool URLDatabase::FillURLRow(sql::Statement& s, URLRow* i) {
|
||||
DCHECK(i);
|
||||
|
||||
GURL url(s.ColumnString(1));
|
||||
GURL url(s.ColumnStringView(1));
|
||||
if (!url.is_valid()) {
|
||||
return false;
|
||||
}
|
||||
@ -214,7 +214,7 @@ bool URLDatabase::URLTableContainsAutoincrement() {
|
||||
if (!statement.Step())
|
||||
return false;
|
||||
|
||||
std::string urls_schema = statement.ColumnString(0);
|
||||
std::string_view urls_schema = statement.ColumnStringView(0);
|
||||
// We check if the whole schema contains "AUTOINCREMENT", since
|
||||
// "AUTOINCREMENT" only can be used for "INTEGER PRIMARY KEY", so we assume no
|
||||
// other columns could contain "AUTOINCREMENT".
|
||||
|
@ -482,14 +482,14 @@ bool VisitAnnotationsDatabase::GetContentAnnotationsForVisit(
|
||||
out_content_annotations->model_annotations.visibility_score =
|
||||
static_cast<float>(statement.ColumnDouble(1));
|
||||
out_content_annotations->model_annotations.categories =
|
||||
GetCategoriesFromStringColumn(statement.ColumnString(2));
|
||||
GetCategoriesFromStringColumn(statement.ColumnStringView(2));
|
||||
out_content_annotations->model_annotations.page_topics_model_version =
|
||||
statement.ColumnInt64(3);
|
||||
out_content_annotations->annotation_flags = statement.ColumnInt64(4);
|
||||
out_content_annotations->model_annotations.entities =
|
||||
GetCategoriesFromStringColumn(statement.ColumnString(5));
|
||||
GetCategoriesFromStringColumn(statement.ColumnStringView(5));
|
||||
out_content_annotations->related_searches =
|
||||
DeserializeFromStringColumn(statement.ColumnString(6));
|
||||
DeserializeFromStringColumn(statement.ColumnStringView(6));
|
||||
out_content_annotations->search_normalized_url =
|
||||
GURL(statement.ColumnStringView(7));
|
||||
out_content_annotations->search_terms = statement.ColumnString16(8);
|
||||
@ -1420,7 +1420,7 @@ bool VisitAnnotationsDatabase::ClustersTableContainsAutoincrement() {
|
||||
return false;
|
||||
}
|
||||
|
||||
std::string clusters_schema = statement.ColumnString(0);
|
||||
std::string_view clusters_schema = statement.ColumnStringView(0);
|
||||
// We check if the whole schema contains "AUTOINCREMENT", since
|
||||
// "AUTOINCREMENT" only can be used for "INTEGER PRIMARY KEY", so we assume no
|
||||
// other columns could contain "AUTOINCREMENT".
|
||||
@ -1506,7 +1506,7 @@ std::string VisitAnnotationsDatabase::ConvertCategoriesToStringColumn(
|
||||
// functions should not be changed.
|
||||
std::vector<VisitContentModelAnnotations::Category>
|
||||
VisitAnnotationsDatabase::GetCategoriesFromStringColumn(
|
||||
const std::string& column_value) {
|
||||
std::string_view column_value) {
|
||||
std::vector<VisitContentModelAnnotations::Category> categories;
|
||||
|
||||
std::vector<std::string> category_strings = base::SplitString(
|
||||
@ -1538,7 +1538,7 @@ std::string VisitAnnotationsDatabase::SerializeToStringColumn(
|
||||
// format is already being synced, the implementation of these functions
|
||||
// should not be changed.
|
||||
std::vector<std::string> VisitAnnotationsDatabase::DeserializeFromStringColumn(
|
||||
const std::string& column_value) {
|
||||
std::string_view column_value) {
|
||||
using std::string_literals::operator""s;
|
||||
return base::SplitString(column_value, "\0"s, base::TRIM_WHITESPACE,
|
||||
base::SPLIT_WANT_NONEMPTY);
|
||||
|
@ -5,6 +5,7 @@
|
||||
#ifndef COMPONENTS_HISTORY_CORE_BROWSER_VISIT_ANNOTATIONS_DATABASE_H_
|
||||
#define COMPONENTS_HISTORY_CORE_BROWSER_VISIT_ANNOTATIONS_DATABASE_H_
|
||||
|
||||
#include <string_view>
|
||||
#include <vector>
|
||||
|
||||
#include "base/time/time.h"
|
||||
@ -159,7 +160,7 @@ class VisitAnnotationsDatabase {
|
||||
// the serialized format is already being synced, the implementation of these
|
||||
// functions should not be changed.
|
||||
static std::vector<VisitContentModelAnnotations::Category>
|
||||
GetCategoriesFromStringColumn(const std::string& column_value);
|
||||
GetCategoriesFromStringColumn(std::string_view column_value);
|
||||
|
||||
// Serializes a vector of strings into a string separated by null character
|
||||
// that can be stored in the db. As the serialized format is already being
|
||||
@ -171,7 +172,7 @@ class VisitAnnotationsDatabase {
|
||||
// of strings. As the serialized format is already being synced, the
|
||||
// implementation of these functions should not be changed.
|
||||
static std::vector<std::string> DeserializeFromStringColumn(
|
||||
const std::string& column_value);
|
||||
std::string_view column_value);
|
||||
|
||||
protected:
|
||||
// Returns the database for the functions in this interface.
|
||||
|
@ -1387,7 +1387,7 @@ bool VisitDatabase::VisitTableContainsAutoincrement() {
|
||||
if (!statement.Step())
|
||||
return false;
|
||||
|
||||
std::string urls_schema = statement.ColumnString(0);
|
||||
std::string_view urls_schema = statement.ColumnStringView(0);
|
||||
// We check if the whole schema contains "AUTOINCREMENT", since
|
||||
// "AUTOINCREMENT" only can be used for "INTEGER PRIMARY KEY", so we assume no
|
||||
// other columns could contain "AUTOINCREMENT".
|
||||
|
@ -312,7 +312,7 @@ VisitSegmentDatabase::QuerySegmentUsage(
|
||||
for (std::unique_ptr<PageUsageData>& pud : segments) {
|
||||
statement2.BindInt64(0, pud->GetID());
|
||||
if (statement2.Step()) {
|
||||
GURL url(statement2.ColumnString(0));
|
||||
GURL url(statement2.ColumnStringView(0));
|
||||
if (url_filter.is_null() || url_filter.Run(url)) {
|
||||
pud->SetURL(url);
|
||||
pud->SetTitle(statement2.ColumnString16(1));
|
||||
@ -375,7 +375,7 @@ bool VisitSegmentDatabase::MigrateVisitSegmentNames() {
|
||||
bool success = true;
|
||||
while (select.Step()) {
|
||||
SegmentID id = select.ColumnInt64(0);
|
||||
std::string old_name = select.ColumnString(1);
|
||||
std::string_view old_name = select.ColumnStringView(1);
|
||||
std::string new_name = ComputeSegmentName(GURL(old_name));
|
||||
if (new_name.empty() || old_name == new_name)
|
||||
continue;
|
||||
|
@ -168,7 +168,7 @@ std::vector<blink::StorageKey> MediaDeviceSaltDatabase::GetAllStorageKeys() {
|
||||
sql::Statement statement(db_.GetUniqueStatement(kGetStorageKeysSql));
|
||||
while (statement.Step()) {
|
||||
std::optional<blink::StorageKey> key =
|
||||
blink::StorageKey::Deserialize(statement.ColumnString(0));
|
||||
blink::StorageKey::Deserialize(statement.ColumnStringView(0));
|
||||
if (key.has_value()) {
|
||||
storage_keys.push_back(*key);
|
||||
}
|
||||
|
@ -222,9 +222,9 @@ std::unique_ptr<SavePageRequest> MakeSavePageRequest(
|
||||
const int64_t completed_attempt_count = statement.ColumnInt64(5);
|
||||
const SavePageRequest::RequestState state =
|
||||
ToRequestState(statement.ColumnInt64(6));
|
||||
const GURL url(statement.ColumnString(7));
|
||||
const GURL url(statement.ColumnStringView(7));
|
||||
ClientId client_id(statement.ColumnString(8), statement.ColumnString(9));
|
||||
GURL original_url(statement.ColumnString(10));
|
||||
GURL original_url(statement.ColumnStringView(10));
|
||||
std::string request_origin(statement.ColumnString(11));
|
||||
|
||||
DVLOG(2) << "making save page request - id " << id << " url " << url
|
||||
|
@ -1729,17 +1729,14 @@ PasswordForm LoginDatabase::GetFormWithoutPasswordFromStatement(
|
||||
sql::Statement& s) const {
|
||||
PasswordForm form;
|
||||
form.primary_key = FormPrimaryKey(s.ColumnInt(COLUMN_ID));
|
||||
std::string tmp = s.ColumnString(COLUMN_ORIGIN_URL);
|
||||
form.url = GURL(tmp);
|
||||
tmp = s.ColumnString(COLUMN_ACTION_URL);
|
||||
form.action = GURL(tmp);
|
||||
form.url = GURL(s.ColumnStringView(COLUMN_ORIGIN_URL));
|
||||
form.action = GURL(s.ColumnStringView(COLUMN_ACTION_URL));
|
||||
form.username_element = s.ColumnString16(COLUMN_USERNAME_ELEMENT);
|
||||
form.username_value = s.ColumnString16(COLUMN_USERNAME_VALUE);
|
||||
form.password_element = s.ColumnString16(COLUMN_PASSWORD_ELEMENT);
|
||||
s.ColumnBlobAsString(COLUMN_KEYCHAIN_IDENTIFIER, &form.keychain_identifier);
|
||||
form.submit_element = s.ColumnString16(COLUMN_SUBMIT_ELEMENT);
|
||||
tmp = s.ColumnString(COLUMN_SIGNON_REALM);
|
||||
form.signon_realm = tmp;
|
||||
form.signon_realm = s.ColumnString(COLUMN_SIGNON_REALM);
|
||||
form.date_created = s.ColumnTime(COLUMN_DATE_CREATED);
|
||||
form.blocked_by_user = (s.ColumnInt(COLUMN_BLOCKLISTED_BY_USER) > 0);
|
||||
// TODO(crbug.com/40732888): Add metrics to capture how often these values
|
||||
@ -2116,7 +2113,7 @@ LoginDatabase::SyncMetadataStore::GetDataTypeState(syncer::DataType data_type) {
|
||||
}
|
||||
}
|
||||
|
||||
std::string serialized_state = s.ColumnString(0);
|
||||
std::string_view serialized_state = s.ColumnStringView(0);
|
||||
if (state->ParseFromString(serialized_state)) {
|
||||
return state;
|
||||
}
|
||||
|
@ -71,7 +71,8 @@ bool GetDataTypeState(sql::Database& db,
|
||||
// persisted yet and `Step()` will fail. Don't treat this as an error, but
|
||||
// fallback to the default state instead.
|
||||
if (data_type_state_query.Step() &&
|
||||
!data_type_state.ParseFromString(data_type_state_query.ColumnString(0))) {
|
||||
!data_type_state.ParseFromString(
|
||||
data_type_state_query.ColumnStringView(0))) {
|
||||
return false;
|
||||
}
|
||||
metadata_batch.SetDataTypeState(data_type_state);
|
||||
@ -89,7 +90,7 @@ bool AddEntityMetadata(sql::Database& db,
|
||||
entity_query.BindInt(0, syncer::DataTypeToStableIdentifier(data_type));
|
||||
while (entity_query.Step()) {
|
||||
auto entity_metadata = std::make_unique<sync_pb::EntityMetadata>();
|
||||
if (!entity_metadata->ParseFromString(entity_query.ColumnString(1))) {
|
||||
if (!entity_metadata->ParseFromString(entity_query.ColumnStringView(1))) {
|
||||
return false;
|
||||
}
|
||||
metadata_batch.AddMetadata(entity_query.ColumnString(0),
|
||||
|
@ -344,8 +344,8 @@ std::vector<std::unique_ptr<Power>> PowerBookmarkDatabaseImpl::GetPowersForURL(
|
||||
|
||||
std::optional<sync_pb::PowerBookmarkSpecifics> specifics =
|
||||
DeserializeOrDelete(
|
||||
statement.ColumnString(1),
|
||||
base::Uuid::ParseLowercase(statement.ColumnString(0)));
|
||||
statement.ColumnStringView(1),
|
||||
base::Uuid::ParseLowercase(statement.ColumnStringView(0)));
|
||||
if (!specifics.has_value())
|
||||
continue;
|
||||
|
||||
@ -381,8 +381,8 @@ PowerBookmarkDatabaseImpl::GetPowerOverviewsForType(
|
||||
|
||||
std::optional<sync_pb::PowerBookmarkSpecifics> specifics =
|
||||
DeserializeOrDelete(
|
||||
statement.ColumnString(1),
|
||||
base::Uuid::ParseLowercase(statement.ColumnString(0)));
|
||||
statement.ColumnStringView(1),
|
||||
base::Uuid::ParseLowercase(statement.ColumnStringView(0)));
|
||||
if (!specifics.has_value())
|
||||
continue;
|
||||
|
||||
@ -416,8 +416,8 @@ PowerBookmarkDatabaseImpl::GetPowersForSearchParams(
|
||||
|
||||
std::optional<sync_pb::PowerBookmarkSpecifics> specifics =
|
||||
DeserializeOrDelete(
|
||||
statement.ColumnString(1),
|
||||
base::Uuid::ParseLowercase(statement.ColumnString(0)));
|
||||
statement.ColumnStringView(1),
|
||||
base::Uuid::ParseLowercase(statement.ColumnStringView(0)));
|
||||
if (!specifics.has_value())
|
||||
continue;
|
||||
if (!MatchesSearchParams(specifics.value(), search_params))
|
||||
@ -486,8 +486,8 @@ PowerBookmarkDatabaseImpl::GetPowerOverviewsForSearchParams(
|
||||
|
||||
std::optional<sync_pb::PowerBookmarkSpecifics> specifics =
|
||||
DeserializeOrDelete(
|
||||
statement.ColumnString(1),
|
||||
base::Uuid::ParseLowercase(statement.ColumnString(0)));
|
||||
statement.ColumnStringView(1),
|
||||
base::Uuid::ParseLowercase(statement.ColumnStringView(0)));
|
||||
if (!specifics.has_value()) {
|
||||
continue;
|
||||
}
|
||||
@ -620,8 +620,8 @@ PowerBookmarkDatabaseImpl::GetPowersForGUIDs(
|
||||
|
||||
std::optional<sync_pb::PowerBookmarkSpecifics> specifics =
|
||||
DeserializeOrDelete(
|
||||
statement.ColumnString(1),
|
||||
base::Uuid::ParseLowercase(statement.ColumnString(0)));
|
||||
statement.ColumnStringView(1),
|
||||
base::Uuid::ParseLowercase(statement.ColumnStringView(0)));
|
||||
if (!specifics.has_value())
|
||||
continue;
|
||||
|
||||
@ -649,8 +649,8 @@ std::vector<std::unique_ptr<Power>> PowerBookmarkDatabaseImpl::GetAllPowers() {
|
||||
|
||||
std::optional<sync_pb::PowerBookmarkSpecifics> specifics =
|
||||
DeserializeOrDelete(
|
||||
statement.ColumnString(1),
|
||||
base::Uuid::ParseLowercase(statement.ColumnString(0)));
|
||||
statement.ColumnStringView(1),
|
||||
base::Uuid::ParseLowercase(statement.ColumnStringView(0)));
|
||||
if (!specifics.has_value())
|
||||
continue;
|
||||
|
||||
@ -682,8 +682,8 @@ std::unique_ptr<Power> PowerBookmarkDatabaseImpl::GetPowerForGUID(
|
||||
|
||||
std::optional<sync_pb::PowerBookmarkSpecifics> specifics =
|
||||
DeserializeOrDelete(
|
||||
statement.ColumnString(1),
|
||||
base::Uuid::ParseLowercase(statement.ColumnString(0)));
|
||||
statement.ColumnStringView(1),
|
||||
base::Uuid::ParseLowercase(statement.ColumnStringView(0)));
|
||||
if (!specifics.has_value())
|
||||
continue;
|
||||
|
||||
@ -716,7 +716,7 @@ PowerBookmarkDatabaseImpl::GetSyncMetadataDatabase() {
|
||||
}
|
||||
|
||||
std::optional<sync_pb::PowerBookmarkSpecifics>
|
||||
PowerBookmarkDatabaseImpl::DeserializeOrDelete(const std::string& data,
|
||||
PowerBookmarkDatabaseImpl::DeserializeOrDelete(std::string_view data,
|
||||
const base::Uuid& id) {
|
||||
sync_pb::PowerBookmarkSpecifics specifics;
|
||||
bool parse_success = specifics.ParseFromString(data);
|
||||
|
@ -72,7 +72,7 @@ class PowerBookmarkDatabaseImpl : public PowerBookmarkDatabase {
|
||||
bool CreateSchema();
|
||||
|
||||
std::optional<sync_pb::PowerBookmarkSpecifics> DeserializeOrDelete(
|
||||
const std::string& data,
|
||||
std::string_view data,
|
||||
const base::Uuid& id);
|
||||
|
||||
std::vector<std::string> GetGUIDsForURL(
|
||||
|
@ -134,7 +134,7 @@ bool PowerBookmarkSyncMetadataDatabase::GetAllSyncEntityMetadata(
|
||||
|
||||
while (s.Step()) {
|
||||
std::string storage_key = s.ColumnString(0);
|
||||
std::string serialized_metadata = s.ColumnString(1);
|
||||
std::string_view serialized_metadata = s.ColumnStringView(1);
|
||||
auto entity_metadata = std::make_unique<sync_pb::EntityMetadata>();
|
||||
if (!entity_metadata->ParseFromString(serialized_metadata)) {
|
||||
DLOG(WARNING) << "Failed to deserialize POWER_BOOKMARK data type "
|
||||
@ -161,4 +161,4 @@ bool PowerBookmarkSyncMetadataDatabase::GetDataTypeState(
|
||||
return false;
|
||||
}
|
||||
|
||||
} // namespace power_bookmarks
|
||||
} // namespace power_bookmarks
|
||||
|
@ -582,7 +582,7 @@ std::optional<TemplateURLData> KeywordTable::GetKeywordDataFromStatement(
|
||||
// reading these out. (GetKeywords() will delete these entries on return.)
|
||||
// NOTE: This code should only be needed as long as we might be reading such
|
||||
// potentially-old data and can be removed afterward.
|
||||
if (s.ColumnString(4).empty()) {
|
||||
if (s.ColumnStringView(4).empty()) {
|
||||
return std::nullopt;
|
||||
}
|
||||
data.SetURL(s.ColumnString(4));
|
||||
@ -596,7 +596,7 @@ std::optional<TemplateURLData> KeywordTable::GetKeywordDataFromStatement(
|
||||
data.originating_url = GURL(s.ColumnStringView(6));
|
||||
data.safe_for_autoreplace = s.ColumnBool(5);
|
||||
data.input_encodings = base::SplitString(
|
||||
s.ColumnString(9), ";", base::TRIM_WHITESPACE, base::SPLIT_WANT_ALL);
|
||||
s.ColumnStringView(9), ";", base::TRIM_WHITESPACE, base::SPLIT_WANT_ALL);
|
||||
data.id = s.ColumnInt64(0);
|
||||
data.date_created = s.ColumnTime(7);
|
||||
data.last_modified = s.ColumnTime(13);
|
||||
@ -614,7 +614,8 @@ std::optional<TemplateURLData> KeywordTable::GetKeywordDataFromStatement(
|
||||
data.enforced_by_policy = s.ColumnBool(25);
|
||||
data.featured_by_policy = s.ColumnBool(26);
|
||||
|
||||
std::optional<base::Value> value(base::JSONReader::Read(s.ColumnString(15)));
|
||||
std::optional<base::Value> value(
|
||||
base::JSONReader::Read(s.ColumnStringView(15)));
|
||||
if (value && value->is_list()) {
|
||||
for (const base::Value& alternate_url : value->GetList()) {
|
||||
if (alternate_url.is_string()) {
|
||||
|
@ -28,11 +28,13 @@ UkmMetricsTable::MetricsRow GetMetricsRowWithQuery(sql::Statement& statement) {
|
||||
row.url_id = UrlId::FromUnsafeValue(statement.ColumnInt64(3));
|
||||
row.event_id = MetricsRowEventId::FromUnsafeValue(statement.ColumnInt64(4));
|
||||
uint64_t event_hash = 0;
|
||||
if (base::HexStringToUInt64(statement.ColumnString(5), &event_hash))
|
||||
if (base::HexStringToUInt64(statement.ColumnStringView(5), &event_hash)) {
|
||||
row.event_hash = UkmEventHash::FromUnsafeValue(event_hash);
|
||||
}
|
||||
uint64_t metric_hash = 0;
|
||||
if (base::HexStringToUInt64(statement.ColumnString(6), &metric_hash))
|
||||
if (base::HexStringToUInt64(statement.ColumnStringView(6), &metric_hash)) {
|
||||
row.metric_hash = UkmMetricHash::FromUnsafeValue(metric_hash);
|
||||
}
|
||||
row.metric_value = statement.ColumnInt64(7);
|
||||
return row;
|
||||
}
|
||||
@ -45,7 +47,7 @@ UmaMetricEntry GetUmaMetricsRowWithQuery(sql::Statement& statement) {
|
||||
row.time = statement.ColumnTime(1);
|
||||
row.type = static_cast<proto::SignalType>(statement.ColumnInt64(3));
|
||||
uint64_t metric_hash = 0;
|
||||
if (base::HexStringToUInt64(statement.ColumnString(4), &metric_hash)) {
|
||||
if (base::HexStringToUInt64(statement.ColumnStringView(4), &metric_hash)) {
|
||||
row.name_hash = metric_hash;
|
||||
}
|
||||
row.value = statement.ColumnInt64(5);
|
||||
|
@ -175,7 +175,7 @@ bool MigrateToVersion4(sql::Database& db, sql::MetaTable& meta_table) {
|
||||
|
||||
while (select_statement.Step()) {
|
||||
net::SchemefulSite context_site =
|
||||
net::SchemefulSite::Deserialize(select_statement.ColumnString(1));
|
||||
net::SchemefulSite::Deserialize(select_statement.ColumnStringView(1));
|
||||
if (context_site.opaque() ||
|
||||
context_site.GetURL().scheme() == url::kFileScheme) {
|
||||
continue;
|
||||
@ -250,7 +250,7 @@ bool MigrateToVersion3(sql::Database& db, sql::MetaTable& meta_table) {
|
||||
while (select_statement.Step()) {
|
||||
sql::Statement insert_statement(
|
||||
db.GetCachedStatement(SQL_FROM_HERE, kInsertIntoNewValuesSql));
|
||||
insert_statement.BindString(0, select_statement.ColumnString(0));
|
||||
insert_statement.BindString(0, select_statement.ColumnStringView(0));
|
||||
insert_statement.BindBlob(1, select_statement.ColumnString16(1));
|
||||
insert_statement.BindBlob(2, select_statement.ColumnString16(2));
|
||||
insert_statement.BindTime(3, select_statement.ColumnTime(3));
|
||||
|
@ -434,11 +434,11 @@ std::optional<net::GlobalFirstPartySets> FirstPartySetsDatabase::GetGlobalSets(
|
||||
while (statement.Step()) {
|
||||
std::optional<net::SchemefulSite> site =
|
||||
FirstPartySetParser::CanonicalizeRegisteredDomain(
|
||||
statement.ColumnString(0), /*emit_errors=*/false);
|
||||
statement.ColumnStringView(0), /*emit_errors=*/false);
|
||||
|
||||
std::optional<net::SchemefulSite> primary =
|
||||
FirstPartySetParser::CanonicalizeRegisteredDomain(
|
||||
statement.ColumnString(1), /*emit_errors=*/false);
|
||||
statement.ColumnStringView(1), /*emit_errors=*/false);
|
||||
|
||||
std::optional<net::SiteType> site_type =
|
||||
net::FirstPartySetEntry::DeserializeSiteType(statement.ColumnInt(2));
|
||||
@ -558,7 +558,7 @@ FirstPartySetsDatabase::FetchSitesToClear(
|
||||
while (statement.Step()) {
|
||||
std::optional<net::SchemefulSite> site =
|
||||
FirstPartySetParser::CanonicalizeRegisteredDomain(
|
||||
statement.ColumnString(0), /*emit_errors=*/false);
|
||||
statement.ColumnStringView(0), /*emit_errors=*/false);
|
||||
// TODO(crbug.com/40221249): Invalid sites should be rare case but possible.
|
||||
// Consider deleting them from DB.
|
||||
if (site.has_value()) {
|
||||
@ -593,7 +593,7 @@ FirstPartySetsDatabase::FetchAllSitesToClearFilter(
|
||||
while (statement.Step()) {
|
||||
std::optional<net::SchemefulSite> site =
|
||||
FirstPartySetParser::CanonicalizeRegisteredDomain(
|
||||
statement.ColumnString(0), /*emit_errors=*/false);
|
||||
statement.ColumnStringView(0), /*emit_errors=*/false);
|
||||
// TODO(crbug.com/40221249): Invalid sites should be rare case but possible.
|
||||
// Consider deleting them from DB.
|
||||
if (site.has_value()) {
|
||||
@ -629,10 +629,10 @@ FirstPartySetsDatabase::FetchPolicyConfigurations(
|
||||
while (statement.Step()) {
|
||||
std::optional<net::SchemefulSite> site =
|
||||
FirstPartySetParser::CanonicalizeRegisteredDomain(
|
||||
statement.ColumnString(0), /*emit_errors=*/false);
|
||||
statement.ColumnStringView(0), /*emit_errors=*/false);
|
||||
|
||||
std::optional<net::SchemefulSite> maybe_primary_site;
|
||||
if (std::string primary_site = statement.ColumnString(1);
|
||||
if (std::string_view primary_site = statement.ColumnStringView(1);
|
||||
!primary_site.empty()) {
|
||||
maybe_primary_site = FirstPartySetParser::CanonicalizeRegisteredDomain(
|
||||
primary_site, /*emit_errors=*/false);
|
||||
@ -703,13 +703,13 @@ FirstPartySetsDatabase::FetchManualConfiguration(
|
||||
while (statement.Step()) {
|
||||
std::optional<net::SchemefulSite> site =
|
||||
FirstPartySetParser::CanonicalizeRegisteredDomain(
|
||||
statement.ColumnString(0), /*emit_errors=*/false);
|
||||
statement.ColumnStringView(0), /*emit_errors=*/false);
|
||||
|
||||
std::optional<net::SchemefulSite> maybe_primary_site;
|
||||
std::optional<net::SiteType> maybe_site_type;
|
||||
// DB entry for "deleted" site will have null `primary_site` and
|
||||
// `site_type`.
|
||||
if (std::string primary_site = statement.ColumnString(1);
|
||||
if (std::string_view primary_site = statement.ColumnStringView(1);
|
||||
!primary_site.empty()) {
|
||||
maybe_primary_site = FirstPartySetParser::CanonicalizeRegisteredDomain(
|
||||
primary_site, /*emit_errors=*/false);
|
||||
|
@ -4588,13 +4588,13 @@ DoGetViewClickCountsForProviderAndEligible(sql::Database& db,
|
||||
return std::nullopt;
|
||||
}
|
||||
if (!result.uncompacted_view_events.ParseFromString(
|
||||
get_counts.ColumnString(0)) ||
|
||||
get_counts.ColumnStringView(0)) ||
|
||||
!result.compacted_view_events.ParseFromString(
|
||||
get_counts.ColumnString(1)) ||
|
||||
get_counts.ColumnStringView(1)) ||
|
||||
!result.uncompacted_click_events.ParseFromString(
|
||||
get_counts.ColumnString(2)) ||
|
||||
get_counts.ColumnStringView(2)) ||
|
||||
!result.compacted_click_events.ParseFromString(
|
||||
get_counts.ColumnString(3))) {
|
||||
get_counts.ColumnStringView(3))) {
|
||||
base::UmaHistogramEnumeration(
|
||||
"Storage.InterestGroup.ProtoDeserializationResult.ListOfTimestamps",
|
||||
InterestGroupStorageProtoSerializationResult::kFailed);
|
||||
@ -4740,9 +4740,9 @@ void DoRecordViewClick(sql::Database& db,
|
||||
if (get_counts.Step()) {
|
||||
row_exists = true;
|
||||
if (!uncompacted_view_events.ParseFromString(
|
||||
get_counts.ColumnString(0)) ||
|
||||
get_counts.ColumnStringView(0)) ||
|
||||
!uncompacted_click_events.ParseFromString(
|
||||
get_counts.ColumnString(1))) {
|
||||
get_counts.ColumnStringView(1))) {
|
||||
// TODO(crbug.com/355010821): Consider bubbling out the failure.
|
||||
base::UmaHistogramEnumeration(
|
||||
"Storage.InterestGroup.ProtoDeserializationResult.ListOfTimestamps",
|
||||
|
@ -287,7 +287,7 @@ CdmStorageKeyUsageSize CdmStorageDatabase::GetUsagePerAllStorageKeys(
|
||||
while (get_all_storage_keys_statement.Step()) {
|
||||
std::optional<blink::StorageKey> maybe_storage_key =
|
||||
blink::StorageKey::Deserialize(
|
||||
get_all_storage_keys_statement.ColumnString(0));
|
||||
get_all_storage_keys_statement.ColumnStringView(0));
|
||||
if (maybe_storage_key) {
|
||||
auto storage_key = maybe_storage_key.value();
|
||||
usage_per_storage_keys.emplace_back(
|
||||
|
@ -26,7 +26,7 @@ const char kLocalTracesTableName[] = "local_traces";
|
||||
constexpr int kCurrentVersionNumber = 5;
|
||||
|
||||
ClientTraceReport GetReportFromStatement(sql::Statement& statement) {
|
||||
auto trace_id = base::Token::FromString(statement.ColumnString(0));
|
||||
auto trace_id = base::Token::FromString(statement.ColumnStringView(0));
|
||||
CHECK(trace_id.has_value());
|
||||
|
||||
ClientTraceReport client_report;
|
||||
|
@ -78,7 +78,7 @@ base::TaskPriority GetReportingAndNelStoreBackgroundSequencePriority() {
|
||||
// Attempts to convert a string returned by NetworkAnonymizationKeyToString() to
|
||||
// a NetworkAnonymizationKey. Returns false on failure.
|
||||
[[nodiscard]] bool NetworkAnonymizationKeyFromString(
|
||||
const std::string& string,
|
||||
std::string_view string,
|
||||
NetworkAnonymizationKey* out_network_anonymization_key) {
|
||||
std::optional<base::Value> value = base::JSONReader::Read(string);
|
||||
if (!value)
|
||||
@ -1301,9 +1301,10 @@ void SQLitePersistentReportingAndNelStore::Backend::
|
||||
// Attempt to reconstitute a NEL policy from the fields stored in the
|
||||
// database.
|
||||
NetworkAnonymizationKey network_anonymization_key;
|
||||
if (!NetworkAnonymizationKeyFromString(smt.ColumnString(0),
|
||||
&network_anonymization_key))
|
||||
if (!NetworkAnonymizationKeyFromString(smt.ColumnStringView(0),
|
||||
&network_anonymization_key)) {
|
||||
continue;
|
||||
}
|
||||
NetworkErrorLoggingService::NelPolicy policy;
|
||||
policy.key = NetworkErrorLoggingService::NelPolicyKey(
|
||||
network_anonymization_key,
|
||||
@ -1311,8 +1312,10 @@ void SQLitePersistentReportingAndNelStore::Backend::
|
||||
/* origin_scheme = */ smt.ColumnString(1),
|
||||
/* origin_host = */ smt.ColumnString(2),
|
||||
/* origin_port = */ smt.ColumnInt(3)));
|
||||
if (!policy.received_ip_address.AssignFromIPLiteral(smt.ColumnString(4)))
|
||||
if (!policy.received_ip_address.AssignFromIPLiteral(
|
||||
smt.ColumnStringView(4))) {
|
||||
policy.received_ip_address = IPAddress();
|
||||
}
|
||||
policy.report_to = smt.ColumnString(5);
|
||||
policy.expires = base::Time::FromDeltaSinceWindowsEpoch(
|
||||
base::Microseconds(smt.ColumnInt64(6)));
|
||||
@ -1388,9 +1391,11 @@ void SQLitePersistentReportingAndNelStore::Backend::
|
||||
// Attempt to reconstitute a ReportingEndpoint from the fields stored in the
|
||||
// database.
|
||||
NetworkAnonymizationKey network_anonymization_key;
|
||||
if (!NetworkAnonymizationKeyFromString(endpoints_statement.ColumnString(0),
|
||||
&network_anonymization_key))
|
||||
if (!NetworkAnonymizationKeyFromString(
|
||||
endpoints_statement.ColumnStringView(0),
|
||||
&network_anonymization_key)) {
|
||||
continue;
|
||||
}
|
||||
// The target_type is set to kDeveloper because this function is used for
|
||||
// V0 reporting, which only includes web developer entities.
|
||||
ReportingEndpointGroupKey group_key(
|
||||
@ -1416,9 +1421,10 @@ void SQLitePersistentReportingAndNelStore::Backend::
|
||||
// stored in the database.
|
||||
NetworkAnonymizationKey network_anonymization_key;
|
||||
if (!NetworkAnonymizationKeyFromString(
|
||||
endpoint_groups_statement.ColumnString(0),
|
||||
&network_anonymization_key))
|
||||
endpoint_groups_statement.ColumnStringView(0),
|
||||
&network_anonymization_key)) {
|
||||
continue;
|
||||
}
|
||||
// The target_type is set to kDeveloper because this function is used for
|
||||
// V0 reporting, which only includes web developer entities.
|
||||
ReportingEndpointGroupKey group_key(
|
||||
|
@ -1006,7 +1006,7 @@ SQLitePersistentSharedDictionaryStore::Backend::GetOriginsBetweenImpl(
|
||||
|
||||
std::set<url::Origin> origins;
|
||||
while (statement.Step()) {
|
||||
const std::string frame_origin_string = statement.ColumnString(0);
|
||||
const std::string_view frame_origin_string = statement.ColumnStringView(0);
|
||||
origins.insert(url::Origin::Create(GURL(frame_origin_string)));
|
||||
}
|
||||
return base::ok(std::vector<url::Origin>(origins.begin(), origins.end()));
|
||||
|
@ -1718,13 +1718,13 @@ std::string Database::GetSchema() {
|
||||
|
||||
std::string schema;
|
||||
while (statement.Step()) {
|
||||
schema += statement.ColumnString(0);
|
||||
schema += statement.ColumnStringView(0);
|
||||
schema += '|';
|
||||
schema += statement.ColumnString(1);
|
||||
schema += statement.ColumnStringView(1);
|
||||
schema += '|';
|
||||
schema += statement.ColumnString(2);
|
||||
schema += statement.ColumnStringView(2);
|
||||
schema += '|';
|
||||
schema += statement.ColumnString(3);
|
||||
schema += statement.ColumnStringView(3);
|
||||
schema += '\n';
|
||||
}
|
||||
|
||||
|
@ -322,7 +322,7 @@ std::string ExecuteWithResults(Database* db,
|
||||
for (int i = 0; i < s.ColumnCount(); ++i) {
|
||||
if (i > 0)
|
||||
ret += column_sep;
|
||||
ret += s.ColumnString(i);
|
||||
ret += s.ColumnStringView(i);
|
||||
}
|
||||
}
|
||||
return ret;
|
||||
|
@ -135,7 +135,7 @@ QuotaErrorOr<BucketInfo> BucketInfoFromSqlStatement(sql::Statement& statement) {
|
||||
}
|
||||
|
||||
std::optional<StorageKey> storage_key =
|
||||
StorageKey::Deserialize(statement.ColumnString(1));
|
||||
StorageKey::Deserialize(statement.ColumnStringView(1));
|
||||
if (!storage_key.has_value()) {
|
||||
return base::unexpected(QuotaError::kStorageKeyError);
|
||||
}
|
||||
@ -621,7 +621,7 @@ QuotaErrorOr<mojom::BucketTableEntryPtr> QuotaDatabase::GetBucketInfoForTest(
|
||||
}
|
||||
|
||||
std::optional<StorageKey> storage_key =
|
||||
StorageKey::Deserialize(statement.ColumnString(1));
|
||||
StorageKey::Deserialize(statement.ColumnStringView(1));
|
||||
if (!storage_key.has_value()) {
|
||||
return base::unexpected(QuotaError::kStorageKeyError);
|
||||
}
|
||||
@ -707,7 +707,7 @@ QuotaErrorOr<std::set<BucketLocator>> QuotaDatabase::GetBucketsForEviction(
|
||||
|
||||
while (statement.Step()) {
|
||||
std::optional<StorageKey> read_storage_key =
|
||||
StorageKey::Deserialize(statement.ColumnString(1));
|
||||
StorageKey::Deserialize(statement.ColumnStringView(1));
|
||||
if (!read_storage_key.has_value()) {
|
||||
// TODO(estade): this row needs to be deleted.
|
||||
continue;
|
||||
@ -719,7 +719,7 @@ QuotaErrorOr<std::set<BucketLocator>> QuotaDatabase::GetBucketsForEviction(
|
||||
}
|
||||
|
||||
// Only the default bucket is persisted by `navigator.storage.persist()`.
|
||||
const bool is_default = statement.ColumnString(2) == kDefaultBucketName;
|
||||
const bool is_default = statement.ColumnStringView(2) == kDefaultBucketName;
|
||||
const GURL read_gurl = read_storage_key->origin().GetURL();
|
||||
if (is_default && special_storage_policy &&
|
||||
(special_storage_policy->IsStorageDurable(read_gurl) ||
|
||||
@ -760,7 +760,7 @@ QuotaErrorOr<std::set<StorageKey>> QuotaDatabase::GetStorageKeysForType(
|
||||
std::set<StorageKey> storage_keys;
|
||||
while (statement.Step()) {
|
||||
std::optional<StorageKey> read_storage_key =
|
||||
StorageKey::Deserialize(statement.ColumnString(0));
|
||||
StorageKey::Deserialize(statement.ColumnStringView(0));
|
||||
if (!read_storage_key.has_value()) {
|
||||
continue;
|
||||
}
|
||||
@ -796,13 +796,13 @@ QuotaErrorOr<std::set<BucketLocator>> QuotaDatabase::GetBucketsModifiedBetween(
|
||||
std::set<BucketLocator> buckets;
|
||||
while (statement.Step()) {
|
||||
std::optional<StorageKey> read_storage_key =
|
||||
StorageKey::Deserialize(statement.ColumnString(1));
|
||||
StorageKey::Deserialize(statement.ColumnStringView(1));
|
||||
if (!read_storage_key.has_value()) {
|
||||
continue;
|
||||
}
|
||||
buckets.emplace(BucketId(statement.ColumnInt64(0)),
|
||||
read_storage_key.value(), type,
|
||||
statement.ColumnString(2) == kDefaultBucketName);
|
||||
statement.ColumnStringView(2) == kDefaultBucketName);
|
||||
}
|
||||
return buckets;
|
||||
}
|
||||
@ -1305,7 +1305,7 @@ QuotaError QuotaDatabase::DumpBucketTable(const BucketTableCallback& callback) {
|
||||
|
||||
while (statement.Step()) {
|
||||
std::optional<StorageKey> storage_key =
|
||||
StorageKey::Deserialize(statement.ColumnString(1));
|
||||
StorageKey::Deserialize(statement.ColumnStringView(1));
|
||||
if (!storage_key.has_value()) {
|
||||
continue;
|
||||
}
|
||||
|
@ -181,7 +181,7 @@ bool QuotaDatabaseMigrations::MigrateFromVersion7ToVersion8(
|
||||
insert_statement.BindInt64(0, bucket_id.value());
|
||||
|
||||
// Populate storage key and host.
|
||||
std::string storage_key_string = select_statement.ColumnString(1);
|
||||
std::string_view storage_key_string = select_statement.ColumnStringView(1);
|
||||
insert_statement.BindString(1, storage_key_string);
|
||||
|
||||
std::optional<blink::StorageKey> storage_key =
|
||||
@ -194,7 +194,7 @@ bool QuotaDatabaseMigrations::MigrateFromVersion7ToVersion8(
|
||||
// Populate type, name, use_count, last_accessed, last_modified,
|
||||
// expiration and quota.
|
||||
insert_statement.BindInt(3, select_statement.ColumnInt(2));
|
||||
insert_statement.BindString(4, select_statement.ColumnString(3));
|
||||
insert_statement.BindString(4, select_statement.ColumnStringView(3));
|
||||
insert_statement.BindInt(5, select_statement.ColumnInt(4));
|
||||
insert_statement.BindTime(6, select_statement.ColumnTime(5));
|
||||
insert_statement.BindTime(7, select_statement.ColumnTime(6));
|
||||
@ -282,11 +282,10 @@ bool QuotaDatabaseMigrations::MigrateFromVersion8ToVersion9(
|
||||
last_bucket_id = BucketId(select_statement.ColumnInt64(0));
|
||||
|
||||
insert_statement.BindInt64(0, select_statement.ColumnInt64(0));
|
||||
insert_statement.BindString(1, select_statement.ColumnString(1));
|
||||
insert_statement.BindString(2, select_statement.ColumnString(2));
|
||||
insert_statement.BindString(1, select_statement.ColumnStringView(1));
|
||||
insert_statement.BindString(2, select_statement.ColumnStringView(2));
|
||||
insert_statement.BindInt(3, select_statement.ColumnInt(3));
|
||||
const std::string bucket_name = select_statement.ColumnString(4);
|
||||
insert_statement.BindString(4, bucket_name);
|
||||
insert_statement.BindString(4, select_statement.ColumnStringView(4));
|
||||
insert_statement.BindInt(5, select_statement.ColumnInt(5));
|
||||
insert_statement.BindTime(6, select_statement.ColumnTime(6));
|
||||
insert_statement.BindTime(7, select_statement.ColumnTime(7));
|
||||
|
Loading…
x
Reference in New Issue
Block a user