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

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

Issue 1891083002: Blimp: Add BlobChannelReceiver and bindings interface. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@blobchannel-sender
Patch Set: wez feedback Created 4 years, 8 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
(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/net/blob_channel/blob_channel_receiver.h"
6
7 #include "base/logging.h"
8 #include "base/macros.h"
9 #include "blimp/common/blob_cache/blob_cache.h"
10
11 namespace blimp {
12
13 BlobChannelReceiver::Delegate::Delegate() {}
14
15 BlobChannelReceiver::Delegate::~Delegate() {
16 DCHECK(!receiver_);
17 }
18
19 void BlobChannelReceiver::Delegate::SetReceiver(BlobChannelReceiver* receiver) {
20 receiver_ = receiver;
21 }
22
23 void BlobChannelReceiver::Delegate::OnBlobReceived(const BlobId& id,
24 BlobDataPtr data) {
25 if (receiver_) {
26 receiver_->OnBlobReceived(id, data);
27 }
28 }
29
30 BlobChannelReceiver::BlobChannelReceiver(std::unique_ptr<BlobCache> cache,
31 std::unique_ptr<Delegate> delegate)
32 : cache_(std::move(cache)), delegate_(std::move(delegate)) {
33 DCHECK(cache_);
34 DCHECK(delegate_);
35 delegate_->SetReceiver(this);
36 }
37
38 BlobChannelReceiver::~BlobChannelReceiver() {
39 delegate_->SetReceiver(nullptr);
40 }
41
42 BlobDataPtr BlobChannelReceiver::Get(const BlobId& id) {
43 DVLOG(2) << "Get blob: " << id;
44
45 base::AutoLock lock(lock_);
46 return cache_->Get(id);
47 }
48
49 void BlobChannelReceiver::OnBlobReceived(const BlobId& id, BlobDataPtr data) {
50 DVLOG(2) << "Blob received: " << id;
51
52 base::AutoLock lock(lock_);
53 cache_->Put(id, data);
54 }
55
56 } // namespace blimp
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698