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

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

Issue 8120007: Update Breakpad to r842 and fix the Breakpad bootstrap service leak and -10810 errors (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src/
Patch Set: '' Created 9 years, 2 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 | « chrome/app/chrome_main.cc ('k') | chrome/tools/build/mac/dump_product_syms » ('j') | 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) 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/renderer/chrome_render_process_observer.h" 5 #include "chrome/renderer/chrome_render_process_observer.h"
6 6
7 #include "base/command_line.h" 7 #include "base/command_line.h"
8 #include "base/file_util.h" 8 #include "base/file_util.h"
9 #include "base/metrics/field_trial.h" 9 #include "base/metrics/field_trial.h"
10 #include "base/metrics/histogram.h" 10 #include "base/metrics/histogram.h"
(...skipping 29 matching lines...) Expand all
40 #include "third_party/WebKit/Source/WebKit/chromium/public/WebFontCache.h" 40 #include "third_party/WebKit/Source/WebKit/chromium/public/WebFontCache.h"
41 #include "third_party/WebKit/Source/WebKit/chromium/public/WebFrame.h" 41 #include "third_party/WebKit/Source/WebKit/chromium/public/WebFrame.h"
42 #include "third_party/WebKit/Source/WebKit/chromium/public/WebRuntimeFeatures.h" 42 #include "third_party/WebKit/Source/WebKit/chromium/public/WebRuntimeFeatures.h"
43 #include "third_party/WebKit/Source/WebKit/chromium/public/WebView.h" 43 #include "third_party/WebKit/Source/WebKit/chromium/public/WebView.h"
44 #include "v8/include/v8.h" 44 #include "v8/include/v8.h"
45 45
46 #if defined(OS_WIN) 46 #if defined(OS_WIN)
47 #include "base/win/iat_patch_function.h" 47 #include "base/win/iat_patch_function.h"
48 #endif 48 #endif
49 49
50 #if defined(OS_MACOSX)
51 #include "base/eintr_wrapper.h"
52 #include "chrome/app/breakpad_mac.h"
53 #endif
54
55 using WebKit::WebCache; 50 using WebKit::WebCache;
56 using WebKit::WebCrossOriginPreflightResultCache; 51 using WebKit::WebCrossOriginPreflightResultCache;
57 using WebKit::WebFontCache; 52 using WebKit::WebFontCache;
58 using WebKit::WebRuntimeFeatures; 53 using WebKit::WebRuntimeFeatures;
59 54
60 namespace { 55 namespace {
61 56
62 static const unsigned int kCacheStatsDelayMS = 2000 /* milliseconds */; 57 static const unsigned int kCacheStatsDelayMS = 2000 /* milliseconds */;
63 58
64 class RendererResourceDelegate : public ResourceDispatcherDelegate { 59 class RendererResourceDelegate : public ResourceDispatcherDelegate {
(...skipping 118 matching lines...) Expand 10 before | Expand all | Expand 10 after
183 // processed (because that message loop is stuck in V8). 178 // processed (because that message loop is stuck in V8).
184 // 179 //
185 // One could make the browser SIGKILL the renderers, but that leaves open a 180 // One could make the browser SIGKILL the renderers, but that leaves open a
186 // large window where a browser failure (or a user, manually terminating 181 // large window where a browser failure (or a user, manually terminating
187 // the browser because "it's stuck") will leave behind a process eating all 182 // the browser because "it's stuck") will leave behind a process eating all
188 // the CPU. 183 // the CPU.
189 // 184 //
190 // So, we install a filter on the channel so that we can process this event 185 // So, we install a filter on the channel so that we can process this event
191 // here and kill the process. 186 // here and kill the process.
192 187
193 #if defined(OS_MACOSX)
194 // TODO(viettrungluu): crbug.com/28547: The following is needed, as a
195 // stopgap, to avoid leaking due to not releasing Breakpad properly.
196 // TODO(viettrungluu): Investigate why this is being called.
197 if (IsCrashReporterEnabled()) {
198 VLOG(1) << "Cleaning up Breakpad.";
199 DestructCrashReporter();
200 } else {
201 VLOG(1) << "Breakpad not enabled; no clean-up needed.";
202 }
203 #endif // OS_MACOSX
204
205 _exit(0); 188 _exit(0);
206 } 189 }
207 }; 190 };
208 #endif // OS_POSIX 191 #endif // OS_POSIX
209 192
210 #if defined(OS_MACOSX)
211 // TODO(viettrungluu): crbug.com/28547: The following signal handling is needed,
212 // as a stopgap, to avoid leaking due to not releasing Breakpad properly.
213 // Without this problem, this could all be eliminated. Remove when Breakpad is
214 // fixed?
215 // TODO(viettrungluu): Code taken from browser_main.cc (with a bit of editing).
216 // The code should be properly shared (or this code should be eliminated).
217 int g_shutdown_pipe_write_fd = -1;
218
219 void SIGTERMHandler(int signal) {
220 RAW_CHECK(signal == SIGTERM);
221
222 // Reinstall the default handler. We had one shot at graceful shutdown.
223 struct sigaction action;
224 memset(&action, 0, sizeof(action));
225 action.sa_handler = SIG_DFL;
226 CHECK(sigaction(signal, &action, NULL) == 0);
227
228 RAW_CHECK(g_shutdown_pipe_write_fd != -1);
229 size_t bytes_written = 0;
230 do {
231 int rv = HANDLE_EINTR(
232 write(g_shutdown_pipe_write_fd,
233 reinterpret_cast<const char*>(&signal) + bytes_written,
234 sizeof(signal) - bytes_written));
235 RAW_CHECK(rv >= 0);
236 bytes_written += rv;
237 } while (bytes_written < sizeof(signal));
238 }
239
240 class ShutdownDetector : public base::PlatformThread::Delegate {
241 public:
242 explicit ShutdownDetector(int shutdown_fd) : shutdown_fd_(shutdown_fd) {
243 CHECK(shutdown_fd_ != -1);
244 }
245
246 virtual void ThreadMain() {
247 int signal;
248 size_t bytes_read = 0;
249 ssize_t ret;
250 do {
251 ret = HANDLE_EINTR(
252 read(shutdown_fd_,
253 reinterpret_cast<char*>(&signal) + bytes_read,
254 sizeof(signal) - bytes_read));
255 if (ret < 0) {
256 NOTREACHED() << "Unexpected error: " << strerror(errno);
257 break;
258 } else if (ret == 0) {
259 NOTREACHED() << "Unexpected closure of shutdown pipe.";
260 break;
261 }
262 bytes_read += ret;
263 } while (bytes_read < sizeof(signal));
264
265 if (bytes_read == sizeof(signal))
266 VLOG(1) << "Handling shutdown for signal " << signal << ".";
267 else
268 VLOG(1) << "Handling shutdown for unknown signal.";
269
270 // Clean up Breakpad if necessary.
271 if (IsCrashReporterEnabled()) {
272 VLOG(1) << "Cleaning up Breakpad.";
273 DestructCrashReporter();
274 } else {
275 VLOG(1) << "Breakpad not enabled; no clean-up needed.";
276 }
277
278 // Something went seriously wrong, so get out.
279 if (bytes_read != sizeof(signal)) {
280 LOG(WARNING) << "Failed to get signal. Quitting ungracefully.";
281 _exit(1);
282 }
283
284 // Re-raise the signal.
285 kill(getpid(), signal);
286
287 // The signal may be handled on another thread. Give that a chance to
288 // happen.
289 sleep(3);
290
291 // We really should be dead by now. For whatever reason, we're not. Exit
292 // immediately, with the exit status set to the signal number with bit 8
293 // set. On the systems that we care about, this exit status is what is
294 // normally used to indicate an exit by this signal's default handler.
295 // This mechanism isn't a de jure standard, but even in the worst case, it
296 // should at least result in an immediate exit.
297 LOG(WARNING) << "Still here, exiting really ungracefully.";
298 _exit(signal | (1 << 7));
299 }
300
301 private:
302 const int shutdown_fd_;
303
304 DISALLOW_COPY_AND_ASSIGN(ShutdownDetector);
305 };
306 #endif // OS_MACOSX
307
308 } // namespace 193 } // namespace
309 194
310 bool ChromeRenderProcessObserver::is_incognito_process_ = false; 195 bool ChromeRenderProcessObserver::is_incognito_process_ = false;
311 196
312 ChromeRenderProcessObserver::ChromeRenderProcessObserver( 197 ChromeRenderProcessObserver::ChromeRenderProcessObserver(
313 chrome::ChromeContentRendererClient* client) 198 chrome::ChromeContentRendererClient* client)
314 : client_(client), 199 : client_(client),
315 clear_cache_pending_(false) { 200 clear_cache_pending_(false) {
316 const CommandLine& command_line = *CommandLine::ForCurrentProcess(); 201 const CommandLine& command_line = *CommandLine::ForCurrentProcess();
317 if (command_line.HasSwitch(switches::kEnableWatchdog)) { 202 if (command_line.HasSwitch(switches::kEnableWatchdog)) {
318 // TODO(JAR): Need to implement renderer IO msgloop watchdog. 203 // TODO(JAR): Need to implement renderer IO msgloop watchdog.
319 } 204 }
320 205
321 if (command_line.HasSwitch(switches::kDumpHistogramsOnExit)) { 206 if (command_line.HasSwitch(switches::kDumpHistogramsOnExit)) {
322 base::StatisticsRecorder::set_dump_on_exit(true); 207 base::StatisticsRecorder::set_dump_on_exit(true);
323 } 208 }
324 209
325 RenderThread* thread = RenderThread::current(); 210 RenderThread* thread = RenderThread::current();
326 resource_delegate_.reset(new RendererResourceDelegate()); 211 resource_delegate_.reset(new RendererResourceDelegate());
327 thread->resource_dispatcher()->set_delegate(resource_delegate_.get()); 212 thread->resource_dispatcher()->set_delegate(resource_delegate_.get());
328 213
329 #if defined(OS_POSIX) 214 #if defined(OS_POSIX)
330 thread->AddFilter(new SuicideOnChannelErrorFilter()); 215 thread->AddFilter(new SuicideOnChannelErrorFilter());
331 #endif 216 #endif
332 217
333 #if defined(OS_MACOSX)
334 // TODO(viettrungluu): Code taken from browser_main.cc.
335 int pipefd[2];
336 int ret = pipe(pipefd);
337 if (ret < 0) {
338 PLOG(DFATAL) << "Failed to create pipe";
339 } else {
340 int shutdown_pipe_read_fd = pipefd[0];
341 g_shutdown_pipe_write_fd = pipefd[1];
342 const size_t kShutdownDetectorThreadStackSize = 4096;
343 if (!base::PlatformThread::CreateNonJoinable(
344 kShutdownDetectorThreadStackSize,
345 new ShutdownDetector(shutdown_pipe_read_fd))) {
346 LOG(DFATAL) << "Failed to create shutdown detector task.";
347 }
348 }
349
350 // crbug.com/28547: When Breakpad is in use, handle SIGTERM to avoid leaking
351 // Mach ports.
352 struct sigaction action;
353 memset(&action, 0, sizeof(action));
354 action.sa_handler = SIGTERMHandler;
355 CHECK(sigaction(SIGTERM, &action, NULL) == 0);
356 #endif
357
358 // Configure modules that need access to resources. 218 // Configure modules that need access to resources.
359 net::NetModule::SetResourceProvider(chrome_common_net::NetResourceProvider); 219 net::NetModule::SetResourceProvider(chrome_common_net::NetResourceProvider);
360 220
361 #if defined(OS_WIN) 221 #if defined(OS_WIN)
362 // Need to patch a few functions for font loading to work correctly. 222 // Need to patch a few functions for font loading to work correctly.
363 FilePath pdf; 223 FilePath pdf;
364 if (PathService::Get(chrome::FILE_PDF_PLUGIN, &pdf) && 224 if (PathService::Get(chrome::FILE_PDF_PLUGIN, &pdf) &&
365 file_util::PathExists(pdf)) { 225 file_util::PathExists(pdf)) {
366 g_iat_patch_createdca.Patch( 226 g_iat_patch_createdca.Patch(
367 pdf.value().c_str(), "gdi32.dll", "CreateDCA", CreateDCAPatch); 227 pdf.value().c_str(), "gdi32.dll", "CreateDCA", CreateDCAPatch);
(...skipping 186 matching lines...) Expand 10 before | Expand all | Expand 10 after
554 if (client_) 414 if (client_)
555 client_->OnPurgeMemory(); 415 client_->OnPurgeMemory();
556 } 416 }
557 417
558 void ChromeRenderProcessObserver::ExecutePendingClearCache() { 418 void ChromeRenderProcessObserver::ExecutePendingClearCache() {
559 if (clear_cache_pending_) { 419 if (clear_cache_pending_) {
560 clear_cache_pending_ = false; 420 clear_cache_pending_ = false;
561 WebCache::clear(); 421 WebCache::clear();
562 } 422 }
563 } 423 }
OLDNEW
« no previous file with comments | « chrome/app/chrome_main.cc ('k') | chrome/tools/build/mac/dump_product_syms » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698