Commit 3d3d4172 authored by Julie Jeongeun Kim's avatar Julie Jeongeun Kim Committed by Commit Bot

Convert WebCache to new Mojo types

This CL converts WebCachePtr and WebCacheRequest
to new Mojo types using Remote, ReceiverSet and
PendingReceiver.

Bug: 955171
Change-Id: Ie26db230a04880aca1fe6be076ae43ae01dfc492
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1818881Reviewed-by: default avatarScott Violet <sky@chromium.org>
Reviewed-by: default avatarKen Rockot <rockot@google.com>
Commit-Queue: Julie Kim <jkim@igalia.com>
Cr-Commit-Position: refs/heads/master@{#699612}
parent db71b051
include_rules = [
"+content/public/browser",
"+content/public",
"+mojo/public/cpp/bindings",
"+services/service_manager/public/cpp",
"+third_party/blink/public/web",
]
......@@ -85,8 +85,8 @@ void WebCacheManager::Add(int renderer_id) {
content::RenderProcessHost* host =
content::RenderProcessHost::FromID(renderer_id);
if (host) {
mojom::WebCachePtr service;
BindInterface(host, &service);
mojo::Remote<mojom::WebCache> service;
BindInterface(host, service.BindNewPipeAndPassReceiver());
web_cache_services_[renderer_id] = std::move(service);
}
......@@ -306,10 +306,10 @@ void WebCacheManager::EnactStrategy(const AllocationStrategy& strategy) {
// This is the capacity this renderer has been allocated.
uint64_t capacity = allocation->second;
// Find the WebCachePtr by renderer process id.
// Find the mojo::Remote<WebCache> by renderer process id.
auto it = web_cache_services_.find(allocation->first);
if (it != web_cache_services_.end()) {
const mojom::WebCachePtr& service = it->second;
const mojo::Remote<mojom::WebCache>& service = it->second;
DCHECK(service);
service->SetCacheCapacity(capacity);
}
......@@ -332,10 +332,10 @@ void WebCacheManager::ClearRendererCache(
content::RenderProcessHost* host =
content::RenderProcessHost::FromID(*iter);
if (host) {
// Find the WebCachePtr by renderer process id.
// Find the mojo::Remote<WebCache> by renderer process id.
auto it = web_cache_services_.find(*iter);
if (it != web_cache_services_.end()) {
const mojom::WebCachePtr& service = it->second;
const mojo::Remote<mojom::WebCache>& service = it->second;
DCHECK(service);
service->ClearCache(occasion == ON_NAVIGATION);
}
......
......@@ -22,6 +22,7 @@
#include "components/web_cache/public/mojom/web_cache.mojom.h"
#include "content/public/browser/notification_observer.h"
#include "content/public/browser/notification_registrar.h"
#include "mojo/public/cpp/bindings/remote.h"
namespace base {
template<typename Type>
......@@ -133,7 +134,7 @@ class WebCacheManager : public content::NotificationObserver {
typedef std::list<Allocation> AllocationStrategy;
// The key is the unique id of every render process host.
typedef std::map<int, mojom::WebCachePtr> WebCacheServicesMap;
typedef std::map<int, mojo::Remote<mojom::WebCache>> WebCacheServicesMap;
// This class is a singleton. Do not instantiate directly.
WebCacheManager();
......@@ -239,7 +240,8 @@ class WebCacheManager : public content::NotificationObserver {
content::NotificationRegistrar registrar_;
// Maps every renderer_id with its corresponding mojom::WebCachePtr.
// Maps every renderer_id with its corresponding
// mojo::Remote<mojom::WebCache>.
WebCacheServicesMap web_cache_services_;
base::WeakPtrFactory<WebCacheManager> weak_factory_{this};
......
......@@ -21,7 +21,7 @@ namespace web_cache {
WebCacheImpl::WebCacheImpl() : clear_cache_state_(kInit) {
auto registry = std::make_unique<service_manager::BinderRegistry>();
registry->AddInterface(
base::Bind(&WebCacheImpl::BindRequest, base::Unretained(this)),
base::Bind(&WebCacheImpl::BindReceiver, base::Unretained(this)),
base::ThreadTaskRunnerHandle::Get());
if (content::ChildThread::Get()) {
content::ChildThread::Get()
......@@ -33,8 +33,9 @@ WebCacheImpl::WebCacheImpl() : clear_cache_state_(kInit) {
WebCacheImpl::~WebCacheImpl() {}
void WebCacheImpl::BindRequest(mojom::WebCacheRequest web_cache_request) {
bindings_.AddBinding(this, std::move(web_cache_request));
void WebCacheImpl::BindReceiver(
mojo::PendingReceiver<mojom::WebCache> web_cache_receiver) {
receivers_.Add(this, std::move(web_cache_receiver));
}
void WebCacheImpl::ExecutePendingClearCache() {
......
......@@ -11,7 +11,8 @@
#include "base/compiler_specific.h"
#include "base/macros.h"
#include "components/web_cache/public/mojom/web_cache.mojom.h"
#include "mojo/public/cpp/bindings/binding_set.h"
#include "mojo/public/cpp/bindings/pending_receiver.h"
#include "mojo/public/cpp/bindings/receiver_set.h"
namespace web_cache {
......@@ -21,7 +22,7 @@ class WebCacheImpl : public mojom::WebCache {
WebCacheImpl();
~WebCacheImpl() override;
void BindRequest(mojom::WebCacheRequest web_cache_request);
void BindReceiver(mojo::PendingReceiver<mojom::WebCache> web_cache_receiver);
// Needs to be called by RenderViews in case of navigations to execute
// any 'clear cache' commands that were delayed until the next navigation.
......@@ -45,7 +46,7 @@ class WebCacheImpl : public mojom::WebCache {
// get executed on navigation.
State clear_cache_state_;
mojo::BindingSet<mojom::WebCache> bindings_;
mojo::ReceiverSet<mojom::WebCache> receivers_;
DISALLOW_COPY_AND_ASSIGN(WebCacheImpl);
};
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment