Chromium Code Reviews

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

Issue 155876: Revert r21117 as it caused reliability failures.... (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: Created 11 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments.
Jump to:
View unified diff | | Annotate | Revision Log
« no previous file with comments | « chrome/renderer/render_process.h ('k') | chrome/renderer/render_process_unittest.cc » ('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) 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...)
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 : ALLOW_THIS_IN_INITIALIZER_LIST(shared_mem_cache_cleaner_( 50 : ChildProcess(new RenderThread()),
51 ALLOW_THIS_IN_INITIALIZER_LIST(shared_mem_cache_cleaner_(
51 base::TimeDelta::FromSeconds(5), 52 base::TimeDelta::FromSeconds(5),
52 this, &RenderProcess::ClearTransportDIBCache)), 53 this, &RenderProcess::ClearTransportDIBCache)),
53 sequence_number_(0) { 54 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() {
54 in_process_plugins_ = InProcessPlugins(); 87 in_process_plugins_ = InProcessPlugins();
55 for (size_t i = 0; i < arraysize(shared_mem_cache_); ++i) 88 for (size_t i = 0; i < arraysize(shared_mem_cache_); ++i)
56 shared_mem_cache_[i] = NULL; 89 shared_mem_cache_[i] = NULL;
57 90
58 #if defined(OS_WIN) 91 #if defined(OS_WIN)
59 // HACK: See http://b/issue?id=1024307 for rationale. 92 // HACK: See http://b/issue?id=1024307 for rationale.
60 if (GetModuleHandle(L"LPK.DLL") == NULL) { 93 if (GetModuleHandle(L"LPK.DLL") == NULL) {
61 // Makes sure lpk.dll is loaded by gdi32 to make sure ExtTextOut() works 94 // Makes sure lpk.dll is loaded by gdi32 to make sure ExtTextOut() works
62 // when buffering into a EMF buffer for printing. 95 // when buffering into a EMF buffer for printing.
63 typedef BOOL (__stdcall *GdiInitializeLanguagePack)(int LoadedShapingDLLs); 96 typedef BOOL (__stdcall *GdiInitializeLanguagePack)(int LoadedShapingDLLs);
(...skipping 27 matching lines...)
91 if (command_line.HasSwitch(switches::kDumpHistogramsOnExit)) { 124 if (command_line.HasSwitch(switches::kDumpHistogramsOnExit)) {
92 StatisticsRecorder::set_dump_on_exit(true); 125 StatisticsRecorder::set_dump_on_exit(true);
93 } 126 }
94 127
95 FilePath module_path; 128 FilePath module_path;
96 initialized_media_library_ = 129 initialized_media_library_ =
97 PathService::Get(base::DIR_MODULE, &module_path) && 130 PathService::Get(base::DIR_MODULE, &module_path) &&
98 media::InitializeMediaLibrary(module_path); 131 media::InitializeMediaLibrary(module_path);
99 } 132 }
100 133
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
113 bool RenderProcess::InProcessPlugins() { 134 bool RenderProcess::InProcessPlugins() {
114 const CommandLine& command_line = *CommandLine::ForCurrentProcess(); 135 const CommandLine& command_line = *CommandLine::ForCurrentProcess();
115 #if defined(OS_LINUX) 136 #if defined(OS_LINUX)
116 // Plugin processes require a UI message loop, and the Linux message loop 137 // Plugin processes require a UI message loop, and the Linux message loop
117 // implementation only allows one UI loop per process. 138 // implementation only allows one UI loop per process.
118 if (command_line.HasSwitch(switches::kInProcessPlugins)) 139 if (command_line.HasSwitch(switches::kInProcessPlugins))
119 NOTIMPLEMENTED() << ": in process plugins not supported on Linux"; 140 NOTIMPLEMENTED() << ": in process plugins not supported on Linux";
120 return command_line.HasSwitch(switches::kInProcessPlugins); 141 return command_line.HasSwitch(switches::kInProcessPlugins);
121 #else 142 #else
122 return command_line.HasSwitch(switches::kInProcessPlugins) || 143 return command_line.HasSwitch(switches::kInProcessPlugins) ||
123 command_line.HasSwitch(switches::kSingleProcess); 144 command_line.HasSwitch(switches::kSingleProcess);
124 #endif 145 #endif
125 } 146 }
126 147
127 // ----------------------------------------------------------------------------- 148 // -----------------------------------------------------------------------------
128 // Platform specific code for dealing with bitmap transport... 149 // Platform specific code for dealing with bitmap transport...
129 150
130 TransportDIB* RenderProcess::CreateTransportDIB(size_t size) { 151 TransportDIB* RenderProcess::CreateTransportDIB(size_t size) {
131 #if defined(OS_WIN) || defined(OS_LINUX) 152 #if defined(OS_WIN) || defined(OS_LINUX)
132 // Windows and Linux create transport DIBs inside the renderer 153 // Windows and Linux create transport DIBs inside the renderer
133 return TransportDIB::Create(size, sequence_number_++); 154 return TransportDIB::Create(size, sequence_number_++);
134 #elif defined(OS_MACOSX) // defined(OS_WIN) || defined(OS_LINUX) 155 #elif defined(OS_MACOSX) // defined(OS_WIN) || defined(OS_LINUX)
135 // Mac creates transport DIBs in the browser, so we need to do a sync IPC to 156 // Mac creates transport DIBs in the browser, so we need to do a sync IPC to
136 // get one. 157 // get one.
137 TransportDIB::Handle handle; 158 TransportDIB::Handle handle;
138 IPC::Message* msg = new ViewHostMsg_AllocTransportDIB(size, &handle); 159 IPC::Message* msg = new ViewHostMsg_AllocTransportDIB(size, &handle);
139 if (!main_thread()->Send(msg)) 160 if (!child_thread()->Send(msg))
140 return NULL; 161 return NULL;
141 if (handle.fd < 0) 162 if (handle.fd < 0)
142 return NULL; 163 return NULL;
143 return TransportDIB::Map(handle); 164 return TransportDIB::Map(handle);
144 #endif // defined(OS_MACOSX) 165 #endif // defined(OS_MACOSX)
145 } 166 }
146 167
147 void RenderProcess::FreeTransportDIB(TransportDIB* dib) { 168 void RenderProcess::FreeTransportDIB(TransportDIB* dib) {
148 if (!dib) 169 if (!dib)
149 return; 170 return;
150 171
151 #if defined(OS_MACOSX) 172 #if defined(OS_MACOSX)
152 // On Mac we need to tell the browser that it can drop a reference to the 173 // On Mac we need to tell the browser that it can drop a reference to the
153 // shared memory. 174 // shared memory.
154 IPC::Message* msg = new ViewHostMsg_FreeTransportDIB(dib->id()); 175 IPC::Message* msg = new ViewHostMsg_FreeTransportDIB(dib->id());
155 main_thread()->Send(msg); 176 child_thread()->Send(msg);
156 #endif 177 #endif
157 178
158 delete dib; 179 delete dib;
159 } 180 }
160 181
161 // ----------------------------------------------------------------------------- 182 // -----------------------------------------------------------------------------
162 183
163 184
164 skia::PlatformCanvas* RenderProcess::GetDrawingCanvas( 185 skia::PlatformCanvas* RenderProcess::GetDrawingCanvas(
165 TransportDIB** memory, const gfx::Rect& rect) { 186 TransportDIB** memory, const gfx::Rect& rect) {
(...skipping 81 matching lines...)
247 } 268 }
248 269
249 void RenderProcess::ClearTransportDIBCache() { 270 void RenderProcess::ClearTransportDIBCache() {
250 for (size_t i = 0; i < arraysize(shared_mem_cache_); ++i) { 271 for (size_t i = 0; i < arraysize(shared_mem_cache_); ++i) {
251 if (shared_mem_cache_[i]) { 272 if (shared_mem_cache_[i]) {
252 FreeTransportDIB(shared_mem_cache_[i]); 273 FreeTransportDIB(shared_mem_cache_[i]);
253 shared_mem_cache_[i] = NULL; 274 shared_mem_cache_[i] = NULL;
254 } 275 }
255 } 276 }
256 } 277 }
OLDNEW
« no previous file with comments | « chrome/renderer/render_process.h ('k') | chrome/renderer/render_process_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine