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

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

Issue 2731913002: NotForReview: Expose the global memory budget (chromium side)
Patch Set: Add --simulate-memory-pressure Created 3 years, 9 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_impl.cc
diff --git a/content/browser/memory/memory_coordinator_impl.cc b/content/browser/memory/memory_coordinator_impl.cc
index 0e2cfa92443f2aaef59cf197bbc9ed930400b58c..dbbf7c314d016b30d7b518a81be79dd0f718ab9b 100644
--- a/content/browser/memory/memory_coordinator_impl.cc
+++ b/content/browser/memory/memory_coordinator_impl.cc
@@ -89,6 +89,16 @@ class MemoryCoordinatorHandleImpl : public mojom::MemoryCoordinatorHandle {
// mojom::MemoryCoordinatorHandle:
void AddChild(mojom::ChildMemoryCoordinatorPtr child) override;
+ void GetGlobalBudgetHandle(
+ const GetGlobalBudgetHandleCallback& callback) override {
+ auto handle = coordinator_->global_budget_handle_->Clone(
+ mojo::SharedBufferHandle::AccessMode::READ_ONLY);
+ callback.Run(std::move(handle));
+ }
+ void SetGlobalBudgetUpdateInterval(uint32_t interval_ms) override {
+ base::TimeDelta interval = base::TimeDelta::FromMilliseconds(interval_ms);
+ coordinator_->condition_observer_->ScheduleUpdateCondition(interval);
+ }
mojom::ChildMemoryCoordinatorPtr& child() { return child_; }
mojo::Binding<mojom::MemoryCoordinatorHandle>& binding() { return binding_; }
@@ -151,10 +161,14 @@ MemoryCoordinatorImpl::MemoryCoordinatorImpl(
memory_monitor_(std::move(memory_monitor)),
condition_observer_(
base::MakeUnique<MemoryConditionObserver>(this, task_runner)),
- minimum_state_transition_period_(base::TimeDelta::FromSeconds(
- kDefaultMinimumTransitionPeriodSeconds)) {
+ minimum_state_transition_period_(
+ base::TimeDelta::FromSeconds(kDefaultMinimumTransitionPeriodSeconds)),
+ global_budget_handle_(mojo::SharedBufferHandle::Create(sizeof(int64_t))),
+ global_budget_mapping_(global_budget_handle_->Map(sizeof(int64_t))) {
DCHECK(memory_monitor_.get());
+ DCHECK(global_budget_mapping_.get());
base::MemoryCoordinatorProxy::SetMemoryCoordinator(this);
+ UpdateGlobalBudget(-1);
}
MemoryCoordinatorImpl::~MemoryCoordinatorImpl() {
@@ -232,6 +246,16 @@ MemoryState MemoryCoordinatorImpl::GetCurrentMemoryState() const {
return browser_memory_state_;
}
+int64_t MemoryCoordinatorImpl::GetGlobalBudget() {
+ return *reinterpret_cast<int64_t*>(global_budget_mapping_.get());
+}
+
+void MemoryCoordinatorImpl::SetGlobalBudgetUpdateInterval(
+ uint32_t interval_ms) {
+ condition_observer_->ScheduleUpdateCondition(
+ base::TimeDelta::FromMilliseconds(interval_ms));
+}
+
void MemoryCoordinatorImpl::ForceSetMemoryCondition(MemoryCondition condition,
base::TimeDelta duration) {
UpdateConditionIfNeeded(condition);
@@ -309,6 +333,10 @@ void MemoryCoordinatorImpl::UpdateConditionIfNeeded(
}
}
+void MemoryCoordinatorImpl::UpdateGlobalBudget(int budget) {
+ *reinterpret_cast<int64_t*>(global_budget_mapping_.get()) = budget;
+}
+
void MemoryCoordinatorImpl::DiscardTab() {
if (delegate_)
delegate_->DiscardTab();
« no previous file with comments | « content/browser/memory/memory_coordinator_impl.h ('k') | content/child/memory/child_memory_coordinator_impl.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698