Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(10)

Side by Side Diff: blimp/engine/renderer/blob_channel_sender_proxy.cc

Issue 2056993003: Add Mojo IPC for seeding new Renderer with Browser's cached blob state. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@blobchannel-master
Patch Set: Revert type converters Created 4 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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.
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::Array<mojom::CacheStateEntryPtr> cache_state) {
69 VLOG(1) << "Received cache state from browser (" << cache_state.size()
70 << " items)";
71 replication_state_.clear();
dcheng 2016/06/28 21:34:52 Are there callbacks to update this state later? I'
Kevin M 2016/06/29 21:01:22 For now, this is called only once at the beginning
72 for (const auto& next_item : cache_state) {
73 replication_state_[next_item->id] = next_item->was_delivered;
74 }
75 }
76
55 } // namespace engine 77 } // namespace engine
56 } // namespace blimp 78 } // namespace blimp
OLDNEW
« no previous file with comments | « blimp/engine/renderer/blob_channel_sender_proxy.h ('k') | blimp/net/blob_channel/blob_channel_sender.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698