| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "content/browser/gpu/gpu_process_host.h" | 5 #include "content/browser/gpu/gpu_process_host.h" |
| 6 | 6 |
| 7 #include "base/base64.h" | 7 #include "base/base64.h" |
| 8 #include "base/base_switches.h" | 8 #include "base/base_switches.h" |
| 9 #include "base/basictypes.h" | 9 #include "base/basictypes.h" |
| 10 #include "base/bind.h" | 10 #include "base/bind.h" |
| (...skipping 15 matching lines...) Expand all Loading... |
| 26 #include "content/common/gpu/gpu_messages.h" | 26 #include "content/common/gpu/gpu_messages.h" |
| 27 #include "content/common/view_messages.h" | 27 #include "content/common/view_messages.h" |
| 28 #include "content/port/browser/render_widget_host_view_frame_subscriber.h" | 28 #include "content/port/browser/render_widget_host_view_frame_subscriber.h" |
| 29 #include "content/public/browser/browser_thread.h" | 29 #include "content/public/browser/browser_thread.h" |
| 30 #include "content/public/browser/content_browser_client.h" | 30 #include "content/public/browser/content_browser_client.h" |
| 31 #include "content/public/browser/render_process_host.h" | 31 #include "content/public/browser/render_process_host.h" |
| 32 #include "content/public/browser/render_widget_host_view.h" | 32 #include "content/public/browser/render_widget_host_view.h" |
| 33 #include "content/public/common/content_client.h" | 33 #include "content/public/common/content_client.h" |
| 34 #include "content/public/common/content_switches.h" | 34 #include "content/public/common/content_switches.h" |
| 35 #include "content/public/common/result_codes.h" | 35 #include "content/public/common/result_codes.h" |
| 36 #include "content/public/common/sandboxed_process_launcher_delegate.h" |
| 36 #include "gpu/command_buffer/service/gpu_switches.h" | 37 #include "gpu/command_buffer/service/gpu_switches.h" |
| 37 #include "ipc/ipc_channel_handle.h" | 38 #include "ipc/ipc_channel_handle.h" |
| 38 #include "ipc/ipc_switches.h" | 39 #include "ipc/ipc_switches.h" |
| 39 #include "ui/events/latency_info.h" | 40 #include "ui/events/latency_info.h" |
| 40 #include "ui/gl/gl_switches.h" | 41 #include "ui/gl/gl_switches.h" |
| 41 | 42 |
| 42 | 43 |
| 43 #if defined(OS_WIN) | 44 #if defined(OS_WIN) |
| 44 #include "base/win/windows_version.h" | 45 #include "base/win/windows_version.h" |
| 45 #include "content/common/sandbox_win.h" | 46 #include "content/common/sandbox_win.h" |
| 46 #include "content/public/common/sandboxed_process_launcher_delegate.h" | |
| 47 #include "sandbox/win/src/sandbox_policy.h" | 47 #include "sandbox/win/src/sandbox_policy.h" |
| 48 #include "ui/gfx/switches.h" | 48 #include "ui/gfx/switches.h" |
| 49 #endif | 49 #endif |
| 50 | 50 |
| 51 #if defined(USE_OZONE) | 51 #if defined(USE_OZONE) |
| 52 #include "ui/ozone/ozone_switches.h" | 52 #include "ui/ozone/ozone_switches.h" |
| 53 #endif | 53 #endif |
| 54 | 54 |
| 55 namespace content { | 55 namespace content { |
| 56 | 56 |
| (...skipping 105 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 162 int surface_id, | 162 int surface_id, |
| 163 bool alive, | 163 bool alive, |
| 164 base::TimeTicks timebase, | 164 base::TimeTicks timebase, |
| 165 base::TimeDelta interval, | 165 base::TimeDelta interval, |
| 166 const std::vector<ui::LatencyInfo>& latency_info) { | 166 const std::vector<ui::LatencyInfo>& latency_info) { |
| 167 AcceleratedSurfaceBuffersSwappedCompletedForGPU( | 167 AcceleratedSurfaceBuffersSwappedCompletedForGPU( |
| 168 host_id, route_id, alive, timebase, interval); | 168 host_id, route_id, alive, timebase, interval); |
| 169 AcceleratedSurfaceBuffersSwappedCompletedForRenderer( | 169 AcceleratedSurfaceBuffersSwappedCompletedForRenderer( |
| 170 surface_id, timebase, interval, latency_info); | 170 surface_id, timebase, interval, latency_info); |
| 171 } | 171 } |
| 172 #endif // OS_WIN |
| 172 | 173 |
| 173 // NOTE: changes to this class need to be reviewed by the security team. | 174 // NOTE: changes to this class need to be reviewed by the security team. |
| 174 class GpuSandboxedProcessLauncherDelegate | 175 class GpuSandboxedProcessLauncherDelegate |
| 175 : public SandboxedProcessLauncherDelegate { | 176 : public SandboxedProcessLauncherDelegate { |
| 176 public: | 177 public: |
| 177 explicit GpuSandboxedProcessLauncherDelegate(CommandLine* cmd_line) | 178 GpuSandboxedProcessLauncherDelegate(CommandLine* cmd_line, |
| 179 ChildProcessHost* host) |
| 180 #if defined(OS_WIN) |
| 178 : cmd_line_(cmd_line) {} | 181 : cmd_line_(cmd_line) {} |
| 182 #elif defined(OS_POSIX) |
| 183 : ipc_fd_(host->TakeClientFileDescriptor()) {} |
| 184 #endif |
| 185 |
| 179 virtual ~GpuSandboxedProcessLauncherDelegate() {} | 186 virtual ~GpuSandboxedProcessLauncherDelegate() {} |
| 180 | 187 |
| 181 virtual void ShouldSandbox(bool* in_sandbox) OVERRIDE { | 188 #if defined(OS_WIN) |
| 182 if (cmd_line_->HasSwitch(switches::kDisableGpuSandbox)) { | 189 virtual bool ShouldSandbox() OVERRIDE { |
| 183 *in_sandbox = false; | 190 bool sandbox = !cmd_line_->HasSwitch(switches::kDisableGpuSandbox); |
| 191 if(! sandbox) { |
| 184 DVLOG(1) << "GPU sandbox is disabled"; | 192 DVLOG(1) << "GPU sandbox is disabled"; |
| 185 } | 193 } |
| 194 return sandbox; |
| 186 } | 195 } |
| 187 | 196 |
| 188 virtual void PreSandbox(bool* disable_default_policy, | 197 virtual void PreSandbox(bool* disable_default_policy, |
| 189 base::FilePath* exposed_dir) OVERRIDE { | 198 base::FilePath* exposed_dir) OVERRIDE { |
| 190 *disable_default_policy = true; | 199 *disable_default_policy = true; |
| 191 } | 200 } |
| 192 | 201 |
| 193 // For the GPU process we gotten as far as USER_LIMITED. The next level | 202 // For the GPU process we gotten as far as USER_LIMITED. The next level |
| 194 // which is USER_RESTRICTED breaks both the DirectX backend and the OpenGL | 203 // which is USER_RESTRICTED breaks both the DirectX backend and the OpenGL |
| 195 // backend. Note that the GPU process is connected to the interactive | 204 // backend. Note that the GPU process is connected to the interactive |
| (...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 262 result = policy->AddRule(sandbox::TargetPolicy::SUBSYS_FILES, | 271 result = policy->AddRule(sandbox::TargetPolicy::SUBSYS_FILES, |
| 263 sandbox::TargetPolicy::FILES_ALLOW_ANY, | 272 sandbox::TargetPolicy::FILES_ALLOW_ANY, |
| 264 log_file_path.c_str()); | 273 log_file_path.c_str()); |
| 265 if (result != sandbox::SBOX_ALL_OK) { | 274 if (result != sandbox::SBOX_ALL_OK) { |
| 266 *success = false; | 275 *success = false; |
| 267 return; | 276 return; |
| 268 } | 277 } |
| 269 } | 278 } |
| 270 } | 279 } |
| 271 } | 280 } |
| 281 #elif defined(OS_POSIX) |
| 282 |
| 283 virtual int GetIpcFd() OVERRIDE { |
| 284 return ipc_fd_; |
| 285 } |
| 286 #endif // OS_WIN |
| 272 | 287 |
| 273 private: | 288 private: |
| 289 #if defined(OS_WIN) |
| 274 CommandLine* cmd_line_; | 290 CommandLine* cmd_line_; |
| 291 #elif defined(OS_POSIX) |
| 292 int ipc_fd_; |
| 293 #endif // OS_WIN |
| 275 }; | 294 }; |
| 276 #endif // defined(OS_WIN) | |
| 277 | 295 |
| 278 } // anonymous namespace | 296 } // anonymous namespace |
| 279 | 297 |
| 280 // static | 298 // static |
| 281 bool GpuProcessHost::ValidateHost(GpuProcessHost* host) { | 299 bool GpuProcessHost::ValidateHost(GpuProcessHost* host) { |
| 282 if (!host) | 300 if (!host) |
| 283 return false; | 301 return false; |
| 284 | 302 |
| 285 // The Gpu process is invalid if it's not using SwiftShader, the card is | 303 // The Gpu process is invalid if it's not using SwiftShader, the card is |
| 286 // blacklisted, and we can kill it and start over. | 304 // blacklisted, and we can kill it and start over. |
| (...skipping 843 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1130 } | 1148 } |
| 1131 | 1149 |
| 1132 UMA_HISTOGRAM_BOOLEAN("GPU.GPU.GPUProcessSoftwareRendering", | 1150 UMA_HISTOGRAM_BOOLEAN("GPU.GPU.GPUProcessSoftwareRendering", |
| 1133 swiftshader_rendering_); | 1151 swiftshader_rendering_); |
| 1134 | 1152 |
| 1135 // If specified, prepend a launcher program to the command line. | 1153 // If specified, prepend a launcher program to the command line. |
| 1136 if (!gpu_launcher.empty()) | 1154 if (!gpu_launcher.empty()) |
| 1137 cmd_line->PrependWrapper(gpu_launcher); | 1155 cmd_line->PrependWrapper(gpu_launcher); |
| 1138 | 1156 |
| 1139 process_->Launch( | 1157 process_->Launch( |
| 1140 #if defined(OS_WIN) | 1158 new GpuSandboxedProcessLauncherDelegate(cmd_line, |
| 1141 new GpuSandboxedProcessLauncherDelegate(cmd_line), | 1159 process_->GetHost()), |
| 1142 false, | |
| 1143 #elif defined(OS_POSIX) | |
| 1144 false, | |
| 1145 base::EnvironmentMap(), | |
| 1146 #endif | |
| 1147 cmd_line); | 1160 cmd_line); |
| 1148 process_launched_ = true; | 1161 process_launched_ = true; |
| 1149 | 1162 |
| 1150 UMA_HISTOGRAM_ENUMERATION("GPU.GPUProcessLifetimeEvents", | 1163 UMA_HISTOGRAM_ENUMERATION("GPU.GPUProcessLifetimeEvents", |
| 1151 LAUNCHED, GPU_PROCESS_LIFETIME_EVENT_MAX); | 1164 LAUNCHED, GPU_PROCESS_LIFETIME_EVENT_MAX); |
| 1152 return true; | 1165 return true; |
| 1153 } | 1166 } |
| 1154 | 1167 |
| 1155 void GpuProcessHost::SendOutstandingReplies() { | 1168 void GpuProcessHost::SendOutstandingReplies() { |
| 1156 valid_ = false; | 1169 valid_ = false; |
| (...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1223 TRACE_EVENT0("gpu", "GpuProcessHost::OnCacheShader"); | 1236 TRACE_EVENT0("gpu", "GpuProcessHost::OnCacheShader"); |
| 1224 ClientIdToShaderCacheMap::iterator iter = | 1237 ClientIdToShaderCacheMap::iterator iter = |
| 1225 client_id_to_shader_cache_.find(client_id); | 1238 client_id_to_shader_cache_.find(client_id); |
| 1226 // If the cache doesn't exist then this is an off the record profile. | 1239 // If the cache doesn't exist then this is an off the record profile. |
| 1227 if (iter == client_id_to_shader_cache_.end()) | 1240 if (iter == client_id_to_shader_cache_.end()) |
| 1228 return; | 1241 return; |
| 1229 iter->second->Cache(GetShaderPrefixKey() + ":" + key, shader); | 1242 iter->second->Cache(GetShaderPrefixKey() + ":" + key, shader); |
| 1230 } | 1243 } |
| 1231 | 1244 |
| 1232 } // namespace content | 1245 } // namespace content |
| OLD | NEW |