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

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: moar bindings commentz! 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/synchronization/lock.h"
15 #include "blimp/common/blob_cache/blob_cache.h"
16 #include "blimp/net/blimp_message_processor.h"
17 #include "blimp/net/blimp_net_export.h"
18 #include "blimp/net/blob_channel/blob_channel_bindings.h"
19
20 namespace blimp {
21
22 class BlobCache;
23
24 class BLIMP_NET_EXPORT BlobChannelReceiver
25 : public BlobReceiverBindings::Delegate {
26 public:
27 typedef base::Callback<void(const std::string&,
28 scoped_refptr<RefCountedVector>)>
29 BlobReceivedCallback;
30
31 // Caller must ensure that |cache| and |bindings| outlive |this|.
32 BlobChannelReceiver(BlobCache* cache, BlobReceiverBindings* bindings);
Wez 2016/04/15 17:27:43 See comments on BlobChannelSender re the naming &
Kevin M 2016/04/15 23:53:43 Done.
33 ~BlobChannelReceiver();
34
35 // Gets a blob from the BlobChannel, first pulling from a local cache and
36 // falling back to requesting the data from a remote cache.
37 // If blob |id| is already available, then it is returned synchronously and
38 // |callback| is discarded.
Wez 2016/04/15 17:27:43 Do we need the synchronous path? Or can we just ha
Kevin M 2016/04/15 23:53:44 The synchronous path is pretty essential for getti
39 // If blob |id| has not yet been received, then a null refptr is returned,
40 // and |callback| is invoked later when the blob arrives.
41 // Can be called on any thread. Holds |lock_|.
Wez 2016/04/15 17:27:43 This object isn't ref-counted; how can it "be call
Kevin M 2016/04/15 23:53:44 This is meant to support concurrent calls by a num
Wez 2016/04/18 22:44:47 Best to state such assumptions up-front!
42 scoped_refptr<RefCountedVector> Get(const std::string& id,
43 const BlobReceivedCallback& callback);
44
45 protected:
46 // BlobReceiverBindings::Delegate implementation.
47 // Holds |lock_|.
48 void OnBlobReceived(const std::string& id,
49 std::unique_ptr<std::vector<uint8_t>> data) override;
50
51 private:
52 BlobCache* cache_ = nullptr;
53 BlobReceiverBindings* bindings_ = nullptr;
54
55 // Callbacks waiting to be invoked on read completion, keyed by blob ID.
56 std::multimap<std::string, BlobReceivedCallback> active_read_callbacks_;
57
58 // Guards concurrent access to |cache_| and |active_read_callbacks_|.
59 base::Lock lock_;
60
61 DISALLOW_COPY_AND_ASSIGN(BlobChannelReceiver);
62 };
63
64 } // namespace blimp
65
66 #endif // BLIMP_NET_BLOB_CHANNEL_BLOB_CHANNEL_RECEIVER_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698