1// Copyright (c) 2012 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// Common IPC messages used for child processes.
6// Multiply-included message file, hence no include guard.
7
8#include <string>
9#include <vector>
10
11#include "base/memory/shared_memory.h"
12#include "base/tracked_objects.h"
13#include "base/values.h"
14#include "cc/resources/shared_bitmap_manager.h"
15#include "content/common/content_export.h"
16#include "ipc/ipc_message_macros.h"
17#include "ui/gfx/gpu_memory_buffer.h"
18
19IPC_ENUM_TRAITS_MAX_VALUE(tracked_objects::ThreadData::Status,
20                          tracked_objects::ThreadData::STATUS_LAST)
21
22IPC_STRUCT_TRAITS_BEGIN(tracked_objects::LocationSnapshot)
23  IPC_STRUCT_TRAITS_MEMBER(file_name)
24  IPC_STRUCT_TRAITS_MEMBER(function_name)
25  IPC_STRUCT_TRAITS_MEMBER(line_number)
26IPC_STRUCT_TRAITS_END()
27
28IPC_STRUCT_TRAITS_BEGIN(tracked_objects::BirthOnThreadSnapshot)
29  IPC_STRUCT_TRAITS_MEMBER(location)
30  IPC_STRUCT_TRAITS_MEMBER(thread_name)
31IPC_STRUCT_TRAITS_END()
32
33IPC_STRUCT_TRAITS_BEGIN(tracked_objects::DeathDataSnapshot)
34  IPC_STRUCT_TRAITS_MEMBER(count)
35  IPC_STRUCT_TRAITS_MEMBER(run_duration_sum)
36  IPC_STRUCT_TRAITS_MEMBER(run_duration_max)
37  IPC_STRUCT_TRAITS_MEMBER(run_duration_sample)
38  IPC_STRUCT_TRAITS_MEMBER(queue_duration_sum)
39  IPC_STRUCT_TRAITS_MEMBER(queue_duration_max)
40  IPC_STRUCT_TRAITS_MEMBER(queue_duration_sample)
41IPC_STRUCT_TRAITS_END()
42
43IPC_STRUCT_TRAITS_BEGIN(tracked_objects::TaskSnapshot)
44  IPC_STRUCT_TRAITS_MEMBER(birth)
45  IPC_STRUCT_TRAITS_MEMBER(death_data)
46  IPC_STRUCT_TRAITS_MEMBER(death_thread_name)
47IPC_STRUCT_TRAITS_END()
48
49IPC_STRUCT_TRAITS_BEGIN(tracked_objects::ParentChildPairSnapshot)
50  IPC_STRUCT_TRAITS_MEMBER(parent)
51  IPC_STRUCT_TRAITS_MEMBER(child)
52IPC_STRUCT_TRAITS_END()
53
54IPC_STRUCT_TRAITS_BEGIN(tracked_objects::ProcessDataSnapshot)
55  IPC_STRUCT_TRAITS_MEMBER(tasks)
56  IPC_STRUCT_TRAITS_MEMBER(descendants)
57  IPC_STRUCT_TRAITS_MEMBER(process_id)
58IPC_STRUCT_TRAITS_END()
59
60IPC_ENUM_TRAITS_MAX_VALUE(gfx::GpuMemoryBufferType,
61                          gfx::GPU_MEMORY_BUFFER_TYPE_LAST)
62
63#if defined(OS_ANDROID)
64IPC_STRUCT_TRAITS_BEGIN(gfx::SurfaceTextureId)
65  IPC_STRUCT_TRAITS_MEMBER(primary_id)
66  IPC_STRUCT_TRAITS_MEMBER(secondary_id)
67IPC_STRUCT_TRAITS_END()
68#endif
69
70IPC_STRUCT_TRAITS_BEGIN(gfx::GpuMemoryBufferId)
71  IPC_STRUCT_TRAITS_MEMBER(primary_id)
72  IPC_STRUCT_TRAITS_MEMBER(secondary_id)
73IPC_STRUCT_TRAITS_END()
74
75IPC_STRUCT_TRAITS_BEGIN(gfx::GpuMemoryBufferHandle)
76  IPC_STRUCT_TRAITS_MEMBER(type)
77  IPC_STRUCT_TRAITS_MEMBER(handle)
78  IPC_STRUCT_TRAITS_MEMBER(global_id)
79#if defined(OS_MACOSX)
80  IPC_STRUCT_TRAITS_MEMBER(io_surface_id)
81#endif
82#if defined(OS_ANDROID)
83  IPC_STRUCT_TRAITS_MEMBER(surface_texture_id)
84#endif
85#if defined(USE_X11)
86  IPC_STRUCT_TRAITS_MEMBER(pixmap)
87#endif
88IPC_STRUCT_TRAITS_END()
89
90#undef IPC_MESSAGE_EXPORT
91#define IPC_MESSAGE_EXPORT CONTENT_EXPORT
92
93#define IPC_MESSAGE_START ChildProcessMsgStart
94
95// Messages sent from the browser to the child process.
96
97// Sent in response to ChildProcessHostMsg_ShutdownRequest to tell the child
98// process that it's safe to shutdown.
99IPC_MESSAGE_CONTROL0(ChildProcessMsg_Shutdown)
100
101#if defined(IPC_MESSAGE_LOG_ENABLED)
102// Tell the child process to begin or end IPC message logging.
103IPC_MESSAGE_CONTROL1(ChildProcessMsg_SetIPCLoggingEnabled,
104                     bool /* on or off */)
105#endif
106
107// Tell the child process to enable or disable the profiler status.
108IPC_MESSAGE_CONTROL1(ChildProcessMsg_SetProfilerStatus,
109                     tracked_objects::ThreadData::Status /* profiler status */)
110
111// Send to all the child processes to send back profiler data (ThreadData in
112// tracked_objects).
113IPC_MESSAGE_CONTROL1(ChildProcessMsg_GetChildProfilerData,
114                     int /* sequence_number */)
115
116// Send to all the child processes to send back histogram data.
117IPC_MESSAGE_CONTROL1(ChildProcessMsg_GetChildHistogramData,
118                     int /* sequence_number */)
119
120// Sent to child processes to dump their handle table.
121IPC_MESSAGE_CONTROL0(ChildProcessMsg_DumpHandles)
122
123// Sent to child processes to tell them to enter or leave background mode.
124IPC_MESSAGE_CONTROL1(ChildProcessMsg_SetProcessBackgrounded,
125                     bool /* background */)
126
127#if defined(USE_TCMALLOC)
128// Sent to child process to request tcmalloc stats.
129IPC_MESSAGE_CONTROL0(ChildProcessMsg_GetTcmallocStats)
130#endif
131
132////////////////////////////////////////////////////////////////////////////////
133// Messages sent from the child process to the browser.
134
135IPC_MESSAGE_CONTROL0(ChildProcessHostMsg_ShutdownRequest)
136
137// Send back profiler data (ThreadData in tracked_objects).
138IPC_MESSAGE_CONTROL2(ChildProcessHostMsg_ChildProfilerData,
139                     int, /* sequence_number */
140                     tracked_objects::ProcessDataSnapshot /* profiler_data */)
141
142// Send back histograms as vector of pickled-histogram strings.
143IPC_MESSAGE_CONTROL2(ChildProcessHostMsg_ChildHistogramData,
144                     int, /* sequence_number */
145                     std::vector<std::string> /* histogram_data */)
146
147// Request a histogram from the browser. The browser will send the histogram
148// data only if it has been passed the command line flag
149// switches::kDomAutomationController.
150IPC_SYNC_MESSAGE_CONTROL1_1(ChildProcessHostMsg_GetBrowserHistogram,
151                            std::string, /* histogram_name */
152                            std::string /* histogram_json */)
153
154// Reply to ChildProcessMsg_DumpHandles when handle table dump is complete.
155IPC_MESSAGE_CONTROL0(ChildProcessHostMsg_DumpHandlesDone)
156
157#if defined(OS_WIN)
158// Request that the given font be loaded by the host so it's cached by the
159// OS. Please see ChildProcessHost::PreCacheFont for details.
160IPC_SYNC_MESSAGE_CONTROL1_0(ChildProcessHostMsg_PreCacheFont,
161                            LOGFONT /* font data */)
162
163// Release the cached font
164IPC_MESSAGE_CONTROL0(ChildProcessHostMsg_ReleaseCachedFonts)
165#endif  // defined(OS_WIN)
166
167// Asks the browser to create a block of shared memory for the child process to
168// fill in and pass back to the browser.
169IPC_SYNC_MESSAGE_CONTROL1_1(ChildProcessHostMsg_SyncAllocateSharedMemory,
170                            uint32 /* buffer size */,
171                            base::SharedMemoryHandle)
172
173// Asks the browser to create a block of shared memory for the child process to
174// fill in and pass back to the browser.
175IPC_SYNC_MESSAGE_CONTROL2_1(ChildProcessHostMsg_SyncAllocateSharedBitmap,
176                            uint32 /* buffer size */,
177                            cc::SharedBitmapId,
178                            base::SharedMemoryHandle)
179
180// Informs the browser that the child allocated a shared bitmap.
181IPC_MESSAGE_CONTROL3(ChildProcessHostMsg_AllocatedSharedBitmap,
182                     uint32 /* buffer size */,
183                     base::SharedMemoryHandle,
184                     cc::SharedBitmapId)
185
186// Informs the browser that the child deleted a shared bitmap.
187IPC_MESSAGE_CONTROL1(ChildProcessHostMsg_DeletedSharedBitmap,
188                     cc::SharedBitmapId)
189
190#if defined(USE_TCMALLOC)
191// Reply to ChildProcessMsg_GetTcmallocStats.
192IPC_MESSAGE_CONTROL1(ChildProcessHostMsg_TcmallocStats,
193                     std::string /* output */)
194#endif
195
196// Asks the browser to create a gpu memory buffer.
197IPC_SYNC_MESSAGE_CONTROL4_1(ChildProcessHostMsg_SyncAllocateGpuMemoryBuffer,
198                            uint32 /* width */,
199                            uint32 /* height */,
200                            uint32 /* internalformat */,
201                            uint32 /* usage */,
202                            gfx::GpuMemoryBufferHandle)
203
204// Informs the browser that the child deleted a gpu memory buffer.
205IPC_MESSAGE_CONTROL2(ChildProcessHostMsg_DeletedGpuMemoryBuffer,
206                     gfx::GpuMemoryBufferType,
207                     gfx::GpuMemoryBufferId)
208