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

Unified Diff: content/renderer/dom_storage/local_storage_cached_area.h

Issue 1745603002: Switch LevelDBWrapper::GetAll to use the new Mojo sync IPC mechanism. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: review comment Created 4 years, 10 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 side-by-side diff with in-line comments
Download patch
Index: content/renderer/dom_storage/local_storage_cached_area.h
diff --git a/content/renderer/dom_storage/local_storage_cached_area.h b/content/renderer/dom_storage/local_storage_cached_area.h
new file mode 100644
index 0000000000000000000000000000000000000000..4d56bbeee825aa873698484c64908bd877595472
--- /dev/null
+++ b/content/renderer/dom_storage/local_storage_cached_area.h
@@ -0,0 +1,73 @@
+// Copyright 2016 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#ifndef CONTENT_RENDERER_DOM_STORAGE_LOCAL_STORAGE_CACHED_AREA_H_
+#define CONTENT_RENDERER_DOM_STORAGE_LOCAL_STORAGE_CACHED_AREA_H_
+
+#include "base/macros.h"
+#include "base/memory/ref_counted.h"
+#include "base/strings/nullable_string16.h"
+#include "content/common/leveldb_wrapper.mojom.h"
+#include "mojo/public/cpp/bindings/binding.h"
+#include "url/gurl.h"
+#include "url/origin.h"
+
+namespace content {
+class LocalStorageCachedAreas;
+class StoragePartitionService;
+
+// An in-process implementation of LocalStorage using a LevelDB Mojo service.
+// Maintains a complete cache of the origin's Map of key/value pairs for fast
+// access. The cache is primed on first access and changes are written to the
+// backend through the level db interface pointer. Mutations originating in
+// other processes are applied to the cache via LevelDBObserver callbacks.
+class LocalStorageCachedArea : public LevelDBObserver,
+ public base::RefCounted<LocalStorageCachedArea> {
+ public:
+ LocalStorageCachedArea(const url::Origin& origin,
+ StoragePartitionService* storage_partition_service,
+ LocalStorageCachedAreas* cached_areas);
+
+ // These correspond to blink::WebStorageArea.
+ unsigned GetLength();
+ base::NullableString16 GetKey(unsigned index);
+ base::NullableString16 GetItem(const base::string16& key);
+ bool SetItem(const base::string16& key,
+ const base::string16& value,
+ const GURL& page_url);
+ void RemoveItem(const base::string16& key,
+ const GURL& page_url);
+ void Clear(const GURL& page_url);
+
+ const url::Origin& origin() { return origin_; }
+
+ private:
+ friend class base::RefCounted<LocalStorageCachedArea>;
+ ~LocalStorageCachedArea() override;
+
+ // LevelDBObserver:
+ void KeyChanged(mojo::Array<uint8_t> key,
+ mojo::Array<uint8_t> new_value,
+ mojo::Array<uint8_t> old_value,
+ const mojo::String& source) override;
+ void KeyDeleted(mojo::Array<uint8_t> key,
+ const mojo::String& source) override;
+ void AllDeleted(const mojo::String& source) override;
+
+ // Synchronously fetches the origin's local storage data if it hasn't been
+ // fetched already.
+ void EnsureLoaded();
+
+ bool loaded_;
+ url::Origin origin_;
+ LevelDBWrapperPtr leveldb_;
+ mojo::Binding<LevelDBObserver> binding_;
+ LocalStorageCachedAreas* cached_areas_;
+
+ DISALLOW_COPY_AND_ASSIGN(LocalStorageCachedArea);
+};
+
+} // namespace content
+
+#endif // CONTENT_RENDERER_DOM_STORAGE_LOCAL_STORAGE_CACHED_AREA_H_
« 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