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

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

Issue 155944: Switch the first thread in a child process to be the main thread... (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: sync Created 11 years, 5 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) 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 "build/build_config.h" 5 #include "build/build_config.h"
6 6
7 #if defined(OS_WIN) 7 #if defined(OS_WIN)
8 #include <windows.h> 8 #include <windows.h>
9 #include <objidl.h> 9 #include <objidl.h>
10 #include <mlang.h> 10 #include <mlang.h>
(...skipping 29 matching lines...) Expand all
40 file_util::ReadFileToString(FilePath("/proc/sys/kernel/shmmax"), &contents); 40 file_util::ReadFileToString(FilePath("/proc/sys/kernel/shmmax"), &contents);
41 size = strtoul(contents.c_str(), NULL, 0); 41 size = strtoul(contents.c_str(), NULL, 0);
42 } 42 }
43 #endif 43 #endif
44 return size; 44 return size;
45 } 45 }
46 46
47 //----------------------------------------------------------------------------- 47 //-----------------------------------------------------------------------------
48 48
49 RenderProcess::RenderProcess() 49 RenderProcess::RenderProcess()
50 : ChildProcess(new RenderThread()), 50 : ALLOW_THIS_IN_INITIALIZER_LIST(shared_mem_cache_cleaner_(
51 ALLOW_THIS_IN_INITIALIZER_LIST(shared_mem_cache_cleaner_(
52 base::TimeDelta::FromSeconds(5), 51 base::TimeDelta::FromSeconds(5),
53 this, &RenderProcess::ClearTransportDIBCache)), 52 this, &RenderProcess::ClearTransportDIBCache)),
54 sequence_number_(0) { 53 sequence_number_(0) {
55 Init();
56 }
57
58 RenderProcess::RenderProcess(const std::string& channel_name)
59 : ChildProcess(new RenderThread(channel_name)),
60 ALLOW_THIS_IN_INITIALIZER_LIST(shared_mem_cache_cleaner_(
61 base::TimeDelta::FromSeconds(5),
62 this, &RenderProcess::ClearTransportDIBCache)),
63 sequence_number_(0) {
64 Init();
65 }
66
67 RenderProcess::~RenderProcess() {
68 // TODO(port)
69 // Try and limit what we pull in for our non-Win unit test bundle
70 #ifndef NDEBUG
71 // log important leaked objects
72 webkit_glue::CheckForLeaks();
73 #endif
74
75 GetShutDownEvent()->Signal();
76
77 // We need to stop the RenderThread as the clearer_factory_
78 // member could be in use while the object itself is destroyed,
79 // as a result of the containing RenderProcess object being destroyed.
80 // This race condition causes a crash when the renderer process is shutting
81 // down.
82 child_thread()->Stop();
83 ClearTransportDIBCache();
84 }
85
86 void RenderProcess::Init() {
87 in_process_plugins_ = InProcessPlugins(); 54 in_process_plugins_ = InProcessPlugins();
88 for (size_t i = 0; i < arraysize(shared_mem_cache_); ++i) 55 for (size_t i = 0; i < arraysize(shared_mem_cache_); ++i)
89 shared_mem_cache_[i] = NULL; 56 shared_mem_cache_[i] = NULL;
90 57
91 #if defined(OS_WIN) 58 #if defined(OS_WIN)
92 // HACK: See http://b/issue?id=1024307 for rationale. 59 // HACK: See http://b/issue?id=1024307 for rationale.
93 if (GetModuleHandle(L"LPK.DLL") == NULL) { 60 if (GetModuleHandle(L"LPK.DLL") == NULL) {
94 // Makes sure lpk.dll is loaded by gdi32 to make sure ExtTextOut() works 61 // Makes sure lpk.dll is loaded by gdi32 to make sure ExtTextOut() works
95 // when buffering into a EMF buffer for printing. 62 // when buffering into a EMF buffer for printing.
96 typedef BOOL (__stdcall *GdiInitializeLanguagePack)(int LoadedShapingDLLs); 63 typedef BOOL (__stdcall *GdiInitializeLanguagePack)(int LoadedShapingDLLs);
(...skipping 27 matching lines...) Expand all
124 if (command_line.HasSwitch(switches::kDumpHistogramsOnExit)) { 91 if (command_line.HasSwitch(switches::kDumpHistogramsOnExit)) {
125 StatisticsRecorder::set_dump_on_exit(true); 92 StatisticsRecorder::set_dump_on_exit(true);
126 } 93 }
127 94
128 FilePath module_path; 95 FilePath module_path;
129 initialized_media_library_ = 96 initialized_media_library_ =
130 PathService::Get(base::DIR_MODULE, &module_path) && 97 PathService::Get(base::DIR_MODULE, &module_path) &&
131 media::InitializeMediaLibrary(module_path); 98 media::InitializeMediaLibrary(module_path);
132 } 99 }
133 100
101 RenderProcess::~RenderProcess() {
102 // TODO(port)
103 // Try and limit what we pull in for our non-Win unit test bundle
104 #ifndef NDEBUG
105 // log important leaked objects
106 webkit_glue::CheckForLeaks();
107 #endif
108
109 GetShutDownEvent()->Signal();
110 ClearTransportDIBCache();
111 }
112
134 bool RenderProcess::InProcessPlugins() { 113 bool RenderProcess::InProcessPlugins() {
135 const CommandLine& command_line = *CommandLine::ForCurrentProcess(); 114 const CommandLine& command_line = *CommandLine::ForCurrentProcess();
136 #if defined(OS_LINUX) 115 #if defined(OS_LINUX)
137 // Plugin processes require a UI message loop, and the Linux message loop 116 // Plugin processes require a UI message loop, and the Linux message loop
138 // implementation only allows one UI loop per process. 117 // implementation only allows one UI loop per process.
139 if (command_line.HasSwitch(switches::kInProcessPlugins)) 118 if (command_line.HasSwitch(switches::kInProcessPlugins))
140 NOTIMPLEMENTED() << ": in process plugins not supported on Linux"; 119 NOTIMPLEMENTED() << ": in process plugins not supported on Linux";
141 return command_line.HasSwitch(switches::kInProcessPlugins); 120 return command_line.HasSwitch(switches::kInProcessPlugins);
142 #else 121 #else
143 return command_line.HasSwitch(switches::kInProcessPlugins) || 122 return command_line.HasSwitch(switches::kInProcessPlugins) ||
144 command_line.HasSwitch(switches::kSingleProcess); 123 command_line.HasSwitch(switches::kSingleProcess);
145 #endif 124 #endif
146 } 125 }
147 126
148 // ----------------------------------------------------------------------------- 127 // -----------------------------------------------------------------------------
149 // Platform specific code for dealing with bitmap transport... 128 // Platform specific code for dealing with bitmap transport...
150 129
151 TransportDIB* RenderProcess::CreateTransportDIB(size_t size) { 130 TransportDIB* RenderProcess::CreateTransportDIB(size_t size) {
152 #if defined(OS_WIN) || defined(OS_LINUX) 131 #if defined(OS_WIN) || defined(OS_LINUX)
153 // Windows and Linux create transport DIBs inside the renderer 132 // Windows and Linux create transport DIBs inside the renderer
154 return TransportDIB::Create(size, sequence_number_++); 133 return TransportDIB::Create(size, sequence_number_++);
155 #elif defined(OS_MACOSX) // defined(OS_WIN) || defined(OS_LINUX) 134 #elif defined(OS_MACOSX) // defined(OS_WIN) || defined(OS_LINUX)
156 // Mac creates transport DIBs in the browser, so we need to do a sync IPC to 135 // Mac creates transport DIBs in the browser, so we need to do a sync IPC to
157 // get one. 136 // get one.
158 TransportDIB::Handle handle; 137 TransportDIB::Handle handle;
159 IPC::Message* msg = new ViewHostMsg_AllocTransportDIB(size, &handle); 138 IPC::Message* msg = new ViewHostMsg_AllocTransportDIB(size, &handle);
160 if (!child_thread()->Send(msg)) 139 if (!main_thread()->Send(msg))
161 return NULL; 140 return NULL;
162 if (handle.fd < 0) 141 if (handle.fd < 0)
163 return NULL; 142 return NULL;
164 return TransportDIB::Map(handle); 143 return TransportDIB::Map(handle);
165 #endif // defined(OS_MACOSX) 144 #endif // defined(OS_MACOSX)
166 } 145 }
167 146
168 void RenderProcess::FreeTransportDIB(TransportDIB* dib) { 147 void RenderProcess::FreeTransportDIB(TransportDIB* dib) {
169 if (!dib) 148 if (!dib)
170 return; 149 return;
171 150
172 #if defined(OS_MACOSX) 151 #if defined(OS_MACOSX)
173 // On Mac we need to tell the browser that it can drop a reference to the 152 // On Mac we need to tell the browser that it can drop a reference to the
174 // shared memory. 153 // shared memory.
175 IPC::Message* msg = new ViewHostMsg_FreeTransportDIB(dib->id()); 154 IPC::Message* msg = new ViewHostMsg_FreeTransportDIB(dib->id());
176 child_thread()->Send(msg); 155 main_thread()->Send(msg);
177 #endif 156 #endif
178 157
179 delete dib; 158 delete dib;
180 } 159 }
181 160
182 // ----------------------------------------------------------------------------- 161 // -----------------------------------------------------------------------------
183 162
184 163
185 skia::PlatformCanvas* RenderProcess::GetDrawingCanvas( 164 skia::PlatformCanvas* RenderProcess::GetDrawingCanvas(
186 TransportDIB** memory, const gfx::Rect& rect) { 165 TransportDIB** memory, const gfx::Rect& rect) {
(...skipping 81 matching lines...) Expand 10 before | Expand all | Expand 10 after
268 } 247 }
269 248
270 void RenderProcess::ClearTransportDIBCache() { 249 void RenderProcess::ClearTransportDIBCache() {
271 for (size_t i = 0; i < arraysize(shared_mem_cache_); ++i) { 250 for (size_t i = 0; i < arraysize(shared_mem_cache_); ++i) {
272 if (shared_mem_cache_[i]) { 251 if (shared_mem_cache_[i]) {
273 FreeTransportDIB(shared_mem_cache_[i]); 252 FreeTransportDIB(shared_mem_cache_[i]);
274 shared_mem_cache_[i] = NULL; 253 shared_mem_cache_[i] = NULL;
275 } 254 }
276 } 255 }
277 } 256 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698