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

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

Issue 2632803002: Remove all blimp network code. (Closed)
Patch Set: merge from origin/master for good measure Created 3 years, 11 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 "base/memory/ptr_util.h"
10 #include "blimp/common/blob_cache/blob_cache.h"
11 #include "blimp/common/blob_cache/id_util.h"
12
13 namespace blimp {
14 namespace {
15
16 // Takes incoming blobs from |delegate_| stores them in |cache_|, and provides
17 // callers a getter interface for accessing blobs from |cache_|.
18 class BLIMP_NET_EXPORT BlobChannelReceiverImpl : public BlobChannelReceiver {
19 public:
20 BlobChannelReceiverImpl(std::unique_ptr<BlobCache> cache,
21 std::unique_ptr<Delegate> delegate);
22 ~BlobChannelReceiverImpl() override;
23
24 // BlobChannelReceiver implementation.
25 BlobDataPtr Get(const BlobId& id) override;
26 void OnBlobReceived(const BlobId& id, BlobDataPtr data) override;
27
28 private:
29 std::unique_ptr<BlobCache> cache_;
30 std::unique_ptr<Delegate> delegate_;
31
32 // Guards against concurrent access to |cache_|.
33 base::Lock cache_lock_;
34
35 DISALLOW_COPY_AND_ASSIGN(BlobChannelReceiverImpl);
36 };
37
38 } // namespace
39
40 // static
41 std::unique_ptr<BlobChannelReceiver> BlobChannelReceiver::Create(
42 std::unique_ptr<BlobCache> cache,
43 std::unique_ptr<Delegate> delegate) {
44 return base::WrapUnique(
45 new BlobChannelReceiverImpl(std::move(cache), std::move(delegate)));
46 }
47
48 BlobChannelReceiverImpl::BlobChannelReceiverImpl(
49 std::unique_ptr<BlobCache> cache,
50 std::unique_ptr<Delegate> delegate)
51 : cache_(std::move(cache)), delegate_(std::move(delegate)) {
52 DCHECK(cache_);
53
54 delegate_->SetReceiver(this);
55 }
56
57 BlobChannelReceiverImpl::~BlobChannelReceiverImpl() {}
58
59 BlobDataPtr BlobChannelReceiverImpl::Get(const BlobId& id) {
60 DVLOG(2) << "Get blob: " << BlobIdToString(id);
61
62 base::AutoLock lock(cache_lock_);
63 return cache_->Get(id);
64 }
65
66 void BlobChannelReceiverImpl::OnBlobReceived(const BlobId& id,
67 BlobDataPtr data) {
68 DVLOG(2) << "Blob received: " << BlobIdToString(id)
69 << ", size: " << data->data.size();
70
71 base::AutoLock lock(cache_lock_);
72 cache_->Put(id, data);
73 }
74
75 } // 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