| 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 4374cfc75e737013fef3b39a99ee7f55f304fbcb..7bf66b16c0b172caace37d0f6099d1afac820cf5 100644
|
| --- a/content/browser/memory/memory_coordinator_impl.h
|
| +++ b/content/browser/memory/memory_coordinator_impl.h
|
| @@ -24,16 +24,23 @@ namespace content {
|
|
|
| // NOTE: Memory coordinator is under development and not fully working.
|
|
|
| +class MemoryConditionObserver;
|
| class MemoryCoordinatorHandleImpl;
|
| class MemoryCoordinatorImplTest;
|
| class MemoryMonitor;
|
| -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.
|
| class CONTENT_EXPORT MemoryCoordinatorImpl : public base::MemoryCoordinator,
|
| public MemoryCoordinator,
|
| public NotificationObserver,
|
| @@ -71,18 +78,15 @@ class CONTENT_EXPORT MemoryCoordinatorImpl : public base::MemoryCoordinator,
|
| void RecordMemoryPressure(
|
| base::MemoryPressureMonitor::MemoryPressureLevel level);
|
|
|
| - // Returns the global memory state.
|
| - virtual MemoryState GetGlobalMemoryState() const;
|
| + // Returns the browser's current memory state.
|
| + MemoryState GetBrowserMemoryState() const;
|
|
|
| - // 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.
|
| + // base::MemoryCoordinator implementations:
|
| MemoryState GetCurrentMemoryState() const override;
|
| -
|
| - // Sets the global memory state for testing.
|
| + // Temporarily 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 +94,19 @@ 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);
|
| + // Returns the current memory condition.
|
| + MemoryCondition GetMemoryCondition() const { return memory_condition_; }
|
|
|
| - // 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);
|
| + // 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 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();
|
| @@ -153,10 +160,10 @@ class CONTENT_EXPORT MemoryCoordinatorImpl : public base::MemoryCoordinator,
|
| FRIEND_TEST_ALL_PREFIXES(MemoryCoordinatorWithServiceWorkerTest,
|
| CannotSuspendRendererWithServiceWorker);
|
| #endif
|
| - FRIEND_TEST_ALL_PREFIXES(MemoryCoordinatorImplTest, CalculateNextState);
|
| - FRIEND_TEST_ALL_PREFIXES(MemoryCoordinatorImplTest, UpdateState);
|
| + FRIEND_TEST_ALL_PREFIXES(MemoryCoordinatorImplTest, CalculateNextCondition);
|
| + FRIEND_TEST_ALL_PREFIXES(MemoryCoordinatorImplTest, UpdateCondition);
|
| FRIEND_TEST_ALL_PREFIXES(MemoryCoordinatorImplTest, SetMemoryStateForTesting);
|
| - FRIEND_TEST_ALL_PREFIXES(MemoryCoordinatorImplTest, ForceSetGlobalState);
|
| + FRIEND_TEST_ALL_PREFIXES(MemoryCoordinatorImplTest, ForceSetMemoryCondition);
|
|
|
| friend struct MemoryCoordinatorSingletonTraits;
|
| friend class MemoryCoordinatorHandleImpl;
|
| @@ -166,28 +173,40 @@ class CONTENT_EXPORT MemoryCoordinatorImpl : public base::MemoryCoordinator,
|
|
|
| // 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(
|
| int render_process_id,
|
| std::unique_ptr<MemoryCoordinatorHandleImpl> handle);
|
|
|
| + // Updates the browser's memory state and notifies it to in-process clients.
|
| + void UpdateBrowserStateAndNotifyStateToClients(MemoryState state);
|
| +
|
| // 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);
|
|
|
| std::unique_ptr<MemoryCoordinatorDelegate> delegate_;
|
| std::unique_ptr<MemoryMonitor> memory_monitor_;
|
| - std::unique_ptr<MemoryStateUpdater> state_updater_;
|
| + std::unique_ptr<MemoryConditionObserver> condition_observer_;
|
| NotificationRegistrar notification_registrar_;
|
| - // The global memory state.
|
| - MemoryState current_state_ = MemoryState::NORMAL;
|
| - // The time tick of last global state change.
|
| +
|
| + // The current memory condition.
|
| + MemoryCondition memory_condition_ = MemoryCondition::NORMAL;
|
| +
|
| + // The memory state of the browser process.
|
| + MemoryState browser_memory_state_ = MemoryState::NORMAL;
|
| +
|
| + // 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.
|
|
|