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

Side by Side Diff: chrome/renderer/renderer_main.cc

Issue 466088: Revert 34146 - A place to store the pid>mach_port_t mapping.... (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src/
Patch Set: Created 11 years 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 | « chrome/common/mach_ipc_mac.mm ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2006-2008 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2006-2008 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 "app/hi_res_timer_manager.h" 5 #include "app/hi_res_timer_manager.h"
6 #include "app/l10n_util.h" 6 #include "app/l10n_util.h"
7 #include "app/resource_bundle.h" 7 #include "app/resource_bundle.h"
8 #include "app/system_monitor.h" 8 #include "app/system_monitor.h"
9 #include "base/command_line.h" 9 #include "base/command_line.h"
10 #include "base/field_trial.h" 10 #include "base/field_trial.h"
(...skipping 14 matching lines...) Expand all
25 #include "chrome/renderer/renderer_main_platform_delegate.h" 25 #include "chrome/renderer/renderer_main_platform_delegate.h"
26 #include "chrome/renderer/render_process.h" 26 #include "chrome/renderer/render_process.h"
27 #include "chrome/renderer/render_thread.h" 27 #include "chrome/renderer/render_thread.h"
28 #include "grit/generated_resources.h" 28 #include "grit/generated_resources.h"
29 #include "net/base/net_module.h" 29 #include "net/base/net_module.h"
30 30
31 #if defined(USE_LINUX_BREAKPAD) 31 #if defined(USE_LINUX_BREAKPAD)
32 #include "chrome/app/breakpad_linux.h" 32 #include "chrome/app/breakpad_linux.h"
33 #endif 33 #endif
34 34
35 #if defined(OS_MACOSX)
36 #include "ipc/ipc_switches.h"
37 #include "base/thread.h"
38 #include "chrome/common/mach_ipc_mac.h"
39 #endif
40
41 // This function provides some ways to test crash and assertion handling 35 // This function provides some ways to test crash and assertion handling
42 // behavior of the renderer. 36 // behavior of the renderer.
43 static void HandleRendererErrorTestParameters(const CommandLine& command_line) { 37 static void HandleRendererErrorTestParameters(const CommandLine& command_line) {
44 // This parameter causes an assertion. 38 // This parameter causes an assertion.
45 if (command_line.HasSwitch(switches::kRendererAssertTest)) { 39 if (command_line.HasSwitch(switches::kRendererAssertTest)) {
46 DCHECK(false); 40 DCHECK(false);
47 } 41 }
48 42
49 // This parameter causes a null pointer crash (crash reporter trigger). 43 // This parameter causes a null pointer crash (crash reporter trigger).
50 if (command_line.HasSwitch(switches::kRendererCrashTest)) { 44 if (command_line.HasSwitch(switches::kRendererCrashTest)) {
51 int* bad_pointer = NULL; 45 int* bad_pointer = NULL;
52 *bad_pointer = 0; 46 *bad_pointer = 0;
53 } 47 }
54 48
55 if (command_line.HasSwitch(switches::kRendererStartupDialog)) { 49 if (command_line.HasSwitch(switches::kRendererStartupDialog)) {
56 ChildProcess::WaitForDebugger(L"Renderer"); 50 ChildProcess::WaitForDebugger(L"Renderer");
57 } 51 }
58 } 52 }
59 53
60 #if defined(OS_MACOSX)
61 class MachSendTask : public Task {
62 public:
63 MachSendTask(const std::string& channel_name) : channel_name_(channel_name) {}
64
65 virtual void Run() {
66 // TODO(thakis): Put these somewhere central.
67 const int kMachPortMessageID = 57;
68 const std::string kMachChannelPrefix = "com.Google.Chrome";
69
70 const int kMachPortMessageSendWaitMs = 5000;
71 std::string channel_name = kMachChannelPrefix + channel_name_;
72 printf("Creating send port %s\n", channel_name.c_str());
73 MachPortSender sender(channel_name.c_str());
74 MachSendMessage message(kMachPortMessageID);
75
76 // add some ports to be translated for us
77 message.AddDescriptor(mach_task_self());
78 message.AddDescriptor(mach_host_self());
79
80 kern_return_t result = sender.SendMessage(message,
81 kMachPortMessageSendWaitMs);
82
83 // TODO(thakis): Log error somewhere? (don't printf in any case :-P)
84 fprintf(stderr, "send result: %lu\n", (unsigned long)result);
85 if (result != KERN_SUCCESS)
86 fprintf(stderr, "(Failed :-( )\n");
87 }
88 private:
89 std::string channel_name_;
90 };
91
92 class MachSendThread : public base::Thread {
93 public:
94 MachSendThread() : base::Thread("MachSendThread") {}
95
96 void DoIt() {
97 DCHECK(message_loop());
98 std::string name = CommandLine::ForCurrentProcess()->GetSwitchValueASCII(
99 switches::kProcessChannelID);
100 printf("main thread: %s\n", name.c_str());
101 message_loop()->PostTask(
102 FROM_HERE,
103 new MachSendTask(name));
104 }
105 };
106 #endif
107
108 // mainline routine for running as the Renderer process 54 // mainline routine for running as the Renderer process
109 int RendererMain(const MainFunctionParams& parameters) { 55 int RendererMain(const MainFunctionParams& parameters) {
110 const CommandLine& parsed_command_line = parameters.command_line_; 56 const CommandLine& parsed_command_line = parameters.command_line_;
111 base::ScopedNSAutoreleasePool* pool = parameters.autorelease_pool_; 57 base::ScopedNSAutoreleasePool* pool = parameters.autorelease_pool_;
112 58
113 #if defined(USE_LINUX_BREAKPAD) 59 #if defined(USE_LINUX_BREAKPAD)
114 // Needs to be called after we have chrome::DIR_USER_DATA. 60 // Needs to be called after we have chrome::DIR_USER_DATA.
115 InitCrashReporter(); 61 InitCrashReporter();
116 #endif 62 #endif
117 63
118 // Configure the network module so it has access to resources. 64 // Configure the network module so it has access to resources.
119 net::NetModule::SetResourceProvider(chrome_common_net::NetResourceProvider); 65 net::NetModule::SetResourceProvider(chrome_common_net::NetResourceProvider);
120 66
121 // This function allows pausing execution using the --renderer-startup-dialog 67 // This function allows pausing execution using the --renderer-startup-dialog
122 // flag allowing us to attach a debugger. 68 // flag allowing us to attach a debugger.
123 // Do not move this function down since that would mean we can't easily debug 69 // Do not move this function down since that would mean we can't easily debug
124 // whatever occurs before it. 70 // whatever occurs before it.
125 HandleRendererErrorTestParameters(parsed_command_line); 71 HandleRendererErrorTestParameters(parsed_command_line);
126 72
127 RendererMainPlatformDelegate platform(parameters); 73 RendererMainPlatformDelegate platform(parameters);
128 74
129 StatsScope<StatsCounterTimer> 75 StatsScope<StatsCounterTimer>
130 startup_timer(chrome::Counters::renderer_main()); 76 startup_timer(chrome::Counters::renderer_main());
131 77
132 #if defined(OS_MACOSX) 78 #if defined(OS_MACOSX)
133 {
134 MachSendThread mach_thread;
135 CHECK(mach_thread.Start());
136 mach_thread.DoIt();
137 }
138 #endif
139
140 #if defined(OS_MACOSX)
141 // As long as we use Cocoa in the renderer (for the forseeable future as of 79 // As long as we use Cocoa in the renderer (for the forseeable future as of
142 // now; see http://crbug.com/13890 for info) we need to have a UI loop. 80 // now; see http://crbug.com/13890 for info) we need to have a UI loop.
143 MessageLoop main_message_loop(MessageLoop::TYPE_UI); 81 MessageLoop main_message_loop(MessageLoop::TYPE_UI);
144 #else 82 #else
145 // The main message loop of the renderer services doesn't have IO or UI tasks, 83 // The main message loop of the renderer services doesn't have IO or UI tasks,
146 // unless in-process-plugins is used. 84 // unless in-process-plugins is used.
147 MessageLoop main_message_loop(RenderProcess::InProcessPlugins() ? 85 MessageLoop main_message_loop(RenderProcess::InProcessPlugins() ?
148 MessageLoop::TYPE_UI : MessageLoop::TYPE_DEFAULT); 86 MessageLoop::TYPE_UI : MessageLoop::TYPE_DEFAULT);
149 #endif 87 #endif
150 88
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after
198 136
199 if (run_loop) { 137 if (run_loop) {
200 if (pool) 138 if (pool)
201 pool->Recycle(); 139 pool->Recycle();
202 MessageLoop::current()->Run(); 140 MessageLoop::current()->Run();
203 } 141 }
204 } 142 }
205 platform.PlatformUninitialize(); 143 platform.PlatformUninitialize();
206 return 0; 144 return 0;
207 } 145 }
OLDNEW
« no previous file with comments | « chrome/common/mach_ipc_mac.mm ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698