Index: content/browser/memory/memory_state_updater.h |
diff --git a/content/browser/memory/memory_coordinator_impl.h b/content/browser/memory/memory_state_updater.h |
similarity index 51% |
copy from content/browser/memory/memory_coordinator_impl.h |
copy to content/browser/memory/memory_state_updater.h |
index 95c2a2c2004637ecaeda20d10b66c73cc68663bf..2c8998a853054ac2caec1969905220538e438e6b 100644 |
--- a/content/browser/memory/memory_coordinator_impl.h |
+++ b/content/browser/memory/memory_state_updater.h |
@@ -2,33 +2,25 @@ |
// Use of this source code is governed by a BSD-style license that can be |
// found in the LICENSE file. |
-#ifndef CONTENT_BROWSER_MEMORY_MEMORY_COORDINATOR_IMPL_H_ |
-#define CONTENT_BROWSER_MEMORY_MEMORY_COORDINATOR_IMPL_H_ |
+#ifndef CONTENT_BROWSER_MEMORY_MEMORY_STATE_UPDATER_H_ |
+#define CONTENT_BROWSER_MEMORY_MEMORY_STATE_UPDATER_H_ |
-#include "base/callback.h" |
-#include "base/memory/singleton.h" |
-#include "base/memory/weak_ptr.h" |
+#include "base/cancelable_callback.h" |
#include "base/single_thread_task_runner.h" |
-#include "base/threading/non_thread_safe.h" |
#include "base/time/time.h" |
-#include "content/browser/memory/memory_coordinator.h" |
-#include "content/public/browser/notification_observer.h" |
-#include "content/public/browser/notification_registrar.h" |
+#include "content/browser/memory/memory_coordinator_impl.h" |
+#include "content/common/content_export.h" |
namespace content { |
-class MemoryMonitor; |
-class MemoryCoordinatorImplTest; |
-struct MemoryCoordinatorSingletonTraits; |
- |
-// MemoryCoordinatorImpl is an internal implementation of MemoryCoordinator |
+// MemoryStateUpdater is an internal implementation of MemoryCoordinator |
// which uses a heuristic to determine a single global memory state. |
// In the current implementation browser process and renderer processes share |
// the global state; the memory coordinator will notify the global state to |
// all background renderers if the state has changed. |
// |
// State calculation: |
-// MemoryCoordinatorImpl uses followings to determine the global state: |
+// MemoryStateUpdater uses followings to determine the global state: |
// * Compute "number of renderers which can be created until the system will |
// be in a critical state". Call this N. |
// (See memory_monitor.h for the definition of "critical") |
@@ -36,34 +28,20 @@ struct MemoryCoordinatorSingletonTraits; |
// Once a state is changed to a limited state, larger N will be needed to go |
// back to a relaxed state. (e.g. THROTTLED -> NORMAL) |
// * Once a state is changed, it remains the same for a certain period of time. |
-class CONTENT_EXPORT MemoryCoordinatorImpl : public MemoryCoordinator, |
- public NotificationObserver, |
- public base::NonThreadSafe { |
+class CONTENT_EXPORT MemoryStateUpdater { |
public: |
- MemoryCoordinatorImpl(scoped_refptr<base::SingleThreadTaskRunner> task_runner, |
- std::unique_ptr<MemoryMonitor> monitor); |
- ~MemoryCoordinatorImpl() override; |
- |
- // MemoryCoordinator implementations: |
- void Start() override; |
- void OnChildAdded(int render_process_id) override; |
- |
- MemoryMonitor* memory_monitor() { return memory_monitor_.get(); } |
+ // |coordinator| must outlive than this instance. |
+ MemoryStateUpdater(MemoryCoordinatorImpl* coordinator, |
+ scoped_refptr<base::SingleThreadTaskRunner> task_runner); |
+ ~MemoryStateUpdater(); |
- base::MemoryState GetGlobalMemoryState() const override; |
- base::MemoryState GetCurrentMemoryState() const override; |
- void SetCurrentMemoryStateForTesting(base::MemoryState memory_state) override; |
- |
- // NotificationObserver implementation: |
- void Observe(int type, |
- const NotificationSource& source, |
- const NotificationDetails& details) override; |
+ // Calculates the next global state from the amount of free memory using |
+ // a heuristic. |
+ base::MemoryState CalculateNextState(); |
- // 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); |
+ // Schedules a task to update the global state. The task will be executed |
+ // after |delay| has passed. |
+ void ScheduleUpdateState(base::TimeDelta delay); |
private: |
FRIEND_TEST_ALL_PREFIXES(MemoryCoordinatorImplTest, CalculateNextState); |
@@ -71,43 +49,12 @@ class CONTENT_EXPORT MemoryCoordinatorImpl : public MemoryCoordinator, |
FRIEND_TEST_ALL_PREFIXES(MemoryCoordinatorImplTest, SetMemoryStateForTesting); |
FRIEND_TEST_ALL_PREFIXES(MemoryCoordinatorImplTest, ForceSetGlobalState); |
- friend struct MemoryCoordinatorSingletonTraits; |
- |
- using MemoryState = base::MemoryState; |
- |
- // 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); |
- |
- // Calculates the next global state from the amount of free memory using |
- // a heuristic. |
- MemoryState CalculateNextState(); |
- |
// Periodically called to update the global state. |
void UpdateState(); |
- // Notifies a state change to in-process clients. |
- void NotifyStateToClients(); |
- |
- // Notifies a state change to child processes. |
- void NotifyStateToChildren(); |
- |
- // Records metrics. This is called when the global state is changed. |
- void RecordStateChange(MemoryState prev_state, |
- MemoryState next_state, |
- base::TimeDelta duration); |
- |
- // Schedules a task to update the global state. The task will be executed |
- // after |delay| has passed. |
- void ScheduleUpdateState(base::TimeDelta delay); |
- |
+ MemoryCoordinatorImpl* coordinator_; |
scoped_refptr<base::SingleThreadTaskRunner> task_runner_; |
- NotificationRegistrar notification_registrar_; |
- std::unique_ptr<MemoryMonitor> memory_monitor_; |
base::CancelableClosure update_state_closure_; |
- base::MemoryState current_state_ = MemoryState::NORMAL; |
- base::TimeTicks last_state_change_; |
// Sets up parameters for the heuristic. |
void InitializeParameters(); |
@@ -142,11 +89,9 @@ class CONTENT_EXPORT MemoryCoordinatorImpl : public MemoryCoordinator, |
// The interval of checking the amount of free memory. |
base::TimeDelta monitoring_interval_; |
- base::WeakPtrFactory<MemoryCoordinatorImpl> weak_ptr_factory_; |
- |
- DISALLOW_COPY_AND_ASSIGN(MemoryCoordinatorImpl); |
+ DISALLOW_COPY_AND_ASSIGN(MemoryStateUpdater); |
}; |
} // namespace content |
-#endif // CONTENT_BROWSER_MEMORY_MEMORY_COORDINATOR_IMPL_H_ |
+#endif // CONTENT_BROWSER_MEMORY_MEMORY_STATE_UPDATER_H_ |