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

Side by Side Diff: blimp/common/blob_cache/in_memory_blob_cache.cc

Issue 2056993003: Add Mojo IPC for seeding new Renderer with Browser's cached blob state. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@blobchannel-master
Patch Set: STL containers yay Created 4 years, 5 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 unified diff | Download patch
OLDNEW
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 #include "blimp/common/blob_cache/in_memory_blob_cache.h" 5 #include "blimp/common/blob_cache/in_memory_blob_cache.h"
6 6
7 #include <utility>
8
7 #include "base/logging.h" 9 #include "base/logging.h"
8 10
9 namespace blimp { 11 namespace blimp {
10 12
11 InMemoryBlobCache::InMemoryBlobCache() {} 13 InMemoryBlobCache::InMemoryBlobCache() {}
12 14
13 InMemoryBlobCache::~InMemoryBlobCache() {} 15 InMemoryBlobCache::~InMemoryBlobCache() {}
14 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
15 void InMemoryBlobCache::Put(const BlobId& id, BlobDataPtr data) { 25 void InMemoryBlobCache::Put(const BlobId& id, BlobDataPtr data) {
16 if (Contains(id)) { 26 if (Contains(id)) {
17 // In cases where the engine has miscalculated what is already available 27 // In cases where the engine has miscalculated what is already available
18 // on the client, Put() might be called unnecessarily, which should be 28 // on the client, Put() might be called unnecessarily, which should be
19 // ignored. 29 // ignored.
20 VLOG(2) << "Item with ID " << id << " already exists in cache."; 30 VLOG(2) << "Item with ID " << id << " already exists in cache.";
21 return; 31 return;
22 } 32 }
23 cache_.insert(std::make_pair(id, std::move(data))); 33 cache_.insert(std::make_pair(id, std::move(data)));
24 } 34 }
25 35
26 bool InMemoryBlobCache::Contains(const BlobId& id) const { 36 bool InMemoryBlobCache::Contains(const BlobId& id) const {
27 return cache_.find(id) != cache_.end(); 37 return cache_.find(id) != cache_.end();
28 } 38 }
29 39
30 BlobDataPtr InMemoryBlobCache::Get(const BlobId& id) const { 40 BlobDataPtr InMemoryBlobCache::Get(const BlobId& id) const {
31 if (!Contains(id)) { 41 if (!Contains(id)) {
32 return nullptr; 42 return nullptr;
33 } 43 }
34 44
35 return cache_.find(id)->second; 45 return cache_.find(id)->second;
36 } 46 }
37 47
38 } // namespace blimp 48 } // namespace blimp
OLDNEW
« no previous file with comments | « blimp/common/blob_cache/in_memory_blob_cache.h ('k') | blimp/common/blob_cache/in_memory_blob_cache_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698