Commit 8b7d0e50 authored by Ramin Halavati's avatar Ramin Halavati Committed by Commit Bot

Replace 'incognito' with 'OffTheRecord' in DatabaseTracker.

DatabaseTracker uses the term 'incognito' with the meaning of
'in-memory'. This is used for all profile types that are OffTheRecord
(including incognito, guest, and non-primary OTRs).
To fix the possible misinterpretation, 'incognito' is replaced with
'OffTheRecord'.

This CL does not make any behavioral change and is just for better code
readability.

Bug: 968028
Change-Id: Ifce346865d9d054883ab45679fd3a87144e88bd0
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2201377
Commit-Queue: Victor Costan <pwnall@chromium.org>
Reviewed-by: default avatarKen Buchanan <kenrb@chromium.org>
Reviewed-by: default avatarVictor Costan <pwnall@chromium.org>
Cr-Commit-Position: refs/heads/master@{#768893}
parent f3557fdb
...@@ -116,8 +116,8 @@ void WebDatabaseHostImpl::OpenFileValidated(const base::string16& vfs_file_name, ...@@ -116,8 +116,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 incognito mode, we want to make sure that all DB files are // When in OffTheRecord mode, we want to make sure that all DB files are
// removed when the incognito browser context goes away, so we add the // removed when the OffTheRecord 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.
...@@ -131,14 +131,14 @@ void WebDatabaseHostImpl::OpenFileValidated(const base::string16& vfs_file_name, ...@@ -131,14 +131,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_->IsIncognitoProfile()) { if (db_tracker_->IsOffTheRecordProfile()) {
tracked_file = db_tracker_->GetIncognitoFile(vfs_file_name); tracked_file = db_tracker_->GetOffTheRecordFile(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 = tracked_file = db_tracker_->SaveOffTheRecordFile(vfs_file_name,
db_tracker_->SaveIncognitoFile(vfs_file_name, std::move(file)); std::move(file));
} }
} }
} else { } else {
...@@ -288,20 +288,20 @@ void WebDatabaseHostImpl::DatabaseDeleteFile( ...@@ -288,20 +288,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 incognito mode, we only need to // In order to delete a journal file in OffTheRecord 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_->IsIncognitoProfile()) { if (db_tracker_->IsOffTheRecordProfile()) {
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_->HasSavedIncognitoFileHandle(vfs_file_name) && if (!db_tracker_->HasSavedOffTheRecordFileHandle(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_->CloseIncognitoFileHandle(vfs_file_name); db_tracker_->CloseOffTheRecordFileHandle(vfs_file_name);
error_code = SQLITE_OK; error_code = SQLITE_OK;
} }
} else { } else {
......
...@@ -33,8 +33,8 @@ namespace storage { ...@@ -33,8 +33,8 @@ namespace storage {
const base::FilePath::CharType kDatabaseDirectoryName[] = const base::FilePath::CharType kDatabaseDirectoryName[] =
FILE_PATH_LITERAL("databases"); FILE_PATH_LITERAL("databases");
const base::FilePath::CharType kIncognitoDatabaseDirectoryName[] = const base::FilePath::CharType kOffTheRecordDatabaseDirectoryName[] =
FILE_PATH_LITERAL("databases-incognito"); 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");
static const int kDatabaseTrackerCurrentSchemaVersion = 2; static const int kDatabaseTrackerCurrentSchemaVersion = 2;
...@@ -85,13 +85,13 @@ OriginInfo::OriginInfo(const std::string& origin_identifier, int64_t total_size) ...@@ -85,13 +85,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_incognito, bool is_off_the_record,
SpecialStoragePolicy* special_storage_policy, SpecialStoragePolicy* special_storage_policy,
QuotaManagerProxy* quota_manager_proxy) QuotaManagerProxy* quota_manager_proxy)
: is_incognito_(is_incognito), : is_off_the_record_(is_off_the_record),
profile_path_(profile_path), profile_path_(profile_path),
db_dir_(is_incognito_ db_dir_(is_off_the_record_
? profile_path_.Append(kIncognitoDatabaseDirectoryName) ? profile_path_.Append(kOffTheRecordDatabaseDirectoryName)
: 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),
...@@ -257,7 +257,7 @@ void DatabaseTracker::CloseTrackerDatabaseAndClearCaches() { ...@@ -257,7 +257,7 @@ void DatabaseTracker::CloseTrackerDatabaseAndClearCaches() {
DCHECK(task_runner_->RunsTasksInCurrentSequence()); DCHECK(task_runner_->RunsTasksInCurrentSequence());
ClearAllCachedOriginInfo(); ClearAllCachedOriginInfo();
if (!is_incognito_) { if (!is_off_the_record_) {
meta_table_.reset(nullptr); meta_table_.reset(nullptr);
databases_table_.reset(nullptr); databases_table_.reset(nullptr);
db_->Close(); db_->Close();
...@@ -271,16 +271,16 @@ base::FilePath DatabaseTracker::GetOriginDirectory( ...@@ -271,16 +271,16 @@ base::FilePath DatabaseTracker::GetOriginDirectory(
base::string16 origin_directory; base::string16 origin_directory;
if (!is_incognito_) { if (!is_off_the_record_) {
origin_directory = base::UTF8ToUTF16(origin_identifier); origin_directory = base::UTF8ToUTF16(origin_identifier);
} else { } else {
auto it = incognito_origin_directories_.find(origin_identifier); auto it = off_the_record_origin_directories_.find(origin_identifier);
if (it != incognito_origin_directories_.end()) { if (it != off_the_record_origin_directories_.end()) {
origin_directory = it->second; origin_directory = it->second;
} else { } else {
origin_directory = origin_directory = base::NumberToString16(
base::NumberToString16(incognito_origin_directories_generator_++); off_the_record_origin_directories_generator_++);
incognito_origin_directories_[origin_identifier] = origin_directory; off_the_record_origin_directories_[origin_identifier] = origin_directory;
} }
} }
...@@ -425,18 +425,18 @@ bool DatabaseTracker::DeleteOrigin(const std::string& origin_identifier, ...@@ -425,18 +425,18 @@ bool DatabaseTracker::DeleteOrigin(const std::string& origin_identifier,
base::DeleteFileRecursively(origin_dir); base::DeleteFileRecursively(origin_dir);
base::DeleteFileRecursively(new_origin_dir); // Might fail on windows. base::DeleteFileRecursively(new_origin_dir); // Might fail on windows.
if (is_incognito_) { if (is_off_the_record_) {
incognito_origin_directories_.erase(origin_identifier); off_the_record_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 = incognito_file_handles_.begin(); for (auto it = off_the_record_file_handles_.begin();
it != incognito_file_handles_.end();) { it != off_the_record_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 = incognito_file_handles_.erase(it); it = off_the_record_file_handles_.erase(it);
} else { } else {
++it; ++it;
} }
...@@ -508,8 +508,8 @@ bool DatabaseTracker::LazyInit() { ...@@ -508,8 +508,8 @@ bool DatabaseTracker::LazyInit() {
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);
...@@ -786,64 +786,64 @@ int DatabaseTracker::DeleteDataForOrigin(const url::Origin& origin, ...@@ -786,64 +786,64 @@ int DatabaseTracker::DeleteDataForOrigin(const url::Origin& origin,
return net::OK; return net::OK;
} }
const base::File* DatabaseTracker::GetIncognitoFile( const base::File* DatabaseTracker::GetOffTheRecordFile(
const base::string16& vfs_file_name) const { const base::string16& vfs_file_name) const {
DCHECK(task_runner_->RunsTasksInCurrentSequence()); DCHECK(task_runner_->RunsTasksInCurrentSequence());
DCHECK(is_incognito_); DCHECK(is_off_the_record_);
auto it = incognito_file_handles_.find(vfs_file_name); auto it = off_the_record_file_handles_.find(vfs_file_name);
if (it != incognito_file_handles_.end()) if (it != off_the_record_file_handles_.end())
return it->second; return it->second;
return nullptr; return nullptr;
} }
const base::File* DatabaseTracker::SaveIncognitoFile( const base::File* DatabaseTracker::SaveOffTheRecordFile(
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_incognito_); DCHECK(is_off_the_record_);
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 = auto rv = off_the_record_file_handles_.insert(
incognito_file_handles_.insert(std::make_pair(vfs_file_name, to_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::CloseIncognitoFileHandle( void DatabaseTracker::CloseOffTheRecordFileHandle(
const base::string16& vfs_file_name) { const base::string16& vfs_file_name) {
DCHECK(task_runner_->RunsTasksInCurrentSequence()); DCHECK(task_runner_->RunsTasksInCurrentSequence());
DCHECK(is_incognito_); DCHECK(is_off_the_record_);
DCHECK(incognito_file_handles_.find(vfs_file_name) != DCHECK(off_the_record_file_handles_.find(vfs_file_name) !=
incognito_file_handles_.end()); off_the_record_file_handles_.end());
auto it = incognito_file_handles_.find(vfs_file_name); auto it = off_the_record_file_handles_.find(vfs_file_name);
if (it != incognito_file_handles_.end()) { if (it != off_the_record_file_handles_.end()) {
delete it->second; delete it->second;
incognito_file_handles_.erase(it); off_the_record_file_handles_.erase(it);
} }
} }
bool DatabaseTracker::HasSavedIncognitoFileHandle( bool DatabaseTracker::HasSavedOffTheRecordFileHandle(
const base::string16& vfs_file_name) const { const base::string16& vfs_file_name) const {
DCHECK(task_runner_->RunsTasksInCurrentSequence()); DCHECK(task_runner_->RunsTasksInCurrentSequence());
return (incognito_file_handles_.find(vfs_file_name) != return (off_the_record_file_handles_.find(vfs_file_name) !=
incognito_file_handles_.end()); off_the_record_file_handles_.end());
} }
void DatabaseTracker::DeleteIncognitoDBDirectory() { void DatabaseTracker::DeleteOffTheRecordDBDirectory() {
DCHECK(task_runner_->RunsTasksInCurrentSequence()); DCHECK(task_runner_->RunsTasksInCurrentSequence());
is_initialized_ = false; is_initialized_ = false;
for (auto& pair : incognito_file_handles_) for (auto& pair : off_the_record_file_handles_)
delete pair.second; delete pair.second;
base::FilePath incognito_db_dir = base::FilePath off_the_record_db_dir =
profile_path_.Append(kIncognitoDatabaseDirectoryName); profile_path_.Append(kOffTheRecordDatabaseDirectoryName);
if (base::DirectoryExists(incognito_db_dir)) if (base::DirectoryExists(off_the_record_db_dir))
base::DeleteFileRecursively(incognito_db_dir); base::DeleteFileRecursively(off_the_record_db_dir);
} }
void DatabaseTracker::ClearSessionOnlyOrigins() { void DatabaseTracker::ClearSessionOnlyOrigins() {
...@@ -891,8 +891,8 @@ void DatabaseTracker::Shutdown() { ...@@ -891,8 +891,8 @@ void DatabaseTracker::Shutdown() {
return; return;
} }
shutting_down_ = true; shutting_down_ = true;
if (is_incognito_) if (is_off_the_record_)
DeleteIncognitoDBDirectory(); DeleteOffTheRecordDBDirectory();
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_incognito, bool is_off_the_record,
SpecialStoragePolicy* special_storage_policy, SpecialStoragePolicy* special_storage_policy,
QuotaManagerProxy* quota_manager_proxy); QuotaManagerProxy* quota_manager_proxy);
...@@ -164,16 +164,18 @@ class COMPONENT_EXPORT(STORAGE_BROWSER) DatabaseTracker ...@@ -164,16 +164,18 @@ 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 IsIncognitoProfile() const { return is_incognito_; } bool IsOffTheRecordProfile() const { return is_off_the_record_; }
const base::File* GetIncognitoFile(const base::string16& vfs_file_path) const; const base::File* GetOffTheRecordFile(
const base::File* SaveIncognitoFile(const base::string16& vfs_file_path, const base::string16& vfs_file_path) const;
base::File file); const base::File* SaveOffTheRecordFile(const base::string16& vfs_file_path,
void CloseIncognitoFileHandle(const base::string16& vfs_file_path); base::File file);
bool HasSavedIncognitoFileHandle(const base::string16& vfs_file_path) const; void CloseOffTheRecordFileHandle(const base::string16& vfs_file_path);
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 incognito profile. // used for an OffTheRecord 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();
...@@ -217,8 +219,9 @@ class COMPONENT_EXPORT(STORAGE_BROWSER) DatabaseTracker ...@@ -217,8 +219,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 incognito mode, if it exists. // Deletes the directory that stores all DBs in OffTheRecord mode, if it
void DeleteIncognitoDBDirectory(); // exists.
void DeleteOffTheRecordDBDirectory();
// Deletes session-only databases. Blocks databases from being created/opened. // Deletes session-only databases. Blocks databases from being created/opened.
void ClearSessionOnlyOrigins(); void ClearSessionOnlyOrigins();
...@@ -276,7 +279,7 @@ class COMPONENT_EXPORT(STORAGE_BROWSER) DatabaseTracker ...@@ -276,7 +279,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_incognito_; const bool is_off_the_record_;
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_;
...@@ -309,19 +312,20 @@ class COMPONENT_EXPORT(STORAGE_BROWSER) DatabaseTracker ...@@ -309,19 +312,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 incognito mode, store a DELETE_ON_CLOSE handle to each // When in OffTheRecord mode, store a DELETE_ON_CLOSE handle to each
// main DB and journal file that was accessed. When the incognito profile // main DB and journal file that was accessed. When the OffTheRecord 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*> incognito_file_handles_; std::map<base::string16, base::File*> off_the_record_file_handles_;
// In a non-incognito profile, all DBs in an origin are stored in a directory // In a non-OffTheRecord profile, all DBs in an origin are stored in a
// named after the origin. In an incognito profile though, we do not want the // directory named after the origin. In an OffTheRecord profile though, we do
// directory structure to reveal the origins visited by the user (in case the // not want the directory structure to reveal the origins visited by the user
// browser process crashes and those directories are not deleted). So we use // (in case the browser process crashes and those directories are not
// this map to assign directory names that do not reveal this information. // deleted). So we use this map to assign directory names that do not reveal
std::map<std::string, base::string16> incognito_origin_directories_; // this information.
int incognito_origin_directories_generator_ = 0; std::map<std::string, base::string16> off_the_record_origin_directories_;
int off_the_record_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