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

Side by Side Diff: blimp/net/blob_channel/blob_channel_receiver.cc

Issue 1970463004: Blimp: Add BlobChannel Helium messages and delegate impls. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 4 years, 7 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_receiver.h" 5 #include "blimp/net/blob_channel/blob_channel_receiver.h"
6 6
7 #include "base/logging.h" 7 #include "base/logging.h"
8 #include "base/macros.h" 8 #include "base/macros.h"
9 #include "blimp/common/blob_cache/blob_cache.h" 9 #include "blimp/common/blob_cache/blob_cache.h"
10 10
11 namespace blimp { 11 namespace blimp {
12 12
13 BlobChannelReceiver::Delegate::Delegate() {} 13 BlobChannelReceiver::Delegate::Delegate() {}
14 14
15 BlobChannelReceiver::Delegate::~Delegate() { 15 BlobChannelReceiver::Delegate::~Delegate() {
16 DCHECK(!receiver_); 16 DCHECK(receiver_);
17 } 17 }
18 18
19 void BlobChannelReceiver::Delegate::SetReceiver(BlobChannelReceiver* receiver) { 19 void BlobChannelReceiver::Delegate::SetReceiver(BlobChannelReceiver* receiver) {
20 DCHECK(receiver);
21 DCHECK(!receiver_);
22
20 receiver_ = receiver; 23 receiver_ = receiver;
21 } 24 }
22 25
23 void BlobChannelReceiver::Delegate::OnBlobReceived(const BlobId& id, 26 void BlobChannelReceiver::Delegate::OnBlobReceived(const BlobId& id,
24 BlobDataPtr data) { 27 BlobDataPtr data) {
haibinlu 2016/05/12 18:20:09 DCHECK not needed?
Kevin M 2016/05/13 18:40:24 Done.
25 if (receiver_) { 28 DCHECK(receiver_);
26 receiver_->OnBlobReceived(id, data); 29
27 } 30 receiver_->OnBlobReceived(id, data);
28 } 31 }
29 32
30 BlobChannelReceiver::BlobChannelReceiver(std::unique_ptr<BlobCache> cache, 33 BlobChannelReceiver::BlobChannelReceiver() {}
31 std::unique_ptr<Delegate> delegate) 34
35 BlobChannelReceiver::~BlobChannelReceiver() {}
36
37 BlobChannelReceiverImpl::BlobChannelReceiverImpl(
38 std::unique_ptr<BlobCache> cache,
39 std::unique_ptr<Delegate> delegate)
32 : cache_(std::move(cache)), delegate_(std::move(delegate)) { 40 : cache_(std::move(cache)), delegate_(std::move(delegate)) {
33 DCHECK(cache_); 41 DCHECK(cache_);
42 DCHECK(delegate_);
haibinlu 2016/05/12 18:20:09 ditto
Kevin M 2016/05/13 18:40:24 Done.
43
34 delegate_->SetReceiver(this); 44 delegate_->SetReceiver(this);
35 } 45 }
36 46
37 BlobChannelReceiver::~BlobChannelReceiver() { 47 BlobChannelReceiverImpl::~BlobChannelReceiverImpl() {}
38 delegate_->SetReceiver(nullptr);
39 }
40 48
41 BlobDataPtr BlobChannelReceiver::Get(const BlobId& id) { 49 BlobDataPtr BlobChannelReceiverImpl::Get(const BlobId& id) {
42 DVLOG(2) << "Get blob: " << id; 50 DVLOG(2) << "Get blob: " << id;
43 51
44 base::AutoLock lock(cache_lock_); 52 base::AutoLock lock(cache_lock_);
45 return cache_->Get(id); 53 return cache_->Get(id);
46 } 54 }
47 55
48 void BlobChannelReceiver::OnBlobReceived(const BlobId& id, BlobDataPtr data) { 56 void BlobChannelReceiverImpl::OnBlobReceived(const BlobId& id,
57 BlobDataPtr data) {
49 DVLOG(2) << "Blob received: " << id; 58 DVLOG(2) << "Blob received: " << id;
50 59
51 base::AutoLock lock(cache_lock_); 60 base::AutoLock lock(cache_lock_);
52 cache_->Put(id, data); 61 cache_->Put(id, data);
53 } 62 }
54 63
55 } // namespace blimp 64 } // namespace blimp
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698