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_SENDER_IMPL_H_ | |
6 #define BLIMP_NET_BLOB_CHANNEL_BLOB_CHANNEL_SENDER_IMPL_H_ | |
7 | |
8 #include <memory> | |
9 #include <set> | |
10 #include <string> | |
11 #include <vector> | |
12 | |
13 #include "base/macros.h" | |
14 #include "base/memory/weak_ptr.h" | |
15 #include "base/threading/thread_checker.h" | |
16 #include "blimp/common/blob_cache/blob_cache.h" | |
17 #include "blimp/net/blimp_net_export.h" | |
18 #include "blimp/net/blob_channel/blob_channel_sender.h" | |
19 | |
20 namespace blimp { | |
21 | |
22 // Sends blobs to a remote receiver. | |
23 // The transport-specific details are provided by the caller using the Delegate | |
24 // subclass. | |
25 class BLIMP_NET_EXPORT BlobChannelSenderImpl : public BlobChannelSender { | |
26 public: | |
27 // Delegate interface for transport-specific implementations of blob transfer | |
28 // commands. | |
29 class Delegate { | |
30 public: | |
31 virtual ~Delegate() {} | |
32 | |
33 // Send blob |id| with payload |data| to the receiver. | |
34 virtual void DeliverBlob(const BlobId& id, BlobDataPtr data) = 0; | |
35 }; | |
36 | |
37 BlobChannelSenderImpl(std::unique_ptr<BlobCache> cache, | |
38 std::unique_ptr<Delegate> delegate); | |
39 ~BlobChannelSenderImpl() override; | |
40 | |
41 // BlobChannelSender implementation. | |
42 std::vector<BlobChannelSender::CacheStateEntry> GetCachedBlobIds() | |
43 const override; | |
44 void PutBlob(const BlobId& id, BlobDataPtr data) override; | |
45 void DeliverBlob(const BlobId& id) override; | |
46 | |
47 private: | |
48 std::unique_ptr<BlobCache> cache_; | |
49 std::unique_ptr<Delegate> delegate_; | |
50 | |
51 // Used to track the item IDs in the receiver's cache. This may differ from | |
52 // the set of IDs in |cache_|, for instance if an ID hasn't yet been | |
53 // delivered, or has been evicted at the receiver. | |
54 std::set<BlobId> receiver_cache_contents_; | |
55 | |
56 base::WeakPtrFactory<BlobChannelSenderImpl> weak_factory_; | |
57 | |
58 DISALLOW_COPY_AND_ASSIGN(BlobChannelSenderImpl); | |
59 }; | |
60 | |
61 } // namespace blimp | |
62 | |
63 #endif // BLIMP_NET_BLOB_CHANNEL_BLOB_CHANNEL_SENDER_IMPL_H_ | |
OLD | NEW |