diff options
author | michaeln@google.com <michaeln@google.com@0039d316-1c4b-4281-b951-d872f2087c98> | 2010-04-01 22:02:22 +0000 |
---|---|---|
committer | michaeln@google.com <michaeln@google.com@0039d316-1c4b-4281-b951-d872f2087c98> | 2010-04-01 22:02:22 +0000 |
commit | 5b855a6b9d61b10f8635cce0e187a1c162b5b428 (patch) | |
tree | dcfdba8cb7dd8d6b1fd5496b5743fa059811017b /webkit/database | |
parent | b03cb1e38d95c04a69902c9d4d471f79d806066e (diff) | |
download | chromium_src-5b855a6b9d61b10f8635cce0e187a1c162b5b428.zip chromium_src-5b855a6b9d61b10f8635cce0e187a1c162b5b428.tar.gz chromium_src-5b855a6b9d61b10f8635cce0e187a1c162b5b428.tar.bz2 |
Revert 43381 - Add some safeguards in DatabaseTracker to prevent writing anything to disk for incognito.
TEST=manual and database_tracker_unittest.cc
BUG=none
Review URL: http://codereview.chromium.org/1597003
TBR=michaeln@chromium.org
Review URL: http://codereview.chromium.org/1581007
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@43390 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'webkit/database')
-rw-r--r-- | webkit/database/database_tracker.cc | 33 | ||||
-rw-r--r-- | webkit/database/database_tracker.h | 13 | ||||
-rw-r--r-- | webkit/database/database_tracker_unittest.cc | 8 |
3 files changed, 16 insertions, 38 deletions
diff --git a/webkit/database/database_tracker.cc b/webkit/database/database_tracker.cc index 2f374a2..38c6298 100644 --- a/webkit/database/database_tracker.cc +++ b/webkit/database/database_tracker.cc @@ -24,13 +24,12 @@ const FilePath::CharType kDatabaseDirectoryName[] = FILE_PATH_LITERAL("databases"); const FilePath::CharType kTrackerDatabaseFileName[] = FILE_PATH_LITERAL("Databases.db"); -static const int kCurrentVersion = 2; -static const int kCompatibleVersion = 1; -static const char* kExtensionOriginIdentifierPrefix = "chrome-extension_"; +const int kCurrentVersion = 2; +const int kCompatibleVersion = 1; +const char* kExtensionOriginIdentifierPrefix = "chrome-extension_"; DatabaseTracker::DatabaseTracker(const FilePath& profile_path) - : is_initialized_(false), - is_incognito_(profile_path.empty()), + : initialized_(false), db_dir_(profile_path.Append(FilePath(kDatabaseDirectoryName))), db_(new sql::Connection()), databases_table_(NULL), @@ -83,20 +82,12 @@ void DatabaseTracker::DatabaseModified(const string16& origin_identifier, void DatabaseTracker::DatabaseClosed(const string16& origin_identifier, const string16& database_name) { - if (database_connections_.IsEmpty()) { - DCHECK(!is_initialized_); - return; - } database_connections_.RemoveConnection(origin_identifier, database_name); if (!database_connections_.IsDatabaseOpened(origin_identifier, database_name)) DeleteDatabaseIfNeeded(origin_identifier, database_name); } void DatabaseTracker::CloseDatabases(const DatabaseConnections& connections) { - if (database_connections_.IsEmpty()) { - DCHECK(!is_initialized_); - return; - } std::vector<std::pair<string16, string16> > closed_dbs; database_connections_.RemoveConnections(connections, &closed_dbs); for (std::vector<std::pair<string16, string16> >::iterator it = @@ -157,16 +148,14 @@ void DatabaseTracker::CloseTrackerDatabaseAndClearCaches() { databases_table_.reset(NULL); quota_table_.reset(NULL); db_->Close(); - is_initialized_ = false; + initialized_ = false; } FilePath DatabaseTracker::GetFullDBFilePath( const string16& origin_identifier, - const string16& database_name) { + const string16& database_name) const { DCHECK(!origin_identifier.empty()); DCHECK(!database_name.empty()); - if (!LazyInit()) - return FilePath(); int64 id = databases_table_->GetDatabaseID( origin_identifier, database_name); @@ -284,7 +273,7 @@ bool DatabaseTracker::IsDatabaseScheduledForDeletion( } bool DatabaseTracker::LazyInit() { - if (!is_initialized_ && !is_incognito_) { + if (!initialized_) { DCHECK(!db_->is_open()); DCHECK(!databases_table_.get()); DCHECK(!quota_table_.get()); @@ -307,18 +296,18 @@ bool DatabaseTracker::LazyInit() { quota_table_.reset(new QuotaTable(db_.get())); meta_table_.reset(new sql::MetaTable()); - is_initialized_ = + initialized_ = file_util::CreateDirectory(db_dir_) && (db_->is_open() || db_->Open(kTrackerDatabaseFullPath)) && UpgradeToCurrentVersion(); - if (!is_initialized_) { + if (!initialized_) { databases_table_.reset(NULL); quota_table_.reset(NULL); meta_table_.reset(NULL); db_->Close(); } } - return is_initialized_; + return initialized_; } bool DatabaseTracker::UpgradeToCurrentVersion() { @@ -399,7 +388,7 @@ DatabaseTracker::CachedOriginInfo* DatabaseTracker::GetCachedOriginInfo( } int64 DatabaseTracker::GetDBFileSize(const string16& origin_identifier, - const string16& database_name) { + const string16& database_name) const { FilePath db_file_name = GetFullDBFilePath(origin_identifier, database_name); int64 db_file_size = 0; if (!file_util::GetFileSize(db_file_name, &db_file_size)) diff --git a/webkit/database/database_tracker.h b/webkit/database/database_tracker.h index 35ceca4..f7468e4 100644 --- a/webkit/database/database_tracker.h +++ b/webkit/database/database_tracker.h @@ -26,9 +26,6 @@ class MetaTable; namespace webkit_database { -extern const FilePath::CharType kDatabaseDirectoryName[]; -extern const FilePath::CharType kTrackerDatabaseFileName[]; - class DatabasesTable; class QuotaTable; @@ -123,7 +120,7 @@ class DatabaseTracker const FilePath& DatabaseDirectory() const { return db_dir_; } FilePath GetFullDBFilePath(const string16& origin_identifier, - const string16& database_name); + const string16& database_name) const; bool GetAllOriginsInfo(std::vector<OriginInfo>* origins_info); void SetOriginQuota(const string16& origin_identifier, int64 new_quota); @@ -203,7 +200,7 @@ class DatabaseTracker CachedOriginInfo* GetCachedOriginInfo(const string16& origin_identifier); int64 GetDBFileSize(const string16& origin_identifier, - const string16& database_name); + const string16& database_name) const; int64 GetOriginSpaceAvailable(const string16& origin_identifier); @@ -216,8 +213,7 @@ class DatabaseTracker void ScheduleDatabasesForDeletion(const DatabaseSet& databases, net::CompletionCallback* callback); - bool is_initialized_; - const bool is_incognito_; + bool initialized_; const FilePath db_dir_; scoped_ptr<sql::Connection> db_; scoped_ptr<DatabasesTable> databases_table_; @@ -238,8 +234,7 @@ class DatabaseTracker // to quota_table_ every time an extention is loaded. std::map<string16, int64> in_memory_quotas_; - FRIEND_TEST(DatabaseTrackerTest, DatabaseTracker); - FRIEND_TEST(DatabaseTrackerTest, NoInitIncognito); + FRIEND_TEST(DatabaseTrackerTest, TestIt); }; } // namespace webkit_database diff --git a/webkit/database/database_tracker_unittest.cc b/webkit/database/database_tracker_unittest.cc index e606c7e..88e8981 100644 --- a/webkit/database/database_tracker_unittest.cc +++ b/webkit/database/database_tracker_unittest.cc @@ -167,7 +167,7 @@ TEST(DatabaseTrackerTest, DeleteOpenDatabase) { tracker->RemoveObserver(&observer); } -TEST(DatabaseTrackerTest, DatabaseTracker) { +TEST(DatabaseTrackerTest, TestIt) { // Initialize the tracker database. ScopedTempDir temp_dir; EXPECT_TRUE(temp_dir.CreateUniqueTempDir()); @@ -361,10 +361,4 @@ TEST(DatabaseTrackerTest, DatabaseTracker) { EXPECT_EQ(origin1_quota, tracker->GetOriginSpaceAvailable(kOrigin1)); } -TEST(DatabaseTrackerTest, NoInitIncognito) { - scoped_refptr<DatabaseTracker> tracker(new DatabaseTracker(FilePath())); - EXPECT_TRUE(tracker->is_incognito_); - EXPECT_FALSE(tracker->LazyInit()); -} - } // namespace webkit_database |