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 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
60 #include "ui/base/l10n/l10n_util_win.h" | 60 #include "ui/base/l10n/l10n_util_win.h" |
61 #include "net/base/winsock_init.h" | 61 #include "net/base/winsock_init.h" |
62 #endif | 62 #endif |
63 | 63 |
64 #if defined(OS_LINUX) || defined(OS_OPENBSD) | 64 #if defined(OS_LINUX) || defined(OS_OPENBSD) |
65 #include <glib-object.h> | 65 #include <glib-object.h> |
66 #endif | 66 #endif |
67 | 67 |
68 #if defined(OS_LINUX) | 68 #if defined(OS_LINUX) |
69 #include "content/browser/device_monitor_linux.h" | 69 #include "content/browser/device_monitor_linux.h" |
70 #elif defined(OS_MACOSX) | 70 #elif defined(OS_MACOSX) && !defined(OS_IOS) |
71 #include "content/browser/device_monitor_mac.h" | 71 #include "content/browser/device_monitor_mac.h" |
72 #endif | 72 #endif |
73 | 73 |
74 #if defined(TOOLKIT_GTK) | 74 #if defined(TOOLKIT_GTK) |
75 #include "ui/gfx/gtk_util.h" | 75 #include "ui/gfx/gtk_util.h" |
76 #endif | 76 #endif |
77 | 77 |
78 #if defined(OS_POSIX) && !defined(OS_MACOSX) | 78 #if defined(OS_POSIX) && !defined(OS_MACOSX) |
79 #include <sys/stat.h> | 79 #include <sys/stat.h> |
80 | 80 |
(...skipping 148 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
229 BrowserMainLoop::BrowserMainLoop(const content::MainFunctionParams& parameters) | 229 BrowserMainLoop::BrowserMainLoop(const content::MainFunctionParams& parameters) |
230 : parameters_(parameters), | 230 : parameters_(parameters), |
231 parsed_command_line_(parameters.command_line), | 231 parsed_command_line_(parameters.command_line), |
232 result_code_(content::RESULT_CODE_NORMAL_EXIT) { | 232 result_code_(content::RESULT_CODE_NORMAL_EXIT) { |
233 DCHECK(!g_current_browser_main_loop); | 233 DCHECK(!g_current_browser_main_loop); |
234 g_current_browser_main_loop = this; | 234 g_current_browser_main_loop = this; |
235 } | 235 } |
236 | 236 |
237 BrowserMainLoop::~BrowserMainLoop() { | 237 BrowserMainLoop::~BrowserMainLoop() { |
238 DCHECK_EQ(this, g_current_browser_main_loop); | 238 DCHECK_EQ(this, g_current_browser_main_loop); |
| 239 #if !defined(OS_IOS) |
239 ui::Clipboard::DestroyClipboardForCurrentThread(); | 240 ui::Clipboard::DestroyClipboardForCurrentThread(); |
| 241 #endif // !defined(OS_IOS) |
240 g_current_browser_main_loop = NULL; | 242 g_current_browser_main_loop = NULL; |
241 } | 243 } |
242 | 244 |
243 void BrowserMainLoop::Init() { | 245 void BrowserMainLoop::Init() { |
244 parts_.reset( | 246 parts_.reset( |
245 GetContentClient()->browser()->CreateBrowserMainParts(parameters_)); | 247 GetContentClient()->browser()->CreateBrowserMainParts(parameters_)); |
246 } | 248 } |
247 | 249 |
248 // BrowserMainLoop stages ================================================== | 250 // BrowserMainLoop stages ================================================== |
249 | 251 |
(...skipping 357 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
607 } | 609 } |
608 | 610 |
609 // Close the blocking I/O pool after the other threads. Other threads such | 611 // Close the blocking I/O pool after the other threads. Other threads such |
610 // as the I/O thread may need to schedule work like closing files or flushing | 612 // as the I/O thread may need to schedule work like closing files or flushing |
611 // data during shutdown, so the blocking pool needs to be available. There | 613 // data during shutdown, so the blocking pool needs to be available. There |
612 // may also be slow operations pending that will blcok shutdown, so closing | 614 // may also be slow operations pending that will blcok shutdown, so closing |
613 // it here (which will block until required operations are complete) gives | 615 // it here (which will block until required operations are complete) gives |
614 // more head start for those operations to finish. | 616 // more head start for those operations to finish. |
615 BrowserThreadImpl::ShutdownThreadPool(); | 617 BrowserThreadImpl::ShutdownThreadPool(); |
616 | 618 |
| 619 #if !defined(OS_IOS) |
617 // Must happen after the I/O thread is shutdown since this class lives on the | 620 // Must happen after the I/O thread is shutdown since this class lives on the |
618 // I/O thread and isn't threadsafe. | 621 // I/O thread and isn't threadsafe. |
619 GamepadService::GetInstance()->Terminate(); | 622 GamepadService::GetInstance()->Terminate(); |
| 623 #endif // !defined(OS_IOS) |
620 | 624 |
621 if (parts_.get()) | 625 if (parts_.get()) |
622 parts_->PostDestroyThreads(); | 626 parts_->PostDestroyThreads(); |
623 } | 627 } |
624 | 628 |
625 void BrowserMainLoop::InitializeMainThread() { | 629 void BrowserMainLoop::InitializeMainThread() { |
626 const char* kThreadName = "CrBrowserMain"; | 630 const char* kThreadName = "CrBrowserMain"; |
627 base::PlatformThread::SetName(kThreadName); | 631 base::PlatformThread::SetName(kThreadName); |
628 if (main_message_loop_.get()) | 632 if (main_message_loop_.get()) |
629 main_message_loop_->set_thread_name(kThreadName); | 633 main_message_loop_->set_thread_name(kThreadName); |
(...skipping 24 matching lines...) Expand all Loading... |
654 | 658 |
655 // Initialize the GpuDataManager before we set up the MessageLoops because | 659 // Initialize the GpuDataManager before we set up the MessageLoops because |
656 // otherwise we'll trigger the assertion about doing IO on the UI thread. | 660 // otherwise we'll trigger the assertion about doing IO on the UI thread. |
657 GpuDataManagerImpl::GetInstance()->Initialize(); | 661 GpuDataManagerImpl::GetInstance()->Initialize(); |
658 #endif // !OS_IOS | 662 #endif // !OS_IOS |
659 | 663 |
660 #if defined(ENABLE_INPUT_SPEECH) | 664 #if defined(ENABLE_INPUT_SPEECH) |
661 speech_recognition_manager_.reset(new speech::SpeechRecognitionManagerImpl()); | 665 speech_recognition_manager_.reset(new speech::SpeechRecognitionManagerImpl()); |
662 #endif | 666 #endif |
663 | 667 |
| 668 #if !defined(OS_IOS) |
664 // Alert the clipboard class to which threads are allowed to access the | 669 // Alert the clipboard class to which threads are allowed to access the |
665 // clipboard: | 670 // clipboard: |
666 std::vector<base::PlatformThreadId> allowed_clipboard_threads; | 671 std::vector<base::PlatformThreadId> allowed_clipboard_threads; |
667 // The current thread is the UI thread. | 672 // The current thread is the UI thread. |
668 allowed_clipboard_threads.push_back(base::PlatformThread::CurrentId()); | 673 allowed_clipboard_threads.push_back(base::PlatformThread::CurrentId()); |
669 #if defined(OS_WIN) | 674 #if defined(OS_WIN) |
670 // On Windows, clipboards are also used on the File or IO threads. | 675 // On Windows, clipboards are also used on the File or IO threads. |
671 allowed_clipboard_threads.push_back(file_thread_->thread_id()); | 676 allowed_clipboard_threads.push_back(file_thread_->thread_id()); |
672 allowed_clipboard_threads.push_back(io_thread_->thread_id()); | 677 allowed_clipboard_threads.push_back(io_thread_->thread_id()); |
673 #endif | 678 #endif |
674 ui::Clipboard::SetAllowedThreads(allowed_clipboard_threads); | 679 ui::Clipboard::SetAllowedThreads(allowed_clipboard_threads); |
| 680 #endif // !defined(OS_IOS) |
675 } | 681 } |
676 | 682 |
677 void BrowserMainLoop::InitializeToolkit() { | 683 void BrowserMainLoop::InitializeToolkit() { |
678 // TODO(evan): this function is rather subtle, due to the variety | 684 // TODO(evan): this function is rather subtle, due to the variety |
679 // of intersecting ifdefs we have. To keep it easy to follow, there | 685 // of intersecting ifdefs we have. To keep it easy to follow, there |
680 // are no #else branches on any #ifs. | 686 // are no #else branches on any #ifs. |
681 // TODO(stevenjb): Move platform specific code into platform specific Parts | 687 // TODO(stevenjb): Move platform specific code into platform specific Parts |
682 // (Need to add InitializeToolkit stage to BrowserParts). | 688 // (Need to add InitializeToolkit stage to BrowserParts). |
683 #if defined(OS_LINUX) || defined(OS_OPENBSD) | 689 #if defined(OS_LINUX) || defined(OS_OPENBSD) |
684 // Glib type system initialization. Needed at least for gconf, | 690 // Glib type system initialization. Needed at least for gconf, |
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
722 DCHECK_EQ(MessageLoop::TYPE_UI, MessageLoop::current()->type()); | 728 DCHECK_EQ(MessageLoop::TYPE_UI, MessageLoop::current()->type()); |
723 if (parameters_.ui_task) | 729 if (parameters_.ui_task) |
724 MessageLoopForUI::current()->PostTask(FROM_HERE, *parameters_.ui_task); | 730 MessageLoopForUI::current()->PostTask(FROM_HERE, *parameters_.ui_task); |
725 | 731 |
726 base::RunLoop run_loop; | 732 base::RunLoop run_loop; |
727 run_loop.Run(); | 733 run_loop.Run(); |
728 #endif | 734 #endif |
729 } | 735 } |
730 | 736 |
731 } // namespace content | 737 } // namespace content |
OLD | NEW |