Commit e3ba9b98 authored by marja@chromium.org's avatar marja@chromium.org

DomStorageContext: separate directories for localStorage and sessionStorage.

This is needed to eventually store sessionStorage on disk.

BUG=104292
TEST=NONE


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

git-svn-id: svn://svn.chromium.org/chrome/trunk/src@132555 0039d316-1c4b-4281-b951-d872f2087c98
parent 29f09068
......@@ -65,7 +65,8 @@ void GetAllStorageFilesHelper(
std::vector<FilePath> paths;
for (size_t i = 0; i < infos.size(); ++i) {
paths.push_back(
OriginToFullFilePath(context->directory(), infos[i].origin));
OriginToFullFilePath(context->localstorage_directory(),
infos[i].origin));
}
reply_loop->PostTask(
......@@ -80,9 +81,12 @@ DOMStorageContextImpl::DOMStorageContextImpl(
const FilePath& data_path,
quota::SpecialStoragePolicy* special_storage_policy) {
base::SequencedWorkerPool* worker_pool = BrowserThread::GetBlockingPool();
// TODO(marja): Pass a nonempty session storage directory when session storage
// is backed on disk.
context_ = new dom_storage::DomStorageContext(
data_path.empty() ?
data_path : data_path.AppendASCII(kLocalStorageDirectory),
FilePath(), // Empty session storage directory.
special_storage_policy,
new DomStorageWorkerPoolTaskRunner(
worker_pool,
......@@ -107,7 +111,8 @@ void DOMStorageContextImpl::GetAllStorageFiles(
FilePath DOMStorageContextImpl::GetFilePath(const string16& origin_id) const {
DCHECK(context_);
return OriginToFullFilePath(context_->directory(), OriginIdToGURL(origin_id));
return OriginToFullFilePath(context_->localstorage_directory(),
OriginIdToGURL(origin_id));
}
void DOMStorageContextImpl::DeleteForOrigin(const string16& origin_id) {
......
......@@ -23,10 +23,12 @@ DomStorageContext::UsageInfo::UsageInfo() : data_size(0) {}
DomStorageContext::UsageInfo::~UsageInfo() {}
DomStorageContext::DomStorageContext(
const FilePath& directory,
const FilePath& localstorage_directory,
const FilePath& sessionstorage_directory,
quota::SpecialStoragePolicy* special_storage_policy,
DomStorageTaskRunner* task_runner)
: directory_(directory),
: localstorage_directory_(localstorage_directory),
sessionstorage_directory_(sessionstorage_directory),
task_runner_(task_runner),
is_shutdown_(false),
clear_local_state_(false),
......@@ -48,15 +50,15 @@ DomStorageNamespace* DomStorageContext::GetStorageNamespace(
StorageNamespaceMap::iterator found = namespaces_.find(namespace_id);
if (found == namespaces_.end()) {
if (namespace_id == kLocalStorageNamespaceId) {
if (!directory_.empty()) {
if (!file_util::CreateDirectory(directory_)) {
if (!localstorage_directory_.empty()) {
if (!file_util::CreateDirectory(localstorage_directory_)) {
LOG(ERROR) << "Failed to create 'Local Storage' directory,"
" falling back to in-memory only.";
directory_ = FilePath();
localstorage_directory_ = FilePath();
}
}
DomStorageNamespace* local =
new DomStorageNamespace(directory_, task_runner_);
new DomStorageNamespace(localstorage_directory_, task_runner_);
namespaces_[kLocalStorageNamespaceId] = local;
return local;
}
......@@ -67,9 +69,10 @@ DomStorageNamespace* DomStorageContext::GetStorageNamespace(
void DomStorageContext::GetUsageInfo(std::vector<UsageInfo>* infos,
bool include_file_info) {
if (directory_.empty())
if (localstorage_directory_.empty())
return;
FileEnumerator enumerator(directory_, false, FileEnumerator::FILES);
FileEnumerator enumerator(localstorage_directory_, false,
FileEnumerator::FILES);
for (FilePath path = enumerator.Next(); !path.empty();
path = enumerator.Next()) {
if (path.MatchesExtension(DomStorageArea::kDatabaseFileExtension)) {
......@@ -121,7 +124,7 @@ void DomStorageContext::Shutdown() {
for (; it != namespaces_.end(); ++it)
it->second->Shutdown();
if (directory_.empty())
if (localstorage_directory_.empty())
return;
// Respect the content policy settings about what to
......@@ -225,7 +228,7 @@ void DomStorageContext::ClearLocalStateInCommitSequence() {
continue;
const bool kNotRecursive = false;
FilePath database_file_path = directory_.Append(
FilePath database_file_path = localstorage_directory_.Append(
DomStorageArea::DatabaseFileNameFromOrigin(origin));
file_util::Delete(database_file_path, kNotRecursive);
file_util::Delete(
......
......@@ -88,10 +88,22 @@ class DomStorageContext
virtual ~EventObserver() {}
};
DomStorageContext(const FilePath& directory, // empty for incognito profiles
quota::SpecialStoragePolicy* special_storage_policy,
DomStorageTaskRunner* task_runner);
const FilePath& directory() const { return directory_; }
DomStorageContext(
const FilePath& localstorage_directory, // empty for incognito profiles
const FilePath& sessionstorage_directory, // empty for incognito profiles
quota::SpecialStoragePolicy* special_storage_policy,
DomStorageTaskRunner* task_runner);
// Returns the directory path for localStorage, or an empty directory, if
// there is no backing on disk.
const FilePath& localstorage_directory() { return localstorage_directory_; }
// Returns the directory path for sessionStorage, or an empty directory, if
// there is no backing on disk.
const FilePath& sessionstorage_directory() {
return sessionstorage_directory_;
}
DomStorageTaskRunner* task_runner() const { return task_runner_; }
DomStorageNamespace* GetStorageNamespace(int64 namespace_id);
......@@ -161,7 +173,12 @@ class DomStorageContext
StorageNamespaceMap namespaces_;
// Where localstorage data is stored, maybe empty for the incognito use case.
FilePath directory_;
FilePath localstorage_directory_;
// Where sessionstorage data is stored, maybe empty for the incognito use
// case. Always empty until the file-backed session storage feature is
// implemented.
FilePath sessionstorage_directory_;
// Used to schedule sequenced background tasks.
scoped_refptr<DomStorageTaskRunner> task_runner_;
......
......@@ -42,6 +42,7 @@ class DomStorageContextTest : public testing::Test {
task_runner_ = new MockDomStorageTaskRunner(
base::MessageLoopProxy::current());
context_ = new DomStorageContext(temp_dir_.path(),
FilePath(),
storage_policy_,
task_runner_);
}
......@@ -53,7 +54,7 @@ class DomStorageContextTest : public testing::Test {
void VerifySingleOriginRemains(const GURL& origin) {
// Use a new instance to examine the contexts of temp_dir_.
scoped_refptr<DomStorageContext> context =
new DomStorageContext(temp_dir_.path(), NULL, NULL);
new DomStorageContext(temp_dir_.path(), FilePath(), NULL, NULL);
std::vector<DomStorageContext::UsageInfo> infos;
context->GetUsageInfo(&infos, kDontIncludeFileInfo);
EXPECT_EQ(1u, infos.size());
......@@ -72,7 +73,8 @@ TEST_F(DomStorageContextTest, Basics) {
// This test doesn't do much, checks that the constructor
// initializes members properly and that invoking methods
// on a newly created object w/o any data on disk do no harm.
EXPECT_EQ(temp_dir_.path(), context_->directory());
EXPECT_EQ(temp_dir_.path(), context_->localstorage_directory());
EXPECT_EQ(FilePath(), context_->sessionstorage_directory());
EXPECT_EQ(storage_policy_.get(), context_->special_storage_policy_.get());
context_->PurgeMemory();
context_->DeleteOrigin(GURL("http://chromium.org/"));
......@@ -106,7 +108,7 @@ TEST_F(DomStorageContextTest, UsageInfo) {
// Create a new context that points to the same directory, see that
// it knows about the origin that we stored data for.
context_ = new DomStorageContext(temp_dir_.path(), NULL, NULL);
context_ = new DomStorageContext(temp_dir_.path(), FilePath(), NULL, NULL);
context_->GetUsageInfo(&infos, kDontIncludeFileInfo);
EXPECT_EQ(1u, infos.size());
EXPECT_EQ(kOrigin, infos[0].origin);
......@@ -178,4 +180,3 @@ TEST_F(DomStorageContextTest, SaveSessionState) {
}
} // namespace dom_storage
......@@ -192,7 +192,7 @@ SimpleDomStorageSystem* SimpleDomStorageSystem::g_instance_;
SimpleDomStorageSystem::SimpleDomStorageSystem()
: weak_factory_(this),
context_(new DomStorageContext(FilePath(), NULL, NULL)),
context_(new DomStorageContext(FilePath(), FilePath(), NULL, NULL)),
host_(new DomStorageHost(context_)) {
DCHECK(!g_instance_);
g_instance_ = this;
......
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