Chromium Code Reviews| OLD | NEW |
|---|---|
| 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_AREA_H_ | 5 #ifndef CONTENT_RENDERER_DOM_STORAGE_LOCAL_STORAGE_AREA_H_ |
| 6 #define CONTENT_RENDERER_DOM_STORAGE_LOCAL_STORAGE_AREA_H_ | 6 #define CONTENT_RENDERER_DOM_STORAGE_LOCAL_STORAGE_AREA_H_ |
| 7 | 7 |
| 8 #include "base/macros.h" | 8 #include "base/macros.h" |
| 9 #include "content/common/leveldb_wrapper.mojom.h" | 9 #include "base/memory/ref_counted.h" |
| 10 #include "mojo/public/cpp/bindings/binding.h" | 10 #include "content/renderer/dom_storage/local_storage_cached_area.h" |
| 11 #include "third_party/WebKit/public/platform/WebStorageArea.h" | 11 #include "third_party/WebKit/public/platform/WebStorageArea.h" |
| 12 #include "url/origin.h" | |
| 13 | 12 |
| 14 namespace content { | 13 namespace content { |
| 15 class StoragePartitionService; | |
| 16 | 14 |
| 17 // Maintains a complete cache of the origin's Map of key/value pairs for fast | 15 // There could be n instances of this class for the same origin in a renderer |
| 18 // access. The cache is primed on first access and changes are written to the | 16 // process. It delegates to the one LocalStorageCachedArea instance in a process |
| 19 // backend through the level db interface pointer. Mutations originating in | 17 // for a given origin. |
| 20 // other processes are applied to the cache via the ApplyMutation method. | 18 class LocalStorageArea : public blink::WebStorageArea { |
| 21 class LocalStorageArea : public blink::WebStorageArea, | |
| 22 public LevelDBObserver { | |
| 23 public: | 19 public: |
| 24 LocalStorageArea(const url::Origin& origin, | 20 explicit LocalStorageArea(scoped_refptr<LocalStorageCachedArea> cached_area); |
| 25 StoragePartitionService* storage_partition_service); | |
| 26 ~LocalStorageArea() override; | 21 ~LocalStorageArea() override; |
| 27 | 22 |
| 28 // blink::WebStorageArea.h: | 23 // blink::WebStorageArea: |
| 29 unsigned length() override; | 24 unsigned length() override; |
| 30 blink::WebString key(unsigned index) override; | 25 blink::WebString key(unsigned index) override; |
| 31 blink::WebString getItem(const blink::WebString& key) override; | 26 blink::WebString getItem(const blink::WebString& key) override; |
| 32 void setItem(const blink::WebString& key, | 27 void setItem(const blink::WebString& key, |
| 33 const blink::WebString& value, | 28 const blink::WebString& value, |
| 34 const blink::WebURL& page_url, | 29 const blink::WebURL& page_url, |
| 35 WebStorageArea::Result& result) override; | 30 WebStorageArea::Result& result) override; |
| 36 void removeItem(const blink::WebString& key, | 31 void removeItem(const blink::WebString& key, |
| 37 const blink::WebURL& page_url) override; | 32 const blink::WebURL& page_url) override; |
| 38 void clear(const blink::WebURL& url) override; | 33 void clear(const blink::WebURL& url) override; |
| 39 | 34 |
| 40 // LevelDBObserver: | |
| 41 void KeyChanged(mojo::Array<uint8_t> key, | |
| 42 mojo::Array<uint8_t> new_value, | |
| 43 mojo::Array<uint8_t> old_value, | |
| 44 const mojo::String& source) override; | |
| 45 void KeyDeleted(mojo::Array<uint8_t> key, | |
| 46 const mojo::String& source) override; | |
| 47 void AllDeleted(const mojo::String& source) override; | |
| 48 | |
| 49 private: | 35 private: |
| 50 url::Origin origin_; | 36 scoped_refptr<LocalStorageCachedArea> cached_area_; |
|
michaeln
2016/03/01 01:38:48
hurray for smartptrs!
| |
| 51 LevelDBWrapperPtr leveldb_; | |
| 52 mojo::Binding<LevelDBObserver> binding_; | |
| 53 | 37 |
| 54 DISALLOW_COPY_AND_ASSIGN(LocalStorageArea); | 38 DISALLOW_COPY_AND_ASSIGN(LocalStorageArea); |
| 55 }; | 39 }; |
| 56 | 40 |
| 57 } // namespace content | 41 } // namespace content |
| 58 | 42 |
| 59 #endif // CONTENT_RENDERER_DOM_STORAGE_LOCAL_STORAGE_AREA_H_ | 43 #endif // CONTENT_RENDERER_DOM_STORAGE_LOCAL_STORAGE_AREA_H_ |
| OLD | NEW |