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

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

Issue 2718963002: Drop the global memory state from memory coordinator (Closed)
Patch Set: format Created 3 years, 10 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.h
diff --git a/content/browser/memory/memory_coordinator_impl.h b/content/browser/memory/memory_coordinator_impl.h
index 4374cfc75e737013fef3b39a99ee7f55f304fbcb..b92d83c28c6074680f8f63aad1e8bc4d3ec963b4 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,13 @@ 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. 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.
haraken 2017/02/28 11:33:45 Temporarily
bashi 2017/03/02 04:01:45 Done.
void SetCurrentMemoryStateForTesting(MemoryState memory_state) override;
- // MemoryCoordinator implementation:
+ // content::MemoryCoordinator implementation:
MemoryState GetStateForProcess(base::ProcessHandle handle) override;
// NotificationObserver implementation:
@@ -90,16 +92,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,21 +158,23 @@ 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;
+ // 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,19 +182,29 @@ 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);
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.
+
+ // The current memory condition.
+ MemoryCondition memory_condition_ = MemoryCondition::NORMAL;
+
+ // The memory state of the browser process.
MemoryState current_state_ = MemoryState::NORMAL;
haraken 2017/02/28 11:33:45 current_state_ => browser_memory_state_ ?
bashi 2017/03/02 04:01:45 Yes. Done.
- // 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.

Powered by Google App Engine
This is Rietveld 408576698