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

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: Mojo mapz 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 "base/strings/string_number_conversions.h" 7 #include "base/strings/string_number_conversions.h"
8 #include "blimp/common/blob_cache/blob_cache.h" 8 #include "blimp/common/blob_cache/blob_cache.h"
9 #include "blimp/common/blob_cache/id_util.h" 9 #include "blimp/common/blob_cache/id_util.h"
10 10
11 namespace blimp { 11 namespace blimp {
12 12
13 BlobChannelSenderImpl::BlobChannelSenderImpl(std::unique_ptr<BlobCache> cache, 13 BlobChannelSenderImpl::BlobChannelSenderImpl(std::unique_ptr<BlobCache> cache,
14 std::unique_ptr<Delegate> delegate) 14 std::unique_ptr<Delegate> delegate)
15 : cache_(std::move(cache)), delegate_(std::move(delegate)) { 15 : cache_(std::move(cache)), delegate_(std::move(delegate)) {
16 DCHECK(cache_); 16 DCHECK(cache_);
17 DCHECK(delegate_); 17 DCHECK(delegate_);
18 } 18 }
19 19
20 BlobChannelSenderImpl::~BlobChannelSenderImpl() {} 20 BlobChannelSenderImpl::~BlobChannelSenderImpl() {}
21 21
22 std::vector<BlobChannelSender::CacheStateEntry>
23 BlobChannelSenderImpl::GetCachedBlobIds() const {
24 const auto cache_state = cache_->GetCachedBlobIds();
25 std::vector<CacheStateEntry> output;
26 output.reserve(cache_state.size());
27 for (const std::string& next_item_str : cache_state) {
Wez 2016/07/01 00:30:21 nit: Why not cache_entry, or just cached_id or blo
Kevin M 2016/07/18 16:58:16 Done.
28 CacheStateEntry next_output;
29 next_output.id = next_item_str;
30 next_output.was_delivered = receiver_cache_contents_.find(next_item_str) !=
31 receiver_cache_contents_.end();
32 output.push_back(next_output);
33 }
34 return output;
35 }
36
22 void BlobChannelSenderImpl::PutBlob(const BlobId& id, BlobDataPtr data) { 37 void BlobChannelSenderImpl::PutBlob(const BlobId& id, BlobDataPtr data) {
23 DCHECK(data); 38 DCHECK(data);
24 DCHECK(!id.empty()); 39 DCHECK(!id.empty());
25 40
26 if (cache_->Contains(id)) { 41 if (cache_->Contains(id)) {
27 return; 42 return;
28 } 43 }
29 44
30 VLOG(2) << "Put blob: " << BlobIdToString(id); 45 VLOG(2) << "Put blob: " << BlobIdToString(id);
31 cache_->Put(id, data); 46 cache_->Put(id, data);
32 } 47 }
33 48
34 void BlobChannelSenderImpl::DeliverBlob(const BlobId& id) { 49 void BlobChannelSenderImpl::DeliverBlob(const BlobId& id) {
35 if (!cache_->Contains(id)) { 50 if (!cache_->Contains(id)) {
36 DLOG(FATAL) << "Attempted to push unknown blob: " << BlobIdToString(id); 51 DLOG(FATAL) << "Attempted to push unknown blob: " << BlobIdToString(id);
37 return; 52 return;
38 } 53 }
39 54
40 if (receiver_cache_contents_.find(id) != receiver_cache_contents_.end()) { 55 if (receiver_cache_contents_.find(id) != receiver_cache_contents_.end()) {
41 DVLOG(3) << "Suppressed redundant push: " << BlobIdToString(id); 56 DVLOG(3) << "Suppressed redundant push: " << BlobIdToString(id);
42 return; 57 return;
43 } 58 }
44 receiver_cache_contents_.insert(id); 59 receiver_cache_contents_.insert(id);
45 60
46 VLOG(2) << "Deliver blob: " << BlobIdToString(id); 61 VLOG(2) << "Deliver blob: " << BlobIdToString(id);
47 delegate_->DeliverBlob(id, cache_->Get(id)); 62 delegate_->DeliverBlob(id, cache_->Get(id));
48 } 63 }
49 64
50 } // namespace blimp 65 } // namespace blimp
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698