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/location.h" | 9 #include "base/location.h" |
10 #include "base/logging.h" | 10 #include "base/logging.h" |
(...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
76 #if defined(USE_AURA) | 76 #if defined(USE_AURA) |
77 #include "content/public/browser/context_factory.h" | 77 #include "content/public/browser/context_factory.h" |
78 #include "ui/aura/env.h" | 78 #include "ui/aura/env.h" |
79 #endif | 79 #endif |
80 | 80 |
81 #if !defined(OS_IOS) | 81 #if !defined(OS_IOS) |
82 #include "content/browser/renderer_host/render_process_host_impl.h" | 82 #include "content/browser/renderer_host/render_process_host_impl.h" |
83 #endif | 83 #endif |
84 | 84 |
85 #if defined(OS_ANDROID) | 85 #if defined(OS_ANDROID) |
86 #include <android/native_window.h> | |
87 #include <android/native_window_jni.h> | |
88 | |
86 #include "base/android/jni_android.h" | 89 #include "base/android/jni_android.h" |
90 #include "base/containers/scoped_ptr_hash_map.h" | |
91 #include "base/memory/singleton.h" | |
92 #include "base/synchronization/lock.h" | |
87 #include "content/browser/android/browser_startup_controller.h" | 93 #include "content/browser/android/browser_startup_controller.h" |
88 #include "content/browser/android/browser_surface_texture_manager.h" | 94 #include "content/browser/android/browser_surface_texture_manager.h" |
89 #include "content/browser/android/tracing_controller_android.h" | 95 #include "content/browser/android/tracing_controller_android.h" |
90 #include "content/browser/screen_orientation/screen_orientation_delegate_android .h" | 96 #include "content/browser/screen_orientation/screen_orientation_delegate_android .h" |
97 #include "content/common/android/surface_texture_manager.h" | |
91 #include "content/public/browser/screen_orientation_provider.h" | 98 #include "content/public/browser/screen_orientation_provider.h" |
99 #include "ui/gl/android/scoped_java_surface.h" | |
100 #include "ui/gl/android/surface_texture.h" | |
92 #include "ui/gl/gl_surface.h" | 101 #include "ui/gl/gl_surface.h" |
93 #endif | 102 #endif |
94 | 103 |
95 #if defined(OS_MACOSX) | 104 #if defined(OS_MACOSX) |
96 #include "media/base/mac/avfoundation_glue.h" | 105 #include "media/base/mac/avfoundation_glue.h" |
97 #endif | 106 #endif |
98 | 107 |
99 #if defined(OS_MACOSX) && !defined(OS_IOS) | 108 #if defined(OS_MACOSX) && !defined(OS_IOS) |
109 #include "base/containers/scoped_ptr_hash_map.h" | |
110 #include "base/mac/scoped_mach_port.h" | |
100 #include "base/memory/memory_pressure_monitor_mac.h" | 111 #include "base/memory/memory_pressure_monitor_mac.h" |
112 #include "base/memory/singleton.h" | |
113 #include "base/synchronization/lock.h" | |
101 #include "content/browser/bootstrap_sandbox_mac.h" | 114 #include "content/browser/bootstrap_sandbox_mac.h" |
102 #include "content/browser/browser_io_surface_manager_mac.h" | 115 #include "content/browser/browser_io_surface_manager_mac.h" |
103 #include "content/browser/cocoa/system_hotkey_helper_mac.h" | 116 #include "content/browser/cocoa/system_hotkey_helper_mac.h" |
104 #include "content/browser/compositor/browser_compositor_view_mac.h" | 117 #include "content/browser/compositor/browser_compositor_view_mac.h" |
105 #include "content/browser/theme_helper_mac.h" | 118 #include "content/browser/theme_helper_mac.h" |
119 #include "content/common/mac/io_surface_manager.h" | |
106 #endif | 120 #endif |
107 | 121 |
108 #if defined(OS_WIN) | 122 #if defined(OS_WIN) |
109 #include <windows.h> | 123 #include <windows.h> |
110 #include <commctrl.h> | 124 #include <commctrl.h> |
111 #include <shellapi.h> | 125 #include <shellapi.h> |
112 | 126 |
113 #include "base/memory/memory_pressure_monitor_win.h" | 127 #include "base/memory/memory_pressure_monitor_win.h" |
114 #include "content/browser/system_message_window_win.h" | 128 #include "content/browser/system_message_window_win.h" |
115 #include "content/common/sandbox_win.h" | 129 #include "content/common/sandbox_win.h" |
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
152 #endif | 166 #endif |
153 | 167 |
154 // One of the linux specific headers defines this as a macro. | 168 // One of the linux specific headers defines this as a macro. |
155 #ifdef DestroyAll | 169 #ifdef DestroyAll |
156 #undef DestroyAll | 170 #undef DestroyAll |
157 #endif | 171 #endif |
158 | 172 |
159 namespace content { | 173 namespace content { |
160 namespace { | 174 namespace { |
161 | 175 |
176 #if defined(OS_ANDROID) | |
177 class InProcessSurfaceTextureManager : public SurfaceTextureManager { | |
Daniele Castagna
2015/06/09 14:45:07
I still think these two classes should live somewh
reveman
2015/06/09 17:48:14
Done.
| |
178 public: | |
179 static InProcessSurfaceTextureManager* GetInstance() { | |
180 return Singleton< | |
181 InProcessSurfaceTextureManager, | |
182 LeakySingletonTraits<InProcessSurfaceTextureManager>>::get(); | |
183 } | |
184 | |
185 // Overridden from SurfaceTextureManager: | |
186 void RegisterSurfaceTexture(int surface_texture_id, | |
187 int client_id, | |
188 gfx::SurfaceTexture* surface_texture) override { | |
189 base::AutoLock lock(lock_); | |
190 DCHECK(surface_textures_.find(surface_texture_id) == | |
Daniele Castagna
2015/06/09 14:45:07
nit: DCHECK(!bla.contains()).
reveman
2015/06/09 17:48:14
Kept the existing DCHECK to be consistent with Bro
| |
191 surface_textures_.end()); | |
192 surface_textures_.set( | |
193 surface_texture_id, | |
194 make_scoped_ptr(new gfx::ScopedJavaSurface(surface_texture))); | |
195 } | |
196 void UnregisterSurfaceTexture(int surface_texture_id, | |
197 int client_id) override { | |
198 base::AutoLock lock(lock_); | |
199 DCHECK(surface_textures_.find(surface_texture_id) != | |
Daniele Castagna
2015/06/09 14:45:06
nit: same as above.
reveman
2015/06/09 17:48:14
ditto
| |
200 surface_textures_.end()); | |
201 surface_textures_.erase(surface_texture_id); | |
202 } | |
203 gfx::AcceleratedWidget AcquireNativeWidgetForSurfaceTexture( | |
204 int surface_texture_id) override { | |
205 base::AutoLock lock(lock_); | |
206 DCHECK(surface_textures_.find(surface_texture_id) != | |
207 surface_textures_.end()); | |
208 JNIEnv* env = base::android::AttachCurrentThread(); | |
209 return ANativeWindow_fromSurface( | |
210 env, surface_textures_.get(surface_texture_id)->j_surface().obj()); | |
211 } | |
212 | |
213 private: | |
214 friend struct DefaultSingletonTraits<InProcessSurfaceTextureManager>; | |
215 | |
216 using SurfaceTextureMap = | |
217 base::ScopedPtrHashMap<int, scoped_ptr<gfx::ScopedJavaSurface>>; | |
218 SurfaceTextureMap surface_textures_; | |
219 base::Lock lock_; | |
220 }; | |
221 #endif | |
222 | |
223 #if defined(OS_MACOSX) && !defined(OS_IOS) | |
224 class InProcessIOSurfaceManager : public IOSurfaceManager { | |
225 public: | |
226 static InProcessIOSurfaceManager* GetInstance() { | |
227 return Singleton<InProcessIOSurfaceManager, | |
228 LeakySingletonTraits<InProcessIOSurfaceManager>>::get(); | |
229 } | |
230 | |
231 // Overridden from IOSurfaceManager: | |
232 bool RegisterIOSurface(int io_surface_id, | |
233 int client_id, | |
234 IOSurfaceRef io_surface) override { | |
235 base::AutoLock lock(lock_); | |
236 DCHECK(io_surfaces_.find(io_surface_id) == io_surfaces_.end()); | |
237 io_surfaces_.add(io_surface_id, | |
238 make_scoped_ptr(new base::mac::ScopedMachSendRight( | |
239 IOSurfaceCreateMachPort(io_surface)))); | |
240 return true; | |
241 } | |
242 void UnregisterIOSurface(int io_surface_id, int client_id) override { | |
243 base::AutoLock lock(lock_); | |
244 DCHECK(io_surfaces_.find(io_surface_id) != io_surfaces_.end()); | |
245 io_surfaces_.erase(io_surface_id); | |
246 } | |
247 IOSurfaceRef AcquireIOSurface(int io_surface_id) override { | |
248 base::AutoLock lock(lock_); | |
249 DCHECK(io_surfaces_.find(io_surface_id) != io_surfaces_.end()); | |
250 return IOSurfaceLookupFromMachPort(io_surfaces_.get(io_surface_id)->get()); | |
251 } | |
252 | |
253 private: | |
254 friend struct DefaultSingletonTraits<InProcessIOSurfaceManager>; | |
255 | |
256 using IOSurfaceMap = | |
257 base::ScopedPtrHashMap<int, scoped_ptr<base::mac::ScopedMachSendRight>>; | |
258 IOSurfaceMap io_surfaces_; | |
259 base::Lock lock_; | |
260 }; | |
261 #endif | |
262 | |
162 #if defined(OS_POSIX) && !defined(OS_MACOSX) && !defined(OS_ANDROID) | 263 #if defined(OS_POSIX) && !defined(OS_MACOSX) && !defined(OS_ANDROID) |
163 void SetupSandbox(const base::CommandLine& parsed_command_line) { | 264 void SetupSandbox(const base::CommandLine& parsed_command_line) { |
164 TRACE_EVENT0("startup", "SetupSandbox"); | 265 TRACE_EVENT0("startup", "SetupSandbox"); |
165 base::FilePath sandbox_binary; | 266 base::FilePath sandbox_binary; |
166 | 267 |
167 scoped_ptr<sandbox::SetuidSandboxHost> setuid_sandbox_host( | 268 scoped_ptr<sandbox::SetuidSandboxHost> setuid_sandbox_host( |
168 sandbox::SetuidSandboxHost::Create()); | 269 sandbox::SetuidSandboxHost::Create()); |
169 | 270 |
170 const bool want_setuid_sandbox = | 271 const bool want_setuid_sandbox = |
171 !parsed_command_line.HasSwitch(switches::kNoSandbox) && | 272 !parsed_command_line.HasSwitch(switches::kNoSandbox) && |
(...skipping 410 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
582 // MessagePumpForUI::Start() as it will crash the browser. | 683 // MessagePumpForUI::Start() as it will crash the browser. |
583 if (is_tracing_startup_) { | 684 if (is_tracing_startup_) { |
584 TRACE_EVENT0("startup", "BrowserMainLoop::InitStartupTracing"); | 685 TRACE_EVENT0("startup", "BrowserMainLoop::InitStartupTracing"); |
585 InitStartupTracing(parsed_command_line_); | 686 InitStartupTracing(parsed_command_line_); |
586 } | 687 } |
587 #endif // !defined(OS_IOS) | 688 #endif // !defined(OS_IOS) |
588 | 689 |
589 #if defined(OS_ANDROID) | 690 #if defined(OS_ANDROID) |
590 { | 691 { |
591 TRACE_EVENT0("startup", "BrowserMainLoop::Subsystem:SurfaceTextureManager"); | 692 TRACE_EVENT0("startup", "BrowserMainLoop::Subsystem:SurfaceTextureManager"); |
592 SurfaceTextureManager::SetInstance(new BrowserSurfaceTextureManager); | 693 if (parsed_command_line_.HasSwitch(switches::kSingleProcess)) { |
694 SurfaceTextureManager::SetInstance( | |
695 InProcessSurfaceTextureManager::GetInstance()); | |
696 } else { | |
697 SurfaceTextureManager::SetInstance( | |
698 BrowserSurfaceTextureManager::GetInstance()); | |
699 } | |
593 } | 700 } |
594 | 701 |
595 if (!parsed_command_line_.HasSwitch( | 702 if (!parsed_command_line_.HasSwitch( |
596 switches::kDisableScreenOrientationLock)) { | 703 switches::kDisableScreenOrientationLock)) { |
597 TRACE_EVENT0("startup", | 704 TRACE_EVENT0("startup", |
598 "BrowserMainLoop::Subsystem:ScreenOrientationProvider"); | 705 "BrowserMainLoop::Subsystem:ScreenOrientationProvider"); |
599 screen_orientation_delegate_.reset( | 706 screen_orientation_delegate_.reset( |
600 new ScreenOrientationDelegateAndroid()); | 707 new ScreenOrientationDelegateAndroid()); |
601 ScreenOrientationProvider::SetDelegate(screen_orientation_delegate_.get()); | 708 ScreenOrientationProvider::SetDelegate(screen_orientation_delegate_.get()); |
602 } | 709 } |
603 #endif | 710 #endif |
604 | 711 |
605 #if defined(OS_MACOSX) && !defined(OS_IOS) | 712 #if defined(OS_MACOSX) && !defined(OS_IOS) |
606 { | 713 { |
607 TRACE_EVENT0("startup", "BrowserMainLoop::Subsystem:IOSurfaceManager"); | 714 TRACE_EVENT0("startup", "BrowserMainLoop::Subsystem:IOSurfaceManager"); |
608 IOSurfaceManager::SetInstance(BrowserIOSurfaceManager::GetInstance()); | 715 if (parsed_command_line_.HasSwitch(switches::kSingleProcess)) { |
716 IOSurfaceManager::SetInstance(InProcessIOSurfaceManager::GetInstance()); | |
717 } else { | |
718 IOSurfaceManager::SetInstance(BrowserIOSurfaceManager::GetInstance()); | |
719 } | |
609 } | 720 } |
610 #endif | 721 #endif |
611 | 722 |
612 if (parsed_command_line_.HasSwitch(switches::kMemoryMetrics)) { | 723 if (parsed_command_line_.HasSwitch(switches::kMemoryMetrics)) { |
613 TRACE_EVENT0("startup", "BrowserMainLoop::Subsystem:MemoryObserver"); | 724 TRACE_EVENT0("startup", "BrowserMainLoop::Subsystem:MemoryObserver"); |
614 memory_observer_.reset(new MemoryObserver()); | 725 memory_observer_.reset(new MemoryObserver()); |
615 base::MessageLoop::current()->AddTaskObserver(memory_observer_.get()); | 726 base::MessageLoop::current()->AddTaskObserver(memory_observer_.get()); |
616 } | 727 } |
617 | 728 |
618 if (parsed_command_line_.HasSwitch( | 729 if (parsed_command_line_.HasSwitch( |
(...skipping 749 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1368 DCHECK(is_tracing_startup_); | 1479 DCHECK(is_tracing_startup_); |
1369 | 1480 |
1370 is_tracing_startup_ = false; | 1481 is_tracing_startup_ = false; |
1371 TracingController::GetInstance()->DisableRecording( | 1482 TracingController::GetInstance()->DisableRecording( |
1372 TracingController::CreateFileSink( | 1483 TracingController::CreateFileSink( |
1373 startup_trace_file_, | 1484 startup_trace_file_, |
1374 base::Bind(OnStoppedStartupTracing, startup_trace_file_))); | 1485 base::Bind(OnStoppedStartupTracing, startup_trace_file_))); |
1375 } | 1486 } |
1376 | 1487 |
1377 } // namespace content | 1488 } // namespace content |
OLD | NEW |