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 #include "blimp/engine/renderer/blob_channel_sender_host.h" | |
6 | |
7 #include "content/public/common/service_registry.h" | |
8 #include "content/public/renderer/render_thread.h" | |
9 | |
10 namespace blimp { | |
11 namespace engine { | |
12 namespace { | |
13 | |
14 mojom::BlobChannelPtr GetConnectedBlobChannel() { | |
15 mojom::BlobChannelPtr blob_channel_ptr; | |
16 content::RenderThread::Get()->GetServiceRegistry()->ConnectToRemoteService( | |
17 mojo::GetProxy(&blob_channel_ptr)); | |
18 CHECK(blob_channel_ptr) << "Could not connect to BlobChannel Mojo service."; | |
19 return blob_channel_ptr; | |
20 } | |
21 | |
22 } // namespace | |
23 | |
24 BlobChannelSenderHost::BlobChannelSenderHost() | |
25 : blob_channel_(GetConnectedBlobChannel()) {} | |
26 | |
27 BlobChannelSenderHost::~BlobChannelSenderHost() {} | |
28 | |
29 int BlobChannelSenderHost::GetReplicationState(const std::string& id) const { | |
30 if (replication_state_.find(id) == replication_state_.end()) { | |
31 return 0; | |
32 } else { | |
33 return replication_state_.at(id); | |
34 } | |
35 } | |
36 | |
37 void BlobChannelSenderHost::Put(const std::string& id, | |
38 const std::string& data) { | |
39 // Callers should only call Put() if the blob does not already exist in the | |
40 // BlobChannel. | |
41 DCHECK_NE(ReplicationState::ENGINE, | |
42 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.
| |
43 | |
44 replication_state_[id] = ReplicationState::ENGINE; | |
45 blob_channel_->Put(id, data); | |
46 } | |
47 | |
48 void BlobChannelSenderHost::Push(const std::string& id) { | |
49 // 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.
| |
50 // and the client does not already have it. | |
51 DCHECK_EQ(ReplicationState::ENGINE, GetReplicationState(id)); | |
52 | |
53 // We assume that the client will have the blob if we push it. | |
54 // TODO(kmarshall): Revisit this assumption when asynchronous blob transport | |
55 // is supported. | |
56 replication_state_[id] = replication_state_[id] | ReplicationState::CLIENT; | |
57 | |
58 blob_channel_->Push(id); | |
59 } | |
60 | |
61 } // namespace engine | |
62 } // namespace blimp | |
OLD | NEW |