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" |
(...skipping 10 matching lines...) Expand all Loading... |
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 int64 storage_size); |
32 | 33 |
33 int64 namespace_id() const { return namespace_id_; } | 34 int64 namespace_id() const { return namespace_id_; } |
34 const GURL& origin() const { return origin_; } | 35 const GURL& origin() const { return origin_; } |
35 | 36 |
36 unsigned GetLength(int connection_id); | 37 unsigned GetLength(int connection_id); |
37 NullableString16 GetKey(int connection_id, unsigned index); | 38 NullableString16 GetKey(int connection_id, unsigned index); |
38 NullableString16 GetItem(int connection_id, const string16& key); | 39 NullableString16 GetItem(int connection_id, const string16& key); |
39 bool SetItem(int connection_id, const string16& key, const string16& value, | 40 bool SetItem(int connection_id, const string16& key, const string16& value, |
40 const GURL& page_url); | 41 const GURL& page_url); |
41 void RemoveItem(int connection_id, const string16& key, | 42 void RemoveItem(int connection_id, const string16& key, |
42 const GURL& page_url); | 43 const GURL& page_url); |
43 void Clear(int connection_id, const GURL& page_url); | 44 void Clear(int connection_id, const GURL& page_url); |
44 | 45 |
45 void ApplyMutation(const NullableString16& key, | 46 void ApplyMutation(const NullableString16& key, |
46 const NullableString16& new_value); | 47 const NullableString16& new_value); |
47 | 48 |
48 size_t MemoryBytesUsedByCache() const; | 49 size_t MemoryBytesUsedByCache() const; |
49 | 50 |
| 51 void set_global_storage_size(int64 size) { |
| 52 global_storage_size_ = size; |
| 53 } |
| 54 |
50 private: | 55 private: |
51 friend class DomStorageCachedAreaTest; | 56 friend class DomStorageCachedAreaTest; |
52 friend class base::RefCounted<DomStorageCachedArea>; | 57 friend class base::RefCounted<DomStorageCachedArea>; |
53 ~DomStorageCachedArea(); | 58 ~DomStorageCachedArea(); |
54 | 59 |
55 // Primes the cache, loading all values for the area. | 60 // Primes the cache, loading all values for the area. |
56 void Prime(int connection_id); | 61 void Prime(int connection_id); |
57 void PrimeIfNeeded(int connection_id) { | 62 void PrimeIfNeeded(int connection_id) { |
58 if (!map_) | 63 if (!map_) |
59 Prime(connection_id); | 64 Prime(connection_id); |
(...skipping 16 matching lines...) Expand all Loading... |
76 } | 81 } |
77 | 82 |
78 bool ignore_all_mutations_; | 83 bool ignore_all_mutations_; |
79 std::map<string16, int> ignore_key_mutations_; | 84 std::map<string16, int> ignore_key_mutations_; |
80 | 85 |
81 int64 namespace_id_; | 86 int64 namespace_id_; |
82 GURL origin_; | 87 GURL origin_; |
83 scoped_refptr<DomStorageMap> map_; | 88 scoped_refptr<DomStorageMap> map_; |
84 scoped_refptr<DomStorageProxy> proxy_; | 89 scoped_refptr<DomStorageProxy> proxy_; |
85 base::WeakPtrFactory<DomStorageCachedArea> weak_factory_; | 90 base::WeakPtrFactory<DomStorageCachedArea> weak_factory_; |
| 91 |
| 92 int64 global_storage_size_; |
86 }; | 93 }; |
87 | 94 |
88 } // namespace dom_storage | 95 } // namespace dom_storage |
89 | 96 |
90 #endif // WEBKIT_DOM_STORAGE_DOM_STORAGE_CACHED_AREA_H_ | 97 #endif // WEBKIT_DOM_STORAGE_DOM_STORAGE_CACHED_AREA_H_ |
OLD | NEW |