| 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(OS_CHROMEOS) | 51 #if defined(OS_CHROMEOS) |
| 52 #include "chromeos/chromeos_switches.h" | 52 #include "chromeos/chromeos_switches.h" |
| 53 #endif | 53 #endif |
| 54 | 54 |
| 55 #if defined(USE_OZONE) | 55 #if defined(USE_OZONE) |
| 56 #include "ui/ozone/ozone_switches.h" | 56 #include "ui/ozone/ozone_switches.h" |
| (...skipping 109 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 166 int surface_id, | 166 int surface_id, |
| 167 bool alive, | 167 bool alive, |
| 168 base::TimeTicks timebase, | 168 base::TimeTicks timebase, |
| 169 base::TimeDelta interval, | 169 base::TimeDelta interval, |
| 170 const std::vector<ui::LatencyInfo>& latency_info) { | 170 const std::vector<ui::LatencyInfo>& latency_info) { |
| 171 AcceleratedSurfaceBuffersSwappedCompletedForGPU( | 171 AcceleratedSurfaceBuffersSwappedCompletedForGPU( |
| 172 host_id, route_id, alive, timebase, interval); | 172 host_id, route_id, alive, timebase, interval); |
| 173 AcceleratedSurfaceBuffersSwappedCompletedForRenderer( | 173 AcceleratedSurfaceBuffersSwappedCompletedForRenderer( |
| 174 surface_id, timebase, interval, latency_info); | 174 surface_id, timebase, interval, latency_info); |
| 175 } | 175 } |
| 176 #endif // OS_WIN |
| 176 | 177 |
| 177 // NOTE: changes to this class need to be reviewed by the security team. | 178 // NOTE: changes to this class need to be reviewed by the security team. |
| 178 class GpuSandboxedProcessLauncherDelegate | 179 class GpuSandboxedProcessLauncherDelegate |
| 179 : public SandboxedProcessLauncherDelegate { | 180 : public SandboxedProcessLauncherDelegate { |
| 180 public: | 181 public: |
| 181 explicit GpuSandboxedProcessLauncherDelegate(CommandLine* cmd_line) | 182 GpuSandboxedProcessLauncherDelegate(CommandLine* cmd_line, |
| 183 ChildProcessHost* host) |
| 184 #if defined(OS_WIN) |
| 182 : cmd_line_(cmd_line) {} | 185 : cmd_line_(cmd_line) {} |
| 186 #elif defined(OS_POSIX) |
| 187 : ipc_fd_(host->TakeClientFileDescriptor()) {} |
| 188 #endif |
| 189 |
| 183 virtual ~GpuSandboxedProcessLauncherDelegate() {} | 190 virtual ~GpuSandboxedProcessLauncherDelegate() {} |
| 184 | 191 |
| 185 virtual void ShouldSandbox(bool* in_sandbox) OVERRIDE { | 192 #if defined(OS_WIN) |
| 186 if (cmd_line_->HasSwitch(switches::kDisableGpuSandbox)) { | 193 virtual bool ShouldSandbox() OVERRIDE { |
| 187 *in_sandbox = false; | 194 bool sandbox = !cmd_line_->HasSwitch(switches::kDisableGpuSandbox); |
| 195 if(! sandbox) { |
| 188 DVLOG(1) << "GPU sandbox is disabled"; | 196 DVLOG(1) << "GPU sandbox is disabled"; |
| 189 } | 197 } |
| 198 return sandbox; |
| 190 } | 199 } |
| 191 | 200 |
| 192 virtual void PreSandbox(bool* disable_default_policy, | 201 virtual void PreSandbox(bool* disable_default_policy, |
| 193 base::FilePath* exposed_dir) OVERRIDE { | 202 base::FilePath* exposed_dir) OVERRIDE { |
| 194 *disable_default_policy = true; | 203 *disable_default_policy = true; |
| 195 } | 204 } |
| 196 | 205 |
| 197 // For the GPU process we gotten as far as USER_LIMITED. The next level | 206 // For the GPU process we gotten as far as USER_LIMITED. The next level |
| 198 // which is USER_RESTRICTED breaks both the DirectX backend and the OpenGL | 207 // which is USER_RESTRICTED breaks both the DirectX backend and the OpenGL |
| 199 // backend. Note that the GPU process is connected to the interactive | 208 // backend. Note that the GPU process is connected to the interactive |
| (...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 266 result = policy->AddRule(sandbox::TargetPolicy::SUBSYS_FILES, | 275 result = policy->AddRule(sandbox::TargetPolicy::SUBSYS_FILES, |
| 267 sandbox::TargetPolicy::FILES_ALLOW_ANY, | 276 sandbox::TargetPolicy::FILES_ALLOW_ANY, |
| 268 log_file_path.c_str()); | 277 log_file_path.c_str()); |
| 269 if (result != sandbox::SBOX_ALL_OK) { | 278 if (result != sandbox::SBOX_ALL_OK) { |
| 270 *success = false; | 279 *success = false; |
| 271 return; | 280 return; |
| 272 } | 281 } |
| 273 } | 282 } |
| 274 } | 283 } |
| 275 } | 284 } |
| 285 #elif defined(OS_POSIX) |
| 286 |
| 287 virtual int GetIpcFd() OVERRIDE { |
| 288 return ipc_fd_; |
| 289 } |
| 290 #endif // OS_WIN |
| 276 | 291 |
| 277 private: | 292 private: |
| 293 #if defined(OS_WIN) |
| 278 CommandLine* cmd_line_; | 294 CommandLine* cmd_line_; |
| 295 #elif defined(OS_POSIX) |
| 296 int ipc_fd_; |
| 297 #endif // OS_WIN |
| 279 }; | 298 }; |
| 280 #endif // defined(OS_WIN) | |
| 281 | 299 |
| 282 } // anonymous namespace | 300 } // anonymous namespace |
| 283 | 301 |
| 284 // static | 302 // static |
| 285 bool GpuProcessHost::ValidateHost(GpuProcessHost* host) { | 303 bool GpuProcessHost::ValidateHost(GpuProcessHost* host) { |
| 286 if (!host) | 304 if (!host) |
| 287 return false; | 305 return false; |
| 288 | 306 |
| 289 // The Gpu process is invalid if it's not using SwiftShader, the card is | 307 // The Gpu process is invalid if it's not using SwiftShader, the card is |
| 290 // blacklisted, and we can kill it and start over. | 308 // blacklisted, and we can kill it and start over. |
| (...skipping 843 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1134 } | 1152 } |
| 1135 | 1153 |
| 1136 UMA_HISTOGRAM_BOOLEAN("GPU.GPU.GPUProcessSoftwareRendering", | 1154 UMA_HISTOGRAM_BOOLEAN("GPU.GPU.GPUProcessSoftwareRendering", |
| 1137 swiftshader_rendering_); | 1155 swiftshader_rendering_); |
| 1138 | 1156 |
| 1139 // If specified, prepend a launcher program to the command line. | 1157 // If specified, prepend a launcher program to the command line. |
| 1140 if (!gpu_launcher.empty()) | 1158 if (!gpu_launcher.empty()) |
| 1141 cmd_line->PrependWrapper(gpu_launcher); | 1159 cmd_line->PrependWrapper(gpu_launcher); |
| 1142 | 1160 |
| 1143 process_->Launch( | 1161 process_->Launch( |
| 1144 #if defined(OS_WIN) | 1162 new GpuSandboxedProcessLauncherDelegate(cmd_line, |
| 1145 new GpuSandboxedProcessLauncherDelegate(cmd_line), | 1163 process_->GetHost()), |
| 1146 false, | |
| 1147 #elif defined(OS_POSIX) | |
| 1148 false, | |
| 1149 base::EnvironmentMap(), | |
| 1150 #endif | |
| 1151 cmd_line); | 1164 cmd_line); |
| 1152 process_launched_ = true; | 1165 process_launched_ = true; |
| 1153 | 1166 |
| 1154 UMA_HISTOGRAM_ENUMERATION("GPU.GPUProcessLifetimeEvents", | 1167 UMA_HISTOGRAM_ENUMERATION("GPU.GPUProcessLifetimeEvents", |
| 1155 LAUNCHED, GPU_PROCESS_LIFETIME_EVENT_MAX); | 1168 LAUNCHED, GPU_PROCESS_LIFETIME_EVENT_MAX); |
| 1156 return true; | 1169 return true; |
| 1157 } | 1170 } |
| 1158 | 1171 |
| 1159 void GpuProcessHost::SendOutstandingReplies() { | 1172 void GpuProcessHost::SendOutstandingReplies() { |
| 1160 valid_ = false; | 1173 valid_ = false; |
| (...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1227 TRACE_EVENT0("gpu", "GpuProcessHost::OnCacheShader"); | 1240 TRACE_EVENT0("gpu", "GpuProcessHost::OnCacheShader"); |
| 1228 ClientIdToShaderCacheMap::iterator iter = | 1241 ClientIdToShaderCacheMap::iterator iter = |
| 1229 client_id_to_shader_cache_.find(client_id); | 1242 client_id_to_shader_cache_.find(client_id); |
| 1230 // If the cache doesn't exist then this is an off the record profile. | 1243 // If the cache doesn't exist then this is an off the record profile. |
| 1231 if (iter == client_id_to_shader_cache_.end()) | 1244 if (iter == client_id_to_shader_cache_.end()) |
| 1232 return; | 1245 return; |
| 1233 iter->second->Cache(GetShaderPrefixKey() + ":" + key, shader); | 1246 iter->second->Cache(GetShaderPrefixKey() + ":" + key, shader); |
| 1234 } | 1247 } |
| 1235 | 1248 |
| 1236 } // namespace content | 1249 } // namespace content |
| OLD | NEW |