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

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

Issue 1361963002: Re-land architecture for cross-process memory notification suppressing (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Fixed patch 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 const bool success = memory_message_filters_.insert(filter).second;
25 DCHECK(success);
Sami 2015/09/23 10:29:44 This might complain about |success| not being used
petrcermak 2015/09/23 10:32:37 This pattern is used in other parts of the codebas
26
27 // There's no need to send a message to the child process if memory pressure
28 // notifications are not suppressed.
29 if (base::MemoryPressureListener::AreNotificationsSuppressed())
30 filter->SendSetPressureNotificationsSuppressed(true);
31 }
32
33 void MemoryPressureController::OnMemoryMessageFilterRemoved(
34 MemoryMessageFilter* filter) {
35 DCHECK_CURRENTLY_ON(BrowserThread::IO);
36
37 // Remove the message filter from the set of all memory message filters and
38 // check that it was there beforehand.
39 const bool success = memory_message_filters_.erase(filter) == 1u;
40 DCHECK(success);
41 }
42
43 // static
44 MemoryPressureController* MemoryPressureController::GetInstance() {
45 return base::Singleton<
46 MemoryPressureController,
47 base::LeakySingletonTraits<MemoryPressureController>>::get();
48 }
49
50 void MemoryPressureController::SetPressureNotificationsSuppressedInAllProcesses(
51 bool suppressed) {
52 if (!BrowserThread::CurrentlyOn(BrowserThread::IO)) {
53 // Note that passing base::Unretained(this) is safe here because the
54 // controller is a leaky singleton (i.e. it is never deleted).
55 BrowserThread::PostTask(
56 BrowserThread::IO, FROM_HERE,
57 base::Bind(&MemoryPressureController::
58 SetPressureNotificationsSuppressedInAllProcesses,
59 base::Unretained(this), suppressed));
60 return;
61 }
62
63 // Enable/disable suppressing memory notifications in the browser process.
64 base::MemoryPressureListener::SetNotificationsSuppressed(suppressed);
65
66 // Enable/disable suppressing memory notifications in all child processes.
67 for (MemoryMessageFilterSet::iterator it = memory_message_filters_.begin();
68 it != memory_message_filters_.end(); ++it) {
69 it->get()->SendSetPressureNotificationsSuppressed(suppressed);
70 }
71 }
72
73 } // 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