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

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, 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
(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 delegate_->SetReceiver(this);
35 }
36
37 BlobChannelReceiver::~BlobChannelReceiver() {
38 delegate_->SetReceiver(nullptr);
39 }
40
41 BlobDataPtr BlobChannelReceiver::Get(const BlobId& id) {
42 DVLOG(2) << "Get blob: " << id;
43
44 base::AutoLock lock(cache_lock_);
45 return cache_->Get(id);
46 }
47
48 void BlobChannelReceiver::OnBlobReceived(const BlobId& id, BlobDataPtr data) {
49 DVLOG(2) << "Blob received: " << id;
50
51 base::AutoLock lock(cache_lock_);
52 cache_->Put(id, data);
53 }
54
55 } // namespace blimp
OLDNEW
« no previous file with comments | « blimp/net/blob_channel/blob_channel_receiver.h ('k') | blimp/net/blob_channel/blob_channel_receiver_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698