| 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 #include "blimp/common/blob_cache/in_memory_blob_cache.h" | |
| 6 | |
| 7 #include <utility> | |
| 8 | |
| 9 #include "base/logging.h" | |
| 10 | |
| 11 namespace blimp { | |
| 12 | |
| 13 InMemoryBlobCache::InMemoryBlobCache() {} | |
| 14 | |
| 15 InMemoryBlobCache::~InMemoryBlobCache() {} | |
| 16 | |
| 17 std::vector<BlobId> InMemoryBlobCache::GetCachedBlobIds() const { | |
| 18 std::vector<BlobId> cached_ids; | |
| 19 for (const auto& blob_id_and_data_pair : cache_) { | |
| 20 cached_ids.push_back(blob_id_and_data_pair.first); | |
| 21 } | |
| 22 return cached_ids; | |
| 23 } | |
| 24 | |
| 25 void InMemoryBlobCache::Put(const BlobId& id, BlobDataPtr data) { | |
| 26 if (Contains(id)) { | |
| 27 // In cases where the engine has miscalculated what is already available | |
| 28 // on the client, Put() might be called unnecessarily, which should be | |
| 29 // ignored. | |
| 30 VLOG(2) << "Item with ID " << id << " already exists in cache."; | |
| 31 return; | |
| 32 } | |
| 33 cache_.insert(std::make_pair(id, std::move(data))); | |
| 34 } | |
| 35 | |
| 36 bool InMemoryBlobCache::Contains(const BlobId& id) const { | |
| 37 return cache_.find(id) != cache_.end(); | |
| 38 } | |
| 39 | |
| 40 BlobDataPtr InMemoryBlobCache::Get(const BlobId& id) const { | |
| 41 if (!Contains(id)) { | |
| 42 return nullptr; | |
| 43 } | |
| 44 | |
| 45 return cache_.find(id)->second; | |
| 46 } | |
| 47 | |
| 48 } // namespace blimp | |
| OLD | NEW |