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

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: Address Primiano's comments 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 25 matching lines...) Expand all
44 MemoryPressureController* MemoryPressureController::GetInstance() { 43 MemoryPressureController* MemoryPressureController::GetInstance() {
45 return base::Singleton< 44 return base::Singleton<
46 MemoryPressureController, 45 MemoryPressureController,
47 base::LeakySingletonTraits<MemoryPressureController>>::get(); 46 base::LeakySingletonTraits<MemoryPressureController>>::get();
48 } 47 }
49 48
50 void MemoryPressureController::SetPressureNotificationsSuppressedInAllProcesses( 49 void MemoryPressureController::SetPressureNotificationsSuppressedInAllProcesses(
51 bool suppressed) { 50 bool suppressed) {
52 if (!BrowserThread::CurrentlyOn(BrowserThread::IO)) { 51 if (!BrowserThread::CurrentlyOn(BrowserThread::IO)) {
53 // Note that passing base::Unretained(this) is safe here because the 52 // Note that passing base::Unretained(this) is safe here because the
54 // controller is a leaky singleton (i.e. it is never deleted). 53 // controller is a leaky singleton.
55 BrowserThread::PostTask( 54 BrowserThread::PostTask(
56 BrowserThread::IO, FROM_HERE, 55 BrowserThread::IO, FROM_HERE,
57 base::Bind(&MemoryPressureController:: 56 base::Bind(&MemoryPressureController::
58 SetPressureNotificationsSuppressedInAllProcesses, 57 SetPressureNotificationsSuppressedInAllProcesses,
59 base::Unretained(this), suppressed)); 58 base::Unretained(this), suppressed));
60 return; 59 return;
61 } 60 }
62 61
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 (const scoped_refptr<MemoryMessageFilter>& mf : memory_message_filters_)
nasko 2015/09/30 16:44:58 nit: s/mf/filter/
petrcermak 2015/09/30 18:18:36 Done.
68 it != memory_message_filters_.end(); ++it) { 67 mf->SendSetPressureNotificationsSuppressed(suppressed);
69 it->get()->SendSetPressureNotificationsSuppressed(suppressed); 68 }
69
70 void MemoryPressureController::SimulatePressureNotificationInAllProcesses(
71 base::MemoryPressureListener::MemoryPressureLevel level) {
72 DCHECK_NE(level, base::MemoryPressureListener::MEMORY_PRESSURE_LEVEL_NONE);
73
74 if (!BrowserThread::CurrentlyOn(BrowserThread::IO)) {
75 // Note that passing base::Unretained(this) is safe here because the
76 // controller is a leaky singleton.
77 BrowserThread::PostTask(
78 BrowserThread::IO, FROM_HERE,
79 base::Bind(&MemoryPressureController::
80 SimulatePressureNotificationInAllProcesses,
81 base::Unretained(this), level));
82 return;
70 } 83 }
84
85 // Simulate memory pressure notification in the browser process.
86 base::MemoryPressureListener::SimulatePressureNotification(level);
87
88 // Simulate memory pressure notification in all child processes.
89 for (const scoped_refptr<MemoryMessageFilter>& mf : memory_message_filters_)
nasko 2015/09/30 16:44:58 nit: s/mf/filter/
petrcermak 2015/09/30 18:18:36 Done.
90 mf->SendSimulatePressureNotification(level);
71 } 91 }
72 92
73 } // namespace content 93 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698