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

Unified Diff: blimp/common/blob_cache/in_memory_blob_cache.cc

Issue 1867653002: Initial version of Blimp BlobCache. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Addressed comments from kmarshall, except swap Created 4 years, 8 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: blimp/common/blob_cache/in_memory_blob_cache.cc
diff --git a/blimp/common/blob_cache/in_memory_blob_cache.cc b/blimp/common/blob_cache/in_memory_blob_cache.cc
new file mode 100644
index 0000000000000000000000000000000000000000..7dc2dd9baa840349d13c6b1d6ee7121cf8e88de4
--- /dev/null
+++ b/blimp/common/blob_cache/in_memory_blob_cache.cc
@@ -0,0 +1,40 @@
+// 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.
+
+#include "blimp/common/blob_cache/in_memory_blob_cache.h"
+
+#include "base/logging.h"
+#include "base/sha1.h"
+#include "base/strings/string_number_conversions.h"
+#include "base/strings/string_util.h"
+
+namespace blimp {
+
+InMemoryBlobCache::InMemoryBlobCache() {}
+
+InMemoryBlobCache::~InMemoryBlobCache() {}
+
+void InMemoryBlobCache::Put(const std::string& id,
+ scoped_refptr<RefCountedVector> data) {
+ if (Contains(id)) {
+ DLOG(WARNING) << "Item with ID " << id << " already exists in cache.";
vmpstr 2016/04/15 18:18:54 If this is not an expected scenario, then it shoul
nyquist 2016/04/16 00:25:29 Done.
+ return;
+ }
+ map_.insert(std::make_pair(id, data));
vmpstr 2016/04/15 18:18:54 you can std::move(data) here to avoid ref/unref if
nyquist 2016/04/16 00:25:29 Done.
+}
+
+bool InMemoryBlobCache::Contains(const std::string& id) const {
+ return map_.find(id) != map_.end();
+}
+
+scoped_refptr<RefCountedVector> InMemoryBlobCache::Get(
+ const std::string& id) const {
+ if (!Contains(id)) {
+ return nullptr;
+ }
+
+ return map_.find(id)->second;
+}
+
+} // namespace blimp

Powered by Google App Engine
This is Rietveld 408576698