| Index: content/shell/shell_main_delegate.cc
|
| ===================================================================
|
| --- content/shell/shell_main_delegate.cc (revision 117304)
|
| +++ content/shell/shell_main_delegate.cc (working copy)
|
| @@ -5,12 +5,66 @@
|
| #include "content/shell/shell_main_delegate.h"
|
|
|
| #include "base/command_line.h"
|
| +#include "base/message_loop.h"
|
| #include "content/public/common/content_switches.h"
|
| #include "content/shell/shell_content_browser_client.h"
|
| #include "content/shell/shell_content_plugin_client.h"
|
| #include "content/shell/shell_content_renderer_client.h"
|
| #include "content/shell/shell_content_utility_client.h"
|
|
|
| +#if defined(TEST_EMBEDDED_MESSAGE_LOOP)
|
| +namespace {
|
| +
|
| +// Class used to process events on the current message loop.
|
| +class ShellMessageLoopForUI : public MessageLoopForUI {
|
| + typedef MessageLoopForUI inherited;
|
| +
|
| + public:
|
| + ShellMessageLoopForUI()
|
| + : is_iterating_(true) {
|
| + }
|
| +
|
| + // Returns the MessageLoopForUI of the current thread.
|
| + static ShellMessageLoopForUI* current() {
|
| + MessageLoop* loop = MessageLoop::current();
|
| + DCHECK_EQ(MessageLoop::TYPE_UI, loop->type());
|
| + return static_cast<ShellMessageLoopForUI*>(loop);
|
| + }
|
| +
|
| + virtual bool DoIdleWork() {
|
| + bool valueToRet = inherited::DoIdleWork();
|
| + if (is_iterating_)
|
| + pump_->Quit();
|
| + return valueToRet;
|
| + }
|
| +
|
| + // Do a single interation of the UI message loop.
|
| + void DoMessageLoopIteration() {
|
| +#if defined(OS_MACOSX)
|
| + Run();
|
| +#else
|
| + RunWithDispatcher(NULL);
|
| +#endif
|
| + }
|
| +
|
| + // Run the UI message loop.
|
| + void RunMessageLoop() {
|
| + is_iterating_ = false;
|
| + DoMessageLoopIteration();
|
| + }
|
| +
|
| + bool is_iterating() { return is_iterating_; }
|
| +
|
| + private:
|
| + // True if the message loop is doing one iteration at a time.
|
| + bool is_iterating_;
|
| +
|
| + DISALLOW_COPY_AND_ASSIGN(ShellMessageLoopForUI);
|
| +};
|
| +
|
| +} // namespace
|
| +#endif // TEST_EMBEDDED_MESSAGE_LOOP
|
| +
|
| ShellMainDelegate::ShellMainDelegate() {
|
| }
|
|
|
| @@ -33,9 +87,30 @@
|
| void ShellMainDelegate::SandboxInitialized(const std::string& process_type) {
|
| }
|
|
|
| -int ShellMainDelegate::RunProcess(
|
| +int ShellMainDelegate::RunKnownProcess(
|
| const std::string& process_type,
|
| const content::MainFunctionParams& main_function_params) {
|
| +#if defined(TEST_EMBEDDED_MESSAGE_LOOP)
|
| + if (process_type.empty()) {
|
| + // Use our own browser process runner.
|
| + browser_runner_.reset(content::BrowserMainRunner::CreateMainRunner());
|
| +
|
| + // Initialize browser process state. Results in a call to
|
| + // ShellBrowserMain::GetMainMessageLoop().
|
| + int exit_code = browser_runner_->Initialize(main_function_params);
|
| + if (exit_code >= 0)
|
| + return exit_code;
|
| +
|
| + return 0;
|
| + }
|
| +#endif
|
| +
|
| + return -1;
|
| +}
|
| +
|
| +int ShellMainDelegate::RunUnknownProcess(
|
| + const std::string& process_type,
|
| + const content::MainFunctionParams& main_function_params) {
|
| NOTREACHED();
|
| return -1;
|
| }
|
| @@ -71,10 +146,27 @@
|
| }
|
| #endif // OS_MACOSX
|
|
|
| +#if defined(TEST_EMBEDDED_MESSAGE_LOOP)
|
| +MessageLoop* ShellMainDelegate::CreateBrowserMessageLoop() {
|
| + return new ShellMessageLoopForUI();
|
| +}
|
| +
|
| +void ShellMainDelegate::DoBrowserMessageLoopWork() {
|
| + ShellMessageLoopForUI::current()->DoMessageLoopIteration();
|
| +}
|
| +
|
| +void ShellMainDelegate::ShutdownBrowser() {
|
| + if (browser_runner_.get()) {
|
| + browser_runner_->Shutdown();
|
| + browser_runner_.reset(NULL);
|
| + }
|
| +}
|
| +#endif // TEST_EMBEDDED_MESSAGE_LOOP
|
| +
|
| void ShellMainDelegate::InitializeShellContentClient(
|
| const std::string& process_type) {
|
| if (process_type.empty()) {
|
| - browser_client_.reset(new content::ShellContentBrowserClient);
|
| + browser_client_.reset(new content::ShellContentBrowserClient(this));
|
| content::GetContentClient()->set_browser(browser_client_.get());
|
| } else if (process_type == switches::kRendererProcess) {
|
| renderer_client_.reset(new content::ShellContentRendererClient);
|
|
|