diff options
author | kinuko@chromium.org <kinuko@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2013-08-07 16:59:41 +0000 |
---|---|---|
committer | kinuko@chromium.org <kinuko@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2013-08-07 16:59:41 +0000 |
commit | 5f2aa727f81adfb0dc9c3e34b0d777e52091c664 (patch) | |
tree | ac857fa2a4251d89ba829c77fff8a629f391d239 /webkit/common | |
parent | 5dff8195c05331bfda451a2b135c8965095637ab (diff) | |
download | chromium_src-5f2aa727f81adfb0dc9c3e34b0d777e52091c664.zip chromium_src-5f2aa727f81adfb0dc9c3e34b0d777e52091c664.tar.gz chromium_src-5f2aa727f81adfb0dc9c3e34b0d777e52091c664.tar.bz2 |
Move webkit/{browser,common}/dom_storage into content/
Mechanical changes only, directory moving +
* renamed all DomStorage* to DOMStorage* for consistency
* renamed DOMStorageContextImpl to DOMStorageContextProxy, and renamed DomStorageContext to DOMStorageContextImpl
* other minor cleanups
Diff for dom_storage_context_impl.* may look a bit messy
due to chained renames (it's just replaced with former
webkit/browser/dom_storage/dom_storage_context.*)
BUG=265769
NOTRY=true
Review URL: https://chromiumcodereview.appspot.com/22297005
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@216211 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'webkit/common')
-rw-r--r-- | webkit/common/dom_storage/OWNERS | 1 | ||||
-rw-r--r-- | webkit/common/dom_storage/dom_storage_map.cc | 122 | ||||
-rw-r--r-- | webkit/common/dom_storage/dom_storage_map.h | 64 | ||||
-rw-r--r-- | webkit/common/dom_storage/dom_storage_map_unittest.cc | 124 | ||||
-rw-r--r-- | webkit/common/dom_storage/dom_storage_types.cc | 16 | ||||
-rw-r--r-- | webkit/common/dom_storage/dom_storage_types.h | 62 |
6 files changed, 0 insertions, 389 deletions
diff --git a/webkit/common/dom_storage/OWNERS b/webkit/common/dom_storage/OWNERS deleted file mode 100644 index 88ceed4..0000000 --- a/webkit/common/dom_storage/OWNERS +++ /dev/null @@ -1 +0,0 @@ -marja@chromium.org diff --git a/webkit/common/dom_storage/dom_storage_map.cc b/webkit/common/dom_storage/dom_storage_map.cc deleted file mode 100644 index 5cc3c5e6..0000000 --- a/webkit/common/dom_storage/dom_storage_map.cc +++ /dev/null @@ -1,122 +0,0 @@ -// 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/common/dom_storage/dom_storage_map.h" - -#include "base/logging.h" - -namespace { - -size_t size_of_item(const base::string16& key, const base::string16& value) { - return (key.length() + value.length()) * sizeof(char16); -} - -size_t CountBytes(const dom_storage::ValuesMap& values) { - if (values.size() == 0) - return 0; - - size_t count = 0; - dom_storage::ValuesMap::const_iterator it = values.begin(); - for (; it != values.end(); ++it) - count += size_of_item(it->first, it->second.string()); - return count; -} - -} // namespace - -namespace dom_storage { - -DomStorageMap::DomStorageMap(size_t quota) - : bytes_used_(0), - quota_(quota) { - ResetKeyIterator(); -} - -DomStorageMap::~DomStorageMap() {} - -unsigned DomStorageMap::Length() const { - return values_.size(); -} - -base::NullableString16 DomStorageMap::Key(unsigned index) { - if (index >= values_.size()) - return base::NullableString16(); - while (last_key_index_ != index) { - if (last_key_index_ > index) { - --key_iterator_; - --last_key_index_; - } else { - ++key_iterator_; - ++last_key_index_; - } - } - return base::NullableString16(key_iterator_->first, false); -} - -base::NullableString16 DomStorageMap::GetItem(const base::string16& key) const { - ValuesMap::const_iterator found = values_.find(key); - if (found == values_.end()) - return base::NullableString16(); - return found->second; -} - -bool DomStorageMap::SetItem( - const base::string16& key, const base::string16& value, - base::NullableString16* old_value) { - ValuesMap::const_iterator found = values_.find(key); - if (found == values_.end()) - *old_value = base::NullableString16(); - else - *old_value = found->second; - - size_t old_item_size = old_value->is_null() ? - 0 : size_of_item(key, old_value->string()); - size_t new_item_size = size_of_item(key, value); - size_t new_bytes_used = bytes_used_ - old_item_size + new_item_size; - - // Only check quota if the size is increasing, this allows - // shrinking changes to pre-existing files that are over budget. - if (new_item_size > old_item_size && new_bytes_used > quota_) - return false; - - values_[key] = base::NullableString16(value, false); - ResetKeyIterator(); - bytes_used_ = new_bytes_used; - return true; -} - -bool DomStorageMap::RemoveItem( - const base::string16& key, - base::string16* old_value) { - ValuesMap::iterator found = values_.find(key); - if (found == values_.end()) - return false; - *old_value = found->second.string(); - values_.erase(found); - ResetKeyIterator(); - bytes_used_ -= size_of_item(key, *old_value); - return true; -} - -void DomStorageMap::SwapValues(ValuesMap* values) { - // Note: A pre-existing file may be over the quota budget. - values_.swap(*values); - bytes_used_ = CountBytes(values_); - ResetKeyIterator(); -} - -DomStorageMap* DomStorageMap::DeepCopy() const { - DomStorageMap* copy = new DomStorageMap(quota_); - copy->values_ = values_; - copy->bytes_used_ = bytes_used_; - copy->ResetKeyIterator(); - return copy; -} - -void DomStorageMap::ResetKeyIterator() { - key_iterator_ = values_.begin(); - last_key_index_ = 0; -} - -} // namespace dom_storage diff --git a/webkit/common/dom_storage/dom_storage_map.h b/webkit/common/dom_storage/dom_storage_map.h deleted file mode 100644 index 69db984..0000000 --- a/webkit/common/dom_storage/dom_storage_map.h +++ /dev/null @@ -1,64 +0,0 @@ -// 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_COMMON_DOM_STORAGE_DOM_STORAGE_MAP_H_ -#define WEBKIT_COMMON_DOM_STORAGE_DOM_STORAGE_MAP_H_ - -#include <map> - -#include "base/memory/ref_counted.h" -#include "base/strings/nullable_string16.h" -#include "base/strings/string16.h" -#include "webkit/common/dom_storage/dom_storage_types.h" -#include "webkit/common/webkit_storage_common_export.h" - -namespace dom_storage { - -// A wrapper around a std::map that adds refcounting and -// tracks the size in bytes of the keys/values, enforcing a quota. -// See class comments for DomStorageContext for a larger overview. -class WEBKIT_STORAGE_COMMON_EXPORT DomStorageMap - : public base::RefCountedThreadSafe<DomStorageMap> { - public: - explicit DomStorageMap(size_t quota); - - unsigned Length() const; - base::NullableString16 Key(unsigned index); - base::NullableString16 GetItem(const base::string16& key) const; - bool SetItem(const base::string16& key, const base::string16& value, - base::NullableString16* old_value); - bool RemoveItem(const base::string16& key, base::string16* old_value); - - // Swaps this instances values_ with |map|. - // Note: to grandfather in pre-existing files that are overbudget, - // this method does not do quota checking. - void SwapValues(ValuesMap* map); - - // Writes a copy of the current set of values_ to the |map|. - void ExtractValues(ValuesMap* map) const { *map = values_; } - - // Creates a new instance of DomStorageMap containing - // a deep copy of values_. - DomStorageMap* DeepCopy() const; - - size_t bytes_used() const { return bytes_used_; } - size_t quota() const { return quota_; } - void set_quota(size_t quota) { quota_ = quota; } - - private: - friend class base::RefCountedThreadSafe<DomStorageMap>; - ~DomStorageMap(); - - void ResetKeyIterator(); - - ValuesMap values_; - ValuesMap::const_iterator key_iterator_; - unsigned last_key_index_; - size_t bytes_used_; - size_t quota_; -}; - -} // namespace dom_storage - -#endif // WEBKIT_COMMON_DOM_STORAGE_DOM_STORAGE_MAP_H_ diff --git a/webkit/common/dom_storage/dom_storage_map_unittest.cc b/webkit/common/dom_storage/dom_storage_map_unittest.cc deleted file mode 100644 index d634bce..0000000 --- a/webkit/common/dom_storage/dom_storage_map_unittest.cc +++ /dev/null @@ -1,124 +0,0 @@ -// 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 "base/strings/utf_string_conversions.h" -#include "testing/gtest/include/gtest/gtest.h" -#include "webkit/common/dom_storage/dom_storage_map.h" - -namespace dom_storage { - -TEST(DomStorageMapTest, DomStorageMapBasics) { - const base::string16 kKey(ASCIIToUTF16("key")); - const base::string16 kValue(ASCIIToUTF16("value")); - const size_t kValueBytes = kValue.size() * sizeof(char16); - const size_t kItemBytes = - (kKey.size() + kValue.size()) * sizeof(char16); - const base::string16 kKey2(ASCIIToUTF16("key2")); - const size_t kKey2Bytes = kKey2.size() * sizeof(char16); - const base::string16 kValue2(ASCIIToUTF16("value2")); - const size_t kItem2Bytes = - (kKey2.size() + kValue2.size()) * sizeof(char16); - const size_t kQuota = 1024; // 1K quota for this test. - - scoped_refptr<DomStorageMap> map(new DomStorageMap(kQuota)); - base::string16 old_value; - base::NullableString16 old_nullable_value; - ValuesMap swap; - scoped_refptr<DomStorageMap> copy; - - // Check the behavior of an empty map. - EXPECT_EQ(0u, map->Length()); - EXPECT_TRUE(map->Key(0).is_null()); - EXPECT_TRUE(map->Key(100).is_null()); - EXPECT_TRUE(map->GetItem(kKey).is_null()); - EXPECT_FALSE(map->RemoveItem(kKey, &old_value)); - EXPECT_EQ(0u, map->bytes_used()); - copy = map->DeepCopy(); - EXPECT_EQ(0u, copy->Length()); - EXPECT_EQ(0u, copy->bytes_used()); - map->SwapValues(&swap); - EXPECT_TRUE(swap.empty()); - - // Check the behavior of a map containing some values. - EXPECT_TRUE(map->SetItem(kKey, kValue, &old_nullable_value)); - EXPECT_TRUE(old_nullable_value.is_null()); - EXPECT_EQ(1u, map->Length()); - EXPECT_EQ(kKey, map->Key(0).string()); - EXPECT_TRUE(map->Key(1).is_null()); - EXPECT_EQ(kValue, map->GetItem(kKey).string()); - EXPECT_TRUE(map->GetItem(kKey2).is_null()); - EXPECT_EQ(kItemBytes, map->bytes_used()); - EXPECT_TRUE(map->RemoveItem(kKey, &old_value)); - EXPECT_EQ(0u, map->bytes_used()); - EXPECT_EQ(kValue, old_value); - old_value.clear(); - - EXPECT_TRUE(map->SetItem(kKey, kValue, &old_nullable_value)); - EXPECT_TRUE(map->SetItem(kKey2, kValue, &old_nullable_value)); - EXPECT_TRUE(old_nullable_value.is_null()); - EXPECT_EQ(kItemBytes + kKey2Bytes + kValueBytes, map->bytes_used()); - EXPECT_TRUE(map->SetItem(kKey2, kValue2, &old_nullable_value)); - EXPECT_EQ(kItemBytes + kItem2Bytes, map->bytes_used()); - EXPECT_EQ(kValue, old_nullable_value.string()); - EXPECT_EQ(2u, map->Length()); - EXPECT_EQ(kKey, map->Key(0).string()); - EXPECT_EQ(kKey2, map->Key(1).string()); - EXPECT_EQ(kKey, map->Key(0).string()); - EXPECT_EQ(kItemBytes + kItem2Bytes, map->bytes_used()); - - copy = map->DeepCopy(); - EXPECT_EQ(2u, copy->Length()); - EXPECT_EQ(kValue, copy->GetItem(kKey).string()); - EXPECT_EQ(kValue2, copy->GetItem(kKey2).string()); - EXPECT_EQ(kKey, copy->Key(0).string()); - EXPECT_EQ(kKey2, copy->Key(1).string()); - EXPECT_TRUE(copy->Key(2).is_null()); - EXPECT_EQ(kItemBytes + kItem2Bytes, copy->bytes_used()); - - map->SwapValues(&swap); - EXPECT_EQ(2ul, swap.size()); - EXPECT_EQ(0u, map->Length()); - EXPECT_EQ(0u, map->bytes_used()); -} - -TEST(DomStorageMapTest, EnforcesQuota) { - const base::string16 kKey = ASCIIToUTF16("test_key"); - const base::string16 kValue = ASCIIToUTF16("test_value"); - const base::string16 kKey2 = ASCIIToUTF16("test_key_2"); - - // A 50 byte quota is too small to hold both keys, so we - // should see the DomStorageMap enforcing it. - const size_t kQuota = 50; - - base::string16 old_value; - base::NullableString16 old_nullable_value; - - scoped_refptr<DomStorageMap> map(new DomStorageMap(kQuota)); - EXPECT_TRUE(map->SetItem(kKey, kValue, &old_nullable_value)); - EXPECT_FALSE(map->SetItem(kKey2, kValue, &old_nullable_value)); - EXPECT_EQ(1u, map->Length()); - - EXPECT_TRUE(map->RemoveItem(kKey, &old_value)); - EXPECT_EQ(kValue, old_value); - EXPECT_EQ(0u, map->Length()); - EXPECT_TRUE(map->SetItem(kKey2, kValue, &old_nullable_value)); - EXPECT_EQ(1u, map->Length()); - - // Verify that the SwapValues method does not do quota checking. - ValuesMap swap; - swap[kKey] = base::NullableString16(kValue, false); - swap[kKey2] = base::NullableString16(kValue, false); - map->SwapValues(&swap); - EXPECT_GT(map->bytes_used(), kQuota); - - // When overbudget, a new value of greater size than the existing value can - // not be set, but a new value of lesser or equal size can be set. - EXPECT_TRUE(map->SetItem(kKey, kValue, &old_nullable_value)); - EXPECT_FALSE(map->SetItem(kKey, base::string16(kValue + kValue), - &old_nullable_value)); - EXPECT_TRUE(map->SetItem(kKey, base::string16(), &old_nullable_value)); - EXPECT_EQ(kValue, old_nullable_value.string()); -} - -} // namespace dom_storage diff --git a/webkit/common/dom_storage/dom_storage_types.cc b/webkit/common/dom_storage/dom_storage_types.cc deleted file mode 100644 index 256f32d..0000000 --- a/webkit/common/dom_storage/dom_storage_types.cc +++ /dev/null @@ -1,16 +0,0 @@ -// 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/common/dom_storage/dom_storage_types.h" - -namespace dom_storage { - -LocalStorageUsageInfo::LocalStorageUsageInfo() - : data_size(0) {} -LocalStorageUsageInfo::~LocalStorageUsageInfo() {} - -SessionStorageUsageInfo::SessionStorageUsageInfo() {} -SessionStorageUsageInfo::~SessionStorageUsageInfo() {} - -} // namespace dom_storage diff --git a/webkit/common/dom_storage/dom_storage_types.h b/webkit/common/dom_storage/dom_storage_types.h deleted file mode 100644 index 1d1e585..0000000 --- a/webkit/common/dom_storage/dom_storage_types.h +++ /dev/null @@ -1,62 +0,0 @@ -// 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_COMMON_DOM_STORAGE_DOM_STORAGE_TYPES_H_ -#define WEBKIT_COMMON_DOM_STORAGE_DOM_STORAGE_TYPES_H_ - -#include <map> - -#include "base/basictypes.h" -#include "base/strings/nullable_string16.h" -#include "base/strings/string16.h" -#include "base/time/time.h" -#include "url/gurl.h" -#include "webkit/common/webkit_storage_common_export.h" - -namespace dom_storage { - -// The quota for each storage area. -// This value is enforced in renderer processes and the browser process. -const size_t kPerAreaQuota = 10 * 1024 * 1024; - -// In the browser process we allow some overage to -// accomodate concurrent writes from different renderers -// that were allowed because the limit imposed in the renderer -// wasn't exceeded. -const size_t kPerAreaOverQuotaAllowance = 100 * 1024; - -// Value to indicate the localstorage namespace vs non-zero -// values for sessionstorage namespaces. -const int64 kLocalStorageNamespaceId = 0; - -const int64 kInvalidSessionStorageNamespaceId = kLocalStorageNamespaceId; - -// Start purging memory if the number of in-memory areas exceeds this. -const int64 kMaxInMemoryAreas = 100; - -// Value to indicate an area that not be opened. -const int kInvalidAreaId = -1; - -typedef std::map<base::string16, base::NullableString16> ValuesMap; - -struct WEBKIT_STORAGE_COMMON_EXPORT LocalStorageUsageInfo { - GURL origin; - size_t data_size; - base::Time last_modified; - - LocalStorageUsageInfo(); - ~LocalStorageUsageInfo(); -}; - -struct WEBKIT_STORAGE_COMMON_EXPORT SessionStorageUsageInfo { - GURL origin; - std::string persistent_namespace_id; - - SessionStorageUsageInfo(); - ~SessionStorageUsageInfo(); -}; - -} // namespace dom_storage - -#endif // WEBKIT_COMMON_DOM_STORAGE_DOM_STORAGE_TYPES_H_ |