Chromium Code Reviews| Index: blimp/engine/renderer/blob_channel_sender_host.cc |
| diff --git a/blimp/engine/renderer/blob_channel_sender_host.cc b/blimp/engine/renderer/blob_channel_sender_host.cc |
| new file mode 100644 |
| index 0000000000000000000000000000000000000000..0801709ee1bacd1d9b92058363fec25e4be78b87 |
| --- /dev/null |
| +++ b/blimp/engine/renderer/blob_channel_sender_host.cc |
| @@ -0,0 +1,62 @@ |
| +// 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. |
| + |
| +#include "blimp/engine/renderer/blob_channel_sender_host.h" |
| + |
| +#include "content/public/common/service_registry.h" |
| +#include "content/public/renderer/render_thread.h" |
| + |
| +namespace blimp { |
| +namespace engine { |
| +namespace { |
| + |
| +mojom::BlobChannelPtr GetConnectedBlobChannel() { |
| + mojom::BlobChannelPtr blob_channel_ptr; |
| + content::RenderThread::Get()->GetServiceRegistry()->ConnectToRemoteService( |
| + mojo::GetProxy(&blob_channel_ptr)); |
| + CHECK(blob_channel_ptr) << "Could not connect to BlobChannel Mojo service."; |
| + return blob_channel_ptr; |
| +} |
| + |
| +} // namespace |
| + |
| +BlobChannelSenderHost::BlobChannelSenderHost() |
| + : blob_channel_(GetConnectedBlobChannel()) {} |
| + |
| +BlobChannelSenderHost::~BlobChannelSenderHost() {} |
| + |
| +int BlobChannelSenderHost::GetReplicationState(const std::string& id) const { |
| + if (replication_state_.find(id) == replication_state_.end()) { |
| + return 0; |
| + } else { |
| + return replication_state_.at(id); |
| + } |
| +} |
| + |
| +void BlobChannelSenderHost::Put(const std::string& id, |
| + const std::string& data) { |
| + // Callers should only call Put() if the blob does not already exist in the |
| + // BlobChannel. |
| + DCHECK_NE(ReplicationState::ENGINE, |
| + GetReplicationState(id) & ReplicationState::ENGINE); |
|
Wez
2016/05/21 01:08:04
This DCHECK_NE is effectively just a bool test; yo
Kevin M
2016/05/27 22:35:30
Done.
|
| + |
| + replication_state_[id] = ReplicationState::ENGINE; |
| + blob_channel_->Put(id, data); |
| +} |
| + |
| +void BlobChannelSenderHost::Push(const std::string& id) { |
| + // Callers should only call Push() iff the blob is already in the BlobChannel |
|
Wez
2016/05/21 01:08:04
nit: I've been asked in prior reviews not to use "
Kevin M
2016/05/27 22:35:30
Done.
|
| + // and the client does not already have it. |
| + DCHECK_EQ(ReplicationState::ENGINE, GetReplicationState(id)); |
| + |
| + // We assume that the client will have the blob if we push it. |
| + // TODO(kmarshall): Revisit this assumption when asynchronous blob transport |
| + // is supported. |
| + replication_state_[id] = replication_state_[id] | ReplicationState::CLIENT; |
| + |
| + blob_channel_->Push(id); |
| +} |
| + |
| +} // namespace engine |
| +} // namespace blimp |