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/debug/trace_event.h" | 9 #include "base/debug/trace_event.h" |
10 #include "base/hi_res_timer_manager.h" | 10 #include "base/hi_res_timer_manager.h" |
(...skipping 80 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
91 | 91 |
92 #include "base/process_util.h" | 92 #include "base/process_util.h" |
93 #include "content/browser/renderer_host/render_sandbox_host_linux.h" | 93 #include "content/browser/renderer_host/render_sandbox_host_linux.h" |
94 #include "content/browser/zygote_host/zygote_host_impl_linux.h" | 94 #include "content/browser/zygote_host/zygote_host_impl_linux.h" |
95 #endif | 95 #endif |
96 | 96 |
97 #if defined(USE_X11) | 97 #if defined(USE_X11) |
98 #include <X11/Xlib.h> | 98 #include <X11/Xlib.h> |
99 #endif | 99 #endif |
100 | 100 |
| 101 #if !defined(OS_IOS) |
| 102 #include "webkit/glue/webkit_glue.h" |
| 103 #endif |
| 104 |
101 // One of the linux specific headers defines this as a macro. | 105 // One of the linux specific headers defines this as a macro. |
102 #ifdef DestroyAll | 106 #ifdef DestroyAll |
103 #undef DestroyAll | 107 #undef DestroyAll |
104 #endif | 108 #endif |
105 | 109 |
106 namespace content { | 110 namespace content { |
107 namespace { | 111 namespace { |
108 | 112 |
109 #if defined(OS_POSIX) && !defined(OS_MACOSX) && !defined(OS_ANDROID) | 113 #if defined(OS_POSIX) && !defined(OS_MACOSX) && !defined(OS_ANDROID) |
110 void SetupSandbox(const CommandLine& parsed_command_line) { | 114 void SetupSandbox(const CommandLine& parsed_command_line) { |
(...skipping 108 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
219 #else | 223 #else |
220 NOTIMPLEMENTED(); | 224 NOTIMPLEMENTED(); |
221 #endif | 225 #endif |
222 } | 226 } |
223 }; | 227 }; |
224 | 228 |
225 void ImmediateShutdownAndExitProcess() { | 229 void ImmediateShutdownAndExitProcess() { |
226 BrowserShutdownImpl::ImmediateShutdownAndExitProcess(); | 230 BrowserShutdownImpl::ImmediateShutdownAndExitProcess(); |
227 } | 231 } |
228 | 232 |
| 233 // For measuring memory usage after each task. Behind a command line flag. |
| 234 class BrowserMainLoop::MemoryObserver : public MessageLoop::TaskObserver { |
| 235 public: |
| 236 MemoryObserver() {} |
| 237 virtual ~MemoryObserver() {} |
| 238 |
| 239 virtual void WillProcessTask(base::TimeTicks time_posted) OVERRIDE {} |
| 240 |
| 241 virtual void DidProcessTask(base::TimeTicks time_posted) OVERRIDE { |
| 242 #if !defined(OS_IOS) |
| 243 HISTOGRAM_MEMORY_KB("Memory.BrowserUsed", webkit_glue::MemoryUsageKB()); |
| 244 #endif |
| 245 } |
| 246 private: |
| 247 DISALLOW_COPY_AND_ASSIGN(MemoryObserver); |
| 248 }; |
| 249 |
| 250 |
229 // static | 251 // static |
230 media::AudioManager* BrowserMainLoop::GetAudioManager() { | 252 media::AudioManager* BrowserMainLoop::GetAudioManager() { |
231 return g_current_browser_main_loop->audio_manager_.get(); | 253 return g_current_browser_main_loop->audio_manager_.get(); |
232 } | 254 } |
233 | 255 |
234 // static | 256 // static |
235 AudioMirroringManager* BrowserMainLoop::GetAudioMirroringManager() { | 257 AudioMirroringManager* BrowserMainLoop::GetAudioMirroringManager() { |
236 return g_current_browser_main_loop->audio_mirroring_manager_.get(); | 258 return g_current_browser_main_loop->audio_mirroring_manager_.get(); |
237 } | 259 } |
238 | 260 |
(...skipping 128 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
367 | 389 |
368 if (parts_.get()) | 390 if (parts_.get()) |
369 parts_->PostMainMessageLoopStart(); | 391 parts_->PostMainMessageLoopStart(); |
370 | 392 |
371 #if defined(OS_ANDROID) | 393 #if defined(OS_ANDROID) |
372 SurfaceTexturePeer::InitInstance(new SurfaceTexturePeerBrowserImpl( | 394 SurfaceTexturePeer::InitInstance(new SurfaceTexturePeerBrowserImpl( |
373 parameters_.command_line.HasSwitch( | 395 parameters_.command_line.HasSwitch( |
374 switches::kMediaPlayerInRenderProcess))); | 396 switches::kMediaPlayerInRenderProcess))); |
375 DataFetcherImplAndroid::Init(base::android::AttachCurrentThread()); | 397 DataFetcherImplAndroid::Init(base::android::AttachCurrentThread()); |
376 #endif | 398 #endif |
| 399 |
| 400 if (parsed_command_line_.HasSwitch(switches::kMemoryMetrics)) { |
| 401 memory_observer_.reset(new MemoryObserver()); |
| 402 main_message_loop_->AddTaskObserver(memory_observer_.get()); |
| 403 } |
377 } | 404 } |
378 | 405 |
379 void BrowserMainLoop::CreateThreads() { | 406 void BrowserMainLoop::CreateThreads() { |
380 if (parts_.get()) | 407 if (parts_.get()) |
381 result_code_ = parts_->PreCreateThreads(); | 408 result_code_ = parts_->PreCreateThreads(); |
382 | 409 |
383 #if !defined(OS_IOS) && (!defined(GOOGLE_CHROME_BUILD) || defined(OS_ANDROID)) | 410 #if !defined(OS_IOS) && (!defined(GOOGLE_CHROME_BUILD) || defined(OS_ANDROID)) |
384 // Single-process is an unsupported and not fully tested mode, so | 411 // Single-process is an unsupported and not fully tested mode, so |
385 // don't enable it for official Chrome builds (except on Android). | 412 // don't enable it for official Chrome builds (except on Android). |
386 if (parsed_command_line_.HasSwitch(switches::kSingleProcess)) | 413 if (parsed_command_line_.HasSwitch(switches::kSingleProcess)) |
(...skipping 389 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
776 DCHECK_EQ(MessageLoop::TYPE_UI, MessageLoop::current()->type()); | 803 DCHECK_EQ(MessageLoop::TYPE_UI, MessageLoop::current()->type()); |
777 if (parameters_.ui_task) | 804 if (parameters_.ui_task) |
778 MessageLoopForUI::current()->PostTask(FROM_HERE, *parameters_.ui_task); | 805 MessageLoopForUI::current()->PostTask(FROM_HERE, *parameters_.ui_task); |
779 | 806 |
780 base::RunLoop run_loop; | 807 base::RunLoop run_loop; |
781 run_loop.Run(); | 808 run_loop.Run(); |
782 #endif | 809 #endif |
783 } | 810 } |
784 | 811 |
785 } // namespace content | 812 } // namespace content |
OLD | NEW |