Gordon Guan | 96c21ee | 2019-11-06 15:05:39 | [diff] [blame] | 1 | // 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 Guan | f2f7a840 | 2019-11-27 18:26:44 | [diff] [blame] | 8 | #include "base/memory/discardable_memory.h" |
Gordon Guan | 96c21ee | 2019-11-06 15:05:39 | [diff] [blame] | 9 | #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 | |
| 26 | namespace content { |
| 27 | |
Thiabaud Engelbrecht | c4c4239 | 2020-12-01 18:24:39 | [diff] [blame^] | 28 | scoped_refptr<discardable_memory::ClientDiscardableSharedMemoryManager> |
Gordon Guan | 96c21ee | 2019-11-06 15:05:39 | [diff] [blame] | 29 | CreateDiscardableMemoryAllocator() { |
Gordon Guan | 96c21ee | 2019-11-06 15:05:39 | [diff] [blame] | 30 | 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 Engelbrecht | c4c4239 | 2020-12-01 18:24:39 | [diff] [blame^] | 36 | return base::MakeRefCounted< |
Gordon Guan | 96c21ee | 2019-11-06 15:05:39 | [diff] [blame] | 37 | discardable_memory::ClientDiscardableSharedMemoryManager>( |
Thiabaud Engelbrecht | b26a606 | 2020-09-02 14:11:33 | [diff] [blame] | 38 | std::move(manager_remote), ChildProcess::current()->io_task_runner(), |
| 39 | ChildProcess::current()->main_thread()->main_thread_runner()); |
Gordon Guan | 96c21ee | 2019-11-06 15:05:39 | [diff] [blame] | 40 | } |
| 41 | |
| 42 | } // namespace content |