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

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: Add comment explaining the use of scoped_ptr in the browser test matcher 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_CURRENTLY_ON(BrowserThread::IO);
21
22 // Add the message filter to the set of all memory message filters and check
23 // that it wasn't there beforehand.
24 DCHECK(memory_message_filters_.insert(filter).second);
25
26 // There's no need to send a message to the child process if memory pressure
27 // notifications are not suppressed.
28 if (base::MemoryPressureListener::AreNotificationsSuppressed())
29 filter->SendSetPressureNotificationsSuppressed(true);
30 }
31
32 void MemoryPressureController::OnMemoryMessageFilterRemoved(
33 MemoryMessageFilter* filter) {
34 DCHECK_CURRENTLY_ON(BrowserThread::IO);
35
36 // Remove the message filter from the set of all memory message filters and
37 // check that it was there beforehand.
38 DCHECK_EQ(1u, memory_message_filters_.erase(filter));
39 }
40
41 // static
42 MemoryPressureController* MemoryPressureController::GetInstance() {
43 return base::Singleton<
44 MemoryPressureController,
45 base::LeakySingletonTraits<MemoryPressureController>>::get();
46 }
47
48 void MemoryPressureController::SetPressureNotificationsSuppressedInAllProcesses(
49 bool suppressed) {
50 if (!BrowserThread::CurrentlyOn(BrowserThread::IO)) {
51 // Note that passing base::Unretained(this) is safe here because the
52 // controller is a leaky singleton (i.e. it is never deleted).
53 BrowserThread::PostTask(
54 BrowserThread::IO, FROM_HERE,
55 base::Bind(&MemoryPressureController::
56 SetPressureNotificationsSuppressedInAllProcesses,
57 base::Unretained(this), suppressed));
58 return;
59 }
60
61 // Enable/disable suppressing memory notifications in the browser process.
62 base::MemoryPressureListener::SetNotificationsSuppressed(suppressed);
63
64 // Enable/disable suppressing memory notifications in all child processes.
65 for (MemoryMessageFilterSet::iterator it = memory_message_filters_.begin();
66 it != memory_message_filters_.end(); ++it) {
67 it->get()->SendSetPressureNotificationsSuppressed(suppressed);
68 }
69 }
70
71 } // namespace content
OLDNEW
« no previous file with comments | « content/browser/memory/memory_pressure_controller.h ('k') | content/browser/memory/memory_pressure_controller_browsertest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698