blob: 55ef9a8ebe65ace4ddd27716f7515344dec0baa3 [file] [log] [blame]
Gordon Guan96c21ee2019-11-06 15:05:391// Copyright 2019 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 <utility>
6
7#include "base/command_line.h"
Gordon Guanf2f7a8402019-11-27 18:26:448#include "base/memory/discardable_memory.h"
Gordon Guan96c21ee2019-11-06 15:05:399#include "content/child/child_process.h"
10#include "content/child/child_thread_impl.h"
11#include "content/public/common/content_switches.h"
12#include "content/renderer/discardable_memory_utils.h"
13
14#if defined(OS_POSIX)
15#include <sys/mman.h>
16#include <sys/utsname.h>
17
18#include "base/memory/madv_free_discardable_memory_allocator_posix.h"
19#include "base/memory/madv_free_discardable_memory_posix.h"
20#endif
21
22#if defined(OS_ANDROID)
23#include <third_party/ashmem/ashmem.h>
24#endif
25
26namespace content {
27
Thiabaud Engelbrechtc4c42392020-12-01 18:24:3928scoped_refptr<discardable_memory::ClientDiscardableSharedMemoryManager>
Gordon Guan96c21ee2019-11-06 15:05:3929CreateDiscardableMemoryAllocator() {
Gordon Guan96c21ee2019-11-06 15:05:3930 DVLOG(1) << "Using shared memory for discardable memory";
31
32 mojo::PendingRemote<discardable_memory::mojom::DiscardableSharedMemoryManager>
33 manager_remote;
34 ChildThread::Get()->BindHostReceiver(
35 manager_remote.InitWithNewPipeAndPassReceiver());
Thiabaud Engelbrechtc4c42392020-12-01 18:24:3936 return base::MakeRefCounted<
Gordon Guan96c21ee2019-11-06 15:05:3937 discardable_memory::ClientDiscardableSharedMemoryManager>(
Thiabaud Engelbrechtb26a6062020-09-02 14:11:3338 std::move(manager_remote), ChildProcess::current()->io_task_runner(),
39 ChildProcess::current()->main_thread()->main_thread_runner());
Gordon Guan96c21ee2019-11-06 15:05:3940}
41
42} // namespace content