| Index: content/browser/memory/memory_coordinator_impl.h
|
| diff --git a/content/browser/memory/memory_coordinator_impl.h b/content/browser/memory/memory_coordinator_impl.h
|
| index f3189b6ea19909041064bbfeddc80e6cf696b465..1f096f21a67a25404a924a05e64bd4c7abc3b9ed 100644
|
| --- a/content/browser/memory/memory_coordinator_impl.h
|
| +++ b/content/browser/memory/memory_coordinator_impl.h
|
| @@ -31,6 +31,15 @@ class MemoryStateUpdater;
|
| class RenderProcessHost;
|
| struct MemoryCoordinatorSingletonTraits;
|
|
|
| +// MemoryCondition is an internal state of memory coordinator which is used for
|
| +// various things; calculating memory state for processes, requesting processes
|
| +// to purge memory, and scheduling tab discarding.
|
| +enum class MemoryCondition : int {
|
| + NORMAL = 0,
|
| + WARNING = 1,
|
| + CRITICAL = 2,
|
| +};
|
| +
|
| // MemoryCoordinatorImpl is an implementation of MemoryCoordinator.
|
| // The current implementation uses MemoryStateUpdater to update the global
|
| // memory state. See comments in MemoryStateUpdater for details.
|
| @@ -71,18 +80,16 @@ class CONTENT_EXPORT MemoryCoordinatorImpl : public base::MemoryCoordinator,
|
| void RecordMemoryPressure(
|
| base::MemoryPressureMonitor::MemoryPressureLevel level);
|
|
|
| - // Returns the global memory state.
|
| - virtual MemoryState GetGlobalMemoryState() const;
|
| + // Returns the current memory condition.
|
| + MemoryCondition GetMemoryCondtion() const { return memory_condition_; }
|
|
|
| - // Returns the browser's current memory state. Note that the current state
|
| - // could be different from the global memory state as the browser won't be
|
| - // suspended.
|
| + // Returns the browser's current memory state.
|
| MemoryState GetCurrentMemoryState() const override;
|
|
|
| - // Sets the global memory state for testing.
|
| + // Temporariy sets memory state of the browser process for testing.
|
| void SetCurrentMemoryStateForTesting(MemoryState memory_state) override;
|
|
|
| - // MemoryCoordinator implementation:
|
| + // content::MemoryCoordinator implementation:
|
| MemoryState GetStateForProcess(base::ProcessHandle handle) override;
|
|
|
| // NotificationObserver implementation:
|
| @@ -90,16 +97,16 @@ class CONTENT_EXPORT MemoryCoordinatorImpl : public base::MemoryCoordinator,
|
| const NotificationSource& source,
|
| const NotificationDetails& details) override;
|
|
|
| - // Overrides the global state to |new_state|. State update tasks won't be
|
| - // scheduled until |duration| is passed. This means that the global state
|
| - // remains the same until |duration| is passed or another call of this method.
|
| - void ForceSetGlobalState(base::MemoryState new_state,
|
| - base::TimeDelta duration);
|
| + // Overrides the current memory condition to |condition|. Memory condition
|
| + // update tasks won't be scheduled until |duration| is passed. This means that
|
| + // the memory condition remains the same until |duration| is passed or
|
| + // another call of this method.
|
| + void ForceSetMemoryCondition(MemoryCondition condition,
|
| + base::TimeDelta duration);
|
|
|
| - // Changes the global state and notifies state changes to clients (lives in
|
| - // the browser) and child processes (renderers) if needed. Returns true when
|
| - // the state is actually changed.
|
| - bool ChangeStateIfNeeded(MemoryState prev_state, MemoryState next_state);
|
| + // Changes current memory condition if needed. This may trigger some actions
|
| + // like purging memory and memory state changes.
|
| + void UpdateConditionIfNeeded(MemoryCondition condition);
|
|
|
| // Asks the delegate to discard a tab.
|
| void DiscardTab();
|
| @@ -136,6 +143,7 @@ class CONTENT_EXPORT MemoryCoordinatorImpl : public base::MemoryCoordinator,
|
| ~ChildInfo();
|
|
|
| MemoryState memory_state;
|
| + base::TimeTicks last_state_change;
|
| bool is_visible = false;
|
| std::unique_ptr<MemoryCoordinatorHandleImpl> handle;
|
| };
|
| @@ -161,13 +169,15 @@ class CONTENT_EXPORT MemoryCoordinatorImpl : public base::MemoryCoordinator,
|
| friend struct MemoryCoordinatorSingletonTraits;
|
| friend class MemoryCoordinatorHandleImpl;
|
|
|
| + // Updates the browser's memory state if needed.
|
| + void UpdateCurrentMemoryState(MemoryState state);
|
| +
|
| // Called when ChildMemoryCoordinator calls AddChild().
|
| void OnChildAdded(int render_process_id);
|
|
|
| // Called by SetChildMemoryState() to determine a child memory state based on
|
| // the current status of the child process.
|
| - MemoryState OverrideGlobalState(MemoryState memroy_state,
|
| - const ChildInfo& child);
|
| + MemoryState OverrideState(MemoryState memroy_state, const ChildInfo& child);
|
|
|
| // Helper function of CreateHandle and AddChildForTesting.
|
| void CreateChildInfoMapEntry(
|
| @@ -175,10 +185,10 @@ class CONTENT_EXPORT MemoryCoordinatorImpl : public base::MemoryCoordinator,
|
| std::unique_ptr<MemoryCoordinatorHandleImpl> handle);
|
|
|
| // Notifies a state change to in-process clients.
|
| - void NotifyStateToClients();
|
| + void NotifyStateToClients(MemoryState state);
|
|
|
| // Notifies a state change to child processes.
|
| - void NotifyStateToChildren();
|
| + void NotifyStateToChildren(MemoryState state);
|
|
|
| // Records metrics. This is called when the global state is changed.
|
| void RecordStateChange(MemoryState prev_state,
|
| @@ -189,10 +199,20 @@ class CONTENT_EXPORT MemoryCoordinatorImpl : public base::MemoryCoordinator,
|
| std::unique_ptr<MemoryMonitor> memory_monitor_;
|
| std::unique_ptr<MemoryStateUpdater> state_updater_;
|
| NotificationRegistrar notification_registrar_;
|
| - // The global memory state.
|
| +
|
| + // The current memory condition.
|
| + MemoryCondition memory_condition_ = MemoryCondition::NORMAL;
|
| +
|
| + // The memory state of the browser process.
|
| MemoryState current_state_ = MemoryState::NORMAL;
|
| - // The time tick of last global state change.
|
| +
|
| + // The time tick of last state change of the browser process.
|
| base::TimeTicks last_state_change_;
|
| +
|
| + // Memory state for a process will remain unchanged until this period of time
|
| + // passes.
|
| + base::TimeDelta minimum_state_transition_period_;
|
| +
|
| // Tracks child processes. An entry is added when a renderer connects to
|
| // MemoryCoordinator and removed automatically when an underlying binding is
|
| // disconnected.
|
|
|