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

Side by Side Diff: chrome/app/chrome_main.cc

Issue 7779040: Start moving code from BrowserMain to content, so that it can be reused by all embedders of conte... (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: fix windows unittest Created 9 years, 3 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
« no previous file with comments | « no previous file | chrome/browser/browser_main.h » ('j') | chrome/browser/browser_main.cc » ('J')
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 "chrome/app/chrome_main.h" 5 #include "chrome/app/chrome_main.h"
6 6
7 #include "base/command_line.h" 7 #include "base/command_line.h"
8 #include "base/lazy_instance.h" 8 #include "base/lazy_instance.h"
9 #include "base/message_loop.h" 9 #include "base/message_loop.h"
10 #include "base/metrics/stats_counters.h" 10 #include "base/metrics/stats_counters.h"
11 #include "base/metrics/stats_table.h"
12 #include "base/path_service.h" 11 #include "base/path_service.h"
13 #include "base/process_util.h" 12 #include "base/process_util.h"
14 #include "base/stringprintf.h" 13 #include "base/stringprintf.h"
15 #include "base/string_number_conversions.h"
16 #include "base/utf_string_conversions.h" 14 #include "base/utf_string_conversions.h"
17 #include "build/build_config.h" 15 #include "build/build_config.h"
16 #include "chrome/browser/chrome_content_browser_client.h"
18 #include "chrome/browser/defaults.h" 17 #include "chrome/browser/defaults.h"
19 #include "chrome/browser/diagnostics/diagnostics_main.h" 18 #include "chrome/browser/diagnostics/diagnostics_main.h"
20 #include "chrome/common/chrome_constants.h" 19 #include "chrome/common/chrome_constants.h"
21 #include "chrome/common/chrome_content_client.h" 20 #include "chrome/common/chrome_content_client.h"
22 #include "chrome/common/chrome_content_plugin_client.h" 21 #include "chrome/common/chrome_content_plugin_client.h"
23 #include "chrome/common/chrome_paths.h" 22 #include "chrome/common/chrome_paths.h"
24 #include "chrome/common/chrome_paths_internal.h" 23 #include "chrome/common/chrome_paths_internal.h"
25 #include "chrome/common/chrome_switches.h" 24 #include "chrome/common/chrome_switches.h"
26 #include "chrome/common/chrome_version_info.h" 25 #include "chrome/common/chrome_version_info.h"
27 #include "chrome/common/logging_chrome.h" 26 #include "chrome/common/logging_chrome.h"
28 #include "chrome/common/profiling.h" 27 #include "chrome/common/profiling.h"
29 #include "chrome/common/url_constants.h" 28 #include "chrome/common/url_constants.h"
30 #include "chrome/renderer/chrome_content_renderer_client.h" 29 #include "chrome/renderer/chrome_content_renderer_client.h"
31 #include "chrome/utility/chrome_content_utility_client.h" 30 #include "chrome/utility/chrome_content_utility_client.h"
32 #include "content/app/content_main.h" 31 #include "content/app/content_main.h"
33 #include "content/app/content_main_delegate.h" 32 #include "content/app/content_main_delegate.h"
34 #include "content/browser/renderer_host/render_process_host.h" 33 #include "content/browser/renderer_host/render_process_host.h"
35 #include "content/common/content_client.h" 34 #include "content/common/content_client.h"
36 #include "content/common/content_counters.h" 35 #include "content/common/content_counters.h"
37 #include "content/common/content_paths.h" 36 #include "content/common/content_paths.h"
38 #include "ipc/ipc_switches.h"
39 #include "media/base/media.h" 37 #include "media/base/media.h"
40 #include "ui/base/resource/resource_bundle.h" 38 #include "ui/base/resource/resource_bundle.h"
41 #include "ui/base/ui_base_switches.h" 39 #include "ui/base/ui_base_switches.h"
42 40
43 #if defined(OS_WIN) 41 #if defined(OS_WIN)
44 #include <algorithm> 42 #include <algorithm>
45 #include <atlbase.h> 43 #include <atlbase.h>
46 #include <malloc.h> 44 #include <malloc.h>
47 #include "base/string_util.h" 45 #include "base/string_util.h"
48 #include "base/win/registry.h" 46 #include "base/win/registry.h"
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after
84 #include <stdlib.h> 82 #include <stdlib.h>
85 #include <string.h> 83 #include <string.h>
86 #include "ui/base/x/x11_util.h" 84 #include "ui/base/x/x11_util.h"
87 #endif 85 #endif
88 86
89 #if defined(USE_LINUX_BREAKPAD) 87 #if defined(USE_LINUX_BREAKPAD)
90 #include "chrome/app/breakpad_linux.h" 88 #include "chrome/app/breakpad_linux.h"
91 #endif 89 #endif
92 90
93 #if !defined(NACL_WIN64) // We don't build the this code on win nacl64. 91 #if !defined(NACL_WIN64) // We don't build the this code on win nacl64.
92 base::LazyInstance<chrome::ChromeContentBrowserClient>
93 g_chrome_content_browser_client(base::LINKER_INITIALIZED);
94 base::LazyInstance<chrome::ChromeContentRendererClient> 94 base::LazyInstance<chrome::ChromeContentRendererClient>
95 g_chrome_content_renderer_client(base::LINKER_INITIALIZED); 95 g_chrome_content_renderer_client(base::LINKER_INITIALIZED);
96 base::LazyInstance<chrome::ChromeContentUtilityClient> 96 base::LazyInstance<chrome::ChromeContentUtilityClient>
97 g_chrome_content_utility_client(base::LINKER_INITIALIZED); 97 g_chrome_content_utility_client(base::LINKER_INITIALIZED);
98 #endif // NACL_WIN64 98 #endif // NACL_WIN64
99 99
100 base::LazyInstance<chrome::ChromeContentPluginClient> 100 base::LazyInstance<chrome::ChromeContentPluginClient>
101 g_chrome_content_plugin_client(base::LINKER_INITIALIZED); 101 g_chrome_content_plugin_client(base::LINKER_INITIALIZED);
102 102
103 extern int BrowserMain(const MainFunctionParams&);
104 extern int RendererMain(const MainFunctionParams&); 103 extern int RendererMain(const MainFunctionParams&);
105 extern int NaClMain(const MainFunctionParams&); 104 extern int NaClMain(const MainFunctionParams&);
106 extern int ProfileImportMain(const MainFunctionParams&); 105 extern int ProfileImportMain(const MainFunctionParams&);
107 #if defined(_WIN64) 106 #if defined(_WIN64)
108 extern int NaClBrokerMain(const MainFunctionParams&); 107 extern int NaClBrokerMain(const MainFunctionParams&);
109 #endif 108 #endif
110 extern int ServiceProcessMain(const MainFunctionParams&); 109 extern int ServiceProcessMain(const MainFunctionParams&);
111 110
112 #if defined(OS_WIN) 111 #if defined(OS_WIN)
113 // TODO(erikkay): isn't this already defined somewhere? 112 // TODO(erikkay): isn't this already defined somewhere?
(...skipping 109 matching lines...) Expand 10 before | Expand all | Expand 10 after
223 } 222 }
224 223
225 void InitializeChromeContentRendererClient() { 224 void InitializeChromeContentRendererClient() {
226 #if !defined(NACL_WIN64) // We don't build the renderer code on win nacl64. 225 #if !defined(NACL_WIN64) // We don't build the renderer code on win nacl64.
227 content::GetContentClient()->set_renderer( 226 content::GetContentClient()->set_renderer(
228 &g_chrome_content_renderer_client.Get()); 227 &g_chrome_content_renderer_client.Get());
229 #endif 228 #endif
230 } 229 }
231 230
232 void InitializeChromeContentClient(const std::string& process_type) { 231 void InitializeChromeContentClient(const std::string& process_type) {
233 if (process_type == switches::kPluginProcess) { 232 if (process_type.empty()) {
233 #if !defined(NACL_WIN64) // We don't build the this code on win nacl64.
234 content::GetContentClient()->set_browser(
235 &g_chrome_content_browser_client.Get());
236 #endif
237 } else if (process_type == switches::kPluginProcess) {
234 content::GetContentClient()->set_plugin( 238 content::GetContentClient()->set_plugin(
235 &g_chrome_content_plugin_client.Get()); 239 &g_chrome_content_plugin_client.Get());
236 } else if (process_type == switches::kRendererProcess || 240 } else if (process_type == switches::kRendererProcess ||
237 process_type == switches::kExtensionProcess) { 241 process_type == switches::kExtensionProcess) {
238 InitializeChromeContentRendererClient(); 242 InitializeChromeContentRendererClient();
239 } else if (process_type == switches::kUtilityProcess) { 243 } else if (process_type == switches::kUtilityProcess) {
240 #if !defined(NACL_WIN64) // We don't build this code on win nacl64. 244 #if !defined(NACL_WIN64) // We don't build this code on win nacl64.
241 content::GetContentClient()->set_utility( 245 content::GetContentClient()->set_utility(
242 &g_chrome_content_utility_client.Get()); 246 &g_chrome_content_utility_client.Get());
243 #endif 247 #endif
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after
283 name_id = IDS_UTILITY_APP_NAME; 287 name_id = IDS_UTILITY_APP_NAME;
284 } 288 }
285 if (name_id) { 289 if (name_id) {
286 NSString* app_name = l10n_util::GetNSString(name_id); 290 NSString* app_name = l10n_util::GetNSString(name_id);
287 base::mac::SetProcessName(base::mac::NSToCFCast(app_name)); 291 base::mac::SetProcessName(base::mac::NSToCFCast(app_name));
288 } 292 }
289 } 293 }
290 294
291 #endif // defined(OS_MACOSX) 295 #endif // defined(OS_MACOSX)
292 296
293 void InitializeStatsTable(base::ProcessId browser_pid,
294 const CommandLine& command_line) {
295 // Initialize the Stats Counters table. With this initialized,
296 // the StatsViewer can be utilized to read counters outside of
297 // Chrome. These lines can be commented out to effectively turn
298 // counters 'off'. The table is created and exists for the life
299 // of the process. It is not cleaned up.
300 if (command_line.HasSwitch(switches::kEnableStatsTable) ||
301 command_line.HasSwitch(switches::kEnableBenchmarking)) {
302 // NOTIMPLEMENTED: we probably need to shut this down correctly to avoid
303 // leaking shared memory regions on posix platforms.
304 std::string statsfile =
305 base::StringPrintf("%s-%u",
306 chrome::kStatsFilename,
307 static_cast<unsigned int>(browser_pid));
308 base::StatsTable *stats_table = new base::StatsTable(statsfile,
309 chrome::kStatsMaxThreads, chrome::kStatsMaxCounters);
310 base::StatsTable::set_current(stats_table);
311 }
312 }
313
314 #if defined(OS_POSIX) 297 #if defined(OS_POSIX)
315 // Check for --version and --product-version; return true if we encountered 298 // Check for --version and --product-version; return true if we encountered
316 // one of these switches and should exit now. 299 // one of these switches and should exit now.
317 bool HandleVersionSwitches(const CommandLine& command_line) { 300 bool HandleVersionSwitches(const CommandLine& command_line) {
318 const chrome::VersionInfo version_info; 301 const chrome::VersionInfo version_info;
319 302
320 #if !defined(OS_MACOSX) 303 #if !defined(OS_MACOSX)
321 if (command_line.HasSwitch(switches::kProductVersion)) { 304 if (command_line.HasSwitch(switches::kProductVersion)) {
322 printf("%s\n", version_info.Version().c_str()); 305 printf("%s\n", version_info.Version().c_str());
323 return true; 306 return true;
(...skipping 188 matching lines...) Expand 10 before | Expand all | Expand 10 after
512 InitMacCrashReporter(command_line, process_type); 495 InitMacCrashReporter(command_line, process_type);
513 #endif 496 #endif
514 497
515 // Notice a user data directory override if any 498 // Notice a user data directory override if any
516 FilePath user_data_dir = 499 FilePath user_data_dir =
517 command_line.GetSwitchValuePath(switches::kUserDataDir); 500 command_line.GetSwitchValuePath(switches::kUserDataDir);
518 chrome_main::CheckUserDataDirPolicy(&user_data_dir); 501 chrome_main::CheckUserDataDirPolicy(&user_data_dir);
519 if (!user_data_dir.empty()) 502 if (!user_data_dir.empty())
520 CHECK(PathService::Override(chrome::DIR_USER_DATA, user_data_dir)); 503 CHECK(PathService::Override(chrome::DIR_USER_DATA, user_data_dir));
521 504
522 base::ProcessId browser_pid = base::GetCurrentProcId();
523 if (!process_type.empty() &&
524 #if defined(OS_MACOSX)
525 process_type != switches::kRelauncherProcess &&
526 #endif
527 process_type != switches::kServiceProcess) {
528 #if defined(OS_WIN) || defined(OS_MACOSX)
529 std::string channel_name =
530 command_line.GetSwitchValueASCII(switches::kProcessChannelID);
531
532 int browser_pid_int;
533 base::StringToInt(channel_name, &browser_pid_int);
534 browser_pid = static_cast<base::ProcessId>(browser_pid_int);
535 DCHECK_NE(browser_pid_int, 0);
536 #elif defined(OS_POSIX)
537 // On linux, we're in the zygote here; so we need the parent process' id.
538 browser_pid = base::GetParentProcessId(base::GetCurrentProcId());
539 #endif
540 }
541 InitializeStatsTable(browser_pid, command_line);
542
543 startup_timer_.reset(new base::StatsScope<base::StatsCounterTimer> 505 startup_timer_.reset(new base::StatsScope<base::StatsCounterTimer>
544 (content::Counters::chrome_main())); 506 (content::Counters::chrome_main()));
545 507
546 // Enable the heap profiler as early as possible! 508 // Enable the heap profiler as early as possible!
547 EnableHeapProfiler(command_line); 509 EnableHeapProfiler(command_line);
548 510
549 // Enable Message Loop related state asap. 511 // Enable Message Loop related state asap.
550 if (command_line.HasSwitch(switches::kMessageLoopHistogrammer)) 512 if (command_line.HasSwitch(switches::kMessageLoopHistogrammer))
551 MessageLoop::EnableHistogrammer(true); 513 MessageLoop::EnableHistogrammer(true);
552 514
(...skipping 83 matching lines...) Expand 10 before | Expand all | Expand 10 after
636 // AdjustLinuxOOMScore function too. 598 // AdjustLinuxOOMScore function too.
637 #if defined(OS_LINUX) 599 #if defined(OS_LINUX)
638 AdjustLinuxOOMScore(process_type); 600 AdjustLinuxOOMScore(process_type);
639 #endif 601 #endif
640 } 602 }
641 603
642 virtual int RunProcess( 604 virtual int RunProcess(
643 const std::string& process_type, 605 const std::string& process_type,
644 const MainFunctionParams& main_function_params) OVERRIDE { 606 const MainFunctionParams& main_function_params) OVERRIDE {
645 static const MainFunction kMainFunctions[] = { 607 static const MainFunction kMainFunctions[] = {
646 { "", BrowserMain },
647 // An extension process is just a renderer process. We use a different 608 // An extension process is just a renderer process. We use a different
648 // command line argument to differentiate crash reports. 609 // command line argument to differentiate crash reports.
649 { switches::kExtensionProcess, RendererMain }, 610 { switches::kExtensionProcess, RendererMain },
650 { switches::kServiceProcess, ServiceProcessMain }, 611 { switches::kServiceProcess, ServiceProcessMain },
651 #if defined(OS_MACOSX) 612 #if defined(OS_MACOSX)
652 // TODO(port): Use OOP profile import - http://crbug.com/22142 . 613 // TODO(port): Use OOP profile import - http://crbug.com/22142 .
653 { switches::kProfileImportProcess, ProfileImportMain }, 614 { switches::kProfileImportProcess, ProfileImportMain },
654 { switches::kRelauncherProcess, 615 { switches::kRelauncherProcess,
655 mac_relauncher::internal::RelauncherMain }, 616 mac_relauncher::internal::RelauncherMain },
656 #endif 617 #endif
(...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after
717 #else 678 #else
718 return new NaClForkDelegate(); 679 return new NaClForkDelegate();
719 #endif 680 #endif
720 } 681 }
721 682
722 virtual void ZygoteForked() OVERRIDE { 683 virtual void ZygoteForked() OVERRIDE {
723 const CommandLine& command_line = *CommandLine::ForCurrentProcess(); 684 const CommandLine& command_line = *CommandLine::ForCurrentProcess();
724 std::string process_type = 685 std::string process_type =
725 command_line.GetSwitchValueASCII(switches::kProcessType); 686 command_line.GetSwitchValueASCII(switches::kProcessType);
726 687
727 // The StatsTable must be initialized in each process; we already
728 // initialized for the browser process, now we need to initialize
729 // within the new processes as well.
730 pid_t browser_pid = base::GetParentProcessId(
731 base::GetParentProcessId(base::GetCurrentProcId()));
732 InitializeStatsTable(browser_pid, command_line);
733
734 #if defined(USE_LINUX_BREAKPAD) 688 #if defined(USE_LINUX_BREAKPAD)
735 // Needs to be called after we have chrome::DIR_USER_DATA. BrowserMain sets 689 // Needs to be called after we have chrome::DIR_USER_DATA. BrowserMain sets
736 // this up for the browser process in a different manner. 690 // this up for the browser process in a different manner.
737 InitCrashReporter(); 691 InitCrashReporter();
738 #endif 692 #endif
739 693
740 InitializeChromeContentClient(process_type); 694 InitializeChromeContentClient(process_type);
741 } 695 }
742 #endif // OS_MACOSX 696 #endif // OS_MACOSX
743 697
744 private: 698 private:
745 chrome::ChromeContentClient chrome_content_client_; 699 chrome::ChromeContentClient chrome_content_client_;
746 scoped_ptr<base::StatsScope<base::StatsCounterTimer> > startup_timer_; 700 scoped_ptr<base::StatsScope<base::StatsCounterTimer> > startup_timer_;
747 }; 701 };
748 702
749 } // namespace 703 } // namespace
750 704
751 #if defined(OS_WIN) 705 #if defined(OS_WIN)
752 DLLEXPORT int __cdecl ChromeMain(HINSTANCE instance, 706 DLLEXPORT int __cdecl ChromeMain(HINSTANCE instance,
753 sandbox::SandboxInterfaceInfo* sandbox_info) { 707 sandbox::SandboxInterfaceInfo* sandbox_info) {
754 ChromeMainDelegate chrome_main_delegate; 708 ChromeMainDelegate chrome_main_delegate;
755 return content::ContentMain(instance, sandbox_info, &chrome_main_delegate); 709 return content::ContentMain(instance, sandbox_info, &chrome_main_delegate);
756 #elif defined(OS_POSIX) 710 #elif defined(OS_POSIX)
757 int ChromeMain(int argc, char** argv) { 711 int ChromeMain(int argc, char** argv) {
758 ChromeMainDelegate chrome_main_delegate; 712 ChromeMainDelegate chrome_main_delegate;
759 return content::ContentMain(argc, argv, &chrome_main_delegate); 713 return content::ContentMain(argc, argv, &chrome_main_delegate);
760 #endif 714 #endif
761 } 715 }
OLDNEW
« no previous file with comments | « no previous file | chrome/browser/browser_main.h » ('j') | chrome/browser/browser_main.cc » ('J')

Powered by Google App Engine
This is Rietveld 408576698