diff options
author | jorlow@chromium.org <jorlow@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2009-07-24 01:22:51 +0000 |
---|---|---|
committer | jorlow@chromium.org <jorlow@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2009-07-24 01:22:51 +0000 |
commit | 2a10f681c582df15719956061b6742a55bccb46a (patch) | |
tree | 4e4ee689cafbecb9b211f437f478b7588f6c05c2 /chrome/renderer/renderer_webstoragearea_impl.h | |
parent | 4f9b2a7e42fc567073f4999a888b3140bec460bb (diff) | |
download | chromium_src-2a10f681c582df15719956061b6742a55bccb46a.zip chromium_src-2a10f681c582df15719956061b6742a55bccb46a.tar.gz chromium_src-2a10f681c582df15719956061b6742a55bccb46a.tar.bz2 |
The final CL for plumbing DOM Storage.
Add webKitClient plumbing for getting/creating storage namespaces. Add a chromium implementation for WebStorageArea and WebStorageNamespace which communicates via IPC with the dom_storage_dispatcher_host in the browser process. Flesh out the StorageAreaProxy and StorageNamespaceProxy to use the aforementioned implementations.
The WebStorageArea implementation includes decently aggressive caching optimizations. There's still a lot of work to do, though.
BUG=4360
TEST=none
Review URL: http://codereview.chromium.org/147248
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@21495 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome/renderer/renderer_webstoragearea_impl.h')
-rw-r--r-- | chrome/renderer/renderer_webstoragearea_impl.h | 76 |
1 files changed, 76 insertions, 0 deletions
diff --git a/chrome/renderer/renderer_webstoragearea_impl.h b/chrome/renderer/renderer_webstoragearea_impl.h new file mode 100644 index 0000000..0a313c2 --- /dev/null +++ b/chrome/renderer/renderer_webstoragearea_impl.h @@ -0,0 +1,76 @@ +// Copyright (c) 2009 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 CHROME_RENDERER_RENDERER_WEBSTORAGEAREA_IMPL_H_ +#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" + +class RendererWebStorageAreaImpl : public WebKit::WebStorageArea { + public: + RendererWebStorageAreaImpl(int64 namespace_id, + const WebKit::WebString& origin); + 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, bool& key_exception); + virtual WebKit::WebString getItem(const WebKit::WebString& key); + virtual void setItem(const WebKit::WebString& key, + const WebKit::WebString& value, + bool& quota_exception); + virtual void removeItem(const WebKit::WebString& key); + 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. + 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_ |