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

Side by Side Diff: content/renderer/dom_storage/local_storage_cached_area.h

Issue 1814003002: Implement the renderer side of the mojo based local storage implementation. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: review comments Created 4 years, 9 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
OLDNEW
1 // Copyright 2016 The Chromium Authors. All rights reserved. 1 // Copyright 2016 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_LOCAL_STORAGE_CACHED_AREA_H_ 5 #ifndef CONTENT_RENDERER_DOM_STORAGE_LOCAL_STORAGE_CACHED_AREA_H_
6 #define CONTENT_RENDERER_DOM_STORAGE_LOCAL_STORAGE_CACHED_AREA_H_ 6 #define CONTENT_RENDERER_DOM_STORAGE_LOCAL_STORAGE_CACHED_AREA_H_
7 7
8 #include <map>
9
8 #include "base/macros.h" 10 #include "base/macros.h"
9 #include "base/memory/ref_counted.h" 11 #include "base/memory/ref_counted.h"
10 #include "base/strings/nullable_string16.h" 12 #include "base/strings/nullable_string16.h"
11 #include "content/common/leveldb_wrapper.mojom.h" 13 #include "content/common/leveldb_wrapper.mojom.h"
12 #include "mojo/public/cpp/bindings/binding.h" 14 #include "mojo/public/cpp/bindings/binding.h"
13 #include "url/gurl.h" 15 #include "url/gurl.h"
14 #include "url/origin.h" 16 #include "url/origin.h"
15 17
16 namespace content { 18 namespace content {
19 class DOMStorageMap;
20 class LocalStorageArea;
17 class LocalStorageCachedAreas; 21 class LocalStorageCachedAreas;
18 class StoragePartitionService; 22 class StoragePartitionService;
19 23
20 // An in-process implementation of LocalStorage using a LevelDB Mojo service. 24 // An in-process implementation of LocalStorage using a LevelDB Mojo service.
21 // Maintains a complete cache of the origin's Map of key/value pairs for fast 25 // Maintains a complete cache of the origin's Map of key/value pairs for fast
22 // access. The cache is primed on first access and changes are written to the 26 // access. The cache is primed on first access and changes are written to the
23 // backend through the level db interface pointer. Mutations originating in 27 // backend through the level db interface pointer. Mutations originating in
24 // other processes are applied to the cache via LevelDBObserver callbacks. 28 // other processes are applied to the cache via LevelDBObserver callbacks.
29 // There is one LocalStorageCachedArea for potentially many LocalStorageArea
30 // objects.
25 class LocalStorageCachedArea : public LevelDBObserver, 31 class LocalStorageCachedArea : public LevelDBObserver,
26 public base::RefCounted<LocalStorageCachedArea> { 32 public base::RefCounted<LocalStorageCachedArea> {
27 public: 33 public:
28 LocalStorageCachedArea(const url::Origin& origin, 34 LocalStorageCachedArea(const url::Origin& origin,
29 StoragePartitionService* storage_partition_service, 35 StoragePartitionService* storage_partition_service,
30 LocalStorageCachedAreas* cached_areas); 36 LocalStorageCachedAreas* cached_areas);
31 37
32 // These correspond to blink::WebStorageArea. 38 // These correspond to blink::WebStorageArea.
33 unsigned GetLength(); 39 unsigned GetLength();
34 base::NullableString16 GetKey(unsigned index); 40 base::NullableString16 GetKey(unsigned index);
35 base::NullableString16 GetItem(const base::string16& key); 41 base::NullableString16 GetItem(const base::string16& key);
36 bool SetItem(const base::string16& key, 42 bool SetItem(const base::string16& key,
37 const base::string16& value, 43 const base::string16& value,
38 const GURL& page_url); 44 const GURL& page_url,
45 const std::string& storage_area_id);
39 void RemoveItem(const base::string16& key, 46 void RemoveItem(const base::string16& key,
40 const GURL& page_url); 47 const GURL& page_url,
41 void Clear(const GURL& page_url); 48 const std::string& storage_area_id);
49 void Clear(const GURL& page_url, const std::string& storage_area_id);
50
51 // Allow this object to keep track of the LocalStorageAreas corresponding to
52 // it, which is needed for mutation event notifications.
53 void AreaCreated(LocalStorageArea* area);
54 void AreaDestroyed(LocalStorageArea* area);
42 55
43 const url::Origin& origin() { return origin_; } 56 const url::Origin& origin() { return origin_; }
44 57
45 private: 58 private:
46 friend class base::RefCounted<LocalStorageCachedArea>; 59 friend class base::RefCounted<LocalStorageCachedArea>;
47 ~LocalStorageCachedArea() override; 60 ~LocalStorageCachedArea() override;
48 61
49 // LevelDBObserver: 62 // LevelDBObserver:
50 void KeyChanged(mojo::Array<uint8_t> key, 63 void KeyChanged(mojo::Array<uint8_t> key,
51 mojo::Array<uint8_t> new_value, 64 mojo::Array<uint8_t> new_value,
52 mojo::Array<uint8_t> old_value, 65 mojo::Array<uint8_t> old_value,
53 const mojo::String& source) override; 66 const mojo::String& source) override;
54 void KeyDeleted(mojo::Array<uint8_t> key, 67 void KeyDeleted(mojo::Array<uint8_t> key,
68 mojo::Array<uint8_t> old_value,
55 const mojo::String& source) override; 69 const mojo::String& source) override;
56 void AllDeleted(const mojo::String& source) override; 70 void AllDeleted(const mojo::String& source) override;
57 71
58 // Synchronously fetches the origin's local storage data if it hasn't been 72 // Synchronously fetches the origin's local storage data if it hasn't been
59 // fetched already. 73 // fetched already.
60 void EnsureLoaded(); 74 void EnsureLoaded();
61 75
76 void OnSetItemComplete(const base::string16& key,
77 leveldb::DatabaseError result);
78 void OnRemoveItemComplete(const base::string16& key,
79 leveldb::DatabaseError result);
80 void OnClearComplete(leveldb::DatabaseError result);
81
82 // Resets the object back to its newly constructed state.
83 void Reset();
84
62 bool loaded_; 85 bool loaded_;
63 url::Origin origin_; 86 url::Origin origin_;
87 scoped_refptr<DOMStorageMap> map_;
88 std::map<base::string16, int> ignore_key_mutations_;
64 LevelDBWrapperPtr leveldb_; 89 LevelDBWrapperPtr leveldb_;
65 mojo::Binding<LevelDBObserver> binding_; 90 mojo::Binding<LevelDBObserver> binding_;
66 LocalStorageCachedAreas* cached_areas_; 91 LocalStorageCachedAreas* cached_areas_;
92 std::map<std::string, LocalStorageArea*> areas_;
67 93
68 DISALLOW_COPY_AND_ASSIGN(LocalStorageCachedArea); 94 DISALLOW_COPY_AND_ASSIGN(LocalStorageCachedArea);
69 }; 95 };
70 96
71 } // namespace content 97 } // namespace content
72 98
73 #endif // CONTENT_RENDERER_DOM_STORAGE_LOCAL_STORAGE_CACHED_AREA_H_ 99 #endif // CONTENT_RENDERER_DOM_STORAGE_LOCAL_STORAGE_CACHED_AREA_H_
OLDNEW
« no previous file with comments | « content/renderer/dom_storage/local_storage_area.cc ('k') | content/renderer/dom_storage/local_storage_cached_area.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698