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

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: use a better upstream branch for the patch Created 4 years, 6 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/common/service_registry.h" 7 #include "content/public/common/service_registry.h"
8 #include "content/public/renderer/render_thread.h" 8 #include "content/public/renderer/render_thread.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()->GetServiceRegistry()->ConnectToRemoteService( 16 content::RenderThread::Get()->GetServiceRegistry()->ConnectToRemoteService(
17 mojo::GetProxy(&blob_channel_ptr)); 17 mojo::GetProxy(&blob_channel_ptr));
18 CHECK(blob_channel_ptr) << "Could not connect to BlobChannel Mojo service."; 18 CHECK(blob_channel_ptr) << "Could not connect to BlobChannel Mojo service.";
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 // Asynchronously request the set of cache keys from the browser process.
27 // Knowledge of the browser's cache allows the renderer to avoid re-encoding
28 // and re-transferring image assets that are already tracked by the
29 // browser-side cache.
30 //
31 // If |this| is used in the brief time before the response arrives,
32 // the object will continue to work, but false negatives will be returned
33 // for IsInEngineCache() and IsInClientCache().
Wez 2016/06/21 00:33:33 This is a property the caller needs to be aware of
Kevin M 2016/06/21 21:23:52 Done, moved to header file.
34 //
35 // TODO(kmarshall): Switch to observer push model (vs. the current pull model)
36 // once cache invalidations are introduced.
37 blob_channel_->GetCacheState(base::Bind(
38 &BlobChannelSenderProxy::GotCacheState, weak_factory_.GetWeakPtr()));
39 }
26 40
27 BlobChannelSenderProxy::~BlobChannelSenderProxy() {} 41 BlobChannelSenderProxy::~BlobChannelSenderProxy() {}
28 42
29 bool BlobChannelSenderProxy::IsInEngineCache(const std::string& id) const { 43 bool BlobChannelSenderProxy::IsInEngineCache(const std::string& id) const {
30 return replication_state_.find(id) != replication_state_.end(); 44 return replication_state_.find(id) != replication_state_.end();
31 } 45 }
32 46
33 bool BlobChannelSenderProxy::IsInClientCache(const std::string& id) const { 47 bool BlobChannelSenderProxy::IsInClientCache(const std::string& id) const {
34 return replication_state_.find(id)->second; 48 return replication_state_.find(id)->second;
35 } 49 }
36 50
37 void BlobChannelSenderProxy::PutBlob(const BlobId& id, BlobDataPtr data) { 51 void BlobChannelSenderProxy::PutBlob(const BlobId& id, BlobDataPtr data) {
38 DCHECK(!IsInEngineCache(id)); 52 DCHECK(!IsInEngineCache(id));
39 53
40 replication_state_[id] = false; 54 replication_state_[id] = false;
41 blob_channel_->PutBlob(id, data->data); 55 blob_channel_->PutBlob(id, data->data);
42 } 56 }
43 57
44 void BlobChannelSenderProxy::DeliverBlob(const std::string& id) { 58 void BlobChannelSenderProxy::DeliverBlob(const std::string& id) {
45 DCHECK(!IsInClientCache(id)); 59 DCHECK(!IsInClientCache(id));
46 60
47 // We assume that the client will have the blob if we push it. 61 // We assume that the client will have the blob if we push it.
48 // TODO(kmarshall): Revisit this assumption when asynchronous blob transport 62 // TODO(kmarshall): Revisit this assumption when asynchronous blob transport
49 // is supported. 63 // is supported.
50 replication_state_[id] = true; 64 replication_state_[id] = true;
51 65
52 blob_channel_->DeliverBlob(id); 66 blob_channel_->DeliverBlob(id);
53 } 67 }
54 68
69 std::vector<BlobChannelSender::CacheState>
70 BlobChannelSenderProxy::GetCacheState() const {
71 NOTREACHED();
72 return std::vector<BlobChannelSender::CacheState>();
Wez 2016/06/21 00:33:33 Why not-implemented? Why not return a copy of repl
Kevin M 2016/06/21 21:23:52 Done.
Wez 2016/06/22 19:54:23 (Or is it the case that no-one will ever call this
Kevin M 2016/06/22 23:52:52 Yes, that is the case. <_<
73 }
74
75 void BlobChannelSenderProxy::GotCacheState(
76 mojo::Array<mojom::CacheStateEntryPtr> cache_state) {
77 VLOG(1) << "Received cache state from browser (" << cache_state.size()
78 << " items)";
79 replication_state_.clear();
80 for (const auto& next_item : cache_state) {
81 replication_state_[next_item->id] = next_item->is_replicated;
82 }
83 }
84
55 } // namespace engine 85 } // namespace engine
56 } // namespace blimp 86 } // namespace blimp
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698