Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(177)

Side by Side Diff: content/shell/shell_main_delegate.cc

Issue 9190018: Support sharing of ContentMain and BrowserMain code with embedded use cases. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src/
Patch Set: '' Created 8 years, 11 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2011 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/shell/shell_main_delegate.h" 5 #include "content/shell/shell_main_delegate.h"
6 6
7 #include "base/command_line.h" 7 #include "base/command_line.h"
8 #include "base/message_loop.h"
8 #include "content/public/common/content_switches.h" 9 #include "content/public/common/content_switches.h"
9 #include "content/shell/shell_content_browser_client.h" 10 #include "content/shell/shell_content_browser_client.h"
10 #include "content/shell/shell_content_plugin_client.h" 11 #include "content/shell/shell_content_plugin_client.h"
11 #include "content/shell/shell_content_renderer_client.h" 12 #include "content/shell/shell_content_renderer_client.h"
12 #include "content/shell/shell_content_utility_client.h" 13 #include "content/shell/shell_content_utility_client.h"
13 14
15 #if defined(TEST_EMBEDDED_MESSAGE_LOOP)
16 namespace {
17
18 // Class used to process events on the current message loop.
19 class ShellMessageLoopForUI : public MessageLoopForUI {
20 typedef MessageLoopForUI inherited;
21
22 public:
23 ShellMessageLoopForUI()
24 : is_iterating_(true) {
25 }
26
27 // Returns the MessageLoopForUI of the current thread.
28 static ShellMessageLoopForUI* current() {
29 MessageLoop* loop = MessageLoop::current();
30 DCHECK_EQ(MessageLoop::TYPE_UI, loop->type());
31 return static_cast<ShellMessageLoopForUI*>(loop);
32 }
33
34 virtual bool DoIdleWork() {
35 bool valueToRet = inherited::DoIdleWork();
36 if (is_iterating_)
37 pump_->Quit();
38 return valueToRet;
39 }
40
41 // Do a single interation of the UI message loop.
42 void DoMessageLoopIteration() {
43 #if defined(OS_MACOSX)
44 Run();
45 #else
46 RunWithDispatcher(NULL);
47 #endif
48 }
49
50 // Run the UI message loop.
51 void RunMessageLoop() {
52 is_iterating_ = false;
53 DoMessageLoopIteration();
54 }
55
56 bool is_iterating() { return is_iterating_; }
57
58 private:
59 // True if the message loop is doing one iteration at a time.
60 bool is_iterating_;
61
62 DISALLOW_COPY_AND_ASSIGN(ShellMessageLoopForUI);
63 };
64
65 } // namespace
66 #endif // TEST_EMBEDDED_MESSAGE_LOOP
67
14 ShellMainDelegate::ShellMainDelegate() { 68 ShellMainDelegate::ShellMainDelegate() {
15 } 69 }
16 70
17 ShellMainDelegate::~ShellMainDelegate() { 71 ShellMainDelegate::~ShellMainDelegate() {
18 } 72 }
19 73
20 bool ShellMainDelegate::BasicStartupComplete(int* exit_code) { 74 bool ShellMainDelegate::BasicStartupComplete(int* exit_code) {
21 return false; 75 return false;
22 } 76 }
23 77
24 void ShellMainDelegate::PreSandboxStartup() { 78 void ShellMainDelegate::PreSandboxStartup() {
25 const CommandLine& command_line = *CommandLine::ForCurrentProcess(); 79 const CommandLine& command_line = *CommandLine::ForCurrentProcess();
26 std::string process_type = 80 std::string process_type =
27 command_line.GetSwitchValueASCII(switches::kProcessType); 81 command_line.GetSwitchValueASCII(switches::kProcessType);
28 82
29 content::SetContentClient(&content_client_); 83 content::SetContentClient(&content_client_);
30 InitializeShellContentClient(process_type); 84 InitializeShellContentClient(process_type);
31 } 85 }
32 86
33 void ShellMainDelegate::SandboxInitialized(const std::string& process_type) { 87 void ShellMainDelegate::SandboxInitialized(const std::string& process_type) {
34 } 88 }
35 89
36 int ShellMainDelegate::RunProcess( 90 int ShellMainDelegate::RunKnownProcess(
91 const std::string& process_type,
92 const content::MainFunctionParams& main_function_params) {
93 #if defined(TEST_EMBEDDED_MESSAGE_LOOP)
94 if (process_type.empty()) {
95 // Use our own browser process runner.
96 browser_runner_.reset(content::BrowserMainRunner::CreateMainRunner());
97
98 // Initialize browser process state. Results in a call to
99 // ShellBrowserMain::GetMainMessageLoop().
100 int exit_code = browser_runner_->Initialize(main_function_params);
101 if (exit_code >= 0)
102 return exit_code;
103
104 return 0;
105 }
106 #endif
107
108 return -1;
109 }
110
111 int ShellMainDelegate::RunUnknownProcess(
37 const std::string& process_type, 112 const std::string& process_type,
38 const content::MainFunctionParams& main_function_params) { 113 const content::MainFunctionParams& main_function_params) {
39 NOTREACHED(); 114 NOTREACHED();
40 return -1; 115 return -1;
41 } 116 }
42 117
43 void ShellMainDelegate::ProcessExiting(const std::string& process_type) { 118 void ShellMainDelegate::ProcessExiting(const std::string& process_type) {
44 } 119 }
45 120
46 #if defined(OS_MACOSX) 121 #if defined(OS_MACOSX)
(...skipping 17 matching lines...) Expand all
64 } 139 }
65 140
66 void ShellMainDelegate::ZygoteForked() { 141 void ShellMainDelegate::ZygoteForked() {
67 const CommandLine& command_line = *CommandLine::ForCurrentProcess(); 142 const CommandLine& command_line = *CommandLine::ForCurrentProcess();
68 std::string process_type = 143 std::string process_type =
69 command_line.GetSwitchValueASCII(switches::kProcessType); 144 command_line.GetSwitchValueASCII(switches::kProcessType);
70 InitializeShellContentClient(process_type); 145 InitializeShellContentClient(process_type);
71 } 146 }
72 #endif // OS_MACOSX 147 #endif // OS_MACOSX
73 148
149 #if defined(TEST_EMBEDDED_MESSAGE_LOOP)
150 MessageLoop* ShellMainDelegate::CreateBrowserMessageLoop() {
151 return new ShellMessageLoopForUI();
152 }
153
154 void ShellMainDelegate::DoBrowserMessageLoopWork() {
155 ShellMessageLoopForUI::current()->DoMessageLoopIteration();
156 }
157
158 void ShellMainDelegate::ShutdownBrowser() {
159 if (browser_runner_.get()) {
160 browser_runner_->Shutdown();
161 browser_runner_.reset(NULL);
162 }
163 }
164 #endif // TEST_EMBEDDED_MESSAGE_LOOP
165
74 void ShellMainDelegate::InitializeShellContentClient( 166 void ShellMainDelegate::InitializeShellContentClient(
75 const std::string& process_type) { 167 const std::string& process_type) {
76 if (process_type.empty()) { 168 if (process_type.empty()) {
77 browser_client_.reset(new content::ShellContentBrowserClient); 169 browser_client_.reset(new content::ShellContentBrowserClient(this));
78 content::GetContentClient()->set_browser(browser_client_.get()); 170 content::GetContentClient()->set_browser(browser_client_.get());
79 } else if (process_type == switches::kRendererProcess) { 171 } else if (process_type == switches::kRendererProcess) {
80 renderer_client_.reset(new content::ShellContentRendererClient); 172 renderer_client_.reset(new content::ShellContentRendererClient);
81 content::GetContentClient()->set_renderer(renderer_client_.get()); 173 content::GetContentClient()->set_renderer(renderer_client_.get());
82 } else if (process_type == switches::kPluginProcess) { 174 } else if (process_type == switches::kPluginProcess) {
83 plugin_client_.reset(new content::ShellContentPluginClient); 175 plugin_client_.reset(new content::ShellContentPluginClient);
84 content::GetContentClient()->set_plugin(plugin_client_.get()); 176 content::GetContentClient()->set_plugin(plugin_client_.get());
85 } else if (process_type == switches::kUtilityProcess) { 177 } else if (process_type == switches::kUtilityProcess) {
86 utility_client_.reset(new content::ShellContentUtilityClient); 178 utility_client_.reset(new content::ShellContentUtilityClient);
87 content::GetContentClient()->set_utility(utility_client_.get()); 179 content::GetContentClient()->set_utility(utility_client_.get());
88 } 180 }
89 } 181 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698