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

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

Issue 1891083002: Blimp: Add BlobChannelReceiver and bindings interface. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@blobchannel-sender
Patch Set: git rm *bindings* 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 #ifndef BLIMP_NET_BLOB_CHANNEL_BLOB_CHANNEL_RECEIVER_H_
6 #define BLIMP_NET_BLOB_CHANNEL_BLOB_CHANNEL_RECEIVER_H_
7
8 #include <map>
9 #include <string>
10 #include <vector>
11
12 #include "base/macros.h"
13 #include "base/memory/ref_counted.h"
14 #include "base/memory/weak_ptr.h"
15 #include "base/synchronization/lock.h"
16 #include "blimp/common/blob_cache/blob_cache.h"
17 #include "blimp/net/blimp_message_processor.h"
18 #include "blimp/net/blimp_net_export.h"
19 #include "blimp/net/blob_channel/types.h"
20
21 namespace blimp {
22
23 class BlobCache;
24
25 // Receives blobs from a remote sender.
26 // The transport-specific details are provided by the caller using a Delegate
27 // subclass.
28 class BLIMP_NET_EXPORT BlobChannelReceiver {
29 public:
30 typedef base::Callback<void(const BlobId&, scoped_refptr<RefCountedVector>)>
31 BlobReceivedCallback;
32
33 class Delegate {
34 public:
35 Delegate();
36 ~Delegate();
37
38 // Requests the blob |id| from the sender. The delegate method
39 // OnBlobReceived() is triggered if and when the blob arrives.
40 virtual void Request(const BlobId& id) = 0;
41
42 // Calls OnBlobReceived() on the BlobChannelReceiver.
43 void OnBlobReceived(const BlobId& id, BlobData data);
44
45 private:
46 friend class BlobChannelReceiver;
47
48 // Sets the Receiver object to receive incoming blobs.
49 void SetReceiver(base::WeakPtr<BlobChannelReceiver> receiver);
50
51 // Using a WeakPtr so the BlobChannelReceiver can be destroyed before
52 // |this|.
53 base::WeakPtr<BlobChannelReceiver> receiver_;
54
55 DISALLOW_COPY_AND_ASSIGN(Delegate);
56 };
57
58 // Caller must ensure that |cache| and |delegate| outlive |this|.
59 BlobChannelReceiver(BlobCache* cache, Delegate* delegate);
Wez 2016/04/18 22:40:40 Remind me why the receiver can't just "own" the ca
60 ~BlobChannelReceiver();
61
62 // Gets a blob from the BlobChannel, first pulling from a local cache and
63 // falling back to requesting the data from a remote cache.
64 // If blob |id| is already available, then it is returned synchronously and
65 // |callback| is discarded.
66 // If blob |id| has not yet been received, then a null refptr is returned,
67 // and |callback| is invoked later when the blob arrives.
68 // Can be called on any thread. Holds |lock_|.
Wez 2016/04/18 22:40:40 Holds lock_ is an internal implementation detail.
69 BlobData Get(const BlobId& id, const BlobReceivedCallback& callback);
Wez 2016/04/18 22:40:41 What is BlobData? I don't see it defined anywhere
70
71 private:
72 friend class Delegate;
73
74 // Method called by |delegate_| when a blob arrives from the transport.
75 // Holds |lock_|.
76 void OnBlobReceived(const BlobId& id, BlobData data);
77
78 BlobCache* cache_ = nullptr;
79 Delegate* delegate_ = nullptr;
Wez 2016/04/18 22:56:11 nit: You have no default ctor for this class, so n
80
81 // Callbacks waiting to be invoked on read completion, keyed by blob ID.
82 std::multimap<BlobId, BlobReceivedCallback> active_read_callbacks_;
83
84 // Guards concurrent access to |cache_| and |active_read_callbacks_|.
Wez 2016/04/18 22:40:41 Concurrent access by whom? The delegates call the
85 base::Lock lock_;
86
87 base::WeakPtrFactory<BlobChannelReceiver> weak_factory_;
88
89 DISALLOW_COPY_AND_ASSIGN(BlobChannelReceiver);
90 };
91
92 } // namespace blimp
93
94 #endif // BLIMP_NET_BLOB_CHANNEL_BLOB_CHANNEL_RECEIVER_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698