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

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

Issue 10479023: Simplify how Content*Client interfaces are created. Instead of depending on the embedder to know wh… (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: remove unused function declaration Created 8 years, 6 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) 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 "chrome/app/chrome_main_delegate.h" 5 #include "chrome/app/chrome_main_delegate.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/field_trial.h" 10 #include "base/metrics/field_trial.h"
(...skipping 237 matching lines...) Expand 10 before | Expand all | Expand 10 after
248 // Enable the heap profiler if the appropriate command-line switch is 248 // Enable the heap profiler if the appropriate command-line switch is
249 // present, bailing out of the app we can't. 249 // present, bailing out of the app we can't.
250 void EnableHeapProfiler(const CommandLine& command_line) { 250 void EnableHeapProfiler(const CommandLine& command_line) {
251 #if defined(OS_WIN) 251 #if defined(OS_WIN)
252 if (command_line.HasSwitch(switches::kMemoryProfiling)) 252 if (command_line.HasSwitch(switches::kMemoryProfiling))
253 if (!LoadMemoryProfiler()) 253 if (!LoadMemoryProfiler())
254 exit(-1); 254 exit(-1);
255 #endif 255 #endif
256 } 256 }
257 257
258 void InitializeChromeContentRendererClient() {
259 content::GetContentClient()->set_renderer(
260 &g_chrome_content_renderer_client.Get());
261 }
262
263 void InitializeChromeContentClient(const std::string& process_type) {
264 if (process_type.empty()) {
265 content::GetContentClient()->set_browser(
266 &g_chrome_content_browser_client.Get());
267 } else if (process_type == switches::kPluginProcess) {
268 content::GetContentClient()->set_plugin(
269 &g_chrome_content_plugin_client.Get());
270 } else if (process_type == switches::kRendererProcess) {
271 InitializeChromeContentRendererClient();
272 } else if (process_type == switches::kUtilityProcess) {
273 content::GetContentClient()->set_utility(
274 &g_chrome_content_utility_client.Get());
275 }
276 }
277
278 // Returns true if this subprocess type needs the ResourceBundle initialized 258 // Returns true if this subprocess type needs the ResourceBundle initialized
279 // and resources loaded. 259 // and resources loaded.
280 bool SubprocessNeedsResourceBundle(const std::string& process_type) { 260 bool SubprocessNeedsResourceBundle(const std::string& process_type) {
281 return 261 return
282 #if defined(OS_WIN) || defined(OS_MACOSX) 262 #if defined(OS_WIN) || defined(OS_MACOSX)
283 // Windows needs resources for the default/null plugin. 263 // Windows needs resources for the default/null plugin.
284 // Mac needs them for the plugin process name. 264 // Mac needs them for the plugin process name.
285 process_type == switches::kPluginProcess || 265 process_type == switches::kPluginProcess ||
286 #endif 266 #endif
287 #if defined(OS_POSIX) && !defined(OS_MACOSX) 267 #if defined(OS_POSIX) && !defined(OS_MACOSX)
(...skipping 152 matching lines...) Expand 10 before | Expand all | Expand 10 after
440 *exit_code = 1; 420 *exit_code = 1;
441 return true; 421 return true;
442 } 422 }
443 #endif 423 #endif
444 424
445 if (!command_line.HasSwitch(switches::kProcessType) && 425 if (!command_line.HasSwitch(switches::kProcessType) &&
446 command_line.HasSwitch(switches::kEnableBenchmarking)) { 426 command_line.HasSwitch(switches::kEnableBenchmarking)) {
447 base::FieldTrial::EnableBenchmarking(); 427 base::FieldTrial::EnableBenchmarking();
448 } 428 }
449 429
450 std::string process_type = command_line.GetSwitchValueASCII(
451 switches::kProcessType);
452 content::SetContentClient(&chrome_content_client_); 430 content::SetContentClient(&chrome_content_client_);
453 InitializeChromeContentClient(process_type);
454 431
455 return false; 432 return false;
456 } 433 }
457 434
458 #if defined(OS_MACOSX) 435 #if defined(OS_MACOSX)
459 void ChromeMainDelegate::InitMacCrashReporter(const CommandLine& command_line, 436 void ChromeMainDelegate::InitMacCrashReporter(const CommandLine& command_line,
460 const std::string& process_type) { 437 const std::string& process_type) {
461 // TODO(mark): Right now, InitCrashReporter() needs to be called after 438 // TODO(mark): Right now, InitCrashReporter() needs to be called after
462 // CommandLine::Init() and chrome::RegisterPathProvider(). Ideally, 439 // CommandLine::Init() and chrome::RegisterPathProvider(). Ideally,
463 // Breakpad initialization could occur sooner, preferably even before the 440 // Breakpad initialization could occur sooner, preferably even before the
(...skipping 113 matching lines...) Expand 10 before | Expand all | Expand 10 after
577 startup_timer_.reset(new base::StatsScope<base::StatsCounterTimer> 554 startup_timer_.reset(new base::StatsScope<base::StatsCounterTimer>
578 (stats_counter_timer)); 555 (stats_counter_timer));
579 556
580 // Enable the heap profiler as early as possible! 557 // Enable the heap profiler as early as possible!
581 EnableHeapProfiler(command_line); 558 EnableHeapProfiler(command_line);
582 559
583 // Enable Message Loop related state asap. 560 // Enable Message Loop related state asap.
584 if (command_line.HasSwitch(switches::kMessageLoopHistogrammer)) 561 if (command_line.HasSwitch(switches::kMessageLoopHistogrammer))
585 MessageLoop::EnableHistogrammer(true); 562 MessageLoop::EnableHistogrammer(true);
586 563
587 if (command_line.HasSwitch(switches::kSingleProcess))
588 InitializeChromeContentRendererClient();
589
590 logging::OldFileDeletionState file_state = 564 logging::OldFileDeletionState file_state =
591 logging::APPEND_TO_OLD_LOG_FILE; 565 logging::APPEND_TO_OLD_LOG_FILE;
592 if (process_type.empty()) { 566 if (process_type.empty()) {
593 file_state = logging::DELETE_OLD_LOG_FILE; 567 file_state = logging::DELETE_OLD_LOG_FILE;
594 } 568 }
595 logging::InitChromeLogging(command_line, file_state); 569 logging::InitChromeLogging(command_line, file_state);
596 570
597 #if defined(OS_WIN) 571 #if defined(OS_WIN)
598 // TODO(darin): Kill this once http://crbug.com/52609 is fixed. 572 // TODO(darin): Kill this once http://crbug.com/52609 is fixed.
599 ui::SetResourcesDataDLL(_AtlBaseModule.GetResourceInstance()); 573 ui::SetResourcesDataDLL(_AtlBaseModule.GetResourceInstance());
(...skipping 109 matching lines...) Expand 10 before | Expand all | Expand 10 after
709 #elif defined(OS_POSIX) 683 #elif defined(OS_POSIX)
710 content::ZygoteForkDelegate* ChromeMainDelegate::ZygoteStarting() { 684 content::ZygoteForkDelegate* ChromeMainDelegate::ZygoteStarting() {
711 #if defined(DISABLE_NACL) 685 #if defined(DISABLE_NACL)
712 return NULL; 686 return NULL;
713 #else 687 #else
714 return new NaClForkDelegate(); 688 return new NaClForkDelegate();
715 #endif 689 #endif
716 } 690 }
717 691
718 void ChromeMainDelegate::ZygoteForked() { 692 void ChromeMainDelegate::ZygoteForked() {
719 const CommandLine& command_line = *CommandLine::ForCurrentProcess();
720 std::string process_type =
721 command_line.GetSwitchValueASCII(switches::kProcessType);
722
723 Profiling::ProcessStarted(); 693 Profiling::ProcessStarted();
724 if (Profiling::BeingProfiled()) { 694 if (Profiling::BeingProfiled()) {
725 base::debug::RestartProfilingAfterFork(); 695 base::debug::RestartProfilingAfterFork();
726 SetUpProfilingShutdownHandler(); 696 SetUpProfilingShutdownHandler();
727 } 697 }
728 698
729 #if defined(USE_LINUX_BREAKPAD) 699 #if defined(USE_LINUX_BREAKPAD)
730 // Needs to be called after we have chrome::DIR_USER_DATA. BrowserMain sets 700 // Needs to be called after we have chrome::DIR_USER_DATA. BrowserMain sets
731 // this up for the browser process in a different manner. 701 // this up for the browser process in a different manner.
732 InitCrashReporter(); 702 InitCrashReporter();
733 #endif 703 #endif
704 }
734 705
735 InitializeChromeContentClient(process_type); 706 #endif // OS_MACOSX
707
708 content::ContentBrowserClient*
709 ChromeMainDelegate::CreateContentBrowserClient() {
710 return &g_chrome_content_browser_client.Get();
736 } 711 }
737 #endif // OS_MACOSX 712
713 content::ContentPluginClient* ChromeMainDelegate::CreateContentPluginClient() {
714 return &g_chrome_content_plugin_client.Get();
715 }
716
717 content::ContentRendererClient*
718 ChromeMainDelegate::CreateContentRendererClient() {
719 return &g_chrome_content_renderer_client.Get();
720 }
721
722 content::ContentUtilityClient*
723 ChromeMainDelegate::CreateContentUtilityClient() {
724 return &g_chrome_content_utility_client.Get();
725 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698