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

Unified Diff: content/browser/memory/memory_coordinator.cc

Issue 2374343002: Add MemoryCoordinatorImpl (Closed)
Patch Set: Implement #msg4 Created 4 years, 2 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 side-by-side diff with in-line comments
Download patch
Index: content/browser/memory/memory_coordinator.cc
diff --git a/content/browser/memory/memory_coordinator.cc b/content/browser/memory/memory_coordinator.cc
index 52ee2ece71f8a47def79edd5401bd9c791680b49..8cf5697577a3d8e8b6de4a17a55348802f7ea5d3 100644
--- a/content/browser/memory/memory_coordinator.cc
+++ b/content/browser/memory/memory_coordinator.cc
@@ -5,7 +5,6 @@
#include "content/browser/memory/memory_coordinator.h"
#include "base/memory/memory_coordinator_client_registry.h"
-#include "content/public/common/content_features.h"
namespace content {
@@ -13,32 +12,43 @@ namespace content {
// for the role of this class.
class MemoryCoordinatorHandleImpl : public mojom::MemoryCoordinatorHandle {
public:
- MemoryCoordinatorHandleImpl(mojom::MemoryCoordinatorHandleRequest request)
- : binding_(this, std::move(request)) {
- }
+ MemoryCoordinatorHandleImpl(mojom::MemoryCoordinatorHandleRequest request,
+ MemoryCoordinator* coordinator,
+ int render_process_id);
+ ~MemoryCoordinatorHandleImpl() override;
// mojom::MemoryCoordinatorHandle:
- void AddChild(mojom::ChildMemoryCoordinatorPtr child) override {
- DCHECK(!child_.is_bound());
- child_ = std::move(child);
- }
+ void AddChild(mojom::ChildMemoryCoordinatorPtr child) override;
mojom::ChildMemoryCoordinatorPtr& child() { return child_; }
mojo::Binding<mojom::MemoryCoordinatorHandle>& binding() { return binding_; }
private:
+ MemoryCoordinator* coordinator_;
+ int render_process_id_;
mojom::ChildMemoryCoordinatorPtr child_;
mojo::Binding<mojom::MemoryCoordinatorHandle> binding_;
DISALLOW_COPY_AND_ASSIGN(MemoryCoordinatorHandleImpl);
};
-// static
-MemoryCoordinator* MemoryCoordinator::GetInstance() {
- if (!base::FeatureList::IsEnabled(features::kMemoryCoordinator))
- return nullptr;
- return base::Singleton<MemoryCoordinator,
- base::LeakySingletonTraits<MemoryCoordinator>>::get();
+MemoryCoordinatorHandleImpl::MemoryCoordinatorHandleImpl(
+ mojom::MemoryCoordinatorHandleRequest request,
+ MemoryCoordinator* coordinator,
+ int render_process_id)
+ : coordinator_(coordinator),
+ render_process_id_(render_process_id),
+ binding_(this, std::move(request)) {
+ DCHECK(coordinator_);
+}
+
+MemoryCoordinatorHandleImpl::~MemoryCoordinatorHandleImpl() {}
+
+void MemoryCoordinatorHandleImpl::AddChild(
+ mojom::ChildMemoryCoordinatorPtr child) {
+ DCHECK(!child_.is_bound());
+ child_ = std::move(child);
+ coordinator_->OnChildAdded(render_process_id_);
}
MemoryCoordinator::MemoryCoordinator() {}
@@ -49,7 +59,8 @@ void MemoryCoordinator::CreateHandle(
int render_process_id,
mojom::MemoryCoordinatorHandleRequest request) {
std::unique_ptr<MemoryCoordinatorHandleImpl> handle(
- new MemoryCoordinatorHandleImpl(std::move(request)));
+ new MemoryCoordinatorHandleImpl(std::move(request), this,
+ render_process_id));
handle->binding().set_connection_error_handler(
base::Bind(&MemoryCoordinator::OnConnectionError, base::Unretained(this),
render_process_id));
@@ -71,6 +82,10 @@ bool MemoryCoordinator::SetMemoryState(int render_process_id,
if (iter == children_.end())
return false;
+ // Can't send a message to a child that isn't bound.
+ if (!iter->second.handle->child().is_bound())
+ return false;
+
// A nop doesn't need to be sent, but is considered successful.
if (iter->second.memory_state == memory_state)
return true;
@@ -94,7 +109,8 @@ void MemoryCoordinator::AddChildForTesting(
mojom::MemoryCoordinatorHandlePtr mch;
auto request = mojo::GetProxy(&mch);
std::unique_ptr<MemoryCoordinatorHandleImpl> handle(
- new MemoryCoordinatorHandleImpl(std::move(request)));
+ new MemoryCoordinatorHandleImpl(std::move(request), this,
+ dummy_render_process_id));
handle->AddChild(std::move(child));
CreateChildInfoMapEntry(dummy_render_process_id, std::move(handle));
}

Powered by Google App Engine
This is Rietveld 408576698