Chromium Code Reviews| 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/browser_main_loop.h" | 5 #include "content/browser/browser_main_loop.h" |
| 6 | 6 |
| 7 #include "base/bind.h" | 7 #include "base/bind.h" |
| 8 #include "base/command_line.h" | 8 #include "base/command_line.h" |
| 9 #include "base/logging.h" | 9 #include "base/logging.h" |
| 10 #include "base/message_loop/message_loop.h" | 10 #include "base/message_loop/message_loop.h" |
| (...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 72 #if defined(USE_AURA) | 72 #if defined(USE_AURA) |
| 73 #include "content/public/browser/context_factory.h" | 73 #include "content/public/browser/context_factory.h" |
| 74 #include "ui/aura/env.h" | 74 #include "ui/aura/env.h" |
| 75 #endif | 75 #endif |
| 76 | 76 |
| 77 #if !defined(OS_IOS) | 77 #if !defined(OS_IOS) |
| 78 #include "content/browser/renderer_host/render_process_host_impl.h" | 78 #include "content/browser/renderer_host/render_process_host_impl.h" |
| 79 #endif | 79 #endif |
| 80 | 80 |
| 81 #if defined(OS_ANDROID) | 81 #if defined(OS_ANDROID) |
| 82 #include <android/native_window.h> | |
| 83 #include <android/native_window_jni.h> | |
| 84 | |
| 82 #include "base/android/jni_android.h" | 85 #include "base/android/jni_android.h" |
| 86 #include "base/containers/scoped_ptr_hash_map.h" | |
| 87 #include "base/synchronization/lock.h" | |
| 83 #include "content/browser/android/browser_startup_controller.h" | 88 #include "content/browser/android/browser_startup_controller.h" |
| 84 #include "content/browser/android/browser_surface_texture_manager.h" | 89 #include "content/browser/android/browser_surface_texture_manager.h" |
| 85 #include "content/browser/android/tracing_controller_android.h" | 90 #include "content/browser/android/tracing_controller_android.h" |
| 86 #include "content/browser/screen_orientation/screen_orientation_delegate_android .h" | 91 #include "content/browser/screen_orientation/screen_orientation_delegate_android .h" |
| 92 #include "content/common/android/surface_texture_manager.h" | |
| 93 #include "content/common/android/surface_texture_peer.h" | |
| 87 #include "content/public/browser/screen_orientation_provider.h" | 94 #include "content/public/browser/screen_orientation_provider.h" |
| 95 #include "ui/gl/android/scoped_java_surface.h" | |
| 96 #include "ui/gl/android/surface_texture.h" | |
| 88 #include "ui/gl/gl_surface.h" | 97 #include "ui/gl/gl_surface.h" |
| 89 #endif | 98 #endif |
| 90 | 99 |
| 91 #if defined(OS_MACOSX) && !defined(OS_IOS) | 100 #if defined(OS_MACOSX) && !defined(OS_IOS) |
| 92 #include "base/mac/memory_pressure_monitor_mac.h" | 101 #include "base/mac/memory_pressure_monitor_mac.h" |
| 93 #include "content/browser/bootstrap_sandbox_mac.h" | 102 #include "content/browser/bootstrap_sandbox_mac.h" |
| 94 #include "content/browser/cocoa/system_hotkey_helper_mac.h" | 103 #include "content/browser/cocoa/system_hotkey_helper_mac.h" |
| 95 #include "content/browser/compositor/browser_compositor_view_mac.h" | 104 #include "content/browser/compositor/browser_compositor_view_mac.h" |
| 96 #include "content/browser/theme_helper_mac.h" | 105 #include "content/browser/theme_helper_mac.h" |
| 97 #endif | 106 #endif |
| (...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 142 #endif | 151 #endif |
| 143 | 152 |
| 144 // One of the linux specific headers defines this as a macro. | 153 // One of the linux specific headers defines this as a macro. |
| 145 #ifdef DestroyAll | 154 #ifdef DestroyAll |
| 146 #undef DestroyAll | 155 #undef DestroyAll |
| 147 #endif | 156 #endif |
| 148 | 157 |
| 149 namespace content { | 158 namespace content { |
| 150 namespace { | 159 namespace { |
| 151 | 160 |
| 161 #if defined(OS_ANDROID) | |
| 162 class InProcessSurfaceTextureManager : public SurfaceTextureManager, | |
| 163 public SurfaceTexturePeer { | |
| 164 public: | |
| 165 InProcessSurfaceTextureManager() { SurfaceTexturePeer::InitInstance(this); } | |
| 166 ~InProcessSurfaceTextureManager() override { | |
| 167 SurfaceTexturePeer::InitInstance(NULL); | |
| 168 } | |
| 169 | |
| 170 // Overridden from SurfaceTextureManager: | |
| 171 void RegisterSurfaceTexture(int surface_texture_id, | |
| 172 int client_id, | |
| 173 gfx::SurfaceTexture* surface_texture) override { | |
| 174 base::AutoLock lock(lock_); | |
| 175 DCHECK(surfaces_.find(surface_texture_id) == surfaces_.end()); | |
| 176 surfaces_.set(surface_texture_id, | |
| 177 make_scoped_ptr(new gfx::ScopedJavaSurface(surface_texture))); | |
| 178 } | |
| 179 void UnregisterSurfaceTexture(int surface_texture_id, | |
| 180 int client_id) override { | |
| 181 base::AutoLock lock(lock_); | |
| 182 DCHECK(surfaces_.find(surface_texture_id) != surfaces_.end()); | |
|
Daniele Castagna
2015/05/06 20:46:26
nit: DCHECK_EQ should be preferred.
reveman
2015/06/08 22:20:48
doesn't work with that macro
| |
| 183 surfaces_.erase(surface_texture_id); | |
| 184 } | |
| 185 gfx::AcceleratedWidget AcquireNativeWidgetForSurfaceTexture( | |
| 186 int surface_texture_id) override { | |
| 187 base::AutoLock lock(lock_); | |
| 188 DCHECK(surfaces_.find(surface_texture_id) != surfaces_.end()); | |
|
Daniele Castagna
2015/05/06 20:46:26
Same here: DCHECK_NE
reveman
2015/06/08 22:20:48
same
| |
| 189 JNIEnv* env = base::android::AttachCurrentThread(); | |
| 190 return ANativeWindow_fromSurface( | |
| 191 env, surfaces_.get(surface_texture_id)->j_surface().obj()); | |
|
Daniele Castagna
2015/05/06 20:46:26
You can use surfaces_->operator[] if you prefer.
reveman
2015/06/08 22:20:48
kept use get() of get to be consistent with code i
| |
| 192 } | |
| 193 | |
| 194 // Overridden from SurfaceTexturePeer: | |
| 195 void EstablishSurfaceTexturePeer( | |
| 196 base::ProcessHandle render_process_handle, | |
| 197 scoped_refptr<gfx::SurfaceTexture> surface_texture, | |
| 198 int render_frame_id, | |
| 199 int player_id) override { | |
| 200 NOTIMPLEMENTED(); | |
| 201 } | |
| 202 | |
| 203 private: | |
| 204 typedef base::ScopedPtrHashMap<int, scoped_ptr<gfx::ScopedJavaSurface>> | |
| 205 SurfaceMap; | |
| 206 SurfaceMap surfaces_; | |
| 207 base::Lock lock_; | |
| 208 | |
| 209 DISALLOW_COPY_AND_ASSIGN(InProcessSurfaceTextureManager); | |
| 210 }; | |
| 211 #endif | |
| 212 | |
| 152 #if defined(OS_POSIX) && !defined(OS_MACOSX) && !defined(OS_ANDROID) | 213 #if defined(OS_POSIX) && !defined(OS_MACOSX) && !defined(OS_ANDROID) |
| 153 void SetupSandbox(const base::CommandLine& parsed_command_line) { | 214 void SetupSandbox(const base::CommandLine& parsed_command_line) { |
| 154 TRACE_EVENT0("startup", "SetupSandbox"); | 215 TRACE_EVENT0("startup", "SetupSandbox"); |
| 155 base::FilePath sandbox_binary; | 216 base::FilePath sandbox_binary; |
| 156 | 217 |
| 157 scoped_ptr<sandbox::SetuidSandboxHost> setuid_sandbox_host( | 218 scoped_ptr<sandbox::SetuidSandboxHost> setuid_sandbox_host( |
| 158 sandbox::SetuidSandboxHost::Create()); | 219 sandbox::SetuidSandboxHost::Create()); |
| 159 | 220 |
| 160 const bool want_setuid_sandbox = | 221 const bool want_setuid_sandbox = |
| 161 !parsed_command_line.HasSwitch(switches::kNoSandbox) && | 222 !parsed_command_line.HasSwitch(switches::kNoSandbox) && |
| (...skipping 395 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 557 // MessagePumpForUI::Start() as it will crash the browser. | 618 // MessagePumpForUI::Start() as it will crash the browser. |
| 558 if (is_tracing_startup_) { | 619 if (is_tracing_startup_) { |
| 559 TRACE_EVENT0("startup", "BrowserMainLoop::InitStartupTracing"); | 620 TRACE_EVENT0("startup", "BrowserMainLoop::InitStartupTracing"); |
| 560 InitStartupTracing(parsed_command_line_); | 621 InitStartupTracing(parsed_command_line_); |
| 561 } | 622 } |
| 562 #endif // !defined(OS_IOS) | 623 #endif // !defined(OS_IOS) |
| 563 | 624 |
| 564 #if defined(OS_ANDROID) | 625 #if defined(OS_ANDROID) |
| 565 { | 626 { |
| 566 TRACE_EVENT0("startup", "BrowserMainLoop::Subsystem:SurfaceTextureManager"); | 627 TRACE_EVENT0("startup", "BrowserMainLoop::Subsystem:SurfaceTextureManager"); |
| 567 SurfaceTextureManager::InitInstance(new BrowserSurfaceTextureManager); | 628 if (parsed_command_line_.HasSwitch(switches::kSingleProcess)) |
| 629 SurfaceTextureManager::InitInstance(new InProcessSurfaceTextureManager); | |
| 630 else | |
| 631 SurfaceTextureManager::InitInstance(new BrowserSurfaceTextureManager); | |
| 568 } | 632 } |
| 569 | 633 |
| 570 if (!parsed_command_line_.HasSwitch( | 634 if (!parsed_command_line_.HasSwitch( |
| 571 switches::kDisableScreenOrientationLock)) { | 635 switches::kDisableScreenOrientationLock)) { |
| 572 TRACE_EVENT0("startup", | 636 TRACE_EVENT0("startup", |
| 573 "BrowserMainLoop::Subsystem:ScreenOrientationProvider"); | 637 "BrowserMainLoop::Subsystem:ScreenOrientationProvider"); |
| 574 screen_orientation_delegate_.reset( | 638 screen_orientation_delegate_.reset( |
| 575 new ScreenOrientationDelegateAndroid()); | 639 new ScreenOrientationDelegateAndroid()); |
| 576 ScreenOrientationProvider::SetDelegate(screen_orientation_delegate_.get()); | 640 ScreenOrientationProvider::SetDelegate(screen_orientation_delegate_.get()); |
| 577 } | 641 } |
| (...skipping 732 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1310 | 1374 |
| 1311 void BrowserMainLoop::EndStartupTracing() { | 1375 void BrowserMainLoop::EndStartupTracing() { |
| 1312 is_tracing_startup_ = false; | 1376 is_tracing_startup_ = false; |
| 1313 TracingController::GetInstance()->DisableRecording( | 1377 TracingController::GetInstance()->DisableRecording( |
| 1314 TracingController::CreateFileSink( | 1378 TracingController::CreateFileSink( |
| 1315 startup_trace_file_, | 1379 startup_trace_file_, |
| 1316 base::Bind(OnStoppedStartupTracing, startup_trace_file_))); | 1380 base::Bind(OnStoppedStartupTracing, startup_trace_file_))); |
| 1317 } | 1381 } |
| 1318 | 1382 |
| 1319 } // namespace content | 1383 } // namespace content |
| OLD | NEW |