|
OLD | NEW |
---|---|
(Empty) | |
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 | |
3 // found in the LICENSE file. | |
4 | |
5 #ifndef WEBKIT_DOM_STORAGE_DOM_STORAGE_CACHED_AREA_H_ | |
6 #define WEBKIT_DOM_STORAGE_DOM_STORAGE_CACHED_AREA_H_ | |
7 #pragma once | |
8 | |
9 #include <map> | |
10 | |
11 #include "base/memory/ref_counted.h" | |
12 #include "base/memory/weak_ptr.h" | |
13 #include "base/nullable_string16.h" | |
14 #include "googleurl/src/gurl.h" | |
15 | |
16 namespace dom_storage { | |
17 | |
18 class DomStorageMap; | |
19 class DomStorageProxy; | |
20 | |
21 class DomStorageCachedArea : public base::RefCounted<DomStorageCachedArea> { | |
22 public: | |
23 DomStorageCachedArea(int64 namespace_id, const GURL& origin, | |
24 DomStorageProxy* proxy); | |
25 | |
26 int64 namespace_id() const { return namespace_id_; } | |
27 const GURL& origin() const { return origin_; } | |
28 | |
29 unsigned GetLength(int connection_id); | |
30 NullableString16 GetKey(int connection_id, unsigned index); | |
31 NullableString16 GetItem(int connection_id, const string16& key); | |
32 bool SetItem(int connection_id, const string16& key, const string16& value, | |
33 const GURL& page_url); | |
34 void RemoveItem(int connection_id, const string16& key, | |
35 const GURL& page_url); | |
36 void Clear(int connection_id, const GURL& page_url); | |
37 | |
38 void ApplyMutation(const NullableString16& key, | |
39 const NullableString16& new_value); | |
40 | |
41 private: | |
42 friend class DomStorageCachedAreaTest; | |
43 friend class base::RefCounted<DomStorageCachedArea>; | |
44 ~DomStorageCachedArea(); | |
45 | |
46 // Primes the cache, loading all values for the area. | |
jsbell
2012/05/24 20:20:22
Can you add a comment near the top of the class in
michaeln
2012/05/24 20:43:11
Done.
// Unlike the other classes in the dom_stor
| |
47 void Prime(int connection_id); | |
48 void PrimeIfNeeded(int connection_id) { | |
49 if (!map_) | |
50 Prime(connection_id); | |
51 } | |
52 | |
53 // Resets the class back to its newly constructed state. | |
jsbell
2012/05/24 20:20:22
Nit: s/class/object/
michaeln
2012/05/24 20:43:11
Done.
| |
54 void Reset(); | |
55 | |
56 // Async completion callbacks for proxied operations. | |
57 // These are used to maintain cache consistency by preventing | |
58 // mutation events from other processes from overwriting local | |
59 // changes made after the mutation. | |
60 void OnLoadComplete(bool success); | |
61 void OnSetItemComplete(const string16& key, bool success); | |
62 void OnClearComplete(bool success); | |
63 void OnRemoveItemComplete(const string16& key, bool success); | |
64 | |
65 bool should_ignore_key_mutation(const string16& key) const { | |
66 return ignore_key_mutations_.find(key) != ignore_key_mutations_.end(); | |
67 } | |
68 | |
69 bool ignore_all_mutations_; | |
70 std::map<string16, int> ignore_key_mutations_; | |
71 | |
72 int64 namespace_id_; | |
73 GURL origin_; | |
74 scoped_refptr<DomStorageMap> map_; | |
75 scoped_refptr<DomStorageProxy> proxy_; | |
76 base::WeakPtrFactory<DomStorageCachedArea> weak_factory_; | |
77 }; | |
78 | |
79 } // namespace dom_storage | |
80 | |
81 #endif // WEBKIT_DOM_STORAGE_DOM_STORAGE_CACHED_AREA_H_ | |
OLD | NEW |