summaryrefslogtreecommitdiffstats
path: root/webkit/dom_storage
diff options
context:
space:
mode:
authormarja@chromium.org <marja@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2012-06-20 14:46:26 +0000
committermarja@chromium.org <marja@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2012-06-20 14:46:26 +0000
commit2b7b8932211f5d037598df42e19aceab3b002a94 (patch)
treef4de3395c07b9c623b3e4b4ee2e26147c3c1acc6 /webkit/dom_storage
parentd49062d07fcd2c2dddb02da7b3c503d813c1736a (diff)
downloadchromium_src-2b7b8932211f5d037598df42e19aceab3b002a94.zip
chromium_src-2b7b8932211f5d037598df42e19aceab3b002a94.tar.gz
chromium_src-2b7b8932211f5d037598df42e19aceab3b002a94.tar.bz2
DomStorageArea -> DomStorageDatabase indirection; add *StorageDatabaseAdapter.
(Dom|Local|Session)StorageDatabaseAdapter add an extra layer which unifies handling the backends for localStorage and sessionStorage. This will be useful when backing sessionStorage on disk. BUG=104292 TEST=Updated DomStorageAreaTest.* Review URL: https://chromiumcodereview.appspot.com/10556009 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@143173 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'webkit/dom_storage')
-rw-r--r--webkit/dom_storage/dom_storage_area.cc12
-rw-r--r--webkit/dom_storage/dom_storage_area.h5
-rw-r--r--webkit/dom_storage/dom_storage_area_unittest.cc43
-rw-r--r--webkit/dom_storage/dom_storage_context.cc1
-rw-r--r--webkit/dom_storage/dom_storage_database.h1
-rw-r--r--webkit/dom_storage/dom_storage_database_adapter.h29
-rw-r--r--webkit/dom_storage/local_storage_database_adapter.cc42
-rw-r--r--webkit/dom_storage/local_storage_database_adapter.h47
-rw-r--r--webkit/dom_storage/session_storage_database_adapter.cc32
-rw-r--r--webkit/dom_storage/session_storage_database_adapter.h36
-rw-r--r--webkit/dom_storage/webkit_dom_storage.gypi7
11 files changed, 233 insertions, 22 deletions
diff --git a/webkit/dom_storage/dom_storage_area.cc b/webkit/dom_storage/dom_storage_area.cc
index bdef874..a532194 100644
--- a/webkit/dom_storage/dom_storage_area.cc
+++ b/webkit/dom_storage/dom_storage_area.cc
@@ -5,7 +5,6 @@
#include "webkit/dom_storage/dom_storage_area.h"
#include "base/bind.h"
-#include "base/file_util.h"
#include "base/location.h"
#include "base/logging.h"
#include "base/time.h"
@@ -15,6 +14,7 @@
#include "webkit/dom_storage/dom_storage_namespace.h"
#include "webkit/dom_storage/dom_storage_task_runner.h"
#include "webkit/dom_storage/dom_storage_types.h"
+#include "webkit/dom_storage/local_storage_database_adapter.h"
#include "webkit/fileapi/file_system_util.h"
#include "webkit/glue/webkit_glue.h"
@@ -63,7 +63,7 @@ DomStorageArea::DomStorageArea(const GURL& origin, const FilePath& directory,
commit_batches_in_flight_(0) {
if (!directory.empty()) {
FilePath path = directory.Append(DatabaseFileNameFromOrigin(origin_));
- backing_.reset(new DomStorageDatabase(path));
+ backing_.reset(new LocalStorageDatabaseAdapter(path));
is_initial_import_done_ = false;
}
}
@@ -197,10 +197,8 @@ void DomStorageArea::DeleteOrigin() {
map_ = new DomStorageMap(kPerAreaQuota + kPerAreaOverQuotaAllowance);
if (backing_.get()) {
is_initial_import_done_ = false;
- backing_.reset(new DomStorageDatabase(backing_->file_path()));
- file_util::Delete(backing_->file_path(), false);
- file_util::Delete(
- DomStorageDatabase::GetJournalFilePath(backing_->file_path()), false);
+ backing_->Reset();
+ backing_->DeleteFiles();
}
}
@@ -217,7 +215,7 @@ void DomStorageArea::PurgeMemory() {
// Recreate the database object, this frees up the open sqlite connection
// and its page cache.
- backing_.reset(new DomStorageDatabase(backing_->file_path()));
+ backing_->Reset();
}
void DomStorageArea::Shutdown() {
diff --git a/webkit/dom_storage/dom_storage_area.h b/webkit/dom_storage/dom_storage_area.h
index 8b5a6c3..d0b09a7 100644
--- a/webkit/dom_storage/dom_storage_area.h
+++ b/webkit/dom_storage/dom_storage_area.h
@@ -9,14 +9,15 @@
#include "base/file_path.h"
#include "base/gtest_prod_util.h"
#include "base/memory/ref_counted.h"
+#include "base/memory/scoped_ptr.h"
#include "base/nullable_string16.h"
#include "base/string16.h"
#include "googleurl/src/gurl.h"
-#include "webkit/dom_storage/dom_storage_database.h"
#include "webkit/dom_storage/dom_storage_types.h"
namespace dom_storage {
+class DomStorageDatabaseAdapter;
class DomStorageMap;
class DomStorageTaskRunner;
@@ -118,7 +119,7 @@ class DomStorageArea
FilePath directory_;
scoped_refptr<DomStorageTaskRunner> task_runner_;
scoped_refptr<DomStorageMap> map_;
- scoped_ptr<DomStorageDatabase> backing_;
+ scoped_ptr<DomStorageDatabaseAdapter> backing_;
bool is_initial_import_done_;
bool is_shutdown_;
scoped_ptr<CommitBatch> commit_batch_;
diff --git a/webkit/dom_storage/dom_storage_area_unittest.cc b/webkit/dom_storage/dom_storage_area_unittest.cc
index 6494d8d..e41b080 100644
--- a/webkit/dom_storage/dom_storage_area_unittest.cc
+++ b/webkit/dom_storage/dom_storage_area_unittest.cc
@@ -12,8 +12,11 @@
#include "base/utf_string_conversions.h"
#include "testing/gtest/include/gtest/gtest.h"
#include "webkit/dom_storage/dom_storage_area.h"
+#include "webkit/dom_storage/dom_storage_database.h"
+#include "webkit/dom_storage/dom_storage_database_adapter.h"
#include "webkit/dom_storage/dom_storage_task_runner.h"
#include "webkit/dom_storage/dom_storage_types.h"
+#include "webkit/dom_storage/local_storage_database_adapter.h"
namespace dom_storage {
@@ -161,14 +164,16 @@ TEST_F(DomStorageAreaTest, BackingDatabaseOpened) {
new MockDomStorageTaskRunner(base::MessageLoopProxy::current())));
EXPECT_TRUE(area->backing_.get());
- EXPECT_FALSE(area->backing_->IsOpen());
+ DomStorageDatabase* database = static_cast<LocalStorageDatabaseAdapter*>(
+ area->backing_.get())->db_.get();
+ EXPECT_FALSE(database->IsOpen());
EXPECT_FALSE(area->is_initial_import_done_);
// Inject an in-memory db to speed up the test.
// We will verify that something is written into the database but not
// that a file is written to disk - DOMStorageDatabase unit tests cover
// that.
- area->backing_.reset(new DomStorageDatabase());
+ area->backing_.reset(new LocalStorageDatabaseAdapter());
// Need to write something to ensure that the database is created.
NullableString16 old_value;
@@ -182,7 +187,9 @@ TEST_F(DomStorageAreaTest, BackingDatabaseOpened) {
EXPECT_FALSE(area->commit_batch_.get());
EXPECT_EQ(0, area->commit_batches_in_flight_);
- EXPECT_TRUE(area->backing_->IsOpen());
+ database = static_cast<LocalStorageDatabaseAdapter*>(
+ area->backing_.get())->db_.get();
+ EXPECT_TRUE(database->IsOpen());
EXPECT_EQ(1u, area->Length());
EXPECT_EQ(kValue, area->GetItem(kKey).string());
@@ -203,7 +210,7 @@ TEST_F(DomStorageAreaTest, CommitTasks) {
temp_dir.path(),
new MockDomStorageTaskRunner(base::MessageLoopProxy::current())));
// Inject an in-memory db to speed up the test.
- area->backing_.reset(new DomStorageDatabase());
+ area->backing_.reset(new LocalStorageDatabaseAdapter());
// Unrelated to commits, but while we're here, see that querying Length()
// causes the backing database to be opened and presumably read from.
@@ -282,7 +289,8 @@ TEST_F(DomStorageAreaTest, CommitChangesAtShutdown) {
// Inject an in-memory db to speed up the test and also to verify
// the final changes are commited in it's dtor.
- area->backing_.reset(new VerifyChangesCommittedDatabase());
+ static_cast<LocalStorageDatabaseAdapter*>(area->backing_.get())->db_.reset(
+ new VerifyChangesCommittedDatabase());
ValuesMap values;
NullableString16 old_value;
@@ -307,7 +315,8 @@ TEST_F(DomStorageAreaTest, DeleteOrigin) {
new MockDomStorageTaskRunner(base::MessageLoopProxy::current())));
// This test puts files on disk.
- FilePath db_file_path = area->backing_->file_path();
+ FilePath db_file_path = static_cast<LocalStorageDatabaseAdapter*>(
+ area->backing_.get())->db_->file_path();
FilePath db_journal_file_path =
DomStorageDatabase::GetJournalFilePath(db_file_path);
@@ -367,17 +376,21 @@ TEST_F(DomStorageAreaTest, PurgeMemory) {
new MockDomStorageTaskRunner(base::MessageLoopProxy::current())));
// Inject an in-memory db to speed up the test.
- area->backing_.reset(new DomStorageDatabase());
+ area->backing_.reset(new LocalStorageDatabaseAdapter());
// Unowned ptrs we use to verify that 'purge' has happened.
- DomStorageDatabase* original_backing = area->backing_.get();
+ DomStorageDatabase* original_backing =
+ static_cast<LocalStorageDatabaseAdapter*>(
+ area->backing_.get())->db_.get();
DomStorageMap* original_map = area->map_.get();
// Should do no harm when called on a newly constructed object.
EXPECT_FALSE(area->is_initial_import_done_);
area->PurgeMemory();
EXPECT_FALSE(area->is_initial_import_done_);
- EXPECT_EQ(original_backing, area->backing_.get());
+ DomStorageDatabase* new_backing = static_cast<LocalStorageDatabaseAdapter*>(
+ area->backing_.get())->db_.get();
+ EXPECT_EQ(original_backing, new_backing);
EXPECT_EQ(original_map, area->map_.get());
// Should not do anything when commits are pending.
@@ -388,20 +401,26 @@ TEST_F(DomStorageAreaTest, PurgeMemory) {
area->PurgeMemory();
EXPECT_TRUE(area->is_initial_import_done_);
EXPECT_TRUE(area->HasUncommittedChanges());
- EXPECT_EQ(original_backing, area->backing_.get());
+ new_backing = static_cast<LocalStorageDatabaseAdapter*>(
+ area->backing_.get())->db_.get();
+ EXPECT_EQ(original_backing, new_backing);
EXPECT_EQ(original_map, area->map_.get());
// Commit the changes from above,
MessageLoop::current()->RunAllPending();
EXPECT_FALSE(area->HasUncommittedChanges());
- EXPECT_EQ(original_backing, area->backing_.get());
+ new_backing = static_cast<LocalStorageDatabaseAdapter*>(
+ area->backing_.get())->db_.get();
+ EXPECT_EQ(original_backing, new_backing);
EXPECT_EQ(original_map, area->map_.get());
// Should drop caches and reset database connections
// when invoked on an area that's loaded up primed.
area->PurgeMemory();
EXPECT_FALSE(area->is_initial_import_done_);
- EXPECT_NE(original_backing, area->backing_.get());
+ new_backing = static_cast<LocalStorageDatabaseAdapter*>(
+ area->backing_.get())->db_.get();
+ EXPECT_NE(original_backing, new_backing);
EXPECT_NE(original_map, area->map_.get());
}
diff --git a/webkit/dom_storage/dom_storage_context.cc b/webkit/dom_storage/dom_storage_context.cc
index b8a8234..8d8c4e6 100644
--- a/webkit/dom_storage/dom_storage_context.cc
+++ b/webkit/dom_storage/dom_storage_context.cc
@@ -11,6 +11,7 @@
#include "base/location.h"
#include "base/time.h"
#include "webkit/dom_storage/dom_storage_area.h"
+#include "webkit/dom_storage/dom_storage_database.h"
#include "webkit/dom_storage/dom_storage_namespace.h"
#include "webkit/dom_storage/dom_storage_task_runner.h"
#include "webkit/dom_storage/dom_storage_types.h"
diff --git a/webkit/dom_storage/dom_storage_database.h b/webkit/dom_storage/dom_storage_database.h
index 5d0d9ed..60fe5c8 100644
--- a/webkit/dom_storage/dom_storage_database.h
+++ b/webkit/dom_storage/dom_storage_database.h
@@ -48,6 +48,7 @@ class DomStorageDatabase {
DomStorageDatabase();
private:
+ friend class LocalStorageDatabaseAdapter;
FRIEND_TEST_ALL_PREFIXES(DomStorageDatabaseTest, SimpleOpenAndClose);
FRIEND_TEST_ALL_PREFIXES(DomStorageDatabaseTest, TestLazyOpenIsLazy);
FRIEND_TEST_ALL_PREFIXES(DomStorageDatabaseTest, TestDetectSchemaVersion);
diff --git a/webkit/dom_storage/dom_storage_database_adapter.h b/webkit/dom_storage/dom_storage_database_adapter.h
new file mode 100644
index 0000000..30cd1ff
--- /dev/null
+++ b/webkit/dom_storage/dom_storage_database_adapter.h
@@ -0,0 +1,29 @@
+// Copyright (c) 2012 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#ifndef WEBKIT_DOM_STORAGE_DOM_STORAGE_DATABASE_ADAPTER_H_
+#define WEBKIT_DOM_STORAGE_DOM_STORAGE_DATABASE_ADAPTER_H_
+#pragma once
+
+// Database interface used by DomStorageArea. Abstracts the differences between
+// the per-origin DomStorageDatabases for localStorage and
+// SessionStorageDatabase which stores multiple origins.
+
+#include "webkit/dom_storage/dom_storage_types.h"
+
+namespace dom_storage {
+
+class DomStorageDatabaseAdapter {
+ public:
+ virtual ~DomStorageDatabaseAdapter() {}
+ virtual void ReadAllValues(ValuesMap* result) = 0;
+ virtual bool CommitChanges(
+ bool clear_all_first, const ValuesMap& changes) = 0;
+ virtual void DeleteFiles() {}
+ virtual void Reset() {}
+};
+
+} // namespace dom_storage
+
+#endif // WEBKIT_DOM_STORAGE_DOM_STORAGE_DATABASE_ADAPTER_H_
diff --git a/webkit/dom_storage/local_storage_database_adapter.cc b/webkit/dom_storage/local_storage_database_adapter.cc
new file mode 100644
index 0000000..6e715d7
--- /dev/null
+++ b/webkit/dom_storage/local_storage_database_adapter.cc
@@ -0,0 +1,42 @@
+// Copyright (c) 2012 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#include "webkit/dom_storage/local_storage_database_adapter.h"
+
+#include "base/file_util.h"
+#include "webkit/dom_storage/dom_storage_database.h"
+
+namespace dom_storage {
+
+LocalStorageDatabaseAdapter::LocalStorageDatabaseAdapter(
+ const FilePath& path)
+ : db_(new DomStorageDatabase(path)) {
+}
+
+LocalStorageDatabaseAdapter::~LocalStorageDatabaseAdapter() { }
+
+void LocalStorageDatabaseAdapter::ReadAllValues(ValuesMap* result) {
+ db_->ReadAllValues(result);
+}
+
+bool LocalStorageDatabaseAdapter::CommitChanges(
+ bool clear_all_first, const ValuesMap& changes) {
+ return db_->CommitChanges(clear_all_first, changes);
+}
+
+void LocalStorageDatabaseAdapter::DeleteFiles() {
+ file_util::Delete(db_->file_path(), false);
+ file_util::Delete(
+ DomStorageDatabase::GetJournalFilePath(db_->file_path()), false);
+}
+
+void LocalStorageDatabaseAdapter::Reset() {
+ db_.reset(new DomStorageDatabase(db_->file_path()));
+}
+
+LocalStorageDatabaseAdapter::LocalStorageDatabaseAdapter()
+ : db_(new DomStorageDatabase()) {
+}
+
+} // namespace dom_storage
diff --git a/webkit/dom_storage/local_storage_database_adapter.h b/webkit/dom_storage/local_storage_database_adapter.h
new file mode 100644
index 0000000..52ed314
--- /dev/null
+++ b/webkit/dom_storage/local_storage_database_adapter.h
@@ -0,0 +1,47 @@
+// Copyright (c) 2012 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#ifndef WEBKIT_DOM_STORAGE_LOCAL_STORAGE_DATABASE_ADAPTER_H_
+#define WEBKIT_DOM_STORAGE_LOCAL_STORAGE_DATABASE_ADAPTER_H_
+#pragma once
+
+#include "base/gtest_prod_util.h"
+#include "base/memory/scoped_ptr.h"
+#include "webkit/dom_storage/dom_storage_database_adapter.h"
+
+class FilePath;
+
+namespace dom_storage {
+
+class DomStorageDatabase;
+
+class LocalStorageDatabaseAdapter : public DomStorageDatabaseAdapter {
+ public:
+ explicit LocalStorageDatabaseAdapter(const FilePath& path);
+ virtual ~LocalStorageDatabaseAdapter();
+ virtual void ReadAllValues(ValuesMap* result) OVERRIDE;
+ virtual bool CommitChanges(bool clear_all_first,
+ const ValuesMap& changes) OVERRIDE;
+ virtual void DeleteFiles() OVERRIDE;
+ virtual void Reset() OVERRIDE;
+
+ protected:
+ // Constructor that uses an in-memory sqlite database, for testing.
+ LocalStorageDatabaseAdapter();
+
+ private:
+ FRIEND_TEST_ALL_PREFIXES(DomStorageAreaTest, BackingDatabaseOpened);
+ FRIEND_TEST_ALL_PREFIXES(DomStorageAreaTest, CommitChangesAtShutdown);
+ FRIEND_TEST_ALL_PREFIXES(DomStorageAreaTest, CommitTasks);
+ FRIEND_TEST_ALL_PREFIXES(DomStorageAreaTest, DeleteOrigin);
+ FRIEND_TEST_ALL_PREFIXES(DomStorageAreaTest, PurgeMemory);
+
+ scoped_ptr<DomStorageDatabase> db_;
+
+ DISALLOW_COPY_AND_ASSIGN(LocalStorageDatabaseAdapter);
+};
+
+} // namespace dom_storage
+
+#endif // WEBKIT_DOM_STORAGE_LOCAL_STORAGE_DATABASE_ADAPTER_H_
diff --git a/webkit/dom_storage/session_storage_database_adapter.cc b/webkit/dom_storage/session_storage_database_adapter.cc
new file mode 100644
index 0000000..fb38fd2
--- /dev/null
+++ b/webkit/dom_storage/session_storage_database_adapter.cc
@@ -0,0 +1,32 @@
+// Copyright (c) 2012 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#include "webkit/dom_storage/session_storage_database_adapter.h"
+
+#include "webkit/dom_storage/session_storage_database.h"
+
+namespace dom_storage {
+
+SessionStorageDatabaseAdapter::SessionStorageDatabaseAdapter(
+ SessionStorageDatabase* db,
+ const std::string& permanent_namespace_id,
+ const GURL& origin)
+ : db_(db),
+ permanent_namespace_id_(permanent_namespace_id),
+ origin_(origin) {
+}
+
+SessionStorageDatabaseAdapter::~SessionStorageDatabaseAdapter() { }
+
+void SessionStorageDatabaseAdapter::ReadAllValues(ValuesMap* result) {
+ db_->ReadAreaValues(permanent_namespace_id_, origin_, result);
+}
+
+bool SessionStorageDatabaseAdapter::CommitChanges(
+ bool clear_all_first, const ValuesMap& changes) {
+ return db_->CommitAreaChanges(permanent_namespace_id_, origin_,
+ clear_all_first, changes);
+}
+
+} // namespace dom_storage
diff --git a/webkit/dom_storage/session_storage_database_adapter.h b/webkit/dom_storage/session_storage_database_adapter.h
new file mode 100644
index 0000000..106b3bf
--- /dev/null
+++ b/webkit/dom_storage/session_storage_database_adapter.h
@@ -0,0 +1,36 @@
+// Copyright (c) 2012 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#ifndef WEBKIT_DOM_STORAGE_SESSION_STORAGE_DATABASE_ADAPTER_H_
+#define WEBKIT_DOM_STORAGE_SESSION_STORAGE_DATABASE_ADAPTER_H_
+#pragma once
+
+#include "base/memory/ref_counted.h"
+#include "googleurl/src/gurl.h"
+#include "webkit/dom_storage/dom_storage_database_adapter.h"
+
+namespace dom_storage {
+
+class SessionStorageDatabase;
+
+class SessionStorageDatabaseAdapter : public DomStorageDatabaseAdapter {
+ public:
+ SessionStorageDatabaseAdapter(SessionStorageDatabase* db,
+ const std::string& permanent_namespace_id,
+ const GURL& origin);
+ virtual ~SessionStorageDatabaseAdapter();
+ virtual void ReadAllValues(ValuesMap* result) OVERRIDE;
+ virtual bool CommitChanges(bool clear_all_first,
+ const ValuesMap& changes) OVERRIDE;
+ private:
+ scoped_refptr<SessionStorageDatabase> db_;
+ std::string permanent_namespace_id_;
+ GURL origin_;
+
+ DISALLOW_COPY_AND_ASSIGN(SessionStorageDatabaseAdapter);
+};
+
+} // namespace dom_storage
+
+#endif // WEBKIT_DOM_STORAGE_SESSION_STORAGE_DATABASE_ADAPTER_H_
diff --git a/webkit/dom_storage/webkit_dom_storage.gypi b/webkit/dom_storage/webkit_dom_storage.gypi
index 525617d..22ec711 100644
--- a/webkit/dom_storage/webkit_dom_storage.gypi
+++ b/webkit/dom_storage/webkit_dom_storage.gypi
@@ -24,6 +24,7 @@
'dom_storage_context.h',
'dom_storage_database.cc',
'dom_storage_database.h',
+ 'dom_storage_database_adapter.h',
'dom_storage_host.cc',
'dom_storage_host.h',
'dom_storage_map.cc',
@@ -36,8 +37,12 @@
'dom_storage_task_runner.cc',
'dom_storage_task_runner.h',
'dom_storage_types.h',
+ 'local_storage_database_adapter.cc',
+ 'local_storage_database_adapter.h',
'session_storage_database.cc',
- 'session_storage_database.h'
+ 'session_storage_database.h',
+ 'session_storage_database_adapter.cc',
+ 'session_storage_database_adapter.h',
],
'conditions': [
['inside_chromium_build==0', {