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

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

Issue 1332583002: Architecture for cross-process memory notification suppressing (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Remove unnecessary includes Created 5 years, 3 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
(Empty)
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
3 // found in the LICENSE file.
4
5 #include "content/browser/memory/memory_pressure_controller.h"
6
7 #include "base/bind.h"
8 #include "base/memory/memory_pressure_listener.h"
9 #include "content/browser/memory/memory_message_filter.h"
10 #include "content/public/browser/browser_thread.h"
11
12 namespace content {
13
14 MemoryPressureController::MemoryPressureController() {}
15
16 MemoryPressureController::~MemoryPressureController() {}
17
18 void MemoryPressureController::OnMemoryMessageFilterAdded(
19 MemoryMessageFilter* filter) {
20 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
21 DCHECK(memory_message_filters_.find(filter) == memory_message_filters_.end());
22
23 memory_message_filters_.insert(filter);
24
25 // There's no need to send a message to the child process if memory pressure
26 // notifications are not suppressed.
27 if (base::MemoryPressureListener::AreNotificationsSuppressed())
28 filter->SendSetPressureNotificationsSuppressed(true);
29 }
30
31 void MemoryPressureController::OnMemoryMessageFilterRemoved(
32 MemoryMessageFilter* filter) {
33 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
34 DCHECK(memory_message_filters_.find(filter) != memory_message_filters_.end());
35
36 memory_message_filters_.erase(filter);
37 }
38
39 // static
40 MemoryPressureController* MemoryPressureController::GetInstance() {
41 return base::Singleton<
42 MemoryPressureController,
43 base::LeakySingletonTraits<MemoryPressureController>>::get();
44 }
45
46 void MemoryPressureController::SetPressureNotificationsSuppressedInAllProcesses(
47 bool suppressed) {
48 if (!BrowserThread::CurrentlyOn(BrowserThread::IO)) {
49 BrowserThread::PostTask(
50 BrowserThread::IO, FROM_HERE,
51 base::Bind(&MemoryPressureController::
52 SetPressureNotificationsSuppressedInAllProcesses,
53 base::Unretained(this), suppressed));
nasko 2015/09/16 21:18:37 Please add a comment why base::Unretained(this) is
petrcermak 2015/09/17 15:24:53 Done.
54 return;
55 }
56
57 // Enable/disable suppressing memory notifications in the browser process.
58 base::MemoryPressureListener::SetNotificationsSuppressed(suppressed);
59
60 // Enable/disable suppressing memory notifications in all child processes.
61 for (MemoryMessageFilterSet::iterator it = memory_message_filters_.begin();
62 it != memory_message_filters_.end(); ++it) {
63 it->get()->SendSetPressureNotificationsSuppressed(suppressed);
64 }
65 }
66
67 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698