summaryrefslogtreecommitdiffstats
path: root/chrome/renderer
diff options
context:
space:
mode:
authorjorlow@chromium.org <jorlow@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2009-09-11 03:58:45 +0000
committerjorlow@chromium.org <jorlow@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2009-09-11 03:58:45 +0000
commit3d392a6fd21a84a4eae5cc340242219f5062b46d (patch)
tree99d0e4dd9d0b1128d6a0ab0b4b381db3f23c3e6c /chrome/renderer
parent8f0bcb9f2381746bfc8f234fe1fcf831321adbf5 (diff)
downloadchromium_src-3d392a6fd21a84a4eae5cc340242219f5062b46d.zip
chromium_src-3d392a6fd21a84a4eae5cc340242219f5062b46d.tar.gz
chromium_src-3d392a6fd21a84a4eae5cc340242219f5062b46d.tar.bz2
Get rid of the half-working traces of locking, caching, and quotas. It
probably shoudln't have been added in to begin with. BUG=none TEST=none Review URL: http://codereview.chromium.org/203015 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@25966 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome/renderer')
-rw-r--r--chrome/renderer/renderer_webstoragearea_impl.cc125
-rw-r--r--chrome/renderer/renderer_webstoragearea_impl.h44
-rw-r--r--chrome/renderer/renderer_webstoragenamespace_impl.cc3
3 files changed, 9 insertions, 163 deletions
diff --git a/chrome/renderer/renderer_webstoragearea_impl.cc b/chrome/renderer/renderer_webstoragearea_impl.cc
index 825d967..b03396d 100644
--- a/chrome/renderer/renderer_webstoragearea_impl.cc
+++ b/chrome/renderer/renderer_webstoragearea_impl.cc
@@ -6,41 +6,20 @@
#include "chrome/common/render_messages.h"
#include "chrome/renderer/render_thread.h"
-#include "webkit/api/public/WebString.h"
using WebKit::WebString;
RendererWebStorageAreaImpl::RendererWebStorageAreaImpl(
- int64 namespace_id,
- const WebString& origin)
- : namespace_id_(namespace_id),
- origin_(origin),
- storage_area_id_(kUninitializedStorageAreaId),
- lock_held_(false),
- bytes_left_in_quota_(0) {
+ int64 namespace_id, const WebString& origin) {
+ RenderThread::current()->Send(
+ new ViewHostMsg_DOMStorageStorageAreaId(namespace_id, origin,
+ &storage_area_id_));
}
RendererWebStorageAreaImpl::~RendererWebStorageAreaImpl() {
}
-void RendererWebStorageAreaImpl::lock(bool& invalidate_cache,
- size_t& bytes_left_in_quota) {
- EnsureInitializedAndLocked();
-}
-
-void RendererWebStorageAreaImpl::unlock() {
- if (storage_area_id_ != kUninitializedStorageAreaId) {
- RenderThread::current()->Send(
- new ViewHostMsg_DOMStorageUnlock(storage_area_id_));
- }
- lock_held_ = false;
-}
-
unsigned RendererWebStorageAreaImpl::length() {
- EnsureInitializedAndLocked();
- // Right now this is always sync. We could cache it, but I can't think of
- // too many use cases where you'd repeatedly look up length() and not be
- // doing so many key() lookups that the length() calls are the problem.
unsigned length;
RenderThread::current()->Send(
new ViewHostMsg_DOMStorageLength(storage_area_id_, &length));
@@ -48,120 +27,32 @@ unsigned RendererWebStorageAreaImpl::length() {
}
WebString RendererWebStorageAreaImpl::key(unsigned index) {
- EnsureInitializedAndLocked();
- // Right now this is always sync. We may want to optimize this by fetching
- // chunks of keys rather than single keys (and flushing the cache on every
- // mutation of the storage area) since this will most often be used to fetch
- // all the keys at once.
NullableString16 key;
RenderThread::current()->Send(
new ViewHostMsg_DOMStorageKey(storage_area_id_, index, &key));
return key;
}
-WebString RendererWebStorageAreaImpl::getItem(const WebString& webkit_key) {
- EnsureInitializedAndLocked();
- string16 key = webkit_key;
-
- // Return from our cache if possible.
- CacheMap::const_iterator iterator = cached_items_.find(key);
- if (iterator != cached_items_.end())
- return iterator->second;
- if (cached_invalid_items_.find(key) != cached_invalid_items_.end())
- return WebString(); // Return a "null" string.
-
- // The item is not in the cache, so we must do a sync IPC. Afterwards,
- // add it to the cache.
- NullableString16 raw_value;
+WebString RendererWebStorageAreaImpl::getItem(const WebString& key) {
+ NullableString16 value;
RenderThread::current()->Send(
- new ViewHostMsg_DOMStorageGetItem(storage_area_id_, key, &raw_value));
- WebString value = raw_value; // Only do the conversion once.
- SetCache(key, value);
+ new ViewHostMsg_DOMStorageGetItem(storage_area_id_, key, &value));
return value;
}
void RendererWebStorageAreaImpl::setItem(const WebString& key,
const WebString& value,
bool& quota_exception) {
- EnsureInitializedAndLocked();
- quota_exception = !UpdateQuota(key, value);
- if (quota_exception)
- return;
RenderThread::current()->Send(
new ViewHostMsg_DOMStorageSetItem(storage_area_id_, key, value));
- SetCache(key, value);
}
void RendererWebStorageAreaImpl::removeItem(const WebString& key) {
- EnsureInitializedAndLocked();
- bool update_succeeded = UpdateQuota(key, WebString());
- DCHECK(update_succeeded);
RenderThread::current()->Send(
new ViewHostMsg_DOMStorageRemoveItem(storage_area_id_, key));
- SetCache(key, WebString());
}
void RendererWebStorageAreaImpl::clear() {
- EnsureInitializedAndLocked();
RenderThread::current()->Send(
- new ViewHostMsg_DOMStorageClear(storage_area_id_,
- &bytes_left_in_quota_));
- // A possible optimization is a flag that says our cache is 100% complete.
- // This could be set here, and then future gets would never require IPC.
- cached_items_.clear();
- cached_invalid_items_.clear();
-}
-
-void RendererWebStorageAreaImpl::EnsureInitializedAndLocked() {
- if (storage_area_id_ == kUninitializedStorageAreaId) {
- RenderThread::current()->Send(
- new ViewHostMsg_DOMStorageStorageAreaId(namespace_id_, origin_,
- &storage_area_id_));
- }
-
- if (lock_held_)
- return;
-
- bool invalidate_cache;
- RenderThread::current()->Send(
- new ViewHostMsg_DOMStorageLock(storage_area_id_, &invalidate_cache,
- &bytes_left_in_quota_));
- lock_held_ = true;
- if (invalidate_cache) {
- cached_items_.clear();
- cached_invalid_items_.clear();
- }
-}
-
-bool RendererWebStorageAreaImpl::UpdateQuota(const WebString& key,
- const WebString& value) {
- // TODO(jorlow): Remove once the bytes_left_in_quota values we're getting
- // are accurate.
- return true;
-
- size_t existing_bytes = getItem(key).length();
- size_t new_bytes = value.length();
-
- if (existing_bytes < new_bytes) {
- size_t delta = new_bytes - existing_bytes;
- if (delta > bytes_left_in_quota_)
- return false;
- bytes_left_in_quota_ -= delta;
- } else {
- size_t delta = existing_bytes - new_bytes;
- DCHECK(delta + bytes_left_in_quota_ >= bytes_left_in_quota_);
- bytes_left_in_quota_ += delta;
- }
- return true;
-}
-
-void RendererWebStorageAreaImpl::SetCache(const string16& key,
- const WebString& value) {
- cached_items_.erase(key);
- cached_invalid_items_.erase(key);
-
- if (!value.isNull())
- cached_items_[key] = value;
- else
- cached_invalid_items_.insert(key);
+ new ViewHostMsg_DOMStorageClear(storage_area_id_));
}
diff --git a/chrome/renderer/renderer_webstoragearea_impl.h b/chrome/renderer/renderer_webstoragearea_impl.h
index 0b734e8..57e13fc 100644
--- a/chrome/renderer/renderer_webstoragearea_impl.h
+++ b/chrome/renderer/renderer_webstoragearea_impl.h
@@ -6,7 +6,6 @@
#define CHROME_RENDERER_RENDERER_WEBSTORAGEAREA_IMPL_H_
#include "base/basictypes.h"
-#include "base/hash_tables.h"
#include "base/string16.h"
#include "webkit/api/public/WebStorageArea.h"
#include "webkit/api/public/WebString.h"
@@ -18,8 +17,6 @@ class RendererWebStorageAreaImpl : public WebKit::WebStorageArea {
virtual ~RendererWebStorageAreaImpl();
// See WebStorageArea.h for documentation on these functions.
- virtual void lock(bool& invalidate_cache, size_t& bytes_left_in_quota);
- virtual void unlock();
virtual unsigned length();
virtual WebKit::WebString key(unsigned index);
virtual WebKit::WebString getItem(const WebKit::WebString& key);
@@ -30,47 +27,8 @@ class RendererWebStorageAreaImpl : public WebKit::WebStorageArea {
virtual void clear();
private:
- // Calls lock if we haven't already done so, and also gets a storage_area_id
- // if we haven't done so. Fetches quota and cache invalidation information
- // while locking. Only call on the WebKit thread.
- void EnsureInitializedAndLocked();
-
- // Update our quota calculation. Returns true if we updated the quota.
- // Returns false if we couldn't update because we would have exceeded the
- // quota. If an item is not in our cache, it'll require a getItem IPC in
- // order to determine the existing value's size.
- bool UpdateQuota(const WebKit::WebString& key,
- const WebKit::WebString& value);
-
- // Set a key/value pair in our cache.
- void SetCache(const string16& key, const WebKit::WebString& value);
-
- // Used for initialization or storage_area_id_.
- int64 namespace_id_;
- string16 origin_;
-
- // The ID we use for all IPC. Initialized lazily.
+ // The ID we use for all IPC.
int64 storage_area_id_;
-
- // storage_area_id_ should equal this iff its unitialized.
- static const int64 kUninitializedStorageAreaId = -1;
-
- // Do we currently hold the lock on this storage area?
- bool lock_held_;
-
- // We track how many bytes are left in the quota between lock and unlock
- // calls. This allows us to avoid sync IPC on setItem.
- size_t bytes_left_in_quota_;
-
- // A cache of key/value pairs. If the item exists, it's put in the
- // cached_items_ map. If not, it's added to the cached_invalid_items_ set.
- // The lock IPC call tells us when to invalidate these caches.
- // TODO(jorlow): Instead of a map + a set, use NullableString16 once it's
- // implemented: http://crbug.com/17343
- typedef base::hash_map<string16, string16> CacheMap;
- typedef base::hash_set<string16> CacheSet;
- CacheMap cached_items_;
- CacheSet cached_invalid_items_;
};
#endif // CHROME_RENDERER_WEBSTORAGEAREA_IMPL_H_
diff --git a/chrome/renderer/renderer_webstoragenamespace_impl.cc b/chrome/renderer/renderer_webstoragenamespace_impl.cc
index 453bbcf..0457207 100644
--- a/chrome/renderer/renderer_webstoragenamespace_impl.cc
+++ b/chrome/renderer/renderer_webstoragenamespace_impl.cc
@@ -22,9 +22,6 @@ RendererWebStorageNamespaceImpl::RendererWebStorageNamespaceImpl(
}
RendererWebStorageNamespaceImpl::~RendererWebStorageNamespaceImpl() {
- if (namespace_id_ != kUninitializedNamespaceId)
- RenderThread::current()->Send(
- new ViewHostMsg_DOMStorageDerefNamespaceId(namespace_id_));
}
WebKit::WebStorageArea* RendererWebStorageNamespaceImpl::createStorageArea(