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 <unordered_map> |
7 #include <utility> | 8 #include <utility> |
8 | 9 |
9 #include "blimp/common/blob_cache/id_util.h" | 10 #include "blimp/common/blob_cache/id_util.h" |
10 #include "content/public/renderer/render_thread.h" | 11 #include "content/public/renderer/render_thread.h" |
11 #include "services/shell/public/cpp/interface_provider.h" | 12 #include "services/shell/public/cpp/interface_provider.h" |
12 | 13 |
13 namespace blimp { | 14 namespace blimp { |
14 namespace engine { | 15 namespace engine { |
15 namespace { | 16 namespace { |
16 | 17 |
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
54 mojo::ScopedSharedBufferHandle remote_handle = | 55 mojo::ScopedSharedBufferHandle remote_handle = |
55 local_handle_->Clone(mojo::SharedBufferHandle::AccessMode::READ_ONLY); | 56 local_handle_->Clone(mojo::SharedBufferHandle::AccessMode::READ_ONLY); |
56 CHECK(remote_handle.is_valid()) | 57 CHECK(remote_handle.is_valid()) |
57 << "Mojo error when creating read-only buffer handle."; | 58 << "Mojo error when creating read-only buffer handle."; |
58 return remote_handle; | 59 return remote_handle; |
59 } | 60 } |
60 | 61 |
61 } // namespace | 62 } // namespace |
62 | 63 |
63 BlobChannelSenderProxy::BlobChannelSenderProxy() | 64 BlobChannelSenderProxy::BlobChannelSenderProxy() |
64 : BlobChannelSenderProxy(GetConnectedBlobChannel()) {} | 65 : blob_channel_(GetConnectedBlobChannel()), weak_factory_(this) { |
| 66 blob_channel_->GetCachedBlobIds( |
| 67 base::Bind(&BlobChannelSenderProxy::OnGetCacheStateComplete, |
| 68 weak_factory_.GetWeakPtr())); |
| 69 } |
65 | 70 |
66 BlobChannelSenderProxy::~BlobChannelSenderProxy() {} | 71 BlobChannelSenderProxy::~BlobChannelSenderProxy() {} |
67 | 72 |
68 BlobChannelSenderProxy::BlobChannelSenderProxy( | 73 BlobChannelSenderProxy::BlobChannelSenderProxy( |
69 mojom::BlobChannelPtr blob_channel) | 74 mojom::BlobChannelPtr blob_channel) |
70 : blob_channel_(std::move(blob_channel)) {} | 75 : blob_channel_(std::move(blob_channel)), weak_factory_(this) {} |
71 | 76 |
72 // static | 77 // static |
73 std::unique_ptr<BlobChannelSenderProxy> BlobChannelSenderProxy::CreateForTest( | 78 std::unique_ptr<BlobChannelSenderProxy> BlobChannelSenderProxy::CreateForTest( |
74 mojom::BlobChannelPtr blob_channel) { | 79 mojom::BlobChannelPtr blob_channel) { |
75 return base::WrapUnique(new BlobChannelSenderProxy(std::move(blob_channel))); | 80 return base::WrapUnique(new BlobChannelSenderProxy(std::move(blob_channel))); |
76 } | 81 } |
77 | 82 |
78 bool BlobChannelSenderProxy::IsInEngineCache(const std::string& id) const { | 83 bool BlobChannelSenderProxy::IsInEngineCache(const std::string& id) const { |
79 return replication_state_.find(id) != replication_state_.end(); | 84 return replication_state_.find(id) != replication_state_.end(); |
80 } | 85 } |
(...skipping 22 matching lines...) Expand all Loading... |
103 << BlobIdToString(id); | 108 << BlobIdToString(id); |
104 | 109 |
105 // We assume that the client will have the blob if we push it. | 110 // We assume that the client will have the blob if we push it. |
106 // TODO(kmarshall): Revisit this assumption when asynchronous blob transport | 111 // TODO(kmarshall): Revisit this assumption when asynchronous blob transport |
107 // is supported. | 112 // is supported. |
108 replication_state_[id] = true; | 113 replication_state_[id] = true; |
109 | 114 |
110 blob_channel_->DeliverBlob(id); | 115 blob_channel_->DeliverBlob(id); |
111 } | 116 } |
112 | 117 |
| 118 std::vector<BlobChannelSender::CacheStateEntry> |
| 119 BlobChannelSenderProxy::GetCachedBlobIds() const { |
| 120 NOTREACHED(); |
| 121 return std::vector<BlobChannelSender::CacheStateEntry>(); |
| 122 } |
| 123 |
| 124 void BlobChannelSenderProxy::OnGetCacheStateComplete( |
| 125 const std::unordered_map<std::string, bool>& cache_state) { |
| 126 VLOG(1) << "Received cache state from browser (" << cache_state.size() |
| 127 << " items)"; |
| 128 replication_state_.clear(); |
| 129 for (const auto& next_item : cache_state) { |
| 130 replication_state_[next_item.first] = next_item.second; |
| 131 } |
| 132 } |
| 133 |
113 } // namespace engine | 134 } // namespace engine |
114 } // namespace blimp | 135 } // namespace blimp |
OLD | NEW |