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

Side by Side Diff: content/browser/memory/memory_coordinator_impl.h

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 unified diff | Download patch
OLDNEW
1 // Copyright 2016 The Chromium Authors. All rights reserved. 1 // Copyright 2016 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #ifndef CONTENT_BROWSER_MEMORY_MEMORY_COORDINATOR_IMPL_H_ 5 #ifndef CONTENT_BROWSER_MEMORY_MEMORY_COORDINATOR_IMPL_H_
6 #define CONTENT_BROWSER_MEMORY_MEMORY_COORDINATOR_IMPL_H_ 6 #define CONTENT_BROWSER_MEMORY_MEMORY_COORDINATOR_IMPL_H_
7 7
8 #include "base/callback.h" 8 #include "base/callback.h"
9 #include "base/memory/memory_coordinator_client.h" 9 #include "base/memory/memory_coordinator_client.h"
10 #include "base/memory/memory_coordinator_proxy.h" 10 #include "base/memory/memory_coordinator_proxy.h"
11 #include "base/memory/memory_pressure_monitor.h" 11 #include "base/memory/memory_pressure_monitor.h"
12 #include "base/memory/singleton.h" 12 #include "base/memory/singleton.h"
13 #include "base/single_thread_task_runner.h" 13 #include "base/single_thread_task_runner.h"
14 #include "base/threading/non_thread_safe.h" 14 #include "base/threading/non_thread_safe.h"
15 #include "base/time/time.h" 15 #include "base/time/time.h"
16 #include "content/common/content_export.h" 16 #include "content/common/content_export.h"
17 #include "content/common/memory_coordinator.mojom.h" 17 #include "content/common/memory_coordinator.mojom.h"
18 #include "content/public/browser/memory_coordinator.h" 18 #include "content/public/browser/memory_coordinator.h"
19 #include "content/public/browser/memory_coordinator_delegate.h" 19 #include "content/public/browser/memory_coordinator_delegate.h"
20 #include "content/public/browser/notification_observer.h" 20 #include "content/public/browser/notification_observer.h"
21 #include "content/public/browser/notification_registrar.h" 21 #include "content/public/browser/notification_registrar.h"
22 #include "mojo/public/cpp/system/buffer.h"
22 23
23 namespace content { 24 namespace content {
24 25
25 // NOTE: Memory coordinator is under development and not fully working. 26 // NOTE: Memory coordinator is under development and not fully working.
26 27
27 class MemoryConditionObserver; 28 class MemoryConditionObserver;
28 class MemoryCoordinatorHandleImpl; 29 class MemoryCoordinatorHandleImpl;
29 class MemoryCoordinatorImplTest; 30 class MemoryCoordinatorImplTest;
30 class MemoryMonitor; 31 class MemoryMonitor;
31 class RenderProcessHost; 32 class RenderProcessHost;
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after
73 // if the process is not tracked by this coordinator. 74 // if the process is not tracked by this coordinator.
74 MemoryState GetChildMemoryState(int render_process_id) const; 75 MemoryState GetChildMemoryState(int render_process_id) const;
75 76
76 // Records memory pressure notifications. Called by MemoryPressureMonitor. 77 // Records memory pressure notifications. Called by MemoryPressureMonitor.
77 // TODO(bashi): Remove this when MemoryPressureMonitor is retired. 78 // TODO(bashi): Remove this when MemoryPressureMonitor is retired.
78 void RecordMemoryPressure( 79 void RecordMemoryPressure(
79 base::MemoryPressureMonitor::MemoryPressureLevel level); 80 base::MemoryPressureMonitor::MemoryPressureLevel level);
80 81
81 // base::MemoryCoordinator implementations: 82 // base::MemoryCoordinator implementations:
82 MemoryState GetCurrentMemoryState() const override; 83 MemoryState GetCurrentMemoryState() const override;
84 int64_t GetGlobalBudget() override;
85 void SetGlobalBudgetUpdateInterval(uint32_t interval_ms) override;
83 86
84 // content::MemoryCoordinator implementation: 87 // content::MemoryCoordinator implementation:
85 MemoryState GetStateForProcess(base::ProcessHandle handle) override; 88 MemoryState GetStateForProcess(base::ProcessHandle handle) override;
86 89
87 // NotificationObserver implementation: 90 // NotificationObserver implementation:
88 void Observe(int type, 91 void Observe(int type,
89 const NotificationSource& source, 92 const NotificationSource& source,
90 const NotificationDetails& details) override; 93 const NotificationDetails& details) override;
91 94
92 // Returns the current memory condition. 95 // Returns the current memory condition.
93 MemoryCondition GetMemoryCondition() const { return memory_condition_; } 96 MemoryCondition GetMemoryCondition() const { return memory_condition_; }
94 97
95 // Overrides the current memory condition to |condition|. Memory condition 98 // Overrides the current memory condition to |condition|. Memory condition
96 // update tasks won't be scheduled until |duration| is passed. This means that 99 // update tasks won't be scheduled until |duration| is passed. This means that
97 // the memory condition remains the same until |duration| is passed or 100 // the memory condition remains the same until |duration| is passed or
98 // another call of this method. 101 // another call of this method.
99 void ForceSetMemoryCondition(MemoryCondition condition, 102 void ForceSetMemoryCondition(MemoryCondition condition,
100 base::TimeDelta duration); 103 base::TimeDelta duration);
101 104
102 // Changes current memory condition if needed. This may trigger some actions 105 // Changes current memory condition if needed. This may trigger some actions
103 // like purging memory and memory state changes. 106 // like purging memory and memory state changes.
104 void UpdateConditionIfNeeded(MemoryCondition condition); 107 void UpdateConditionIfNeeded(MemoryCondition condition);
105 108
109 // Updates the global memory budget.
110 void UpdateGlobalBudget(int budget);
111
106 // Asks the delegate to discard a tab. 112 // Asks the delegate to discard a tab.
107 void DiscardTab(); 113 void DiscardTab();
108 114
109 protected: 115 protected:
110 // Returns the RenderProcessHost which is correspond to the given id. 116 // Returns the RenderProcessHost which is correspond to the given id.
111 // Returns nullptr if there is no corresponding RenderProcessHost. 117 // Returns nullptr if there is no corresponding RenderProcessHost.
112 // This is a virtual method so that we can write tests without having 118 // This is a virtual method so that we can write tests without having
113 // actual RenderProcessHost. 119 // actual RenderProcessHost.
114 virtual RenderProcessHost* GetRenderProcessHost(int render_process_id); 120 virtual RenderProcessHost* GetRenderProcessHost(int render_process_id);
115 121
(...skipping 89 matching lines...) Expand 10 before | Expand all | Expand 10 after
205 211
206 // Memory state for a process will remain unchanged until this period of time 212 // Memory state for a process will remain unchanged until this period of time
207 // passes. 213 // passes.
208 base::TimeDelta minimum_state_transition_period_; 214 base::TimeDelta minimum_state_transition_period_;
209 215
210 // Tracks child processes. An entry is added when a renderer connects to 216 // Tracks child processes. An entry is added when a renderer connects to
211 // MemoryCoordinator and removed automatically when an underlying binding is 217 // MemoryCoordinator and removed automatically when an underlying binding is
212 // disconnected. 218 // disconnected.
213 ChildInfoMap children_; 219 ChildInfoMap children_;
214 220
221 mojo::ScopedSharedBufferHandle global_budget_handle_;
222 mojo::ScopedSharedBufferMapping global_budget_mapping_;
223
215 DISALLOW_COPY_AND_ASSIGN(MemoryCoordinatorImpl); 224 DISALLOW_COPY_AND_ASSIGN(MemoryCoordinatorImpl);
216 }; 225 };
217 226
218 } // namespace content 227 } // namespace content
219 228
220 #endif // CONTENT_BROWSER_MEMORY_MEMORY_COORDINATOR_IMPL_H_ 229 #endif // CONTENT_BROWSER_MEMORY_MEMORY_COORDINATOR_IMPL_H_
OLDNEW
« no previous file with comments | « content/browser/memory/memory_condition_observer.cc ('k') | content/browser/memory/memory_coordinator_impl.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698