From 654512b4c7e02401af2ce207d678c683841eedb6 Mon Sep 17 00:00:00 2001 From: "andybons@chromium.org" Date: Wed, 1 Sep 2010 02:09:42 +0000 Subject: Protect local storage created by extension apps. BUG=49228 TEST=ExtensionsServiceTest.InstallAppsAndCheckStorageProtection TEST=DatabaseTrackerTest.* Review URL: http://codereview.chromium.org/3256003 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@58108 0039d316-1c4b-4281-b951-d872f2087c98 --- webkit/database/database_tracker.cc | 8 ++++++++ webkit/database/database_tracker.h | 8 +++++--- webkit/database/database_tracker_unittest.cc | 9 ++++++--- 3 files changed, 19 insertions(+), 6 deletions(-) (limited to 'webkit/database') diff --git a/webkit/database/database_tracker.cc b/webkit/database/database_tracker.cc index a37c2a0..8a8a21d 100644 --- a/webkit/database/database_tracker.cc +++ b/webkit/database/database_tracker.cc @@ -4,6 +4,7 @@ #include "webkit/database/database_tracker.h" +#include #include #include "app/sql/connection.h" @@ -520,6 +521,7 @@ int DatabaseTracker::DeleteDatabase(const string16& origin_identifier, int DatabaseTracker::DeleteDataModifiedSince( const base::Time& cutoff, + const std::vector& protected_origins, net::CompletionCallback* callback) { if (!LazyInit()) return net::ERR_FAILED; @@ -536,6 +538,12 @@ int DatabaseTracker::DeleteDataModifiedSince( ori != origins.end(); ++ori) { if (StartsWith(*ori, ASCIIToUTF16(kExtensionOriginIdentifierPrefix), true)) continue; + + std::vector::const_iterator find_iter = + std::find(protected_origins.begin(), protected_origins.end(), *ori); + if (find_iter != protected_origins.end()) + continue; + std::vector details; if (!databases_table_->GetAllDatabaseDetailsForOrigin(*ori, &details)) rv = net::ERR_FAILED; diff --git a/webkit/database/database_tracker.h b/webkit/database/database_tracker.h index e4c8183..4976a91 100644 --- a/webkit/database/database_tracker.h +++ b/webkit/database/database_tracker.h @@ -145,10 +145,12 @@ class DatabaseTracker net::CompletionCallback* callback); // Delete any databases that have been touched since the cutoff date that's - // supplied. Returns net::OK on success, net::FAILED if not all databases - // could be deleted, and net::ERR_IO_PENDING and |callback| is invoked upon - // completion, if non-NULL. + // supplied, omitting any that match IDs within |protected_origins|. + // Returns net::OK on success, net::FAILED if not all databases could be + // deleted, and net::ERR_IO_PENDING and |callback| is invoked upon completion, + // if non-NULL. int DeleteDataModifiedSince(const base::Time& cutoff, + const std::vector& protected_origins, net::CompletionCallback* callback); // Delete all databases that belong to the given origin. Returns net::OK on diff --git a/webkit/database/database_tracker_unittest.cc b/webkit/database/database_tracker_unittest.cc index bc255dd..2afdf5e 100644 --- a/webkit/database/database_tracker_unittest.cc +++ b/webkit/database/database_tracker_unittest.cc @@ -156,10 +156,13 @@ class DatabaseTracker_TestHelper_Test { EXPECT_TRUE(file_util::SetLastModifiedTime( tracker->GetFullDBFilePath(kOrigin2, kDB3), three_days_ago)); - // Delete databases modified since yesterday. + // Delete databases modified since yesterday. db2 is whitelisted. base::Time yesterday = base::Time::Now(); yesterday -= base::TimeDelta::FromDays(1); - result = tracker->DeleteDataModifiedSince(yesterday, &callback); + std::vector protected_origins; + protected_origins.push_back(kOrigin2); + result = tracker->DeleteDataModifiedSince( + yesterday, protected_origins, &callback); EXPECT_EQ(net::ERR_IO_PENDING, result); ASSERT_FALSE(callback.have_result()); EXPECT_TRUE(observer.DidReceiveNewNotification()); @@ -169,7 +172,7 @@ class DatabaseTracker_TestHelper_Test { EXPECT_EQ(net::OK, result); EXPECT_FALSE(file_util::PathExists(tracker->DatabaseDirectory().Append( FilePath::FromWStringHack(UTF16ToWide(kOrigin1))))); - EXPECT_FALSE( + EXPECT_TRUE( file_util::PathExists(tracker->GetFullDBFilePath(kOrigin2, kDB2))); EXPECT_TRUE( file_util::PathExists(tracker->GetFullDBFilePath(kOrigin2, kDB3))); -- cgit v1.1