Chromium Code Reviews| OLD | NEW |
|---|---|
| (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 #ifndef BLIMP_NET_BLOB_CHANNEL_BLOB_CHANNEL_RECEIVER_H_ | |
| 6 #define BLIMP_NET_BLOB_CHANNEL_BLOB_CHANNEL_RECEIVER_H_ | |
| 7 | |
| 8 #include "base/macros.h" | |
| 9 #include "base/memory/ref_counted.h" | |
| 10 #include "base/synchronization/lock.h" | |
| 11 #include "blimp/common/blob_cache/blob_cache.h" | |
| 12 #include "blimp/net/blimp_message_processor.h" | |
| 13 #include "blimp/net/blimp_net_export.h" | |
| 14 | |
| 15 namespace blimp { | |
| 16 | |
| 17 class BlobCache; | |
| 18 | |
| 19 // Receives blobs from a remote sender. | |
| 20 // Can be accessed concurrently from any thread. | |
|
Wez
2016/04/21 22:52:50
That's a very strong statement for a not-ref-count
Kevin M
2016/04/22 00:21:24
Done.
| |
| 21 class BLIMP_NET_EXPORT BlobChannelReceiver { | |
| 22 public: | |
| 23 class Delegate { | |
| 24 public: | |
| 25 Delegate(); | |
| 26 virtual ~Delegate(); | |
| 27 | |
| 28 protected: | |
| 29 // Forwards incoming blob data to |receiver_|. | |
| 30 void OnBlobReceived(const BlobId& id, BlobDataPtr data); | |
| 31 | |
| 32 private: | |
| 33 friend class BlobChannelReceiver; | |
| 34 | |
| 35 // Sets the Receiver object which will take incoming blobs. | |
| 36 void SetReceiver(BlobChannelReceiver* receiver); | |
| 37 | |
| 38 BlobChannelReceiver* receiver_ = nullptr; | |
| 39 | |
| 40 DISALLOW_COPY_AND_ASSIGN(Delegate); | |
| 41 }; | |
| 42 | |
| 43 BlobChannelReceiver(std::unique_ptr<BlobCache> cache, | |
| 44 std::unique_ptr<Delegate> delegate); | |
| 45 ~BlobChannelReceiver(); | |
| 46 | |
| 47 // Gets a blob from the BlobChannel. | |
| 48 // Returns nullptr if the blob is not available in the channel. | |
| 49 BlobDataPtr Get(const BlobId& id); | |
| 50 | |
| 51 private: | |
| 52 friend class Delegate; | |
| 53 | |
| 54 // Called by Delegate::OnBlobReceived() when a blob arrives over the channel. | |
| 55 void OnBlobReceived(const BlobId& id, BlobDataPtr data); | |
| 56 | |
| 57 std::unique_ptr<BlobCache> cache_; | |
| 58 std::unique_ptr<Delegate> delegate_; | |
| 59 | |
| 60 // Guards against concurrent access to |cache_|. | |
| 61 base::Lock lock_; | |
| 62 | |
| 63 DISALLOW_COPY_AND_ASSIGN(BlobChannelReceiver); | |
| 64 }; | |
| 65 | |
| 66 } // namespace blimp | |
| 67 | |
| 68 #endif // BLIMP_NET_BLOB_CHANNEL_BLOB_CHANNEL_RECEIVER_H_ | |
| OLD | NEW |