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

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

Issue 10895: Add Terminate() to the Process object, have RenderProcessHost use this to avo... (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: Created 12 years, 1 month 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/renderer/render_process.h ('k') | chrome/renderer/render_thread.h » ('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 <windows.h> 5 #include <windows.h>
6 #include <objidl.h> 6 #include <objidl.h>
7 #include <mlang.h> 7 #include <mlang.h>
8 8
9 #include "chrome/renderer/render_process.h" 9 #include "chrome/renderer/render_process.h"
10 10
(...skipping 90 matching lines...) Expand 10 before | Expand all | Expand 10 after
101 void RenderProcess::GlobalCleanup() { 101 void RenderProcess::GlobalCleanup() {
102 ChildProcess::GlobalCleanup(); 102 ChildProcess::GlobalCleanup();
103 } 103 }
104 104
105 // static 105 // static
106 bool RenderProcess::ShouldLoadPluginsInProcess() { 106 bool RenderProcess::ShouldLoadPluginsInProcess() {
107 return load_plugins_in_process_; 107 return load_plugins_in_process_;
108 } 108 }
109 109
110 // static 110 // static
111 SharedMemory* RenderProcess::AllocSharedMemory(size_t size) { 111 base::SharedMemory* RenderProcess::AllocSharedMemory(size_t size) {
112 self()->clearer_factory_.RevokeAll(); 112 self()->clearer_factory_.RevokeAll();
113 113
114 SharedMemory* mem = self()->GetSharedMemFromCache(size); 114 base::SharedMemory* mem = self()->GetSharedMemFromCache(size);
115 if (mem) 115 if (mem)
116 return mem; 116 return mem;
117 117
118 // Round-up size to allocation granularity 118 // Round-up size to allocation granularity
119 SYSTEM_INFO info; 119 SYSTEM_INFO info;
120 GetSystemInfo(&info); 120 GetSystemInfo(&info);
121 121
122 size = size / info.dwAllocationGranularity + 1; 122 size = size / info.dwAllocationGranularity + 1;
123 size = size * info.dwAllocationGranularity; 123 size = size * info.dwAllocationGranularity;
124 124
125 mem = new SharedMemory(); 125 mem = new base::SharedMemory();
126 if (!mem) 126 if (!mem)
127 return NULL; 127 return NULL;
128 if (!mem->Create(L"", false, true, size)) { 128 if (!mem->Create(L"", false, true, size)) {
129 delete mem; 129 delete mem;
130 return NULL; 130 return NULL;
131 } 131 }
132 132
133 return mem; 133 return mem;
134 } 134 }
135 135
136 // static 136 // static
137 void RenderProcess::FreeSharedMemory(SharedMemory* mem) { 137 void RenderProcess::FreeSharedMemory(base::SharedMemory* mem) {
138 if (self()->PutSharedMemInCache(mem)) { 138 if (self()->PutSharedMemInCache(mem)) {
139 self()->ScheduleCacheClearer(); 139 self()->ScheduleCacheClearer();
140 return; 140 return;
141 } 141 }
142 DeleteSharedMem(mem); 142 DeleteSharedMem(mem);
143 } 143 }
144 144
145 // static 145 // static
146 void RenderProcess::DeleteSharedMem(SharedMemory* mem) { 146 void RenderProcess::DeleteSharedMem(base::SharedMemory* mem) {
147 delete mem; 147 delete mem;
148 } 148 }
149 149
150 SharedMemory* RenderProcess::GetSharedMemFromCache(size_t size) { 150 base::SharedMemory* RenderProcess::GetSharedMemFromCache(size_t size) {
151 // look for a cached object that is suitable for the requested size. 151 // look for a cached object that is suitable for the requested size.
152 for (int i = 0; i < arraysize(shared_mem_cache_); ++i) { 152 for (int i = 0; i < arraysize(shared_mem_cache_); ++i) {
153 SharedMemory* mem = shared_mem_cache_[i]; 153 base::SharedMemory* mem = shared_mem_cache_[i];
154 if (mem && mem->max_size() >= size) { 154 if (mem && mem->max_size() >= size) {
155 shared_mem_cache_[i] = NULL; 155 shared_mem_cache_[i] = NULL;
156 return mem; 156 return mem;
157 } 157 }
158 } 158 }
159 return NULL; 159 return NULL;
160 } 160 }
161 161
162 bool RenderProcess::PutSharedMemInCache(SharedMemory* mem) { 162 bool RenderProcess::PutSharedMemInCache(base::SharedMemory* mem) {
163 // simple algorithm: 163 // simple algorithm:
164 // - look for an empty slot to store mem, or 164 // - look for an empty slot to store mem, or
165 // - if full, then replace any existing cache entry that is smaller than the 165 // - if full, then replace any existing cache entry that is smaller than the
166 // given shared memory object. 166 // given shared memory object.
167 for (int i = 0; i < arraysize(shared_mem_cache_); ++i) { 167 for (int i = 0; i < arraysize(shared_mem_cache_); ++i) {
168 if (!shared_mem_cache_[i]) { 168 if (!shared_mem_cache_[i]) {
169 shared_mem_cache_[i] = mem; 169 shared_mem_cache_[i] = mem;
170 return true; 170 return true;
171 } 171 }
172 } 172 }
173 for (int i = 0; i < arraysize(shared_mem_cache_); ++i) { 173 for (int i = 0; i < arraysize(shared_mem_cache_); ++i) {
174 SharedMemory* cached_mem = shared_mem_cache_[i]; 174 base::SharedMemory* cached_mem = shared_mem_cache_[i];
175 if (cached_mem->max_size() < mem->max_size()) { 175 if (cached_mem->max_size() < mem->max_size()) {
176 shared_mem_cache_[i] = mem; 176 shared_mem_cache_[i] = mem;
177 DeleteSharedMem(cached_mem); 177 DeleteSharedMem(cached_mem);
178 return true; 178 return true;
179 } 179 }
180 } 180 }
181 return false; 181 return false;
182 } 182 }
183 183
184 void RenderProcess::ClearSharedMemCache() { 184 void RenderProcess::ClearSharedMemCache() {
(...skipping 15 matching lines...) Expand all
200 5000 /* 5 seconds */); 200 5000 /* 5 seconds */);
201 } 201 }
202 202
203 void RenderProcess::Cleanup() { 203 void RenderProcess::Cleanup() {
204 #ifndef NDEBUG 204 #ifndef NDEBUG
205 // log important leaked objects 205 // log important leaked objects
206 webkit_glue::CheckForLeaks(); 206 webkit_glue::CheckForLeaks();
207 #endif 207 #endif
208 } 208 }
209 209
OLDNEW
« no previous file with comments | « chrome/renderer/render_process.h ('k') | chrome/renderer/render_thread.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698