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

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: Sync only! 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() {}
Wez 2016/04/21 00:55:02 nit: You can still DCHECK(!receiver.isValid()) dur
Kevin M 2016/04/21 21:24:07 Done.
16
17 void BlobChannelReceiver::Delegate::SetReceiver(BlobChannelReceiver* receiver) {
18 receiver_ = receiver;
19 }
20
21 void BlobChannelReceiver::Delegate::OnBlobReceived(const BlobId& id,
22 BlobDataPtr data) {
23 if (receiver_) {
24 receiver_->OnBlobReceived(id, data);
25 }
26 }
27
28 BlobChannelReceiver::BlobChannelReceiver(std::unique_ptr<BlobCache> cache,
29 std::unique_ptr<Delegate> delegate)
30 : cache_(std::move(cache)), delegate_(std::move(delegate)) {
31 DCHECK(cache_);
32 DCHECK(delegate_);
33 delegate_->SetReceiver(this);
34 }
35
36 BlobChannelReceiver::~BlobChannelReceiver() {
37 delegate_->SetReceiver(nullptr);
38 }
39
40 BlobDataPtr BlobChannelReceiver::Get(const BlobId& id) {
41 DVLOG(2) << "Get blob: " << id;
42
43 base::AutoLock lock(lock_);
44 return cache_->Get(id);
45 }
46
47 void BlobChannelReceiver::OnBlobReceived(const BlobId& id, BlobDataPtr data) {
48 DVLOG(2) << "Blob received: " << id;
49
50 base::AutoLock lock(lock_);
51 cache_->Put(id, data);
52 }
53
54 } // namespace blimp
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698