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

Side by Side Diff: content/browser/memory/memory_coordinator.cc

Issue 2479673002: Expose MemoryCoordinator's global budget information. (Closed)
Patch Set: Small cleanup. Created 4 years, 1 month 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 #include "content/browser/memory/memory_coordinator.h" 5 #include "content/browser/memory/memory_coordinator.h"
6 6
7 #include "base/memory/memory_coordinator_client_registry.h" 7 #include "base/memory/memory_coordinator_client_registry.h"
8 #include "content/public/browser/content_browser_client.h" 8 #include "content/public/browser/content_browser_client.h"
9 #include "content/public/browser/render_process_host.h" 9 #include "content/public/browser/render_process_host.h"
10 #include "content/public/common/content_client.h" 10 #include "content/public/common/content_client.h"
(...skipping 94 matching lines...) Expand 10 before | Expand all | Expand 10 after
105 if (memory_state == mojom::MemoryState::SUSPENDED && 105 if (memory_state == mojom::MemoryState::SUSPENDED &&
106 !CanSuspendRenderer(render_process_id)) 106 !CanSuspendRenderer(render_process_id))
107 return false; 107 return false;
108 108
109 // Update the internal state and send the message. 109 // Update the internal state and send the message.
110 iter->second.memory_state = memory_state; 110 iter->second.memory_state = memory_state;
111 iter->second.handle->child()->OnStateChange(memory_state); 111 iter->second.handle->child()->OnStateChange(memory_state);
112 return true; 112 return true;
113 } 113 }
114 114
115 bool MemoryCoordinator::SetRemainingGlobalBudget(
116 int render_process_id, int64_t remaining_global_budget_mb) {
117 // Can't send a message to a child that doesn't exist.
118 auto iter = children_.find(render_process_id);
119 if (iter == children_.end())
120 return false;
121
122 // Can't send a message to a child that isn't bound.
123 if (!iter->second.handle->child().is_bound())
124 return false;
125
126 // Send the new budget.
127 iter->second.handle->child()->SetRemainingGlobalBudget(
128 remaining_global_budget_mb);
129
130 return true;
131 }
132
115 mojom::MemoryState MemoryCoordinator::GetMemoryState( 133 mojom::MemoryState MemoryCoordinator::GetMemoryState(
116 int render_process_id) const { 134 int render_process_id) const {
117 auto iter = children_.find(render_process_id); 135 auto iter = children_.find(render_process_id);
118 if (iter == children_.end()) 136 if (iter == children_.end())
119 return mojom::MemoryState::UNKNOWN; 137 return mojom::MemoryState::UNKNOWN;
120 return iter->second.memory_state; 138 return iter->second.memory_state;
121 } 139 }
122 140
123 void MemoryCoordinator::EnableFeaturesForTesting() { 141 void MemoryCoordinator::EnableFeaturesForTesting() {
124 base::FeatureList::ClearInstanceForTesting(); 142 base::FeatureList::ClearInstanceForTesting();
125 std::unique_ptr<base::FeatureList> feature_list(new base::FeatureList); 143 std::unique_ptr<base::FeatureList> feature_list(new base::FeatureList);
126 feature_list->InitializeFromCommandLine(features::kMemoryCoordinator.name, 144 feature_list->InitializeFromCommandLine(features::kMemoryCoordinator.name,
127 ""); 145 "");
128 base::FeatureList::SetInstance(std::move(feature_list)); 146 base::FeatureList::SetInstance(std::move(feature_list));
129 } 147 }
130 148
131 base::MemoryState MemoryCoordinator::GetCurrentMemoryState() const { 149 base::MemoryState MemoryCoordinator::GetCurrentMemoryState() const {
132 return base::MemoryState::UNKNOWN; 150 return base::MemoryState::UNKNOWN;
133 } 151 }
134 152
135 void MemoryCoordinator::SetCurrentMemoryStateForTesting( 153 void MemoryCoordinator::SetCurrentMemoryStateForTesting(
136 base::MemoryState memory_state) { 154 base::MemoryState memory_state) {
137 } 155 }
138 156
157 int64_t MemoryCoordinator::GetRemainingGlobalBudget() const {
158 return 0;
159 }
160
139 void MemoryCoordinator::AddChildForTesting( 161 void MemoryCoordinator::AddChildForTesting(
140 int dummy_render_process_id, mojom::ChildMemoryCoordinatorPtr child) { 162 int dummy_render_process_id, mojom::ChildMemoryCoordinatorPtr child) {
141 mojom::MemoryCoordinatorHandlePtr mch; 163 mojom::MemoryCoordinatorHandlePtr mch;
142 auto request = mojo::GetProxy(&mch); 164 auto request = mojo::GetProxy(&mch);
143 std::unique_ptr<MemoryCoordinatorHandleImpl> handle( 165 std::unique_ptr<MemoryCoordinatorHandleImpl> handle(
144 new MemoryCoordinatorHandleImpl(std::move(request), this, 166 new MemoryCoordinatorHandleImpl(std::move(request), this,
145 dummy_render_process_id)); 167 dummy_render_process_id));
146 handle->AddChild(std::move(child)); 168 handle->AddChild(std::move(child));
147 CreateChildInfoMapEntry(dummy_render_process_id, std::move(handle)); 169 CreateChildInfoMapEntry(dummy_render_process_id, std::move(handle));
148 } 170 }
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after
184 206
185 MemoryCoordinator::ChildInfo::ChildInfo() {} 207 MemoryCoordinator::ChildInfo::ChildInfo() {}
186 208
187 MemoryCoordinator::ChildInfo::ChildInfo(const ChildInfo& rhs) { 209 MemoryCoordinator::ChildInfo::ChildInfo(const ChildInfo& rhs) {
188 // This is a nop, but exists for compatibility with STL containers. 210 // This is a nop, but exists for compatibility with STL containers.
189 } 211 }
190 212
191 MemoryCoordinator::ChildInfo::~ChildInfo() {} 213 MemoryCoordinator::ChildInfo::~ChildInfo() {}
192 214
193 } // namespace content 215 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698