| OLD | NEW |
| (Empty) | |
| 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 |
| 3 // found in the LICENSE file. |
| 4 |
| 5 #ifndef CONTENT_RENDERER_DOM_STORAGE_LOCAL_STORAGE_CACHED_AREA_H_ |
| 6 #define CONTENT_RENDERER_DOM_STORAGE_LOCAL_STORAGE_CACHED_AREA_H_ |
| 7 |
| 8 #include "base/macros.h" |
| 9 #include "base/memory/ref_counted.h" |
| 10 #include "base/strings/nullable_string16.h" |
| 11 #include "content/common/leveldb_wrapper.mojom.h" |
| 12 #include "mojo/public/cpp/bindings/binding.h" |
| 13 #include "url/gurl.h" |
| 14 #include "url/origin.h" |
| 15 |
| 16 namespace content { |
| 17 class LocalStorageCachedAreas; |
| 18 class StoragePartitionService; |
| 19 |
| 20 // 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 |
| 22 // 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 |
| 24 // other processes are applied to the cache via LevelDBObserver callbacks. |
| 25 class LocalStorageCachedArea : public LevelDBObserver, |
| 26 public base::RefCounted<LocalStorageCachedArea> { |
| 27 public: |
| 28 LocalStorageCachedArea(const url::Origin& origin, |
| 29 StoragePartitionService* storage_partition_service, |
| 30 LocalStorageCachedAreas* cached_areas); |
| 31 |
| 32 // These correspond to blink::WebStorageArea. |
| 33 unsigned GetLength(); |
| 34 base::NullableString16 GetKey(unsigned index); |
| 35 base::NullableString16 GetItem(const base::string16& key); |
| 36 bool SetItem(const base::string16& key, |
| 37 const base::string16& value, |
| 38 const GURL& page_url); |
| 39 void RemoveItem(const base::string16& key, |
| 40 const GURL& page_url); |
| 41 void Clear(const GURL& page_url); |
| 42 |
| 43 const url::Origin& origin() { return origin_; } |
| 44 |
| 45 private: |
| 46 friend class base::RefCounted<LocalStorageCachedArea>; |
| 47 ~LocalStorageCachedArea() override; |
| 48 |
| 49 // LevelDBObserver: |
| 50 void KeyChanged(mojo::Array<uint8_t> key, |
| 51 mojo::Array<uint8_t> new_value, |
| 52 mojo::Array<uint8_t> old_value, |
| 53 const mojo::String& source) override; |
| 54 void KeyDeleted(mojo::Array<uint8_t> key, |
| 55 const mojo::String& source) override; |
| 56 void AllDeleted(const mojo::String& source) override; |
| 57 |
| 58 // Synchronously fetches the origin's local storage data if it hasn't been |
| 59 // fetched already. |
| 60 void EnsureLoaded(); |
| 61 |
| 62 bool loaded_; |
| 63 url::Origin origin_; |
| 64 LevelDBWrapperPtr leveldb_; |
| 65 mojo::Binding<LevelDBObserver> binding_; |
| 66 LocalStorageCachedAreas* cached_areas_; |
| 67 |
| 68 DISALLOW_COPY_AND_ASSIGN(LocalStorageCachedArea); |
| 69 }; |
| 70 |
| 71 } // namespace content |
| 72 |
| 73 #endif // CONTENT_RENDERER_DOM_STORAGE_LOCAL_STORAGE_CACHED_AREA_H_ |
| OLD | NEW |