Chromium Code Reviews| Index: blimp/net/blob_channel/blob_channel_receiver.h |
| diff --git a/blimp/net/blob_channel/blob_channel_receiver.h b/blimp/net/blob_channel/blob_channel_receiver.h |
| new file mode 100644 |
| index 0000000000000000000000000000000000000000..5464fdf8f17b466e1e451a3263d0044c6909b1b0 |
| --- /dev/null |
| +++ b/blimp/net/blob_channel/blob_channel_receiver.h |
| @@ -0,0 +1,66 @@ |
| +// Copyright 2016 The Chromium Authors. All rights reserved. |
| +// Use of this source code is governed by a BSD-style license that can be |
| +// found in the LICENSE file. |
| + |
| +#ifndef BLIMP_NET_BLOB_CHANNEL_BLOB_CHANNEL_RECEIVER_H_ |
| +#define BLIMP_NET_BLOB_CHANNEL_BLOB_CHANNEL_RECEIVER_H_ |
| + |
| +#include <map> |
| +#include <string> |
| +#include <vector> |
| + |
| +#include "base/macros.h" |
| +#include "base/memory/ref_counted.h" |
| +#include "base/synchronization/lock.h" |
| +#include "blimp/common/blob_cache/blob_cache.h" |
| +#include "blimp/net/blimp_message_processor.h" |
| +#include "blimp/net/blimp_net_export.h" |
| +#include "blimp/net/blob_channel/blob_channel_bindings.h" |
| + |
| +namespace blimp { |
| + |
| +class BlobCache; |
| + |
| +class BLIMP_NET_EXPORT BlobChannelReceiver |
| + : public BlobReceiverBindings::Delegate { |
| + public: |
| + typedef base::Callback<void(const std::string&, |
| + scoped_refptr<RefCountedVector>)> |
| + BlobReceivedCallback; |
| + |
| + // Caller must ensure that |cache| and |bindings| outlive |this|. |
| + 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.
|
| + ~BlobChannelReceiver(); |
| + |
| + // Gets a blob from the BlobChannel, first pulling from a local cache and |
| + // falling back to requesting the data from a remote cache. |
| + // If blob |id| is already available, then it is returned synchronously and |
| + // |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
|
| + // If blob |id| has not yet been received, then a null refptr is returned, |
| + // and |callback| is invoked later when the blob arrives. |
| + // 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!
|
| + scoped_refptr<RefCountedVector> Get(const std::string& id, |
| + const BlobReceivedCallback& callback); |
| + |
| + protected: |
| + // BlobReceiverBindings::Delegate implementation. |
| + // Holds |lock_|. |
| + void OnBlobReceived(const std::string& id, |
| + std::unique_ptr<std::vector<uint8_t>> data) override; |
| + |
| + private: |
| + BlobCache* cache_ = nullptr; |
| + BlobReceiverBindings* bindings_ = nullptr; |
| + |
| + // Callbacks waiting to be invoked on read completion, keyed by blob ID. |
| + std::multimap<std::string, BlobReceivedCallback> active_read_callbacks_; |
| + |
| + // Guards concurrent access to |cache_| and |active_read_callbacks_|. |
| + base::Lock lock_; |
| + |
| + DISALLOW_COPY_AND_ASSIGN(BlobChannelReceiver); |
| +}; |
| + |
| +} // namespace blimp |
| + |
| +#endif // BLIMP_NET_BLOB_CHANNEL_BLOB_CHANNEL_RECEIVER_H_ |