#include "memory_purger.h"
-#include <set>
-
#include "base/allocator/allocator_extension.h"
-#include "base/bind.h"
-#include "base/threading/thread.h"
-#include "content/common/render_messages_efl.h"
#include "content/public/browser/render_process_host.h"
-#include "content/public/browser/render_widget_host.h"
-#include "content/public/browser/browser_thread.h"
-#include "net/proxy/proxy_resolver.h"
-#include "net/proxy/proxy_service.h"
-#include "net/url_request/url_request_context.h"
-#include "net/url_request/url_request_context_getter.h"
using content::BrowserContext;
-using content::BrowserThread;
-
-// PurgeMemoryHelper -----------------------------------------------------------
-
-// This is a small helper class used to ensure that the objects we want to use
-// on multiple threads are properly refed, so they don't get deleted out from
-// under us.
-class PurgeMemoryIOHelper
- : public base::RefCountedThreadSafe<PurgeMemoryIOHelper> {
- public:
- PurgeMemoryIOHelper() {
- }
-
- void AddRequestContextGetter(
- scoped_refptr<net::URLRequestContextGetter> request_context_getter);
-
- void PurgeMemoryOnIOThread();
-
- private:
- friend class base::RefCountedThreadSafe<PurgeMemoryIOHelper>;
-
- virtual ~PurgeMemoryIOHelper() {}
-
- typedef scoped_refptr<net::URLRequestContextGetter> RequestContextGetter;
- std::vector<RequestContextGetter> request_context_getters_;
-
- DISALLOW_COPY_AND_ASSIGN(PurgeMemoryIOHelper);
-};
-
-void PurgeMemoryIOHelper::AddRequestContextGetter(
- scoped_refptr<net::URLRequestContextGetter> request_context_getter) {
- request_context_getters_.push_back(request_context_getter);
-}
-
-void PurgeMemoryIOHelper::PurgeMemoryOnIOThread() {
- // Ask ProxyServices to purge any memory they can (generally garbage in the
- // wrapped ProxyResolver's JS engine).
-#pragma message "[M37] Fix memory purge"
-#if 0
- for (size_t i = 0; i < request_context_getters_.size(); ++i) {
- request_context_getters_[i]->GetURLRequestContext()->proxy_service()->
- PurgeMemory();
- }
-#endif
-}
-
-// -----------------------------------------------------------------------------
// static
void MemoryPurger::PurgeAll(BrowserContext* browser_context) {
// static
void MemoryPurger::PurgeBrowser(BrowserContext* browser_context) {
- // Dump the backing stores.
-#pragma message "[M37] backing stores were removed, so the code below is probably safe to remove, check this."
- //content::RenderWidgetHost::RemoveAllBackingStores();
- scoped_refptr<PurgeMemoryIOHelper> purge_memory_io_helper(
- new PurgeMemoryIOHelper());
- purge_memory_io_helper->AddRequestContextGetter(
- make_scoped_refptr(browser_context->GetRequestContext()));
-#pragma message "[M37] Another non existing function"
- //BrowserContext::PurgeMemory(browser_context);
- BrowserThread::PostTask(
- BrowserThread::IO, FROM_HERE,
- base::Bind(&PurgeMemoryIOHelper::PurgeMemoryOnIOThread,
- purge_memory_io_helper.get()));
// Tell our allocator to release any free pages it's still holding.
- //
- // TODO(pk): A lot of the above calls kick off actions on other threads.
- // Maybe we should find a way to avoid calling this until those actions
- // complete?
base::allocator::ReleaseFreeMemory();
}