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 WEBKIT_DOM_STORAGE_DOM_STORAGE_CACHED_AREA_H_ | 5 #ifndef WEBKIT_DOM_STORAGE_DOM_STORAGE_CACHED_AREA_H_ |
6 #define WEBKIT_DOM_STORAGE_DOM_STORAGE_CACHED_AREA_H_ | 6 #define WEBKIT_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/nullable_string16.h" | 12 #include "base/nullable_base::string16.h" |
13 #include "googleurl/src/gurl.h" | 13 #include "googleurl/src/gurl.h" |
14 #include "webkit/storage/webkit_storage_export.h" | 14 #include "webkit/storage/webkit_storage_export.h" |
15 | 15 |
16 namespace dom_storage { | 16 namespace dom_storage { |
17 | 17 |
18 class DomStorageMap; | 18 class DomStorageMap; |
19 class DomStorageProxy; | 19 class DomStorageProxy; |
20 | 20 |
21 // 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 |
22 // 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 |
23 // 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 |
24 // 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|. |
25 // Mutations originating in other processes are applied to the cache via | 25 // Mutations originating in other processes are applied to the cache via |
26 // the ApplyMutation method. | 26 // the ApplyMutation method. |
27 class WEBKIT_STORAGE_EXPORT DomStorageCachedArea : | 27 class WEBKIT_STORAGE_EXPORT DomStorageCachedArea : |
28 public base::RefCounted<DomStorageCachedArea> { | 28 public base::RefCounted<DomStorageCachedArea> { |
29 public: | 29 public: |
30 DomStorageCachedArea(int64 namespace_id, const GURL& origin, | 30 DomStorageCachedArea(int64 namespace_id, const GURL& origin, |
31 DomStorageProxy* proxy); | 31 DomStorageProxy* proxy); |
32 | 32 |
33 int64 namespace_id() const { return namespace_id_; } | 33 int64 namespace_id() const { return namespace_id_; } |
34 const GURL& origin() const { return origin_; } | 34 const GURL& origin() const { return origin_; } |
35 | 35 |
36 unsigned GetLength(int connection_id); | 36 unsigned GetLength(int connection_id); |
37 NullableString16 GetKey(int connection_id, unsigned index); | 37 NullableString16 GetKey(int connection_id, unsigned index); |
38 NullableString16 GetItem(int connection_id, const string16& key); | 38 NullableString16 GetItem(int connection_id, const base::string16& key); |
39 bool SetItem(int connection_id, const string16& key, const string16& value, | 39 bool SetItem(int connection_id, |
| 40 const base::string16& key, |
| 41 const base::string16& value, |
40 const GURL& page_url); | 42 const GURL& page_url); |
41 void RemoveItem(int connection_id, const string16& key, | 43 void RemoveItem(int connection_id, const base::string16& key, |
42 const GURL& page_url); | 44 const GURL& page_url); |
43 void Clear(int connection_id, const GURL& page_url); | 45 void Clear(int connection_id, const GURL& page_url); |
44 | 46 |
45 void ApplyMutation(const NullableString16& key, | 47 void ApplyMutation(const NullableString16& key, |
46 const NullableString16& new_value); | 48 const NullableString16& new_value); |
47 | 49 |
48 size_t MemoryBytesUsedByCache() const; | 50 size_t MemoryBytesUsedByCache() const; |
49 | 51 |
50 private: | 52 private: |
51 friend class DomStorageCachedAreaTest; | 53 friend class DomStorageCachedAreaTest; |
52 friend class base::RefCounted<DomStorageCachedArea>; | 54 friend class base::RefCounted<DomStorageCachedArea>; |
53 ~DomStorageCachedArea(); | 55 ~DomStorageCachedArea(); |
54 | 56 |
55 // Primes the cache, loading all values for the area. | 57 // Primes the cache, loading all values for the area. |
56 void Prime(int connection_id); | 58 void Prime(int connection_id); |
57 void PrimeIfNeeded(int connection_id) { | 59 void PrimeIfNeeded(int connection_id) { |
58 if (!map_) | 60 if (!map_) |
59 Prime(connection_id); | 61 Prime(connection_id); |
60 } | 62 } |
61 | 63 |
62 // Resets the object back to its newly constructed state. | 64 // Resets the object back to its newly constructed state. |
63 void Reset(); | 65 void Reset(); |
64 | 66 |
65 // Async completion callbacks for proxied operations. | 67 // Async completion callbacks for proxied operations. |
66 // These are used to maintain cache consistency by preventing | 68 // These are used to maintain cache consistency by preventing |
67 // mutation events from other processes from overwriting local | 69 // mutation events from other processes from overwriting local |
68 // changes made after the mutation. | 70 // changes made after the mutation. |
69 void OnLoadComplete(bool success); | 71 void OnLoadComplete(bool success); |
70 void OnSetItemComplete(const string16& key, bool success); | 72 void OnSetItemComplete(const base::string16& key, bool success); |
71 void OnClearComplete(bool success); | 73 void OnClearComplete(bool success); |
72 void OnRemoveItemComplete(const string16& key, bool success); | 74 void OnRemoveItemComplete(const base::string16& key, bool success); |
73 | 75 |
74 bool should_ignore_key_mutation(const string16& key) const { | 76 bool should_ignore_key_mutation(const base::string16& key) const { |
75 return ignore_key_mutations_.find(key) != ignore_key_mutations_.end(); | 77 return ignore_key_mutations_.find(key) != ignore_key_mutations_.end(); |
76 } | 78 } |
77 | 79 |
78 bool ignore_all_mutations_; | 80 bool ignore_all_mutations_; |
79 std::map<string16, int> ignore_key_mutations_; | 81 std::map<base::string16, int> ignore_key_mutations_; |
80 | 82 |
81 int64 namespace_id_; | 83 int64 namespace_id_; |
82 GURL origin_; | 84 GURL origin_; |
83 scoped_refptr<DomStorageMap> map_; | 85 scoped_refptr<DomStorageMap> map_; |
84 scoped_refptr<DomStorageProxy> proxy_; | 86 scoped_refptr<DomStorageProxy> proxy_; |
85 base::WeakPtrFactory<DomStorageCachedArea> weak_factory_; | 87 base::WeakPtrFactory<DomStorageCachedArea> weak_factory_; |
86 }; | 88 }; |
87 | 89 |
88 } // namespace dom_storage | 90 } // namespace dom_storage |
89 | 91 |
90 #endif // WEBKIT_DOM_STORAGE_DOM_STORAGE_CACHED_AREA_H_ | 92 #endif // WEBKIT_DOM_STORAGE_DOM_STORAGE_CACHED_AREA_H_ |
OLD | NEW |