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 215 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
226 NOTIMPLEMENTED(); | 226 NOTIMPLEMENTED(); |
227 #endif | 227 #endif |
228 } | 228 } |
229 }; | 229 }; |
230 | 230 |
231 void ImmediateShutdownAndExitProcess() { | 231 void ImmediateShutdownAndExitProcess() { |
232 BrowserShutdownImpl::ImmediateShutdownAndExitProcess(); | 232 BrowserShutdownImpl::ImmediateShutdownAndExitProcess(); |
233 } | 233 } |
234 | 234 |
235 // For measuring memory usage after each task. Behind a command line flag. | 235 // For measuring memory usage after each task. Behind a command line flag. |
236 class BrowserMainLoop::MemoryObserver : public MessageLoop::TaskObserver { | 236 class BrowserMainLoop::MemoryObserver : public base::MessageLoop::TaskObserver { |
237 public: | 237 public: |
238 MemoryObserver() {} | 238 MemoryObserver() {} |
239 virtual ~MemoryObserver() {} | 239 virtual ~MemoryObserver() {} |
240 | 240 |
241 virtual void WillProcessTask(const base::PendingTask& pending_task) OVERRIDE { | 241 virtual void WillProcessTask(const base::PendingTask& pending_task) OVERRIDE { |
242 } | 242 } |
243 | 243 |
244 virtual void DidProcessTask(const base::PendingTask& pending_task) OVERRIDE { | 244 virtual void DidProcessTask(const base::PendingTask& pending_task) OVERRIDE { |
245 #if !defined(OS_IOS) // No ProcessMetrics on IOS. | 245 #if !defined(OS_IOS) // No ProcessMetrics on IOS. |
246 scoped_ptr<base::ProcessMetrics> process_metrics( | 246 scoped_ptr<base::ProcessMetrics> process_metrics( |
(...skipping 109 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
356 #if defined(OS_WIN) | 356 #if defined(OS_WIN) |
357 // If we're running tests (ui_task is non-null), then the ResourceBundle | 357 // If we're running tests (ui_task is non-null), then the ResourceBundle |
358 // has already been initialized. | 358 // has already been initialized. |
359 if (!parameters_.ui_task) { | 359 if (!parameters_.ui_task) { |
360 // Override the configured locale with the user's preferred UI language. | 360 // Override the configured locale with the user's preferred UI language. |
361 l10n_util::OverrideLocaleWithUILanguageList(); | 361 l10n_util::OverrideLocaleWithUILanguageList(); |
362 } | 362 } |
363 #endif | 363 #endif |
364 | 364 |
365 // Create a MessageLoop if one does not already exist for the current thread. | 365 // Create a MessageLoop if one does not already exist for the current thread. |
366 if (!MessageLoop::current()) | 366 if (!base::MessageLoop::current()) |
367 main_message_loop_.reset(new MessageLoop(MessageLoop::TYPE_UI)); | 367 main_message_loop_.reset(new base::MessageLoop(base::MessageLoop::TYPE_UI)); |
368 | 368 |
369 InitializeMainThread(); | 369 InitializeMainThread(); |
370 | 370 |
371 system_monitor_.reset(new base::SystemMonitor); | 371 system_monitor_.reset(new base::SystemMonitor); |
372 power_monitor_.reset(new base::PowerMonitor); | 372 power_monitor_.reset(new base::PowerMonitor); |
373 hi_res_timer_manager_.reset(new HighResolutionTimerManager); | 373 hi_res_timer_manager_.reset(new HighResolutionTimerManager); |
374 network_change_notifier_.reset(net::NetworkChangeNotifier::Create()); | 374 network_change_notifier_.reset(net::NetworkChangeNotifier::Create()); |
375 audio_manager_.reset(media::AudioManager::Create()); | 375 audio_manager_.reset(media::AudioManager::Create()); |
376 | 376 |
377 #if !defined(OS_IOS) | 377 #if !defined(OS_IOS) |
(...skipping 26 matching lines...) Expand all Loading... |
404 if (parts_) | 404 if (parts_) |
405 parts_->PostMainMessageLoopStart(); | 405 parts_->PostMainMessageLoopStart(); |
406 | 406 |
407 #if defined(OS_ANDROID) | 407 #if defined(OS_ANDROID) |
408 SurfaceTexturePeer::InitInstance(new SurfaceTexturePeerBrowserImpl()); | 408 SurfaceTexturePeer::InitInstance(new SurfaceTexturePeerBrowserImpl()); |
409 DataFetcherImplAndroid::Init(base::android::AttachCurrentThread()); | 409 DataFetcherImplAndroid::Init(base::android::AttachCurrentThread()); |
410 #endif | 410 #endif |
411 | 411 |
412 if (parsed_command_line_.HasSwitch(switches::kMemoryMetrics)) { | 412 if (parsed_command_line_.HasSwitch(switches::kMemoryMetrics)) { |
413 memory_observer_.reset(new MemoryObserver()); | 413 memory_observer_.reset(new MemoryObserver()); |
414 MessageLoop::current()->AddTaskObserver(memory_observer_.get()); | 414 base::MessageLoop::current()->AddTaskObserver(memory_observer_.get()); |
415 } | 415 } |
416 } | 416 } |
417 | 417 |
418 void BrowserMainLoop::CreateThreads() { | 418 void BrowserMainLoop::CreateThreads() { |
419 TRACE_EVENT0("startup", "BrowserMainLoop::CreateThreads") | 419 TRACE_EVENT0("startup", "BrowserMainLoop::CreateThreads") |
420 | 420 |
421 if (parts_) { | 421 if (parts_) { |
422 TRACE_EVENT0("startup", | 422 TRACE_EVENT0("startup", |
423 "BrowserMainLoop::MainMessageLoopStart:PreCreateThreads"); | 423 "BrowserMainLoop::MainMessageLoopStart:PreCreateThreads"); |
424 result_code_ = parts_->PreCreateThreads(); | 424 result_code_ = parts_->PreCreateThreads(); |
425 } | 425 } |
426 | 426 |
427 #if !defined(OS_IOS) && (!defined(GOOGLE_CHROME_BUILD) || defined(OS_ANDROID)) | 427 #if !defined(OS_IOS) && (!defined(GOOGLE_CHROME_BUILD) || defined(OS_ANDROID)) |
428 // Single-process is an unsupported and not fully tested mode, so | 428 // Single-process is an unsupported and not fully tested mode, so |
429 // don't enable it for official Chrome builds (except on Android). | 429 // don't enable it for official Chrome builds (except on Android). |
430 if (parsed_command_line_.HasSwitch(switches::kSingleProcess)) | 430 if (parsed_command_line_.HasSwitch(switches::kSingleProcess)) |
431 RenderProcessHost::SetRunRendererInProcess(true); | 431 RenderProcessHost::SetRunRendererInProcess(true); |
432 #endif | 432 #endif |
433 | 433 |
434 if (result_code_ > 0) | 434 if (result_code_ > 0) |
435 return; | 435 return; |
436 | 436 |
437 base::Thread::Options default_options; | 437 base::Thread::Options default_options; |
438 base::Thread::Options io_message_loop_options; | 438 base::Thread::Options io_message_loop_options; |
439 io_message_loop_options.message_loop_type = MessageLoop::TYPE_IO; | 439 io_message_loop_options.message_loop_type = base::MessageLoop::TYPE_IO; |
440 base::Thread::Options ui_message_loop_options; | 440 base::Thread::Options ui_message_loop_options; |
441 ui_message_loop_options.message_loop_type = MessageLoop::TYPE_UI; | 441 ui_message_loop_options.message_loop_type = base::MessageLoop::TYPE_UI; |
442 | 442 |
443 // Start threads in the order they occur in the BrowserThread::ID | 443 // Start threads in the order they occur in the BrowserThread::ID |
444 // enumeration, except for BrowserThread::UI which is the main | 444 // enumeration, except for BrowserThread::UI which is the main |
445 // thread. | 445 // thread. |
446 // | 446 // |
447 // Must be size_t so we can increment it. | 447 // Must be size_t so we can increment it. |
448 for (size_t thread_id = BrowserThread::UI + 1; | 448 for (size_t thread_id = BrowserThread::UI + 1; |
449 thread_id < BrowserThread::ID_COUNT; | 449 thread_id < BrowserThread::ID_COUNT; |
450 ++thread_id) { | 450 ++thread_id) { |
451 scoped_ptr<BrowserProcessSubThread>* thread_to_start = NULL; | 451 scoped_ptr<BrowserProcessSubThread>* thread_to_start = NULL; |
(...skipping 250 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
702 parts_->PostDestroyThreads(); | 702 parts_->PostDestroyThreads(); |
703 } | 703 } |
704 | 704 |
705 void BrowserMainLoop::InitializeMainThread() { | 705 void BrowserMainLoop::InitializeMainThread() { |
706 const char* kThreadName = "CrBrowserMain"; | 706 const char* kThreadName = "CrBrowserMain"; |
707 base::PlatformThread::SetName(kThreadName); | 707 base::PlatformThread::SetName(kThreadName); |
708 if (main_message_loop_) | 708 if (main_message_loop_) |
709 main_message_loop_->set_thread_name(kThreadName); | 709 main_message_loop_->set_thread_name(kThreadName); |
710 | 710 |
711 // Register the main thread by instantiating it, but don't call any methods. | 711 // Register the main thread by instantiating it, but don't call any methods. |
712 main_thread_.reset(new BrowserThreadImpl(BrowserThread::UI, | 712 main_thread_.reset( |
713 MessageLoop::current())); | 713 new BrowserThreadImpl(BrowserThread::UI, base::MessageLoop::current())); |
714 } | 714 } |
715 | 715 |
716 #if defined(OS_ANDROID) | 716 #if defined(OS_ANDROID) |
717 // TODO(epenner): Move thread priorities to base. (crbug.com/170549) | 717 // TODO(epenner): Move thread priorities to base. (crbug.com/170549) |
718 namespace { | 718 namespace { |
719 void SetHighThreadPriority() { | 719 void SetHighThreadPriority() { |
720 int nice_value = -6; // High priority. | 720 int nice_value = -6; // High priority. |
721 setpriority(PRIO_PROCESS, base::PlatformThread::CurrentId(), nice_value); | 721 setpriority(PRIO_PROCESS, base::PlatformThread::CurrentId(), nice_value); |
722 } | 722 } |
723 } | 723 } |
(...skipping 128 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
852 | 852 |
853 if (parts_) | 853 if (parts_) |
854 parts_->ToolkitInitialized(); | 854 parts_->ToolkitInitialized(); |
855 } | 855 } |
856 | 856 |
857 void BrowserMainLoop::MainMessageLoopRun() { | 857 void BrowserMainLoop::MainMessageLoopRun() { |
858 #if defined(OS_ANDROID) | 858 #if defined(OS_ANDROID) |
859 // Android's main message loop is the Java message loop. | 859 // Android's main message loop is the Java message loop. |
860 NOTREACHED(); | 860 NOTREACHED(); |
861 #else | 861 #else |
862 DCHECK_EQ(MessageLoop::TYPE_UI, MessageLoop::current()->type()); | 862 DCHECK_EQ(base::MessageLoop::TYPE_UI, base::MessageLoop::current()->type()); |
863 if (parameters_.ui_task) | 863 if (parameters_.ui_task) |
864 MessageLoopForUI::current()->PostTask(FROM_HERE, *parameters_.ui_task); | 864 base::MessageLoopForUI::current()->PostTask(FROM_HERE, |
| 865 *parameters_.ui_task); |
865 | 866 |
866 base::RunLoop run_loop; | 867 base::RunLoop run_loop; |
867 run_loop.Run(); | 868 run_loop.Run(); |
868 #endif | 869 #endif |
869 } | 870 } |
870 | 871 |
871 } // namespace content | 872 } // namespace content |
OLD | NEW |