Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(584)

Unified Diff: content/browser/dom_storage/dom_storage_area.cc

Issue 22297005: Move webkit/{browser,common}/dom_storage into content/ (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 7 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: content/browser/dom_storage/dom_storage_area.cc
diff --git a/webkit/browser/dom_storage/dom_storage_area.cc b/content/browser/dom_storage/dom_storage_area.cc
similarity index 76%
rename from webkit/browser/dom_storage/dom_storage_area.cc
rename to content/browser/dom_storage/dom_storage_area.cc
index d0e2ac3efd28625352467c12dce3b5bd5304211b..cdf3ad2b854ccb088f419d85f087f5823f171ea3 100644
--- a/webkit/browser/dom_storage/dom_storage_area.cc
+++ b/content/browser/dom_storage/dom_storage_area.cc
@@ -2,7 +2,7 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
-#include "webkit/browser/dom_storage/dom_storage_area.h"
+#include "content/browser/dom_storage/dom_storage_area.h"
#include "base/bind.h"
#include "base/location.h"
@@ -10,35 +10,35 @@
#include "base/metrics/histogram.h"
#include "base/strings/utf_string_conversions.h"
#include "base/time/time.h"
+#include "content/browser/dom_storage/dom_storage_namespace.h"
+#include "content/browser/dom_storage/dom_storage_task_runner.h"
+#include "content/browser/dom_storage/local_storage_database_adapter.h"
+#include "content/browser/dom_storage/session_storage_database.h"
+#include "content/browser/dom_storage/session_storage_database_adapter.h"
+#include "content/common/dom_storage/dom_storage_map.h"
+#include "content/common/dom_storage/dom_storage_types.h"
#include "webkit/browser/database/database_util.h"
-#include "webkit/browser/dom_storage/dom_storage_namespace.h"
-#include "webkit/browser/dom_storage/dom_storage_task_runner.h"
-#include "webkit/browser/dom_storage/local_storage_database_adapter.h"
-#include "webkit/browser/dom_storage/session_storage_database.h"
-#include "webkit/browser/dom_storage/session_storage_database_adapter.h"
#include "webkit/common/database/database_identifier.h"
-#include "webkit/common/dom_storage/dom_storage_map.h"
-#include "webkit/common/dom_storage/dom_storage_types.h"
#include "webkit/common/fileapi/file_system_util.h"
using webkit_database::DatabaseUtil;
-namespace dom_storage {
+namespace content {
static const int kCommitTimerSeconds = 1;
-DomStorageArea::CommitBatch::CommitBatch()
+DOMStorageArea::CommitBatch::CommitBatch()
: clear_all_first(false) {
}
-DomStorageArea::CommitBatch::~CommitBatch() {}
+DOMStorageArea::CommitBatch::~CommitBatch() {}
// static
-const base::FilePath::CharType DomStorageArea::kDatabaseFileExtension[] =
+const base::FilePath::CharType DOMStorageArea::kDatabaseFileExtension[] =
FILE_PATH_LITERAL(".localstorage");
// static
-base::FilePath DomStorageArea::DatabaseFileNameFromOrigin(const GURL& origin) {
+base::FilePath DOMStorageArea::DatabaseFileNameFromOrigin(const GURL& origin) {
std::string filename = webkit_database::GetIdentifierFromOrigin(origin);
// There is no base::FilePath.AppendExtension() method, so start with just the
// extension as the filename, and then InsertBeforeExtension the desired
@@ -48,19 +48,21 @@ base::FilePath DomStorageArea::DatabaseFileNameFromOrigin(const GURL& origin) {
}
// static
-GURL DomStorageArea::OriginFromDatabaseFileName(const base::FilePath& name) {
+GURL DOMStorageArea::OriginFromDatabaseFileName(const base::FilePath& name) {
DCHECK(name.MatchesExtension(kDatabaseFileExtension));
std::string origin_id =
name.BaseName().RemoveExtension().MaybeAsASCII();
return webkit_database::GetOriginFromIdentifier(origin_id);
}
-DomStorageArea::DomStorageArea(const GURL& origin, const base::FilePath& directory,
- DomStorageTaskRunner* task_runner)
+DOMStorageArea::DOMStorageArea(
+ const GURL& origin, const base::FilePath& directory,
+ DOMStorageTaskRunner* task_runner)
: namespace_id_(kLocalStorageNamespaceId), origin_(origin),
directory_(directory),
task_runner_(task_runner),
- map_(new DomStorageMap(kPerAreaQuota + kPerAreaOverQuotaAllowance)),
+ map_(new DOMStorageMap(kPerStorageAreaQuota +
+ kPerStorageAreaOverQuotaAllowance)),
is_initial_import_done_(true),
is_shutdown_(false),
commit_batches_in_flight_(0) {
@@ -71,17 +73,18 @@ DomStorageArea::DomStorageArea(const GURL& origin, const base::FilePath& directo
}
}
-DomStorageArea::DomStorageArea(
+DOMStorageArea::DOMStorageArea(
int64 namespace_id,
const std::string& persistent_namespace_id,
const GURL& origin,
SessionStorageDatabase* session_storage_backing,
- DomStorageTaskRunner* task_runner)
+ DOMStorageTaskRunner* task_runner)
: namespace_id_(namespace_id),
persistent_namespace_id_(persistent_namespace_id),
origin_(origin),
task_runner_(task_runner),
- map_(new DomStorageMap(kPerAreaQuota + kPerAreaOverQuotaAllowance)),
+ map_(new DOMStorageMap(kPerStorageAreaQuota +
+ kPerStorageAreaOverQuotaAllowance)),
session_storage_backing_(session_storage_backing),
is_initial_import_done_(true),
is_shutdown_(false),
@@ -94,38 +97,38 @@ DomStorageArea::DomStorageArea(
}
}
-DomStorageArea::~DomStorageArea() {
+DOMStorageArea::~DOMStorageArea() {
}
-void DomStorageArea::ExtractValues(ValuesMap* map) {
+void DOMStorageArea::ExtractValues(DOMStorageValuesMap* map) {
if (is_shutdown_)
return;
InitialImportIfNeeded();
map_->ExtractValues(map);
}
-unsigned DomStorageArea::Length() {
+unsigned DOMStorageArea::Length() {
if (is_shutdown_)
return 0;
InitialImportIfNeeded();
return map_->Length();
}
-base::NullableString16 DomStorageArea::Key(unsigned index) {
+base::NullableString16 DOMStorageArea::Key(unsigned index) {
if (is_shutdown_)
return base::NullableString16();
InitialImportIfNeeded();
return map_->Key(index);
}
-base::NullableString16 DomStorageArea::GetItem(const base::string16& key) {
+base::NullableString16 DOMStorageArea::GetItem(const base::string16& key) {
if (is_shutdown_)
return base::NullableString16();
InitialImportIfNeeded();
return map_->GetItem(key);
}
-bool DomStorageArea::SetItem(const base::string16& key,
+bool DOMStorageArea::SetItem(const base::string16& key,
const base::string16& value,
base::NullableString16* old_value) {
if (is_shutdown_)
@@ -141,7 +144,7 @@ bool DomStorageArea::SetItem(const base::string16& key,
return success;
}
-bool DomStorageArea::RemoveItem(const base::string16& key,
+bool DOMStorageArea::RemoveItem(const base::string16& key,
base::string16* old_value) {
if (is_shutdown_)
return false;
@@ -156,14 +159,15 @@ bool DomStorageArea::RemoveItem(const base::string16& key,
return success;
}
-bool DomStorageArea::Clear() {
+bool DOMStorageArea::Clear() {
if (is_shutdown_)
return false;
InitialImportIfNeeded();
if (map_->Length() == 0)
return false;
- map_ = new DomStorageMap(kPerAreaQuota + kPerAreaOverQuotaAllowance);
+ map_ = new DOMStorageMap(kPerStorageAreaQuota +
+ kPerStorageAreaOverQuotaAllowance);
if (backing_) {
CommitBatch* commit_batch = CreateCommitBatchIfNeeded();
@@ -174,14 +178,15 @@ bool DomStorageArea::Clear() {
return true;
}
-void DomStorageArea::FastClear() {
+void DOMStorageArea::FastClear() {
// TODO(marja): Unify clearing localStorage and sessionStorage. The problem is
// to make the following 3 to work together: 1) FastClear, 2) PurgeMemory and
// 3) not creating events when clearing an empty area.
if (is_shutdown_)
return;
- map_ = new DomStorageMap(kPerAreaQuota + kPerAreaOverQuotaAllowance);
+ map_ = new DOMStorageMap(kPerStorageAreaQuota +
+ kPerStorageAreaOverQuotaAllowance);
// This ensures no import will happen while we're waiting to clear the data
// from the database. This mechanism fails if PurgeMemory is called.
is_initial_import_done_ = true;
@@ -193,13 +198,13 @@ void DomStorageArea::FastClear() {
}
}
-DomStorageArea* DomStorageArea::ShallowCopy(
+DOMStorageArea* DOMStorageArea::ShallowCopy(
int64 destination_namespace_id,
const std::string& destination_persistent_namespace_id) {
DCHECK_NE(kLocalStorageNamespaceId, namespace_id_);
DCHECK_NE(kLocalStorageNamespaceId, destination_namespace_id);
- DomStorageArea* copy = new DomStorageArea(
+ DOMStorageArea* copy = new DOMStorageArea(
destination_namespace_id, destination_persistent_namespace_id, origin_,
session_storage_backing_.get(), task_runner_.get());
copy->map_ = map_;
@@ -215,12 +220,12 @@ DomStorageArea* DomStorageArea::ShallowCopy(
return copy;
}
-bool DomStorageArea::HasUncommittedChanges() const {
+bool DOMStorageArea::HasUncommittedChanges() const {
DCHECK(!is_shutdown_);
return commit_batch_.get() || commit_batches_in_flight_;
}
-void DomStorageArea::DeleteOrigin() {
+void DOMStorageArea::DeleteOrigin() {
DCHECK(!is_shutdown_);
// This function shouldn't be called for sessionStorage.
DCHECK(!session_storage_backing_.get());
@@ -233,7 +238,8 @@ void DomStorageArea::DeleteOrigin() {
Clear();
return;
}
- map_ = new DomStorageMap(kPerAreaQuota + kPerAreaOverQuotaAllowance);
+ map_ = new DOMStorageMap(kPerStorageAreaQuota +
+ kPerStorageAreaOverQuotaAllowance);
if (backing_) {
is_initial_import_done_ = false;
backing_->Reset();
@@ -241,7 +247,7 @@ void DomStorageArea::DeleteOrigin() {
}
}
-void DomStorageArea::PurgeMemory() {
+void DOMStorageArea::PurgeMemory() {
DCHECK(!is_shutdown_);
// Purging sessionStorage is not supported; it won't work with FastClear.
DCHECK(!session_storage_backing_.get());
@@ -252,14 +258,15 @@ void DomStorageArea::PurgeMemory() {
// Drop the in memory cache, we'll reload when needed.
is_initial_import_done_ = false;
- map_ = new DomStorageMap(kPerAreaQuota + kPerAreaOverQuotaAllowance);
+ map_ = new DOMStorageMap(kPerStorageAreaQuota +
+ kPerStorageAreaOverQuotaAllowance);
// Recreate the database object, this frees up the open sqlite connection
// and its page cache.
backing_->Reset();
}
-void DomStorageArea::Shutdown() {
+void DOMStorageArea::Shutdown() {
DCHECK(!is_shutdown_);
is_shutdown_ = true;
map_ = NULL;
@@ -268,19 +275,19 @@ void DomStorageArea::Shutdown() {
bool success = task_runner_->PostShutdownBlockingTask(
FROM_HERE,
- DomStorageTaskRunner::COMMIT_SEQUENCE,
- base::Bind(&DomStorageArea::ShutdownInCommitSequence, this));
+ DOMStorageTaskRunner::COMMIT_SEQUENCE,
+ base::Bind(&DOMStorageArea::ShutdownInCommitSequence, this));
DCHECK(success);
}
-void DomStorageArea::InitialImportIfNeeded() {
+void DOMStorageArea::InitialImportIfNeeded() {
if (is_initial_import_done_)
return;
DCHECK(backing_.get());
base::TimeTicks before = base::TimeTicks::Now();
- ValuesMap initial_values;
+ DOMStorageValuesMap initial_values;
backing_->ReadAllValues(&initial_values);
map_->SwapValues(&initial_values);
is_initial_import_done_ = true;
@@ -310,7 +317,7 @@ void DomStorageArea::InitialImportIfNeeded() {
}
}
-DomStorageArea::CommitBatch* DomStorageArea::CreateCommitBatchIfNeeded() {
+DOMStorageArea::CommitBatch* DOMStorageArea::CreateCommitBatchIfNeeded() {
DCHECK(!is_shutdown_);
if (!commit_batch_) {
commit_batch_.reset(new CommitBatch());
@@ -321,14 +328,14 @@ DomStorageArea::CommitBatch* DomStorageArea::CreateCommitBatchIfNeeded() {
if (!commit_batches_in_flight_) {
task_runner_->PostDelayedTask(
FROM_HERE,
- base::Bind(&DomStorageArea::OnCommitTimer, this),
+ base::Bind(&DOMStorageArea::OnCommitTimer, this),
base::TimeDelta::FromSeconds(kCommitTimerSeconds));
}
}
return commit_batch_.get();
}
-void DomStorageArea::OnCommitTimer() {
+void DOMStorageArea::OnCommitTimer() {
if (is_shutdown_)
return;
@@ -344,14 +351,14 @@ void DomStorageArea::OnCommitTimer() {
DCHECK(task_runner_->IsRunningOnPrimarySequence());
bool success = task_runner_->PostShutdownBlockingTask(
FROM_HERE,
- DomStorageTaskRunner::COMMIT_SEQUENCE,
- base::Bind(&DomStorageArea::CommitChanges, this,
+ DOMStorageTaskRunner::COMMIT_SEQUENCE,
+ base::Bind(&DOMStorageArea::CommitChanges, this,
base::Owned(commit_batch_.release())));
++commit_batches_in_flight_;
DCHECK(success);
}
-void DomStorageArea::CommitChanges(const CommitBatch* commit_batch) {
+void DOMStorageArea::CommitChanges(const CommitBatch* commit_batch) {
// This method executes on the commit sequence.
DCHECK(task_runner_->IsRunningOnCommitSequence());
bool success = backing_->CommitChanges(commit_batch->clear_all_first,
@@ -359,10 +366,10 @@ void DomStorageArea::CommitChanges(const CommitBatch* commit_batch) {
DCHECK(success); // TODO(michaeln): what if it fails?
task_runner_->PostTask(
FROM_HERE,
- base::Bind(&DomStorageArea::OnCommitComplete, this));
+ base::Bind(&DOMStorageArea::OnCommitComplete, this));
}
-void DomStorageArea::OnCommitComplete() {
+void DOMStorageArea::OnCommitComplete() {
// We're back on the primary sequence in this method.
DCHECK(task_runner_->IsRunningOnPrimarySequence());
--commit_batches_in_flight_;
@@ -372,12 +379,12 @@ void DomStorageArea::OnCommitComplete() {
// More changes have accrued, restart the timer.
task_runner_->PostDelayedTask(
FROM_HERE,
- base::Bind(&DomStorageArea::OnCommitTimer, this),
+ base::Bind(&DOMStorageArea::OnCommitTimer, this),
base::TimeDelta::FromSeconds(kCommitTimerSeconds));
}
}
-void DomStorageArea::ShutdownInCommitSequence() {
+void DOMStorageArea::ShutdownInCommitSequence() {
// This method executes on the commit sequence.
DCHECK(task_runner_->IsRunningOnCommitSequence());
DCHECK(backing_.get());
@@ -393,4 +400,4 @@ void DomStorageArea::ShutdownInCommitSequence() {
session_storage_backing_ = NULL;
}
-} // namespace dom_storage
+} // namespace content
« no previous file with comments | « content/browser/dom_storage/dom_storage_area.h ('k') | content/browser/dom_storage/dom_storage_area_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698