summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authormarja@chromium.org <marja@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2012-04-17 09:30:14 +0000
committermarja@chromium.org <marja@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2012-04-17 09:30:14 +0000
commite3ba9b981fc250741a2d5c4d7f0561309184a0f0 (patch)
treef1e3f6b948f768904157dcb3dd25ea4d684f0d7c
parent29f090682db790799d64915f89c5cf03bcb35b0f (diff)
downloadchromium_src-e3ba9b981fc250741a2d5c4d7f0561309184a0f0.zip
chromium_src-e3ba9b981fc250741a2d5c4d7f0561309184a0f0.tar.gz
chromium_src-e3ba9b981fc250741a2d5c4d7f0561309184a0f0.tar.bz2
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
-rw-r--r--content/browser/dom_storage/dom_storage_context_impl.cc9
-rw-r--r--webkit/dom_storage/dom_storage_context.cc23
-rw-r--r--webkit/dom_storage/dom_storage_context.h27
-rw-r--r--webkit/dom_storage/dom_storage_context_unittest.cc9
-rw-r--r--webkit/tools/test_shell/simple_dom_storage_system.cc2
5 files changed, 48 insertions, 22 deletions
diff --git a/content/browser/dom_storage/dom_storage_context_impl.cc b/content/browser/dom_storage/dom_storage_context_impl.cc
index 8eb0b39..683e105 100644
--- a/content/browser/dom_storage/dom_storage_context_impl.cc
+++ b/content/browser/dom_storage/dom_storage_context_impl.cc
@@ -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) {
diff --git a/webkit/dom_storage/dom_storage_context.cc b/webkit/dom_storage/dom_storage_context.cc
index 78363d4..e310190 100644
--- a/webkit/dom_storage/dom_storage_context.cc
+++ b/webkit/dom_storage/dom_storage_context.cc
@@ -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(
diff --git a/webkit/dom_storage/dom_storage_context.h b/webkit/dom_storage/dom_storage_context.h
index 1370913..3bcc6ca 100644
--- a/webkit/dom_storage/dom_storage_context.h
+++ b/webkit/dom_storage/dom_storage_context.h
@@ -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_;
diff --git a/webkit/dom_storage/dom_storage_context_unittest.cc b/webkit/dom_storage/dom_storage_context_unittest.cc
index d83dbde..da6a2ad 100644
--- a/webkit/dom_storage/dom_storage_context_unittest.cc
+++ b/webkit/dom_storage/dom_storage_context_unittest.cc
@@ -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
-
diff --git a/webkit/tools/test_shell/simple_dom_storage_system.cc b/webkit/tools/test_shell/simple_dom_storage_system.cc
index ef2322a..f9bd9bb 100644
--- a/webkit/tools/test_shell/simple_dom_storage_system.cc
+++ b/webkit/tools/test_shell/simple_dom_storage_system.cc
@@ -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;