diff options
author | huangs <huangs@chromium.org> | 2015-09-22 09:59:54 -0700 |
---|---|---|
committer | Commit bot <commit-bot@chromium.org> | 2015-09-22 17:00:31 +0000 |
commit | baa42d336b9a858a1180be0db455a6874761e418 (patch) | |
tree | 7602f13584b1f2fae89561d70f7dae3a9c4068de /content/browser/memory | |
parent | 97745f79debe9ec1e8a200fe5b12091f82dcf421 (diff) | |
download | chromium_src-baa42d336b9a858a1180be0db455a6874761e418.zip chromium_src-baa42d336b9a858a1180be0db455a6874761e418.tar.gz chromium_src-baa42d336b9a858a1180be0db455a6874761e418.tar.bz2 |
Revert of Architecture for cross-process memory notification suppressing (patchset #11 id:240001 of https://codereview.chromium.org/1332583002/ )
Reason for revert:
This seems to cause failure in Cast Linux: content_browsertests: MemoryPressureControllerBrowserTest.SetPressureNotificationsSuppressedInAllProcesses
Original issue's description:
> Architecture for cross-process memory notification suppressing
>
> This patch adds IPC architecture for suppressing memory pressure
> notifications in all processes:
>
> BROWSER PROCESS CHILD PROCESSES
>
> MemoryPressureListener:: MemoryPressureListener::
> SetNotificationsSuppressed SetNotificationsSuppressed
> (existing static method*) (existing static method*)
> ^ ^
> | |
> +--------------------------+ |
> | MemoryPressureController | |
> +..> | (singleton) | |
> : +--------------------------+ |
> : | |
> : V |
> : +--------------------------+ +--------------------------+
> : | MemoryMessageFilter | <===> | ChildMemoryMessageFilter |
> : | (per child process) | IPC | (singleton) |
> : +--------------------------+ +--------------------------+
> :
> :
> +.. Memory.setPressureNotificationsSuppressed
> (proposed DevTools API**)
>
> *) The required functionality for individual processes was added in:
> https://codereview.chromium.org/1312163003.
> **) The new DevTools API will be added in the following 3-sided patch:
> https://codereview.chromium.org/1336363002,
> https://codereview.chromium.org/1311343007, and
> https://codereview.chromium.org/1342833004.
>
> This patch adds new message filters on both sides (MemoryMessageFilter
> in the browser process and ChildMemoryMessageFilter in the child
> process) because we anticipate more functionality to be added to
> MemoryPressureController in the near future (methods for simulating
> memory pressure signals and, more importantly, propagating memory
> pressure signals to all processes on desktop Chrome). Encapsulating the
> relevant IPC communication in dedicated message filters is arguably
> better than keeping augmenting (and having duplicate code in)
> BrowserChildProcessHostImpl, RenderProcessHostImpl, and
> ChildThreadImpl.
>
> This patch represents the second step towards implementing a DevTools
> API for suppressing and simulating memory pressure signals in Chrome.
> The main use case for this feature is to enforce consistent conditions
> across memory measurements. See https://goo.gl/cZFdH3 for more details.
>
> BUG=516776
>
> Committed: https://crrev.com/0b119f3392d6c6169bbb792347a04f34ce649156
> Cr-Commit-Position: refs/heads/master@{#350169}
TBR=skyostil@chromium.org,primiano@chromium.org,nasko@chromium.org,chrisha@chromium.org,petrcermak@chromium.org
NOPRESUBMIT=true
NOTREECHECKS=true
NOTRY=true
BUG=516776
Review URL: https://codereview.chromium.org/1359873002
Cr-Commit-Position: refs/heads/master@{#350175}
Diffstat (limited to 'content/browser/memory')
-rw-r--r-- | content/browser/memory/memory_message_filter.cc | 34 | ||||
-rw-r--r-- | content/browser/memory/memory_message_filter.h | 35 | ||||
-rw-r--r-- | content/browser/memory/memory_pressure_controller.cc | 71 | ||||
-rw-r--r-- | content/browser/memory/memory_pressure_controller.h | 48 | ||||
-rw-r--r-- | content/browser/memory/memory_pressure_controller_browsertest.cc | 131 |
5 files changed, 0 insertions, 319 deletions
diff --git a/content/browser/memory/memory_message_filter.cc b/content/browser/memory/memory_message_filter.cc deleted file mode 100644 index b386717..0000000 --- a/content/browser/memory/memory_message_filter.cc +++ /dev/null @@ -1,34 +0,0 @@ -// Copyright 2015 The Chromium Authors. All rights reserved. -// Use of this source code is governed by a BSD-style license that can be -// found in the LICENSE file. - -#include "content/browser/memory/memory_message_filter.h" - -#include "content/browser/memory/memory_pressure_controller.h" -#include "content/common/memory_messages.h" - -namespace content { - -MemoryMessageFilter::MemoryMessageFilter() - : BrowserMessageFilter(MemoryMsgStart) {} - -MemoryMessageFilter::~MemoryMessageFilter() {} - -void MemoryMessageFilter::OnFilterAdded(IPC::Sender* sender) { - MemoryPressureController::GetInstance()->OnMemoryMessageFilterAdded(this); -} - -void MemoryMessageFilter::OnChannelClosing() { - MemoryPressureController::GetInstance()->OnMemoryMessageFilterRemoved(this); -} - -bool MemoryMessageFilter::OnMessageReceived(const IPC::Message& message) { - return false; -} - -void MemoryMessageFilter::SendSetPressureNotificationsSuppressed( - bool suppressed) { - Send(new MemoryMsg_SetPressureNotificationsSuppressed(suppressed)); -} - -} // namespace content diff --git a/content/browser/memory/memory_message_filter.h b/content/browser/memory/memory_message_filter.h deleted file mode 100644 index 122a7aa9..0000000 --- a/content/browser/memory/memory_message_filter.h +++ /dev/null @@ -1,35 +0,0 @@ -// Copyright 2015 The Chromium Authors. All rights reserved. -// Use of this source code is governed by a BSD-style license that can be -// found in the LICENSE file. - -#ifndef CONTENT_BROWSER_MEMORY_MEMORY_MESSAGE_FILTER_H_ -#define CONTENT_BROWSER_MEMORY_MEMORY_MESSAGE_FILTER_H_ - -#include "content/common/content_export.h" -#include "content/public/browser/browser_message_filter.h" - -namespace content { - -// This class sends memory messages from the browser process. -// See also: child_memory_message_filter.h -class CONTENT_EXPORT MemoryMessageFilter : public BrowserMessageFilter { - public: - MemoryMessageFilter(); - - // BrowserMessageFilter implementation. - void OnFilterAdded(IPC::Sender* sender) override; - void OnChannelClosing() override; - bool OnMessageReceived(const IPC::Message& message) override; - - void SendSetPressureNotificationsSuppressed(bool suppressed); - - protected: - ~MemoryMessageFilter() override; - - private: - DISALLOW_COPY_AND_ASSIGN(MemoryMessageFilter); -}; - -} // namespace content - -#endif // CONTENT_BROWSER_MEMORY_MEMORY_MESSAGE_FILTER_H_ diff --git a/content/browser/memory/memory_pressure_controller.cc b/content/browser/memory/memory_pressure_controller.cc deleted file mode 100644 index 0aa72ac..0000000 --- a/content/browser/memory/memory_pressure_controller.cc +++ /dev/null @@ -1,71 +0,0 @@ -// Copyright 2015 The Chromium Authors. All rights reserved. -// Use of this source code is governed by a BSD-style license that can be -// found in the LICENSE file. - -#include "content/browser/memory/memory_pressure_controller.h" - -#include "base/bind.h" -#include "base/memory/memory_pressure_listener.h" -#include "content/browser/memory/memory_message_filter.h" -#include "content/public/browser/browser_thread.h" - -namespace content { - -MemoryPressureController::MemoryPressureController() {} - -MemoryPressureController::~MemoryPressureController() {} - -void MemoryPressureController::OnMemoryMessageFilterAdded( - MemoryMessageFilter* filter) { - DCHECK_CURRENTLY_ON(BrowserThread::IO); - - // Add the message filter to the set of all memory message filters and check - // that it wasn't there beforehand. - DCHECK(memory_message_filters_.insert(filter).second); - - // There's no need to send a message to the child process if memory pressure - // notifications are not suppressed. - if (base::MemoryPressureListener::AreNotificationsSuppressed()) - filter->SendSetPressureNotificationsSuppressed(true); -} - -void MemoryPressureController::OnMemoryMessageFilterRemoved( - MemoryMessageFilter* filter) { - DCHECK_CURRENTLY_ON(BrowserThread::IO); - - // Remove the message filter from the set of all memory message filters and - // check that it was there beforehand. - DCHECK_EQ(1u, memory_message_filters_.erase(filter)); -} - -// static -MemoryPressureController* MemoryPressureController::GetInstance() { - return base::Singleton< - MemoryPressureController, - base::LeakySingletonTraits<MemoryPressureController>>::get(); -} - -void MemoryPressureController::SetPressureNotificationsSuppressedInAllProcesses( - bool suppressed) { - if (!BrowserThread::CurrentlyOn(BrowserThread::IO)) { - // Note that passing base::Unretained(this) is safe here because the - // controller is a leaky singleton (i.e. it is never deleted). - BrowserThread::PostTask( - BrowserThread::IO, FROM_HERE, - base::Bind(&MemoryPressureController:: - SetPressureNotificationsSuppressedInAllProcesses, - base::Unretained(this), suppressed)); - return; - } - - // Enable/disable suppressing memory notifications in the browser process. - base::MemoryPressureListener::SetNotificationsSuppressed(suppressed); - - // Enable/disable suppressing memory notifications in all child processes. - for (MemoryMessageFilterSet::iterator it = memory_message_filters_.begin(); - it != memory_message_filters_.end(); ++it) { - it->get()->SendSetPressureNotificationsSuppressed(suppressed); - } -} - -} // namespace content diff --git a/content/browser/memory/memory_pressure_controller.h b/content/browser/memory/memory_pressure_controller.h deleted file mode 100644 index 848b2d4..0000000 --- a/content/browser/memory/memory_pressure_controller.h +++ /dev/null @@ -1,48 +0,0 @@ -// Copyright 2015 The Chromium Authors. All rights reserved. -// Use of this source code is governed by a BSD-style license that can be -// found in the LICENSE file. - -#ifndef CONTENT_BROWSER_MEMORY_MEMORY_PRESSURE_CONTROLLER_H_ -#define CONTENT_BROWSER_MEMORY_MEMORY_PRESSURE_CONTROLLER_H_ - -#include <set> - -#include "base/callback.h" -#include "base/memory/singleton.h" -#include "content/common/content_export.h" - -namespace content { - -class MemoryMessageFilter; - -class CONTENT_EXPORT MemoryPressureController { - public: - // These methods must be called on the IO thread. - void OnMemoryMessageFilterAdded(MemoryMessageFilter* filter); - void OnMemoryMessageFilterRemoved(MemoryMessageFilter* filter); - - // This method can be called from any thread. - void SetPressureNotificationsSuppressedInAllProcesses(bool suppressed); - - // This method can be called from any thread. - static MemoryPressureController* GetInstance(); - - protected: - virtual ~MemoryPressureController(); - - private: - friend struct base::DefaultSingletonTraits<MemoryPressureController>; - - MemoryPressureController(); - - // Set of all memory message filters in the browser process. Always accessed - // on the IO thread. - typedef std::set<scoped_refptr<MemoryMessageFilter>> MemoryMessageFilterSet; - MemoryMessageFilterSet memory_message_filters_; - - DISALLOW_COPY_AND_ASSIGN(MemoryPressureController); -}; - -} // namespace content - -#endif // CONTENT_BROWSER_MEMORY_MEMORY_PRESSURE_CONTROLLER_H_ diff --git a/content/browser/memory/memory_pressure_controller_browsertest.cc b/content/browser/memory/memory_pressure_controller_browsertest.cc deleted file mode 100644 index b1452d8..0000000 --- a/content/browser/memory/memory_pressure_controller_browsertest.cc +++ /dev/null @@ -1,131 +0,0 @@ -// Copyright 2015 The Chromium Authors. All rights reserved. -// Use of this source code is governed by a BSD-style license that can be -// found in the LICENSE file. - -#include "base/bind.h" -#include "base/memory/memory_pressure_listener.h" -#include "content/browser/memory/memory_message_filter.h" -#include "content/browser/memory/memory_pressure_controller.h" -#include "content/common/memory_messages.h" -#include "content/public/test/content_browser_test.h" -#include "content/public/test/content_browser_test_utils.h" -#include "content/public/test/test_utils.h" -#include "ipc/ipc_message.h" -#include "testing/gmock/include/gmock/gmock.h" - -namespace content { - -MATCHER_P(IsSetSuppressedMessage, suppressed, "") { - // Ensure that the message is deleted upon return. - scoped_ptr<IPC::Message> message(arg); - if (message == nullptr) - return false; - MemoryMsg_SetPressureNotificationsSuppressed::Param param; - if (!MemoryMsg_SetPressureNotificationsSuppressed::Read(message.get(), - ¶m)) - return false; - return suppressed == base::get<0>(param); -} - -class MemoryMessageFilterForTesting : public MemoryMessageFilter { - public: - MOCK_METHOD1(Send, bool(IPC::Message* message)); - - void Add() { - // The filter must be added on the IO thread. - if (!BrowserThread::CurrentlyOn(BrowserThread::IO)) { - BrowserThread::PostTask(BrowserThread::IO, FROM_HERE, - base::Bind(&MemoryMessageFilterForTesting::Add, - base::Unretained(this))); - RunAllPendingInMessageLoop(BrowserThread::IO); - return; - } - OnChannelConnected(0); - OnFilterAdded(nullptr); - } - - void Remove() { - // The filter must be removed on the IO thread. - if (!BrowserThread::CurrentlyOn(BrowserThread::IO)) { - BrowserThread::PostTask(BrowserThread::IO, FROM_HERE, - base::Bind(&MemoryMessageFilterForTesting::Remove, - base::Unretained(this))); - RunAllPendingInMessageLoop(BrowserThread::IO); - return; - } - OnChannelClosing(); - OnFilterRemoved(); - } - - protected: - ~MemoryMessageFilterForTesting() override {} -}; - -class MemoryPressureControllerBrowserTest : public ContentBrowserTest { - protected: - void SetPressureNotificationsSuppressedInAllProcessesAndWait( - bool suppressed) { - MemoryPressureController::GetInstance() - ->SetPressureNotificationsSuppressedInAllProcesses(suppressed); - RunAllPendingInMessageLoop(BrowserThread::IO); - } -}; - -IN_PROC_BROWSER_TEST_F(MemoryPressureControllerBrowserTest, - SetPressureNotificationsSuppressedInAllProcesses) { - scoped_refptr<MemoryMessageFilterForTesting> filter1( - new MemoryMessageFilterForTesting); - scoped_refptr<MemoryMessageFilterForTesting> filter2( - new MemoryMessageFilterForTesting); - - NavigateToURL(shell(), GetTestUrl("", "title.html")); - - // Add the first filter. No messages should be sent because notifications are - // not suppressed. - EXPECT_CALL(*filter1, Send(testing::_)).Times(0); - EXPECT_CALL(*filter2, Send(testing::_)).Times(0); - filter1->Add(); - EXPECT_FALSE(base::MemoryPressureListener::AreNotificationsSuppressed()); - - // Enable suppressing memory pressure notifications in all processes. The - // first filter should send a message. - EXPECT_CALL(*filter1, Send(IsSetSuppressedMessage(true))).Times(1); - EXPECT_CALL(*filter2, Send(testing::_)).Times(0); - SetPressureNotificationsSuppressedInAllProcessesAndWait(true); - EXPECT_TRUE(base::MemoryPressureListener::AreNotificationsSuppressed()); - - // Add the second filter. It should send a message because notifications are - // suppressed. - EXPECT_CALL(*filter1, Send(testing::_)).Times(0); - EXPECT_CALL(*filter2, Send(IsSetSuppressedMessage(true))).Times(1); - filter2->Add(); - - // Disable suppressing memory pressure notifications in all processes. Both - // filters should send a message. - EXPECT_CALL(*filter1, Send(IsSetSuppressedMessage(false))).Times(1); - EXPECT_CALL(*filter2, Send(IsSetSuppressedMessage(false))).Times(1); - SetPressureNotificationsSuppressedInAllProcessesAndWait(false); - EXPECT_FALSE(base::MemoryPressureListener::AreNotificationsSuppressed()); - - // Remove the first filter. No messages should be sent. - EXPECT_CALL(*filter1, Send(testing::_)).Times(0); - EXPECT_CALL(*filter2, Send(testing::_)).Times(0); - filter1->Remove(); - - // Enable suppressing memory pressure notifications in all processes. The - // second filter should send a message. - EXPECT_CALL(*filter1, Send(testing::_)).Times(0); - EXPECT_CALL(*filter2, Send(IsSetSuppressedMessage(true))).Times(1); - SetPressureNotificationsSuppressedInAllProcessesAndWait(true); - EXPECT_TRUE(base::MemoryPressureListener::AreNotificationsSuppressed()); - - // Remove the second filter and disable suppressing memory pressure - // notifications in all processes. No messages should be sent. - EXPECT_CALL(*filter1, Send(testing::_)).Times(0); - EXPECT_CALL(*filter2, Send(testing::_)).Times(0); - filter2->Remove(); - SetPressureNotificationsSuppressedInAllProcessesAndWait(false); - EXPECT_FALSE(base::MemoryPressureListener::AreNotificationsSuppressed()); -} - -} // namespace content |