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

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

Issue 1970463004: Blimp: Add BlobChannel Helium messages and delegate impls. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: haibinlu 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
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 #ifndef BLIMP_NET_BLOB_CHANNEL_BLOB_CHANNEL_RECEIVER_H_ 5 #ifndef BLIMP_NET_BLOB_CHANNEL_BLOB_CHANNEL_RECEIVER_H_
6 #define BLIMP_NET_BLOB_CHANNEL_BLOB_CHANNEL_RECEIVER_H_ 6 #define BLIMP_NET_BLOB_CHANNEL_BLOB_CHANNEL_RECEIVER_H_
7 7
8 #include "base/macros.h" 8 #include "base/macros.h"
9 #include "base/memory/ref_counted.h" 9 #include "base/memory/ref_counted.h"
10 #include "base/synchronization/lock.h" 10 #include "base/synchronization/lock.h"
11 #include "blimp/common/blob_cache/blob_cache.h" 11 #include "blimp/common/blob_cache/blob_cache.h"
12 #include "blimp/net/blimp_message_processor.h" 12 #include "blimp/net/blimp_message_processor.h"
13 #include "blimp/net/blimp_net_export.h" 13 #include "blimp/net/blimp_net_export.h"
14 14
15 namespace blimp { 15 namespace blimp {
16 16
17 class BlobCache; 17 class BlobCache;
18 18
19 // Receives blobs from a remote sender.
20 class BLIMP_NET_EXPORT BlobChannelReceiver { 19 class BLIMP_NET_EXPORT BlobChannelReceiver {
21 public: 20 public:
22 class Delegate { 21 class Delegate {
23 public: 22 public:
24 Delegate(); 23 Delegate();
25 virtual ~Delegate(); 24 virtual ~Delegate();
26 25
26 // Sets the Receiver object which will take incoming blobs.
27 void SetReceiver(BlobChannelReceiver* receiver);
28
27 protected: 29 protected:
28 // Forwards incoming blob data to |receiver_|. 30 // Forwards incoming blob data to |receiver_|.
29 void OnBlobReceived(const BlobId& id, BlobDataPtr data); 31 void OnBlobReceived(const BlobId& id, BlobDataPtr data);
30 32
31 private: 33 private:
32 friend class BlobChannelReceiver;
33
34 // Sets the Receiver object which will take incoming blobs.
35 void SetReceiver(BlobChannelReceiver* receiver);
36
37 BlobChannelReceiver* receiver_ = nullptr; 34 BlobChannelReceiver* receiver_ = nullptr;
38 35
39 DISALLOW_COPY_AND_ASSIGN(Delegate); 36 DISALLOW_COPY_AND_ASSIGN(Delegate);
40 }; 37 };
41 38
42 BlobChannelReceiver(std::unique_ptr<BlobCache> cache, 39 BlobChannelReceiver();
Wez 2016/05/20 21:46:17 This is a pure interface, so no need for ctor to b
Kevin M 2016/05/23 20:48:07 Done.
43 std::unique_ptr<Delegate> delegate); 40 virtual ~BlobChannelReceiver();
Wez 2016/05/20 21:46:17 Pure interface, so no-op virtual dtor can be decla
Kevin M 2016/05/23 20:48:07 Done.
44 ~BlobChannelReceiver();
45 41
46 // Gets a blob from the BlobChannel. 42 // Gets a blob from the BlobChannel.
47 // Returns nullptr if the blob is not available in the channel. 43 // Returns nullptr if the blob is not available in the channel.
48 // Can be accessed concurrently from any thread. Calling code must ensure that 44 // Can be accessed concurrently from any thread. Calling code must ensure that
49 // the object instance outlives all calls to Get(). 45 // the object instance outlives all calls to Get().
50 BlobDataPtr Get(const BlobId& id); 46 virtual BlobDataPtr Get(const BlobId& id) = 0;
47
48 // Called by Delegate::OnBlobReceived() when a blob arrives over the channel.
49 virtual void OnBlobReceived(const BlobId& id, BlobDataPtr data) = 0;
50 };
51
52 // Receives blobs from a remote sender.
Wez 2016/05/20 21:46:17 And does what with them? :)
Kevin M 2016/05/23 20:48:07 Done.
53 class BLIMP_NET_EXPORT BlobChannelReceiverImpl : public BlobChannelReceiver {
Wez 2016/05/20 21:46:17 Rather than declare this implementation in the hea
Kevin M 2016/05/23 20:48:07 Done.
54 public:
55 BlobChannelReceiverImpl(std::unique_ptr<BlobCache> cache,
56 std::unique_ptr<Delegate> delegate);
57 ~BlobChannelReceiverImpl() override;
58
59 // BlobChannelReceiver implementation.
60 BlobDataPtr Get(const BlobId& id) override;
61 void OnBlobReceived(const BlobId& id, BlobDataPtr data) override;
51 62
52 private: 63 private:
53 friend class Delegate;
54
55 // Called by Delegate::OnBlobReceived() when a blob arrives over the channel.
56 void OnBlobReceived(const BlobId& id, BlobDataPtr data);
57
58 std::unique_ptr<BlobCache> cache_; 64 std::unique_ptr<BlobCache> cache_;
59 std::unique_ptr<Delegate> delegate_; 65 std::unique_ptr<Delegate> delegate_;
60 66
61 // Guards against concurrent access to |cache_|. 67 // Guards against concurrent access to |cache_|.
62 base::Lock cache_lock_; 68 base::Lock cache_lock_;
63 69
64 DISALLOW_COPY_AND_ASSIGN(BlobChannelReceiver); 70 DISALLOW_COPY_AND_ASSIGN(BlobChannelReceiverImpl);
65 }; 71 };
66 72
67 } // namespace blimp 73 } // namespace blimp
68 74
69 #endif // BLIMP_NET_BLOB_CHANNEL_BLOB_CHANNEL_RECEIVER_H_ 75 #endif // BLIMP_NET_BLOB_CHANNEL_BLOB_CHANNEL_RECEIVER_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698