Commit 89e4a67b authored by Victor Costan's avatar Victor Costan Committed by Chromium LUCI CQ

WebSQL: Replace off_the_record with incognito.

The majority of the storage code uses incognito instead of
off_the_record. This CL gets WebSQL in line, to reduce cognitive
overhead for readers.

Change-Id: I8fcce58f82da24e22aa7b14b201dc7ed935b1114
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2634551
Auto-Submit: Victor Costan <pwnall@chromium.org>
Reviewed-by: default avatarJoshua Bell <jsbell@chromium.org>
Commit-Queue: Joshua Bell <jsbell@chromium.org>
Cr-Commit-Position: refs/heads/master@{#844845}
parent 0c1b242b
...@@ -115,8 +115,8 @@ void WebDatabaseHostImpl::OpenFileValidated(const base::string16& vfs_file_name, ...@@ -115,8 +115,8 @@ void WebDatabaseHostImpl::OpenFileValidated(const base::string16& vfs_file_name,
std::string origin_identifier; std::string origin_identifier;
base::string16 database_name; base::string16 database_name;
// When in OffTheRecord mode, we want to make sure that all DB files are // When in Incognito mode, we want to make sure that all DB files are
// removed when the OffTheRecord browser context goes away, so we add the // removed when the Incognito browser context goes away, so we add the
// SQLITE_OPEN_DELETEONCLOSE flag when opening all files, and keep // SQLITE_OPEN_DELETEONCLOSE flag when opening all files, and keep
// open handles to them in the database tracker to make sure they're // open handles to them in the database tracker to make sure they're
// around for as long as needed. // around for as long as needed.
...@@ -130,14 +130,14 @@ void WebDatabaseHostImpl::OpenFileValidated(const base::string16& vfs_file_name, ...@@ -130,14 +130,14 @@ void WebDatabaseHostImpl::OpenFileValidated(const base::string16& vfs_file_name,
base::FilePath db_file = DatabaseUtil::GetFullFilePathForVfsFile( base::FilePath db_file = DatabaseUtil::GetFullFilePathForVfsFile(
db_tracker_.get(), vfs_file_name); db_tracker_.get(), vfs_file_name);
if (!db_file.empty()) { if (!db_file.empty()) {
if (db_tracker_->IsOffTheRecordProfile()) { if (db_tracker_->IsIncognitoProfile()) {
tracked_file = db_tracker_->GetOffTheRecordFile(vfs_file_name); tracked_file = db_tracker_->GetIncognitoFile(vfs_file_name);
if (!tracked_file) { if (!tracked_file) {
file = VfsBackend::OpenFile( file = VfsBackend::OpenFile(
db_file, desired_flags | SQLITE_OPEN_DELETEONCLOSE); db_file, desired_flags | SQLITE_OPEN_DELETEONCLOSE);
if (!(desired_flags & SQLITE_OPEN_DELETEONCLOSE)) { if (!(desired_flags & SQLITE_OPEN_DELETEONCLOSE)) {
tracked_file = db_tracker_->SaveOffTheRecordFile(vfs_file_name, tracked_file =
std::move(file)); db_tracker_->SaveIncognitoFile(vfs_file_name, std::move(file));
} }
} }
} else { } else {
...@@ -287,20 +287,20 @@ void WebDatabaseHostImpl::DatabaseDeleteFile( ...@@ -287,20 +287,20 @@ void WebDatabaseHostImpl::DatabaseDeleteFile(
base::FilePath db_file = base::FilePath db_file =
DatabaseUtil::GetFullFilePathForVfsFile(db_tracker_.get(), vfs_file_name); DatabaseUtil::GetFullFilePathForVfsFile(db_tracker_.get(), vfs_file_name);
if (!db_file.empty()) { if (!db_file.empty()) {
// In order to delete a journal file in OffTheRecord mode, we only need to // In order to delete a journal file in Incognito mode, we only need to
// close the open handle to it that's stored in the database tracker. // close the open handle to it that's stored in the database tracker.
if (db_tracker_->IsOffTheRecordProfile()) { if (db_tracker_->IsIncognitoProfile()) {
const base::string16 wal_suffix(base::ASCIIToUTF16("-wal")); const base::string16 wal_suffix(base::ASCIIToUTF16("-wal"));
base::string16 sqlite_suffix; base::string16 sqlite_suffix;
// WAL files can be deleted without having previously been opened. // WAL files can be deleted without having previously been opened.
if (!db_tracker_->HasSavedOffTheRecordFileHandle(vfs_file_name) && if (!db_tracker_->HasSavedIncognitoFileHandle(vfs_file_name) &&
DatabaseUtil::CrackVfsFileName(vfs_file_name, nullptr, nullptr, DatabaseUtil::CrackVfsFileName(vfs_file_name, nullptr, nullptr,
&sqlite_suffix) && &sqlite_suffix) &&
sqlite_suffix == wal_suffix) { sqlite_suffix == wal_suffix) {
error_code = SQLITE_OK; error_code = SQLITE_OK;
} else { } else {
db_tracker_->CloseOffTheRecordFileHandle(vfs_file_name); db_tracker_->CloseIncognitoFileHandle(vfs_file_name);
error_code = SQLITE_OK; error_code = SQLITE_OK;
} }
} else { } else {
......
...@@ -34,7 +34,7 @@ namespace storage { ...@@ -34,7 +34,7 @@ namespace storage {
const base::FilePath::CharType kDatabaseDirectoryName[] = const base::FilePath::CharType kDatabaseDirectoryName[] =
FILE_PATH_LITERAL("databases"); FILE_PATH_LITERAL("databases");
const base::FilePath::CharType kOffTheRecordDatabaseDirectoryName[] = const base::FilePath::CharType kIncognitoDatabaseDirectoryName[] =
FILE_PATH_LITERAL("databases-off-the-record"); FILE_PATH_LITERAL("databases-off-the-record");
const base::FilePath::CharType kTrackerDatabaseFileName[] = const base::FilePath::CharType kTrackerDatabaseFileName[] =
FILE_PATH_LITERAL("Databases.db"); FILE_PATH_LITERAL("Databases.db");
...@@ -86,13 +86,13 @@ OriginInfo::OriginInfo(const std::string& origin_identifier, int64_t total_size) ...@@ -86,13 +86,13 @@ OriginInfo::OriginInfo(const std::string& origin_identifier, int64_t total_size)
: origin_identifier_(origin_identifier), total_size_(total_size) {} : origin_identifier_(origin_identifier), total_size_(total_size) {}
DatabaseTracker::DatabaseTracker(const base::FilePath& profile_path, DatabaseTracker::DatabaseTracker(const base::FilePath& profile_path,
bool is_off_the_record, bool is_incognito,
SpecialStoragePolicy* special_storage_policy, SpecialStoragePolicy* special_storage_policy,
QuotaManagerProxy* quota_manager_proxy) QuotaManagerProxy* quota_manager_proxy)
: is_off_the_record_(is_off_the_record), : is_incognito_(is_incognito),
profile_path_(profile_path), profile_path_(profile_path),
db_dir_(is_off_the_record_ db_dir_(is_incognito_
? profile_path_.Append(kOffTheRecordDatabaseDirectoryName) ? profile_path_.Append(kIncognitoDatabaseDirectoryName)
: profile_path_.Append(kDatabaseDirectoryName)), : profile_path_.Append(kDatabaseDirectoryName)),
db_(new sql::Database()), db_(new sql::Database()),
special_storage_policy_(special_storage_policy), special_storage_policy_(special_storage_policy),
...@@ -260,7 +260,7 @@ void DatabaseTracker::CloseTrackerDatabaseAndClearCaches() { ...@@ -260,7 +260,7 @@ void DatabaseTracker::CloseTrackerDatabaseAndClearCaches() {
DCHECK(task_runner_->RunsTasksInCurrentSequence()); DCHECK(task_runner_->RunsTasksInCurrentSequence());
ClearAllCachedOriginInfo(); ClearAllCachedOriginInfo();
if (!is_off_the_record_) { if (!is_incognito_) {
meta_table_.reset(nullptr); meta_table_.reset(nullptr);
databases_table_.reset(nullptr); databases_table_.reset(nullptr);
db_->Close(); db_->Close();
...@@ -274,16 +274,16 @@ base::FilePath DatabaseTracker::GetOriginDirectory( ...@@ -274,16 +274,16 @@ base::FilePath DatabaseTracker::GetOriginDirectory(
base::string16 origin_directory; base::string16 origin_directory;
if (!is_off_the_record_) { if (!is_incognito_) {
origin_directory = base::UTF8ToUTF16(origin_identifier); origin_directory = base::UTF8ToUTF16(origin_identifier);
} else { } else {
auto it = off_the_record_origin_directories_.find(origin_identifier); auto it = incognito_origin_directories_.find(origin_identifier);
if (it != off_the_record_origin_directories_.end()) { if (it != incognito_origin_directories_.end()) {
origin_directory = it->second; origin_directory = it->second;
} else { } else {
origin_directory = base::NumberToString16( origin_directory =
off_the_record_origin_directories_generator_++); base::NumberToString16(incognito_origin_directories_generator_++);
off_the_record_origin_directories_[origin_identifier] = origin_directory; incognito_origin_directories_[origin_identifier] = origin_directory;
} }
} }
...@@ -428,18 +428,18 @@ bool DatabaseTracker::DeleteOrigin(const std::string& origin_identifier, ...@@ -428,18 +428,18 @@ bool DatabaseTracker::DeleteOrigin(const std::string& origin_identifier,
base::DeletePathRecursively(origin_dir); base::DeletePathRecursively(origin_dir);
base::DeletePathRecursively(new_origin_dir); // Might fail on windows. base::DeletePathRecursively(new_origin_dir); // Might fail on windows.
if (is_off_the_record_) { if (is_incognito_) {
off_the_record_origin_directories_.erase(origin_identifier); incognito_origin_directories_.erase(origin_identifier);
// TODO(jsbell): Consider alternate data structures to avoid this // TODO(jsbell): Consider alternate data structures to avoid this
// linear scan. // linear scan.
for (auto it = off_the_record_file_handles_.begin(); for (auto it = incognito_file_handles_.begin();
it != off_the_record_file_handles_.end();) { it != incognito_file_handles_.end();) {
std::string id; std::string id;
if (DatabaseUtil::CrackVfsFileName(it->first, &id, nullptr, nullptr) && if (DatabaseUtil::CrackVfsFileName(it->first, &id, nullptr, nullptr) &&
id == origin_identifier) { id == origin_identifier) {
delete it->second; delete it->second;
it = off_the_record_file_handles_.erase(it); it = incognito_file_handles_.erase(it);
} else { } else {
++it; ++it;
} }
...@@ -508,12 +508,11 @@ bool DatabaseTracker::LazyInit() { ...@@ -508,12 +508,11 @@ bool DatabaseTracker::LazyInit() {
databases_table_.reset(new DatabasesTable(db_.get())); databases_table_.reset(new DatabasesTable(db_.get()));
meta_table_.reset(new sql::MetaTable()); meta_table_.reset(new sql::MetaTable());
is_initialized_ = is_initialized_ = base::CreateDirectory(db_dir_) &&
base::CreateDirectory(db_dir_) && (db_->is_open() ||
(db_->is_open() || (is_incognito_ ? db_->OpenInMemory()
(is_off_the_record_ ? db_->OpenInMemory() : db_->Open(kTrackerDatabaseFullPath))) &&
: db_->Open(kTrackerDatabaseFullPath))) && UpgradeToCurrentVersion();
UpgradeToCurrentVersion();
if (!is_initialized_) { if (!is_initialized_) {
databases_table_.reset(nullptr); databases_table_.reset(nullptr);
meta_table_.reset(nullptr); meta_table_.reset(nullptr);
...@@ -789,64 +788,64 @@ int DatabaseTracker::DeleteDataForOrigin(const url::Origin& origin, ...@@ -789,64 +788,64 @@ int DatabaseTracker::DeleteDataForOrigin(const url::Origin& origin,
return net::OK; return net::OK;
} }
const base::File* DatabaseTracker::GetOffTheRecordFile( const base::File* DatabaseTracker::GetIncognitoFile(
const base::string16& vfs_file_name) const { const base::string16& vfs_file_name) const {
DCHECK(task_runner_->RunsTasksInCurrentSequence()); DCHECK(task_runner_->RunsTasksInCurrentSequence());
DCHECK(is_off_the_record_); DCHECK(is_incognito_);
auto it = off_the_record_file_handles_.find(vfs_file_name); auto it = incognito_file_handles_.find(vfs_file_name);
if (it != off_the_record_file_handles_.end()) if (it != incognito_file_handles_.end())
return it->second; return it->second;
return nullptr; return nullptr;
} }
const base::File* DatabaseTracker::SaveOffTheRecordFile( const base::File* DatabaseTracker::SaveIncognitoFile(
const base::string16& vfs_file_name, const base::string16& vfs_file_name,
base::File file) { base::File file) {
DCHECK(task_runner_->RunsTasksInCurrentSequence()); DCHECK(task_runner_->RunsTasksInCurrentSequence());
DCHECK(is_off_the_record_); DCHECK(is_incognito_);
if (!file.IsValid()) if (!file.IsValid())
return nullptr; return nullptr;
base::File* to_insert = new base::File(std::move(file)); base::File* to_insert = new base::File(std::move(file));
auto rv = off_the_record_file_handles_.insert( auto rv =
std::make_pair(vfs_file_name, to_insert)); incognito_file_handles_.insert(std::make_pair(vfs_file_name, to_insert));
DCHECK(rv.second); DCHECK(rv.second);
return rv.first->second; return rv.first->second;
} }
void DatabaseTracker::CloseOffTheRecordFileHandle( void DatabaseTracker::CloseIncognitoFileHandle(
const base::string16& vfs_file_name) { const base::string16& vfs_file_name) {
DCHECK(task_runner_->RunsTasksInCurrentSequence()); DCHECK(task_runner_->RunsTasksInCurrentSequence());
DCHECK(is_off_the_record_); DCHECK(is_incognito_);
DCHECK(off_the_record_file_handles_.find(vfs_file_name) != DCHECK(incognito_file_handles_.find(vfs_file_name) !=
off_the_record_file_handles_.end()); incognito_file_handles_.end());
auto it = off_the_record_file_handles_.find(vfs_file_name); auto it = incognito_file_handles_.find(vfs_file_name);
if (it != off_the_record_file_handles_.end()) { if (it != incognito_file_handles_.end()) {
delete it->second; delete it->second;
off_the_record_file_handles_.erase(it); incognito_file_handles_.erase(it);
} }
} }
bool DatabaseTracker::HasSavedOffTheRecordFileHandle( bool DatabaseTracker::HasSavedIncognitoFileHandle(
const base::string16& vfs_file_name) const { const base::string16& vfs_file_name) const {
DCHECK(task_runner_->RunsTasksInCurrentSequence()); DCHECK(task_runner_->RunsTasksInCurrentSequence());
return (off_the_record_file_handles_.find(vfs_file_name) != return (incognito_file_handles_.find(vfs_file_name) !=
off_the_record_file_handles_.end()); incognito_file_handles_.end());
} }
void DatabaseTracker::DeleteOffTheRecordDBDirectory() { void DatabaseTracker::DeleteIncognitoDBDirectory() {
DCHECK(task_runner_->RunsTasksInCurrentSequence()); DCHECK(task_runner_->RunsTasksInCurrentSequence());
is_initialized_ = false; is_initialized_ = false;
for (auto& pair : off_the_record_file_handles_) for (auto& pair : incognito_file_handles_)
delete pair.second; delete pair.second;
base::FilePath off_the_record_db_dir = base::FilePath incognito_db_dir =
profile_path_.Append(kOffTheRecordDatabaseDirectoryName); profile_path_.Append(kIncognitoDatabaseDirectoryName);
if (base::DirectoryExists(off_the_record_db_dir)) if (base::DirectoryExists(incognito_db_dir))
base::DeletePathRecursively(off_the_record_db_dir); base::DeletePathRecursively(incognito_db_dir);
} }
void DatabaseTracker::ClearSessionOnlyOrigins() { void DatabaseTracker::ClearSessionOnlyOrigins() {
...@@ -894,8 +893,8 @@ void DatabaseTracker::Shutdown() { ...@@ -894,8 +893,8 @@ void DatabaseTracker::Shutdown() {
return; return;
} }
shutting_down_ = true; shutting_down_ = true;
if (is_off_the_record_) if (is_incognito_)
DeleteOffTheRecordDBDirectory(); DeleteIncognitoDBDirectory();
else if (!force_keep_session_state_) else if (!force_keep_session_state_)
ClearSessionOnlyOrigins(); ClearSessionOnlyOrigins();
CloseTrackerDatabaseAndClearCaches(); CloseTrackerDatabaseAndClearCaches();
......
...@@ -98,7 +98,7 @@ class COMPONENT_EXPORT(STORAGE_BROWSER) DatabaseTracker ...@@ -98,7 +98,7 @@ class COMPONENT_EXPORT(STORAGE_BROWSER) DatabaseTracker
}; };
DatabaseTracker(const base::FilePath& profile_path, DatabaseTracker(const base::FilePath& profile_path,
bool is_off_the_record, bool is_incognito,
SpecialStoragePolicy* special_storage_policy, SpecialStoragePolicy* special_storage_policy,
QuotaManagerProxy* quota_manager_proxy); QuotaManagerProxy* quota_manager_proxy);
...@@ -164,18 +164,16 @@ class COMPONENT_EXPORT(STORAGE_BROWSER) DatabaseTracker ...@@ -164,18 +164,16 @@ class COMPONENT_EXPORT(STORAGE_BROWSER) DatabaseTracker
virtual int DeleteDataForOrigin(const url::Origin& origin, virtual int DeleteDataForOrigin(const url::Origin& origin,
net::CompletionOnceCallback callback); net::CompletionOnceCallback callback);
bool IsOffTheRecordProfile() const { return is_off_the_record_; } bool IsIncognitoProfile() const { return is_incognito_; }
const base::File* GetOffTheRecordFile( const base::File* GetIncognitoFile(const base::string16& vfs_file_path) const;
const base::string16& vfs_file_path) const; const base::File* SaveIncognitoFile(const base::string16& vfs_file_path,
const base::File* SaveOffTheRecordFile(const base::string16& vfs_file_path, base::File file);
base::File file); void CloseIncognitoFileHandle(const base::string16& vfs_file_path);
void CloseOffTheRecordFileHandle(const base::string16& vfs_file_path); bool HasSavedIncognitoFileHandle(const base::string16& vfs_file_path) const;
bool HasSavedOffTheRecordFileHandle(
const base::string16& vfs_file_path) const;
// Shutdown the database tracker, deleting database files if the tracker is // Shutdown the database tracker, deleting database files if the tracker is
// used for an OffTheRecord profile. // used for an Incognito profile.
void Shutdown(); void Shutdown();
// Disables the exit-time deletion of session-only data. // Disables the exit-time deletion of session-only data.
void SetForceKeepSessionState(); void SetForceKeepSessionState();
...@@ -219,9 +217,9 @@ class COMPONENT_EXPORT(STORAGE_BROWSER) DatabaseTracker ...@@ -219,9 +217,9 @@ class COMPONENT_EXPORT(STORAGE_BROWSER) DatabaseTracker
// virtual for unit-testing only. // virtual for unit-testing only.
virtual ~DatabaseTracker(); virtual ~DatabaseTracker();
// Deletes the directory that stores all DBs in OffTheRecord mode, if it // Deletes the directory that stores all DBs in Incognito mode, if it
// exists. // exists.
void DeleteOffTheRecordDBDirectory(); void DeleteIncognitoDBDirectory();
// Deletes session-only databases. Blocks databases from being created/opened. // Deletes session-only databases. Blocks databases from being created/opened.
void ClearSessionOnlyOrigins(); void ClearSessionOnlyOrigins();
...@@ -279,7 +277,7 @@ class COMPONENT_EXPORT(STORAGE_BROWSER) DatabaseTracker ...@@ -279,7 +277,7 @@ class COMPONENT_EXPORT(STORAGE_BROWSER) DatabaseTracker
base::FilePath GetOriginDirectory(const std::string& origin_identifier); base::FilePath GetOriginDirectory(const std::string& origin_identifier);
bool is_initialized_ = false; bool is_initialized_ = false;
const bool is_off_the_record_; const bool is_incognito_;
bool force_keep_session_state_ = false; bool force_keep_session_state_ = false;
bool shutting_down_ = false; bool shutting_down_ = false;
const base::FilePath profile_path_; const base::FilePath profile_path_;
...@@ -312,20 +310,20 @@ class COMPONENT_EXPORT(STORAGE_BROWSER) DatabaseTracker ...@@ -312,20 +310,20 @@ class COMPONENT_EXPORT(STORAGE_BROWSER) DatabaseTracker
// The database tracker thread we're supposed to run file IO on. // The database tracker thread we're supposed to run file IO on.
scoped_refptr<base::SequencedTaskRunner> task_runner_; scoped_refptr<base::SequencedTaskRunner> task_runner_;
// When in OffTheRecord mode, store a DELETE_ON_CLOSE handle to each // When in Incognito mode, store a DELETE_ON_CLOSE handle to each
// main DB and journal file that was accessed. When the OffTheRecord profile // main DB and journal file that was accessed. When the Incognito profile
// goes away (or when the browser crashes), all these handles will be // goes away (or when the browser crashes), all these handles will be
// closed, and the files will be deleted. // closed, and the files will be deleted.
std::map<base::string16, base::File*> off_the_record_file_handles_; std::map<base::string16, base::File*> incognito_file_handles_;
// In a non-OffTheRecord profile, all DBs in an origin are stored in a // In a non-Incognito profile, all DBs in an origin are stored in a
// directory named after the origin. In an OffTheRecord profile though, we do // directory named after the origin. In an Incognito profile though, we do
// not want the directory structure to reveal the origins visited by the user // not want the directory structure to reveal the origins visited by the user
// (in case the browser process crashes and those directories are not // (in case the browser process crashes and those directories are not
// deleted). So we use this map to assign directory names that do not reveal // deleted). So we use this map to assign directory names that do not reveal
// this information. // this information.
std::map<std::string, base::string16> off_the_record_origin_directories_; std::map<std::string, base::string16> incognito_origin_directories_;
int off_the_record_origin_directories_generator_ = 0; int incognito_origin_directories_generator_ = 0;
FRIEND_TEST_ALL_PREFIXES(DatabaseTracker, TestHelper); FRIEND_TEST_ALL_PREFIXES(DatabaseTracker, TestHelper);
}; };
......
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