Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright 2016 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "blimp/engine/renderer/blob_channel_sender_proxy.h" | 5 #include "blimp/engine/renderer/blob_channel_sender_proxy.h" |
| 6 | 6 |
| 7 #include "content/public/renderer/render_thread.h" | 7 #include "content/public/renderer/render_thread.h" |
| 8 #include "services/shell/public/cpp/interface_provider.h" | 8 #include "services/shell/public/cpp/interface_provider.h" |
| 9 | 9 |
| 10 namespace blimp { | 10 namespace blimp { |
| 11 namespace engine { | 11 namespace engine { |
| 12 namespace { | 12 namespace { |
| 13 | 13 |
| 14 mojom::BlobChannelPtr GetConnectedBlobChannel() { | 14 mojom::BlobChannelPtr GetConnectedBlobChannel() { |
| 15 mojom::BlobChannelPtr blob_channel_ptr; | 15 mojom::BlobChannelPtr blob_channel_ptr; |
| 16 content::RenderThread::Get()->GetRemoteInterfaces()->GetInterface( | 16 content::RenderThread::Get()->GetRemoteInterfaces()->GetInterface( |
| 17 &blob_channel_ptr); | 17 &blob_channel_ptr); |
| 18 CHECK(blob_channel_ptr) << "Could not connect to BlobChannel Mojo interface."; | 18 CHECK(blob_channel_ptr) << "Could not connect to BlobChannel Mojo interface."; |
| 19 return blob_channel_ptr; | 19 return blob_channel_ptr; |
| 20 } | 20 } |
| 21 | 21 |
| 22 } // namespace | 22 } // namespace |
| 23 | 23 |
| 24 BlobChannelSenderProxy::BlobChannelSenderProxy() | 24 BlobChannelSenderProxy::BlobChannelSenderProxy() |
| 25 : blob_channel_(GetConnectedBlobChannel()) {} | 25 : blob_channel_(GetConnectedBlobChannel()), weak_factory_(this) { |
| 26 // TODO(kmarshall): Switch to observer push model (vs. the current pull model) | |
| 27 // once cache invalidations are introduced. | |
|
Wez
2016/07/01 00:30:20
nit: Either refer to the bug for this TODO, or rem
nyquist
2016/07/15 22:13:46
Yeah, and if there is no bug for it, just file one
Kevin M
2016/07/18 16:58:16
Done.
Kevin M
2016/07/18 16:58:16
Done.
| |
| 28 blob_channel_->GetCachedBlobIds( | |
| 29 base::Bind(&BlobChannelSenderProxy::OnGetCacheStateComplete, | |
| 30 weak_factory_.GetWeakPtr())); | |
| 31 } | |
| 26 | 32 |
| 27 BlobChannelSenderProxy::~BlobChannelSenderProxy() {} | 33 BlobChannelSenderProxy::~BlobChannelSenderProxy() {} |
| 28 | 34 |
| 29 bool BlobChannelSenderProxy::IsInEngineCache(const std::string& id) const { | 35 bool BlobChannelSenderProxy::IsInEngineCache(const std::string& id) const { |
| 30 return replication_state_.find(id) != replication_state_.end(); | 36 return replication_state_.find(id) != replication_state_.end(); |
| 31 } | 37 } |
| 32 | 38 |
| 33 bool BlobChannelSenderProxy::IsInClientCache(const std::string& id) const { | 39 bool BlobChannelSenderProxy::IsInClientCache(const std::string& id) const { |
| 34 return replication_state_.find(id)->second; | 40 return replication_state_.find(id)->second; |
| 35 } | 41 } |
| 36 | 42 |
| 37 void BlobChannelSenderProxy::PutBlob(const BlobId& id, BlobDataPtr data) { | 43 void BlobChannelSenderProxy::PutBlob(const BlobId& id, BlobDataPtr data) { |
| 38 DCHECK(!IsInEngineCache(id)); | 44 DCHECK(!IsInEngineCache(id)); |
| 39 | 45 |
| 40 replication_state_[id] = false; | 46 replication_state_[id] = false; |
| 41 blob_channel_->PutBlob(id, data->data); | 47 blob_channel_->PutBlob(id, data->data); |
| 42 } | 48 } |
| 43 | 49 |
| 44 void BlobChannelSenderProxy::DeliverBlob(const std::string& id) { | 50 void BlobChannelSenderProxy::DeliverBlob(const std::string& id) { |
| 45 DCHECK(!IsInClientCache(id)); | 51 DCHECK(!IsInClientCache(id)); |
| 46 | 52 |
| 47 // We assume that the client will have the blob if we push it. | 53 // We assume that the client will have the blob if we push it. |
| 48 // TODO(kmarshall): Revisit this assumption when asynchronous blob transport | 54 // TODO(kmarshall): Revisit this assumption when asynchronous blob transport |
| 49 // is supported. | 55 // is supported. |
| 50 replication_state_[id] = true; | 56 replication_state_[id] = true; |
| 51 | 57 |
| 52 blob_channel_->DeliverBlob(id); | 58 blob_channel_->DeliverBlob(id); |
| 53 } | 59 } |
| 54 | 60 |
| 61 std::vector<BlobChannelSender::CacheStateEntry> | |
| 62 BlobChannelSenderProxy::GetCachedBlobIds() const { | |
| 63 NOTREACHED(); | |
| 64 return std::vector<BlobChannelSender::CacheStateEntry>(); | |
| 65 } | |
| 66 | |
| 67 void BlobChannelSenderProxy::OnGetCacheStateComplete( | |
| 68 mojo::Map<mojo::String, bool> cache_state | |
| 69 ) { | |
|
Wez
2016/07/01 00:30:21
nit: This is very strange looking line-wrapping! I
Kevin M
2016/07/18 16:58:16
Re-ran git cl format, formatting is saner. I must'
| |
| 70 VLOG(1) << "Received cache state from browser (" << cache_state.size() | |
| 71 << " items)"; | |
| 72 replication_state_.clear(); | |
| 73 for (const auto& next_item : cache_state) { | |
| 74 replication_state_[next_item.first] = next_item.second; | |
| 75 } | |
| 76 } | |
| 77 | |
| 55 } // namespace engine | 78 } // namespace engine |
| 56 } // namespace blimp | 79 } // namespace blimp |
| OLD | NEW |