| OLD | NEW |
| 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 "chrome/browser/renderer_host/render_widget_helper.h" | 5 #include "chrome/browser/renderer_host/render_widget_helper.h" |
| 6 | 6 |
| 7 #include "base/eintr_wrapper.h" | 7 #include "base/eintr_wrapper.h" |
| 8 #include "base/threading/thread.h" | 8 #include "base/threading/thread.h" |
| 9 #include "chrome/browser/browser_thread.h" | 9 #include "chrome/browser/browser_thread.h" |
| 10 #include "chrome/browser/renderer_host/render_process_host.h" | 10 #include "chrome/browser/renderer_host/render_process_host.h" |
| (...skipping 84 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 95 } | 95 } |
| 96 | 96 |
| 97 bool RenderWidgetHelper::WaitForUpdateMsg(int render_widget_id, | 97 bool RenderWidgetHelper::WaitForUpdateMsg(int render_widget_id, |
| 98 const base::TimeDelta& max_delay, | 98 const base::TimeDelta& max_delay, |
| 99 IPC::Message* msg) { | 99 IPC::Message* msg) { |
| 100 base::TimeTicks time_start = base::TimeTicks::Now(); | 100 base::TimeTicks time_start = base::TimeTicks::Now(); |
| 101 | 101 |
| 102 for (;;) { | 102 for (;;) { |
| 103 UpdateMsgProxy* proxy = NULL; | 103 UpdateMsgProxy* proxy = NULL; |
| 104 { | 104 { |
| 105 AutoLock lock(pending_paints_lock_); | 105 base::AutoLock lock(pending_paints_lock_); |
| 106 | 106 |
| 107 UpdateMsgProxyMap::iterator it = pending_paints_.find(render_widget_id); | 107 UpdateMsgProxyMap::iterator it = pending_paints_.find(render_widget_id); |
| 108 if (it != pending_paints_.end()) { | 108 if (it != pending_paints_.end()) { |
| 109 proxy = it->second; | 109 proxy = it->second; |
| 110 | 110 |
| 111 // Flag the proxy as cancelled so that when it is run as a task it will | 111 // Flag the proxy as cancelled so that when it is run as a task it will |
| 112 // do nothing. | 112 // do nothing. |
| 113 proxy->cancelled = true; | 113 proxy->cancelled = true; |
| 114 | 114 |
| 115 pending_paints_.erase(it); | 115 pending_paints_.erase(it); |
| (...skipping 16 matching lines...) Expand all Loading... |
| 132 } | 132 } |
| 133 | 133 |
| 134 return false; | 134 return false; |
| 135 } | 135 } |
| 136 | 136 |
| 137 void RenderWidgetHelper::DidReceiveUpdateMsg(const IPC::Message& msg) { | 137 void RenderWidgetHelper::DidReceiveUpdateMsg(const IPC::Message& msg) { |
| 138 int render_widget_id = msg.routing_id(); | 138 int render_widget_id = msg.routing_id(); |
| 139 | 139 |
| 140 UpdateMsgProxy* proxy = NULL; | 140 UpdateMsgProxy* proxy = NULL; |
| 141 { | 141 { |
| 142 AutoLock lock(pending_paints_lock_); | 142 base::AutoLock lock(pending_paints_lock_); |
| 143 | 143 |
| 144 UpdateMsgProxyMap::value_type new_value(render_widget_id, NULL); | 144 UpdateMsgProxyMap::value_type new_value(render_widget_id, NULL); |
| 145 | 145 |
| 146 // We expect only a single PaintRect message at a time. Optimize for the | 146 // We expect only a single PaintRect message at a time. Optimize for the |
| 147 // case that we don't already have an entry by using the 'insert' method. | 147 // case that we don't already have an entry by using the 'insert' method. |
| 148 std::pair<UpdateMsgProxyMap::iterator, bool> result = | 148 std::pair<UpdateMsgProxyMap::iterator, bool> result = |
| 149 pending_paints_.insert(new_value); | 149 pending_paints_.insert(new_value); |
| 150 if (!result.second) { | 150 if (!result.second) { |
| 151 NOTREACHED() << "Unexpected PaintRect message!"; | 151 NOTREACHED() << "Unexpected PaintRect message!"; |
| 152 return; | 152 return; |
| 153 } | 153 } |
| 154 | 154 |
| 155 result.first->second = (proxy = new UpdateMsgProxy(this, msg)); | 155 result.first->second = (proxy = new UpdateMsgProxy(this, msg)); |
| 156 } | 156 } |
| 157 | 157 |
| 158 // Notify anyone waiting on the UI thread that there is a new entry in the | 158 // Notify anyone waiting on the UI thread that there is a new entry in the |
| 159 // proxy map. If they don't find the entry they are looking for, then they | 159 // proxy map. If they don't find the entry they are looking for, then they |
| 160 // will just continue waiting. | 160 // will just continue waiting. |
| 161 event_.Signal(); | 161 event_.Signal(); |
| 162 | 162 |
| 163 // The proxy will be deleted when it is run as a task. | 163 // The proxy will be deleted when it is run as a task. |
| 164 BrowserThread::PostTask(BrowserThread::UI, FROM_HERE, proxy); | 164 BrowserThread::PostTask(BrowserThread::UI, FROM_HERE, proxy); |
| 165 } | 165 } |
| 166 | 166 |
| 167 void RenderWidgetHelper::OnDiscardUpdateMsg(UpdateMsgProxy* proxy) { | 167 void RenderWidgetHelper::OnDiscardUpdateMsg(UpdateMsgProxy* proxy) { |
| 168 const IPC::Message& msg = proxy->message; | 168 const IPC::Message& msg = proxy->message; |
| 169 | 169 |
| 170 // Remove the proxy from the map now that we are going to handle it normally. | 170 // Remove the proxy from the map now that we are going to handle it normally. |
| 171 { | 171 { |
| 172 AutoLock lock(pending_paints_lock_); | 172 base::AutoLock lock(pending_paints_lock_); |
| 173 | 173 |
| 174 UpdateMsgProxyMap::iterator it = pending_paints_.find(msg.routing_id()); | 174 UpdateMsgProxyMap::iterator it = pending_paints_.find(msg.routing_id()); |
| 175 DCHECK(it != pending_paints_.end()); | 175 DCHECK(it != pending_paints_.end()); |
| 176 DCHECK(it->second == proxy); | 176 DCHECK(it->second == proxy); |
| 177 | 177 |
| 178 pending_paints_.erase(it); | 178 pending_paints_.erase(it); |
| 179 } | 179 } |
| 180 } | 180 } |
| 181 | 181 |
| 182 void RenderWidgetHelper::OnDispatchUpdateMsg(UpdateMsgProxy* proxy) { | 182 void RenderWidgetHelper::OnDispatchUpdateMsg(UpdateMsgProxy* proxy) { |
| (...skipping 86 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 269 | 269 |
| 270 void RenderWidgetHelper::OnCreateFullscreenWidgetOnUI( | 270 void RenderWidgetHelper::OnCreateFullscreenWidgetOnUI( |
| 271 int opener_id, int route_id, WebKit::WebPopupType popup_type) { | 271 int opener_id, int route_id, WebKit::WebPopupType popup_type) { |
| 272 RenderViewHost* host = RenderViewHost::FromID(render_process_id_, opener_id); | 272 RenderViewHost* host = RenderViewHost::FromID(render_process_id_, opener_id); |
| 273 if (host) | 273 if (host) |
| 274 host->CreateNewFullscreenWidget(route_id, popup_type); | 274 host->CreateNewFullscreenWidget(route_id, popup_type); |
| 275 } | 275 } |
| 276 | 276 |
| 277 #if defined(OS_MACOSX) | 277 #if defined(OS_MACOSX) |
| 278 TransportDIB* RenderWidgetHelper::MapTransportDIB(TransportDIB::Id dib_id) { | 278 TransportDIB* RenderWidgetHelper::MapTransportDIB(TransportDIB::Id dib_id) { |
| 279 AutoLock locked(allocated_dibs_lock_); | 279 base::AutoLock locked(allocated_dibs_lock_); |
| 280 | 280 |
| 281 const std::map<TransportDIB::Id, int>::iterator | 281 const std::map<TransportDIB::Id, int>::iterator |
| 282 i = allocated_dibs_.find(dib_id); | 282 i = allocated_dibs_.find(dib_id); |
| 283 if (i == allocated_dibs_.end()) | 283 if (i == allocated_dibs_.end()) |
| 284 return NULL; | 284 return NULL; |
| 285 | 285 |
| 286 base::FileDescriptor fd(dup(i->second), true); | 286 base::FileDescriptor fd(dup(i->second), true); |
| 287 return TransportDIB::Map(fd); | 287 return TransportDIB::Map(fd); |
| 288 } | 288 } |
| 289 | 289 |
| 290 void RenderWidgetHelper::AllocTransportDIB( | 290 void RenderWidgetHelper::AllocTransportDIB( |
| 291 size_t size, bool cache_in_browser, TransportDIB::Handle* result) { | 291 size_t size, bool cache_in_browser, TransportDIB::Handle* result) { |
| 292 scoped_ptr<base::SharedMemory> shared_memory(new base::SharedMemory()); | 292 scoped_ptr<base::SharedMemory> shared_memory(new base::SharedMemory()); |
| 293 if (!shared_memory->CreateAnonymous(size)) { | 293 if (!shared_memory->CreateAnonymous(size)) { |
| 294 result->fd = -1; | 294 result->fd = -1; |
| 295 result->auto_close = false; | 295 result->auto_close = false; |
| 296 return; | 296 return; |
| 297 } | 297 } |
| 298 | 298 |
| 299 shared_memory->GiveToProcess(0 /* pid, not needed */, result); | 299 shared_memory->GiveToProcess(0 /* pid, not needed */, result); |
| 300 | 300 |
| 301 if (cache_in_browser) { | 301 if (cache_in_browser) { |
| 302 // Keep a copy of the file descriptor around | 302 // Keep a copy of the file descriptor around |
| 303 AutoLock locked(allocated_dibs_lock_); | 303 base::AutoLock locked(allocated_dibs_lock_); |
| 304 allocated_dibs_[shared_memory->id()] = dup(result->fd); | 304 allocated_dibs_[shared_memory->id()] = dup(result->fd); |
| 305 } | 305 } |
| 306 } | 306 } |
| 307 | 307 |
| 308 void RenderWidgetHelper::FreeTransportDIB(TransportDIB::Id dib_id) { | 308 void RenderWidgetHelper::FreeTransportDIB(TransportDIB::Id dib_id) { |
| 309 AutoLock locked(allocated_dibs_lock_); | 309 base::AutoLock locked(allocated_dibs_lock_); |
| 310 | 310 |
| 311 const std::map<TransportDIB::Id, int>::iterator | 311 const std::map<TransportDIB::Id, int>::iterator |
| 312 i = allocated_dibs_.find(dib_id); | 312 i = allocated_dibs_.find(dib_id); |
| 313 | 313 |
| 314 if (i != allocated_dibs_.end()) { | 314 if (i != allocated_dibs_.end()) { |
| 315 if (HANDLE_EINTR(close(i->second)) < 0) | 315 if (HANDLE_EINTR(close(i->second)) < 0) |
| 316 PLOG(ERROR) << "close"; | 316 PLOG(ERROR) << "close"; |
| 317 allocated_dibs_.erase(i); | 317 allocated_dibs_.erase(i); |
| 318 } else { | 318 } else { |
| 319 DLOG(WARNING) << "Renderer asked us to free unknown transport DIB"; | 319 DLOG(WARNING) << "Renderer asked us to free unknown transport DIB"; |
| 320 } | 320 } |
| 321 } | 321 } |
| 322 | 322 |
| 323 void RenderWidgetHelper::ClearAllocatedDIBs() { | 323 void RenderWidgetHelper::ClearAllocatedDIBs() { |
| 324 for (std::map<TransportDIB::Id, int>::iterator | 324 for (std::map<TransportDIB::Id, int>::iterator |
| 325 i = allocated_dibs_.begin(); i != allocated_dibs_.end(); ++i) { | 325 i = allocated_dibs_.begin(); i != allocated_dibs_.end(); ++i) { |
| 326 if (HANDLE_EINTR(close(i->second)) < 0) | 326 if (HANDLE_EINTR(close(i->second)) < 0) |
| 327 PLOG(ERROR) << "close: " << i->first; | 327 PLOG(ERROR) << "close: " << i->first; |
| 328 } | 328 } |
| 329 | 329 |
| 330 allocated_dibs_.clear(); | 330 allocated_dibs_.clear(); |
| 331 } | 331 } |
| 332 #endif | 332 #endif |
| OLD | NEW |