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

Side by Side Diff: blimp/net/blob_channel/blob_channel_sender_impl.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/net/blob_channel/blob_channel_sender_impl.h" 5 #include "blimp/net/blob_channel/blob_channel_sender_impl.h"
6 6
7 #include <utility>
8
9 #include "base/stl_util.h"
7 #include "base/strings/string_number_conversions.h" 10 #include "base/strings/string_number_conversions.h"
8 #include "blimp/common/blob_cache/blob_cache.h" 11 #include "blimp/common/blob_cache/blob_cache.h"
9 #include "blimp/common/blob_cache/id_util.h" 12 #include "blimp/common/blob_cache/id_util.h"
10 13
11 namespace blimp { 14 namespace blimp {
12 15
13 BlobChannelSenderImpl::BlobChannelSenderImpl(std::unique_ptr<BlobCache> cache, 16 BlobChannelSenderImpl::BlobChannelSenderImpl(std::unique_ptr<BlobCache> cache,
14 std::unique_ptr<Delegate> delegate) 17 std::unique_ptr<Delegate> delegate)
15 : cache_(std::move(cache)), delegate_(std::move(delegate)) { 18 : cache_(std::move(cache)), delegate_(std::move(delegate)) {
16 DCHECK(cache_); 19 DCHECK(cache_);
17 DCHECK(delegate_); 20 DCHECK(delegate_);
18 } 21 }
19 22
20 BlobChannelSenderImpl::~BlobChannelSenderImpl() {} 23 BlobChannelSenderImpl::~BlobChannelSenderImpl() {}
21 24
25 std::vector<BlobChannelSender::CacheStateEntry>
26 BlobChannelSenderImpl::GetCachedBlobIds() const {
27 const auto cache_state = cache_->GetCachedBlobIds();
28 std::vector<CacheStateEntry> output;
29 output.reserve(cache_state.size());
30 for (const std::string& cached_id : cache_state) {
31 CacheStateEntry next_output;
32 next_output.id = cached_id;
33 next_output.was_delivered =
34 ContainsKey(receiver_cache_contents_, cached_id);
35 output.push_back(next_output);
36 }
37 return output;
38 }
39
22 void BlobChannelSenderImpl::PutBlob(const BlobId& id, BlobDataPtr data) { 40 void BlobChannelSenderImpl::PutBlob(const BlobId& id, BlobDataPtr data) {
23 DCHECK(data); 41 DCHECK(data);
24 DCHECK(!id.empty()); 42 DCHECK(!id.empty());
25 43
26 if (cache_->Contains(id)) { 44 if (cache_->Contains(id)) {
27 return; 45 return;
28 } 46 }
29 47
30 VLOG(2) << "Put blob: " << BlobIdToString(id); 48 VLOG(2) << "Put blob: " << BlobIdToString(id);
31 cache_->Put(id, data); 49 cache_->Put(id, data);
32 } 50 }
33 51
34 void BlobChannelSenderImpl::DeliverBlob(const BlobId& id) { 52 void BlobChannelSenderImpl::DeliverBlob(const BlobId& id) {
35 if (!cache_->Contains(id)) { 53 if (!cache_->Contains(id)) {
36 DLOG(FATAL) << "Attempted to push unknown blob: " << BlobIdToString(id); 54 DLOG(FATAL) << "Attempted to push unknown blob: " << BlobIdToString(id);
37 return; 55 return;
38 } 56 }
39 57
40 if (receiver_cache_contents_.find(id) != receiver_cache_contents_.end()) { 58 if (receiver_cache_contents_.find(id) != receiver_cache_contents_.end()) {
41 DVLOG(3) << "Suppressed redundant push: " << BlobIdToString(id); 59 DVLOG(3) << "Suppressed redundant push: " << BlobIdToString(id);
42 return; 60 return;
43 } 61 }
44 receiver_cache_contents_.insert(id); 62 receiver_cache_contents_.insert(id);
45 63
46 VLOG(2) << "Deliver blob: " << BlobIdToString(id); 64 VLOG(2) << "Deliver blob: " << BlobIdToString(id);
47 delegate_->DeliverBlob(id, cache_->Get(id)); 65 delegate_->DeliverBlob(id, cache_->Get(id));
48 } 66 }
49 67
50 } // namespace blimp 68 } // namespace blimp
OLDNEW
« no previous file with comments | « blimp/net/blob_channel/blob_channel_sender_impl.h ('k') | blimp/net/blob_channel/blob_channel_sender_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698