Commit 9e0c115f authored by marja@chromium.org's avatar marja@chromium.org

Session-only appcache.


BUG=47049
TEST=ChromeAppCacheServiceTest.*


Review URL: http://codereview.chromium.org/7741040

git-svn-id: svn://svn.chromium.org/chrome/trunk/src@98804 0039d316-1c4b-4281-b951-d872f2087c98
parent 4c6107e4
...@@ -24,6 +24,7 @@ const FilePath::CharType kTestingAppCacheDirname[] = ...@@ -24,6 +24,7 @@ const FilePath::CharType kTestingAppCacheDirname[] =
// test. // test.
const char kProtectedManifest[] = "http://www.protected.com/cache.manifest"; const char kProtectedManifest[] = "http://www.protected.com/cache.manifest";
const char kNormalManifest[] = "http://www.normal.com/cache.manifest"; const char kNormalManifest[] = "http://www.normal.com/cache.manifest";
const char kSessionOnlyManifest[] = "http://www.sessiononly.com/cache.manifest";
} // namespace } // namespace
...@@ -35,6 +36,7 @@ class ChromeAppCacheServiceTest : public testing::Test { ...@@ -35,6 +36,7 @@ class ChromeAppCacheServiceTest : public testing::Test {
: message_loop_(MessageLoop::TYPE_IO), : message_loop_(MessageLoop::TYPE_IO),
kProtectedManifestURL(kProtectedManifest), kProtectedManifestURL(kProtectedManifest),
kNormalManifestURL(kNormalManifest), kNormalManifestURL(kNormalManifest),
kSessionOnlyManifestURL(kSessionOnlyManifest),
db_thread_(BrowserThread::DB, &message_loop_), db_thread_(BrowserThread::DB, &message_loop_),
file_thread_(BrowserThread::FILE, &message_loop_), file_thread_(BrowserThread::FILE, &message_loop_),
cache_thread_(BrowserThread::CACHE, &message_loop_), cache_thread_(BrowserThread::CACHE, &message_loop_),
...@@ -51,6 +53,7 @@ class ChromeAppCacheServiceTest : public testing::Test { ...@@ -51,6 +53,7 @@ class ChromeAppCacheServiceTest : public testing::Test {
ScopedTempDir temp_dir_; ScopedTempDir temp_dir_;
const GURL kProtectedManifestURL; const GURL kProtectedManifestURL;
const GURL kNormalManifestURL; const GURL kNormalManifestURL;
const GURL kSessionOnlyManifestURL;
private: private:
BrowserThread db_thread_; BrowserThread db_thread_;
...@@ -69,6 +72,7 @@ ChromeAppCacheServiceTest::CreateAppCacheService( ...@@ -69,6 +72,7 @@ ChromeAppCacheServiceTest::CreateAppCacheService(
scoped_refptr<quota::MockSpecialStoragePolicy> mock_policy = scoped_refptr<quota::MockSpecialStoragePolicy> mock_policy =
new quota::MockSpecialStoragePolicy; new quota::MockSpecialStoragePolicy;
mock_policy->AddProtected(kProtectedManifestURL.GetOrigin()); mock_policy->AddProtected(kProtectedManifestURL.GetOrigin());
mock_policy->AddSessionOnly(kSessionOnlyManifestURL.GetOrigin());
BrowserThread::PostTask( BrowserThread::PostTask(
BrowserThread::IO, FROM_HERE, BrowserThread::IO, FROM_HERE,
NewRunnableMethod(appcache_service.get(), NewRunnableMethod(appcache_service.get(),
...@@ -94,13 +98,16 @@ void ChromeAppCacheServiceTest::InsertDataIntoAppCache( ...@@ -94,13 +98,16 @@ void ChromeAppCacheServiceTest::InsertDataIntoAppCache(
AppCacheTestHelper appcache_helper; AppCacheTestHelper appcache_helper;
appcache_helper.AddGroupAndCache(appcache_service, kNormalManifestURL); appcache_helper.AddGroupAndCache(appcache_service, kNormalManifestURL);
appcache_helper.AddGroupAndCache(appcache_service, kProtectedManifestURL); appcache_helper.AddGroupAndCache(appcache_service, kProtectedManifestURL);
appcache_helper.AddGroupAndCache(appcache_service, kSessionOnlyManifestURL);
// Verify that adding the data succeeded // Verify that adding the data succeeded
std::set<GURL> origins; std::set<GURL> origins;
appcache_helper.GetOriginsWithCaches(appcache_service, &origins); appcache_helper.GetOriginsWithCaches(appcache_service, &origins);
ASSERT_EQ(2UL, origins.size()); ASSERT_EQ(3UL, origins.size());
ASSERT_TRUE(origins.find(kProtectedManifestURL.GetOrigin()) != origins.end()); ASSERT_TRUE(origins.find(kProtectedManifestURL.GetOrigin()) != origins.end());
ASSERT_TRUE(origins.find(kNormalManifestURL.GetOrigin()) != origins.end()); ASSERT_TRUE(origins.find(kNormalManifestURL.GetOrigin()) != origins.end());
ASSERT_TRUE(origins.find(kSessionOnlyManifestURL.GetOrigin()) !=
origins.end());
} }
TEST_F(ChromeAppCacheServiceTest, KeepOnDestruction) { TEST_F(ChromeAppCacheServiceTest, KeepOnDestruction) {
...@@ -125,13 +132,15 @@ TEST_F(ChromeAppCacheServiceTest, KeepOnDestruction) { ...@@ -125,13 +132,15 @@ TEST_F(ChromeAppCacheServiceTest, KeepOnDestruction) {
// The directory is still there // The directory is still there
ASSERT_TRUE(file_util::PathExists(appcache_path)); ASSERT_TRUE(file_util::PathExists(appcache_path));
// The appcache data is also there // The appcache data is also there, except the session-only origin.
AppCacheTestHelper appcache_helper; AppCacheTestHelper appcache_helper;
std::set<GURL> origins; std::set<GURL> origins;
appcache_helper.GetOriginsWithCaches(appcache_service, &origins); appcache_helper.GetOriginsWithCaches(appcache_service, &origins);
EXPECT_EQ(2UL, origins.size()); EXPECT_EQ(2UL, origins.size());
EXPECT_TRUE(origins.find(kProtectedManifestURL.GetOrigin()) != origins.end()); EXPECT_TRUE(origins.find(kProtectedManifestURL.GetOrigin()) != origins.end());
EXPECT_TRUE(origins.find(kNormalManifestURL.GetOrigin()) != origins.end()); EXPECT_TRUE(origins.find(kNormalManifestURL.GetOrigin()) != origins.end());
EXPECT_TRUE(origins.find(kSessionOnlyManifestURL.GetOrigin()) ==
origins.end());
// Delete and let cleanup tasks run prior to returning. // Delete and let cleanup tasks run prior to returning.
appcache_service = NULL; appcache_service = NULL;
...@@ -168,6 +177,8 @@ TEST_F(ChromeAppCacheServiceTest, RemoveOnDestruction) { ...@@ -168,6 +177,8 @@ TEST_F(ChromeAppCacheServiceTest, RemoveOnDestruction) {
EXPECT_EQ(1UL, origins.size()); EXPECT_EQ(1UL, origins.size());
EXPECT_TRUE(origins.find(kProtectedManifestURL.GetOrigin()) != origins.end()); EXPECT_TRUE(origins.find(kProtectedManifestURL.GetOrigin()) != origins.end());
EXPECT_TRUE(origins.find(kNormalManifestURL.GetOrigin()) == origins.end()); EXPECT_TRUE(origins.find(kNormalManifestURL.GetOrigin()) == origins.end());
EXPECT_TRUE(origins.find(kSessionOnlyManifestURL.GetOrigin()) ==
origins.end());
// Delete and let cleanup tasks run prior to returning. // Delete and let cleanup tasks run prior to returning.
appcache_service = NULL; appcache_service = NULL;
......
...@@ -68,9 +68,17 @@ bool DeleteGroupAndRelatedRecords(AppCacheDatabase* database, ...@@ -68,9 +68,17 @@ bool DeleteGroupAndRelatedRecords(AppCacheDatabase* database,
return success; return success;
} }
void ClearOnExit( // Deletes all appcache data (if clear_all_data is true), or session-only
// appcache data. Also, schedules the database to be destroyed.
void CleanUpOnDatabaseThread(
AppCacheDatabase* database, AppCacheDatabase* database,
scoped_refptr<quota::SpecialStoragePolicy> special_storage_policy) { scoped_refptr<quota::SpecialStoragePolicy> special_storage_policy,
bool clear_all_appcaches) {
scoped_ptr<AppCacheDatabase> database_to_delete(database);
if (!clear_all_appcaches && !special_storage_policy)
return;
std::set<GURL> origins; std::set<GURL> origins;
database->FindOriginsWithGroups(&origins); database->FindOriginsWithGroups(&origins);
if (origins.empty()) if (origins.empty())
...@@ -84,6 +92,9 @@ void ClearOnExit( ...@@ -84,6 +92,9 @@ void ClearOnExit(
std::set<GURL>::const_iterator origin; std::set<GURL>::const_iterator origin;
for (origin = origins.begin(); origin != origins.end(); ++origin) { for (origin = origins.begin(); origin != origins.end(); ++origin) {
if (!clear_all_appcaches &&
!special_storage_policy->IsStorageSessionOnly(*origin))
continue;
if (special_storage_policy && if (special_storage_policy &&
special_storage_policy->IsStorageProtected(*origin)) special_storage_policy->IsStorageProtected(*origin))
continue; continue;
...@@ -1148,16 +1159,14 @@ AppCacheStorageImpl::~AppCacheStorageImpl() { ...@@ -1148,16 +1159,14 @@ AppCacheStorageImpl::~AppCacheStorageImpl() {
std::mem_fun(&DatabaseTask::CancelCompletion)); std::mem_fun(&DatabaseTask::CancelCompletion));
if (database_) { if (database_) {
if (service()->clear_local_state_on_exit()) { AppCacheThread::PostTask(
AppCacheThread::PostTask( AppCacheThread::db(),
AppCacheThread::db(), FROM_HERE,
FROM_HERE, NewRunnableFunction(
NewRunnableFunction( CleanUpOnDatabaseThread,
ClearOnExit, database_,
database_, make_scoped_refptr(service_->special_storage_policy()),
make_scoped_refptr(service_->special_storage_policy()))); service()->clear_local_state_on_exit()));
}
AppCacheThread::DeleteSoon(AppCacheThread::db(), FROM_HERE, database_);
} }
} }
......
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