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

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

Issue 1362233003: Add architecture for simulating memory pressure notifications in all processes (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 5 years, 2 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 2015 The Chromium Authors. All rights reserved. 1 // Copyright 2015 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_pressure_controller.h" 5 #include "content/browser/memory/memory_pressure_controller.h"
6 6
7 #include "base/bind.h" 7 #include "base/bind.h"
8 #include "base/memory/memory_pressure_listener.h"
9 #include "content/browser/memory/memory_message_filter.h" 8 #include "content/browser/memory/memory_message_filter.h"
10 #include "content/public/browser/browser_thread.h" 9 #include "content/public/browser/browser_thread.h"
11 10
12 namespace content { 11 namespace content {
13 12
14 MemoryPressureController::MemoryPressureController() {} 13 MemoryPressureController::MemoryPressureController() {}
15 14
16 MemoryPressureController::~MemoryPressureController() {} 15 MemoryPressureController::~MemoryPressureController() {}
17 16
18 void MemoryPressureController::OnMemoryMessageFilterAdded( 17 void MemoryPressureController::OnMemoryMessageFilterAdded(
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after
63 // Enable/disable suppressing memory notifications in the browser process. 62 // Enable/disable suppressing memory notifications in the browser process.
64 base::MemoryPressureListener::SetNotificationsSuppressed(suppressed); 63 base::MemoryPressureListener::SetNotificationsSuppressed(suppressed);
65 64
66 // Enable/disable suppressing memory notifications in all child processes. 65 // Enable/disable suppressing memory notifications in all child processes.
67 for (MemoryMessageFilterSet::iterator it = memory_message_filters_.begin(); 66 for (MemoryMessageFilterSet::iterator it = memory_message_filters_.begin();
68 it != memory_message_filters_.end(); ++it) { 67 it != memory_message_filters_.end(); ++it) {
69 it->get()->SendSetPressureNotificationsSuppressed(suppressed); 68 it->get()->SendSetPressureNotificationsSuppressed(suppressed);
70 } 69 }
71 } 70 }
72 71
72 void MemoryPressureController::SimulatePressureNotificationInAllProcesses(
73 MemoryPressureLevel level) {
74 DCHECK_NE(level, MemoryPressureLevel::MEMORY_PRESSURE_LEVEL_NONE);
75
76 if (!BrowserThread::CurrentlyOn(BrowserThread::IO)) {
77 // Note that passing base::Unretained(this) is safe here because the
78 // controller is a leaky singleton (i.e. it is never deleted).
Primiano Tucci (use gerrit) 2015/09/28 12:47:31 the i.e. part in parenthesis is really superfluos
petrcermak 2015/09/28 15:39:32 Done (removed in both methods).
79 BrowserThread::PostTask(
80 BrowserThread::IO, FROM_HERE,
81 base::Bind(&MemoryPressureController::
82 SimulatePressureNotificationInAllProcesses,
83 base::Unretained(this), level));
84 return;
85 }
86
87 // Simulate memory pressure notification in the browser process.
88 base::MemoryPressureListener::SimulatePressureNotification(level);
89
90 // Simulate memory pressure notification in all child processes.
91 for (MemoryMessageFilterSet::iterator it = memory_message_filters_.begin();
Primiano Tucci (use gerrit) 2015/09/28 12:47:31 you could use a one-line C++11 style foreach here
petrcermak 2015/09/28 15:39:32 Done (in both methods).
92 it != memory_message_filters_.end(); ++it) {
93 it->get()->SendSimulatePressureNotification(level);
Primiano Tucci (use gerrit) 2015/09/28 12:47:32 ..and that will avoid you to use the ->get() What
petrcermak 2015/09/28 15:39:32 Done.
94 }
95 }
96
73 } // namespace content 97 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698