Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(229)

Side by Side Diff: webkit/dom_storage/dom_storage_cached_area.h

Issue 10450009: DomStorageCachedArea + DomStorageProxy interface and unittests. These classes aren't used yet. (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: Created 8 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « no previous file | webkit/dom_storage/dom_storage_cached_area.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Property Changes:
Added: svn:eol-style
+ LF
OLDNEW
(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 // Unlike the other classes in the dom_storage library, this one is intended
22 // for use in renderer processes. It maintains a complete cach of the an
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|.
25 // Mutations originating in other processes are applied to the cache via
26 // the ApplyMutation method.
27 class DomStorageCachedArea : public base::RefCounted<DomStorageCachedArea> {
28 public:
29 DomStorageCachedArea(int64 namespace_id, const GURL& origin,
30 DomStorageProxy* proxy);
31
32 int64 namespace_id() const { return namespace_id_; }
33 const GURL& origin() const { return origin_; }
34
35 unsigned GetLength(int connection_id);
36 NullableString16 GetKey(int connection_id, unsigned index);
37 NullableString16 GetItem(int connection_id, const string16& key);
38 bool SetItem(int connection_id, const string16& key, const string16& value,
39 const GURL& page_url);
40 void RemoveItem(int connection_id, const string16& key,
41 const GURL& page_url);
42 void Clear(int connection_id, const GURL& page_url);
43
44 void ApplyMutation(const NullableString16& key,
45 const NullableString16& new_value);
46
47 private:
48 friend class DomStorageCachedAreaTest;
49 friend class base::RefCounted<DomStorageCachedArea>;
50 ~DomStorageCachedArea();
51
52 // Primes the cache, loading all values for the area.
53 void Prime(int connection_id);
54 void PrimeIfNeeded(int connection_id) {
55 if (!map_)
56 Prime(connection_id);
57 }
58
59 // Resets the object back to its newly constructed state.
60 void Reset();
61
62 // Async completion callbacks for proxied operations.
63 // These are used to maintain cache consistency by preventing
64 // mutation events from other processes from overwriting local
65 // changes made after the mutation.
66 void OnLoadComplete(bool success);
67 void OnSetItemComplete(const string16& key, bool success);
68 void OnClearComplete(bool success);
69 void OnRemoveItemComplete(const string16& key, bool success);
70
71 bool should_ignore_key_mutation(const string16& key) const {
72 return ignore_key_mutations_.find(key) != ignore_key_mutations_.end();
73 }
74
75 bool ignore_all_mutations_;
76 std::map<string16, int> ignore_key_mutations_;
77
78 int64 namespace_id_;
79 GURL origin_;
80 scoped_refptr<DomStorageMap> map_;
81 scoped_refptr<DomStorageProxy> proxy_;
82 base::WeakPtrFactory<DomStorageCachedArea> weak_factory_;
83 };
84
85 } // namespace dom_storage
86
87 #endif // WEBKIT_DOM_STORAGE_DOM_STORAGE_CACHED_AREA_H_
OLDNEW
« no previous file with comments | « no previous file | webkit/dom_storage/dom_storage_cached_area.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698