Commit f60b6cfb authored by bashi@chromium.org's avatar bashi@chromium.org

Add MemoryPurgeController

No client so far. Follow-up CLs will add actual clients.

Design doc:
https://docs.google.com/document/d/1TbtkhXpjw_8lftLwELuEPEgcyWfXuVLuqW2KYJZeaBA/edit?pli=1

Non trivial changes from the design doc:
- MemoryPurgeController owns its clients.
- Page owns MemoryPurgeController (because core/ and modules/ will want
  to access MemoryPurgeController to register clients)

I chose Page as the owner of the controller because it has the same
lifetime of WebView.

BUG=520496

Review URL: https://codereview.chromium.org/1303203002

git-svn-id: svn://svn.chromium.org/blink/trunk@201116 bbb929c8-8fbe-4397-9dbb-9b2b20218538
parent fec70a9b
...@@ -560,6 +560,7 @@ DEFINE_TRACE(Page) ...@@ -560,6 +560,7 @@ DEFINE_TRACE(Page)
visitor->trace(m_frameHost); visitor->trace(m_frameHost);
HeapSupplementable<Page>::trace(visitor); HeapSupplementable<Page>::trace(visitor);
#endif #endif
visitor->trace(m_memoryPurgeController);
PageLifecycleNotifier::trace(visitor); PageLifecycleNotifier::trace(visitor);
} }
......
...@@ -32,6 +32,7 @@ ...@@ -32,6 +32,7 @@
#include "core/page/PageLifecycleNotifier.h" #include "core/page/PageLifecycleNotifier.h"
#include "core/page/PageLifecycleObserver.h" #include "core/page/PageLifecycleObserver.h"
#include "core/page/PageVisibilityState.h" #include "core/page/PageVisibilityState.h"
#include "platform/MemoryPurgeController.h"
#include "platform/Supplementable.h" #include "platform/Supplementable.h"
#include "platform/geometry/LayoutRect.h" #include "platform/geometry/LayoutRect.h"
#include "platform/geometry/Region.h" #include "platform/geometry/Region.h"
...@@ -204,6 +205,8 @@ public: ...@@ -204,6 +205,8 @@ public:
static void networkStateChanged(bool online); static void networkStateChanged(bool online);
MemoryPurgeController& memoryPurgeController() { return m_memoryPurgeController; }
DECLARE_TRACE(); DECLARE_TRACE();
void willBeDestroyed(); void willBeDestroyed();
...@@ -273,6 +276,8 @@ private: ...@@ -273,6 +276,8 @@ private:
// A pointer to all the interfaces provided to in-process Frames for this Page. // A pointer to all the interfaces provided to in-process Frames for this Page.
// FIXME: Most of the members of Page should move onto FrameHost. // FIXME: Most of the members of Page should move onto FrameHost.
OwnPtrWillBeMember<FrameHost> m_frameHost; OwnPtrWillBeMember<FrameHost> m_frameHost;
MemoryPurgeController m_memoryPurgeController;
}; };
extern template class CORE_EXTERN_TEMPLATE_EXPORT WillBeHeapSupplement<Page>; extern template class CORE_EXTERN_TEMPLATE_EXPORT WillBeHeapSupplement<Page>;
......
// 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 "config.h"
#include "platform/MemoryPurgeController.h"
#include "public/platform/Platform.h"
namespace blink {
MemoryPurgeController::MemoryPurgeController()
: m_deviceKind(Platform::current()->isLowEndDeviceMode() ? DeviceKind::LowEnd : DeviceKind::NotSpecified)
{
}
void MemoryPurgeController::purgeMemory(MemoryPurgeMode purgeMode)
{
for (auto& client : m_clients)
client->purgeMemory(purgeMode, m_deviceKind);
}
DEFINE_TRACE(MemoryPurgeController)
{
#if ENABLE(OILPAN)
visitor->trace(m_clients);
#endif
}
} // namespace blink
// 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 MemoryPurgeController_h
#define MemoryPurgeController_h
#include "platform/PlatformExport.h"
#include "platform/heap/Handle.h"
#include "wtf/MainThread.h"
namespace blink {
enum class MemoryPurgeMode {
// The tab contains the webview went to background
InactiveTab,
// TODO(bashi): Add more modes as needed.
};
enum class DeviceKind {
NotSpecified,
LowEnd,
};
// Classes which have discardable/reducible memory can implement this
// interface to be informed when they should reduce memory consumption.
// MemoryPurgeController assumes that subclasses of MemoryPurgeClient are
// WillBes.
class MemoryPurgeClient : public WillBeGarbageCollectedMixin {
public:
virtual ~MemoryPurgeClient() { }
// MemoryPurgeController invokes this callback when a memory purge event
// has occurred.
virtual void purgeMemory(MemoryPurgeMode, DeviceKind) = 0;
DECLARE_TRACE();
};
// MemoryPurgeController listens to some events which could be opportunities
// for reducing memory consumption and notifies its clients.
// Since we want to control memory per tab, MemoryPurgeController is owned by
// Page.
class PLATFORM_EXPORT MemoryPurgeController {
public:
MemoryPurgeController();
void registerClient(MemoryPurgeClient* client)
{
ASSERT(isMainThread());
ASSERT(client);
ASSERT(!m_clients.contains(client));
m_clients.add(client);
}
void unregisterClient(MemoryPurgeClient* client)
{
ASSERT(isMainThread());
ASSERT(m_clients.contains(client));
m_clients.remove(client);
}
DECLARE_TRACE();
private:
void purgeMemory(MemoryPurgeMode);
WillBeHeapHashSet<RawPtrWillBeWeakMember<MemoryPurgeClient>> m_clients;
DeviceKind m_deviceKind;
};
} // namespace blink
#endif // MemoryPurgeController_h
...@@ -70,6 +70,8 @@ ...@@ -70,6 +70,8 @@
'MIMETypeFromURL.h', 'MIMETypeFromURL.h',
'MIMETypeRegistry.cpp', 'MIMETypeRegistry.cpp',
'MIMETypeRegistry.h', 'MIMETypeRegistry.h',
'MemoryPurgeController.cpp',
'MemoryPurgeController.h',
'NotImplemented.cpp', 'NotImplemented.cpp',
'NotImplemented.h', 'NotImplemented.h',
'PartitionAllocMemoryDumpProvider.cpp', 'PartitionAllocMemoryDumpProvider.cpp',
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment