| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #ifndef CONTENT_RENDERER_DOM_STORAGE_DOM_STORAGE_CACHED_AREA_H_ | 5 #ifndef CONTENT_RENDERER_DOM_STORAGE_DOM_STORAGE_CACHED_AREA_H_ |
| 6 #define CONTENT_RENDERER_DOM_STORAGE_DOM_STORAGE_CACHED_AREA_H_ | 6 #define CONTENT_RENDERER_DOM_STORAGE_DOM_STORAGE_CACHED_AREA_H_ |
| 7 | 7 |
| 8 #include <map> | 8 #include <map> |
| 9 | 9 |
| 10 #include "base/memory/ref_counted.h" | 10 #include "base/memory/ref_counted.h" |
| 11 #include "base/memory/weak_ptr.h" | 11 #include "base/memory/weak_ptr.h" |
| 12 #include "base/strings/nullable_string16.h" | 12 #include "base/strings/nullable_string16.h" |
| 13 #include "content/common/content_export.h" | 13 #include "content/common/content_export.h" |
| 14 #include "url/gurl.h" | 14 #include "url/gurl.h" |
| 15 | 15 |
| 16 namespace dom_storage { | |
| 17 class DomStorageMap; | |
| 18 } | |
| 19 | |
| 20 namespace content { | 16 namespace content { |
| 21 | 17 |
| 22 class DomStorageProxy; | 18 class DOMStorageMap; |
| 19 class DOMStorageProxy; |
| 23 | 20 |
| 24 // Unlike the other classes in the dom_storage library, this one is intended | 21 // Unlike the other classes in the dom_storage library, this one is intended |
| 25 // for use in renderer processes. It maintains a complete cache of the | 22 // for use in renderer processes. It maintains a complete cache of the |
| 26 // origin's Map of key/value pairs for fast access. The cache is primed on | 23 // origin's Map of key/value pairs for fast access. The cache is primed on |
| 27 // first access and changes are written to the backend thru the |proxy|. | 24 // first access and changes are written to the backend thru the |proxy|. |
| 28 // Mutations originating in other processes are applied to the cache via | 25 // Mutations originating in other processes are applied to the cache via |
| 29 // the ApplyMutation method. | 26 // the ApplyMutation method. |
| 30 class CONTENT_EXPORT DomStorageCachedArea | 27 class CONTENT_EXPORT DOMStorageCachedArea |
| 31 : public base::RefCounted<DomStorageCachedArea> { | 28 : public base::RefCounted<DOMStorageCachedArea> { |
| 32 public: | 29 public: |
| 33 DomStorageCachedArea(int64 namespace_id, | 30 DOMStorageCachedArea(int64 namespace_id, |
| 34 const GURL& origin, | 31 const GURL& origin, |
| 35 DomStorageProxy* proxy); | 32 DOMStorageProxy* proxy); |
| 36 | 33 |
| 37 int64 namespace_id() const { return namespace_id_; } | 34 int64 namespace_id() const { return namespace_id_; } |
| 38 const GURL& origin() const { return origin_; } | 35 const GURL& origin() const { return origin_; } |
| 39 | 36 |
| 40 unsigned GetLength(int connection_id); | 37 unsigned GetLength(int connection_id); |
| 41 base::NullableString16 GetKey(int connection_id, unsigned index); | 38 base::NullableString16 GetKey(int connection_id, unsigned index); |
| 42 base::NullableString16 GetItem(int connection_id, const base::string16& key); | 39 base::NullableString16 GetItem(int connection_id, const base::string16& key); |
| 43 bool SetItem(int connection_id, | 40 bool SetItem(int connection_id, |
| 44 const base::string16& key, | 41 const base::string16& key, |
| 45 const base::string16& value, | 42 const base::string16& value, |
| 46 const GURL& page_url); | 43 const GURL& page_url); |
| 47 void RemoveItem(int connection_id, | 44 void RemoveItem(int connection_id, |
| 48 const base::string16& key, | 45 const base::string16& key, |
| 49 const GURL& page_url); | 46 const GURL& page_url); |
| 50 void Clear(int connection_id, const GURL& page_url); | 47 void Clear(int connection_id, const GURL& page_url); |
| 51 | 48 |
| 52 void ApplyMutation(const base::NullableString16& key, | 49 void ApplyMutation(const base::NullableString16& key, |
| 53 const base::NullableString16& new_value); | 50 const base::NullableString16& new_value); |
| 54 | 51 |
| 55 size_t MemoryBytesUsedByCache() const; | 52 size_t MemoryBytesUsedByCache() const; |
| 56 | 53 |
| 57 private: | 54 private: |
| 58 friend class DomStorageCachedAreaTest; | 55 friend class DOMStorageCachedAreaTest; |
| 59 friend class base::RefCounted<DomStorageCachedArea>; | 56 friend class base::RefCounted<DOMStorageCachedArea>; |
| 60 ~DomStorageCachedArea(); | 57 ~DOMStorageCachedArea(); |
| 61 | 58 |
| 62 // Primes the cache, loading all values for the area. | 59 // Primes the cache, loading all values for the area. |
| 63 void Prime(int connection_id); | 60 void Prime(int connection_id); |
| 64 void PrimeIfNeeded(int connection_id) { | 61 void PrimeIfNeeded(int connection_id) { |
| 65 if (!map_.get()) | 62 if (!map_.get()) |
| 66 Prime(connection_id); | 63 Prime(connection_id); |
| 67 } | 64 } |
| 68 | 65 |
| 69 // Resets the object back to its newly constructed state. | 66 // Resets the object back to its newly constructed state. |
| 70 void Reset(); | 67 void Reset(); |
| 71 | 68 |
| 72 // Async completion callbacks for proxied operations. | 69 // Async completion callbacks for proxied operations. |
| 73 // These are used to maintain cache consistency by preventing | 70 // These are used to maintain cache consistency by preventing |
| 74 // mutation events from other processes from overwriting local | 71 // mutation events from other processes from overwriting local |
| 75 // changes made after the mutation. | 72 // changes made after the mutation. |
| 76 void OnLoadComplete(bool success); | 73 void OnLoadComplete(bool success); |
| 77 void OnSetItemComplete(const base::string16& key, bool success); | 74 void OnSetItemComplete(const base::string16& key, bool success); |
| 78 void OnClearComplete(bool success); | 75 void OnClearComplete(bool success); |
| 79 void OnRemoveItemComplete(const base::string16& key, bool success); | 76 void OnRemoveItemComplete(const base::string16& key, bool success); |
| 80 | 77 |
| 81 bool should_ignore_key_mutation(const base::string16& key) const { | 78 bool should_ignore_key_mutation(const base::string16& key) const { |
| 82 return ignore_key_mutations_.find(key) != ignore_key_mutations_.end(); | 79 return ignore_key_mutations_.find(key) != ignore_key_mutations_.end(); |
| 83 } | 80 } |
| 84 | 81 |
| 85 bool ignore_all_mutations_; | 82 bool ignore_all_mutations_; |
| 86 std::map<base::string16, int> ignore_key_mutations_; | 83 std::map<base::string16, int> ignore_key_mutations_; |
| 87 | 84 |
| 88 int64 namespace_id_; | 85 int64 namespace_id_; |
| 89 GURL origin_; | 86 GURL origin_; |
| 90 scoped_refptr<dom_storage::DomStorageMap> map_; | 87 scoped_refptr<DOMStorageMap> map_; |
| 91 scoped_refptr<DomStorageProxy> proxy_; | 88 scoped_refptr<DOMStorageProxy> proxy_; |
| 92 base::WeakPtrFactory<DomStorageCachedArea> weak_factory_; | 89 base::WeakPtrFactory<DOMStorageCachedArea> weak_factory_; |
| 93 }; | 90 }; |
| 94 | 91 |
| 95 } // namespace content | 92 } // namespace content |
| 96 | 93 |
| 97 #endif // CONTENT_RENDERER_DOM_STORAGE_DOM_STORAGE_CACHED_AREA_H_ | 94 #endif // CONTENT_RENDERER_DOM_STORAGE_DOM_STORAGE_CACHED_AREA_H_ |
| OLD | NEW |