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

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

Issue 2448953002: Add MemoryCoordinatorProxy::SetCurrentMemoryStateForTesting (Closed)
Patch Set: Add tests 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_impl.h" 5 #include "content/browser/memory/memory_coordinator_impl.h"
6 6
7 #include "base/threading/thread_task_runner_handle.h" 7 #include "base/threading/thread_task_runner_handle.h"
8 #include "content/browser/memory/memory_monitor.h" 8 #include "content/browser/memory/memory_monitor.h"
9 #include "content/public/browser/notification_service.h" 9 #include "content/public/browser/notification_service.h"
10 #include "content/public/browser/notification_types.h" 10 #include "content/public/browser/notification_types.h"
(...skipping 96 matching lines...) Expand 10 before | Expand all | Expand 10 after
107 107
108 void MemoryCoordinatorImpl::OnChildAdded(int render_process_id) { 108 void MemoryCoordinatorImpl::OnChildAdded(int render_process_id) {
109 // Populate the global state as an initial state of a newly created process. 109 // Populate the global state as an initial state of a newly created process.
110 SetMemoryState(render_process_id, ToMojomMemoryState(current_state_)); 110 SetMemoryState(render_process_id, ToMojomMemoryState(current_state_));
111 } 111 }
112 112
113 base::MemoryState MemoryCoordinatorImpl::GetCurrentMemoryState() const { 113 base::MemoryState MemoryCoordinatorImpl::GetCurrentMemoryState() const {
114 return current_state_; 114 return current_state_;
115 } 115 }
116 116
117 void MemoryCoordinatorImpl::SetCurrentMemoryStateForTesting(
118 base::MemoryState memory_state) {
119 // This changes the current state temporariy for testing. The state will be
120 // updated later by the task posted at ScheduleUpdateState.
121 base::MemoryState prev_state = current_state_;
122 current_state_ = memory_state;
123 if (prev_state != current_state_) {
124 NotifyStateToClients();
125 NotifyStateToChildren();
126 }
127 }
128
117 void MemoryCoordinatorImpl::Observe(int type, 129 void MemoryCoordinatorImpl::Observe(int type,
118 const NotificationSource& source, 130 const NotificationSource& source,
119 const NotificationDetails& details) { 131 const NotificationDetails& details) {
120 DCHECK(type == NOTIFICATION_RENDER_WIDGET_VISIBILITY_CHANGED); 132 DCHECK(type == NOTIFICATION_RENDER_WIDGET_VISIBILITY_CHANGED);
121 RenderWidgetHost* render_widget_host = Source<RenderWidgetHost>(source).ptr(); 133 RenderWidgetHost* render_widget_host = Source<RenderWidgetHost>(source).ptr();
122 RenderProcessHost* process = render_widget_host->GetProcess(); 134 RenderProcessHost* process = render_widget_host->GetProcess();
123 if (!process) 135 if (!process)
124 return; 136 return;
125 auto iter = children().find(process->GetID()); 137 auto iter = children().find(process->GetID());
126 if (iter == children().end()) 138 if (iter == children().end())
(...skipping 82 matching lines...) Expand 10 before | Expand all | Expand 10 after
209 } 221 }
210 222
211 bool MemoryCoordinatorImpl::ValidateParameters() { 223 bool MemoryCoordinatorImpl::ValidateParameters() {
212 return (new_renderers_until_throttled_ > new_renderers_until_suspended_) && 224 return (new_renderers_until_throttled_ > new_renderers_until_suspended_) &&
213 (new_renderers_back_to_normal_ > new_renderers_back_to_throttled_) && 225 (new_renderers_back_to_normal_ > new_renderers_back_to_throttled_) &&
214 (new_renderers_back_to_normal_ > new_renderers_until_throttled_) && 226 (new_renderers_back_to_normal_ > new_renderers_until_throttled_) &&
215 (new_renderers_back_to_throttled_ > new_renderers_until_suspended_); 227 (new_renderers_back_to_throttled_ > new_renderers_until_suspended_);
216 } 228 }
217 229
218 } // namespace content 230 } // namespace content
OLDNEW
« no previous file with comments | « content/browser/memory/memory_coordinator_impl.h ('k') | content/browser/memory/memory_coordinator_impl_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698