Chromium Code Reviews| Index: content/renderer/dom_storage/local_storage_cached_area.h |
| diff --git a/content/renderer/dom_storage/local_storage_cached_area.h b/content/renderer/dom_storage/local_storage_cached_area.h |
| index 4d56bbeee825aa873698484c64908bd877595472..7fa9386a4a4a235bc6ac632c137130b0fc49ee44 100644 |
| --- a/content/renderer/dom_storage/local_storage_cached_area.h |
| +++ b/content/renderer/dom_storage/local_storage_cached_area.h |
| @@ -5,8 +5,9 @@ |
| #ifndef CONTENT_RENDERER_DOM_STORAGE_LOCAL_STORAGE_CACHED_AREA_H_ |
| #define CONTENT_RENDERER_DOM_STORAGE_LOCAL_STORAGE_CACHED_AREA_H_ |
| +#include <map> |
| + |
| #include "base/macros.h" |
| -#include "base/memory/ref_counted.h" |
| #include "base/strings/nullable_string16.h" |
| #include "content/common/leveldb_wrapper.mojom.h" |
| #include "mojo/public/cpp/bindings/binding.h" |
| @@ -14,6 +15,8 @@ |
| #include "url/origin.h" |
| namespace content { |
| +class DOMStorageMap; |
| +class LocalStorageArea; |
| class LocalStorageCachedAreas; |
| class StoragePartitionService; |
| @@ -22,8 +25,9 @@ class StoragePartitionService; |
| // access. The cache is primed on first access and changes are written to the |
| // backend through the level db interface pointer. Mutations originating in |
| // other processes are applied to the cache via LevelDBObserver callbacks. |
| -class LocalStorageCachedArea : public LevelDBObserver, |
| - public base::RefCounted<LocalStorageCachedArea> { |
| +// There is one LocalStorageCachedArea for potentially many LocalStorageArea |
| +// objects. |
| +class LocalStorageCachedArea : public LevelDBObserver { |
| public: |
| LocalStorageCachedArea(const url::Origin& origin, |
| StoragePartitionService* storage_partition_service, |
| @@ -35,15 +39,21 @@ class LocalStorageCachedArea : public LevelDBObserver, |
| base::NullableString16 GetItem(const base::string16& key); |
| bool SetItem(const base::string16& key, |
| const base::string16& value, |
| - const GURL& page_url); |
| + const GURL& page_url, |
| + const std::string& storage_area_id); |
| void RemoveItem(const base::string16& key, |
| - const GURL& page_url); |
| - void Clear(const GURL& page_url); |
| + const GURL& page_url, |
| + const std::string& storage_area_id); |
| + void Clear(const GURL& page_url, const std::string& storage_area_id); |
| + |
| + // Allow this object to keep track of the LocalStorageAreas corresponding to |
| + // it, which is needed for mutation event notifications. |
| + void LocalStorageAreaCreated(LocalStorageArea* area); |
| + void LocalStorageAreaDestroyed(LocalStorageArea* area); |
| const url::Origin& origin() { return origin_; } |
| private: |
| - friend class base::RefCounted<LocalStorageCachedArea>; |
| ~LocalStorageCachedArea() override; |
| // LevelDBObserver: |
| @@ -52,6 +62,7 @@ class LocalStorageCachedArea : public LevelDBObserver, |
| mojo::Array<uint8_t> old_value, |
| const mojo::String& source) override; |
| void KeyDeleted(mojo::Array<uint8_t> key, |
| + mojo::Array<uint8_t> old_value, |
| const mojo::String& source) override; |
| void AllDeleted(const mojo::String& source) override; |
| @@ -59,11 +70,23 @@ class LocalStorageCachedArea : public LevelDBObserver, |
| // fetched already. |
| void EnsureLoaded(); |
| + void OnSetItemComplete(const base::string16& key, |
| + leveldb::DatabaseError result); |
| + void OnRemoveItemComplete(const base::string16& key, |
| + leveldb::DatabaseError result); |
| + void OnClearComplete(leveldb::DatabaseError result); |
| + |
| + // Resets the object back to its newly constructed state. |
| + void Reset(); |
| + |
| bool loaded_; |
| url::Origin origin_; |
| + scoped_refptr<DOMStorageMap> map_; |
| + std::map<base::string16, int> ignore_key_mutations_; |
| LevelDBWrapperPtr leveldb_; |
| mojo::Binding<LevelDBObserver> binding_; |
| LocalStorageCachedAreas* cached_areas_; |
|
michaeln
2016/03/18 01:05:17
have this one be weak
jam
2016/03/18 16:48:33
the way the code is structured is that LocalStorag
michaeln
2016/03/18 22:01:14
ok, but dont be surprised when your surprised by w
|
| + std::map<std::string, LocalStorageArea*> areas_; |
| DISALLOW_COPY_AND_ASSIGN(LocalStorageCachedArea); |
| }; |