| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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 "content/browser/renderer_host/render_widget_helper.h" | 5 #include "content/browser/renderer_host/render_widget_helper.h" |
| 6 | 6 |
| 7 #include "base/bind.h" | 7 #include "base/bind.h" |
| 8 #include "base/bind_helpers.h" | 8 #include "base/bind_helpers.h" |
| 9 #include "base/lazy_instance.h" | 9 #include "base/lazy_instance.h" |
| 10 #include "base/posix/eintr_wrapper.h" | 10 #include "base/posix/eintr_wrapper.h" |
| 11 #include "base/threading/thread.h" | 11 #include "base/threading/thread.h" |
| 12 #include "base/threading/thread_restrictions.h" | 12 #include "base/threading/thread_restrictions.h" |
| 13 #include "content/browser/gpu/gpu_surface_tracker.h" | 13 #include "content/browser/gpu/gpu_surface_tracker.h" |
| 14 #include "content/browser/loader/resource_dispatcher_host_impl.h" | 14 #include "content/browser/loader/resource_dispatcher_host_impl.h" |
| 15 #include "content/browser/renderer_host/render_process_host_impl.h" | 15 #include "content/browser/renderer_host/render_process_host_impl.h" |
| 16 #include "content/browser/renderer_host/render_view_host_impl.h" | 16 #include "content/browser/renderer_host/render_view_host_impl.h" |
| 17 #include "content/browser/dom_storage/session_storage_namespace_impl.h" | 17 #include "content/browser/dom_storage/session_storage_namespace_impl.h" |
| 18 #include "content/common/view_messages.h" | 18 #include "content/common/view_messages.h" |
| 19 | 19 |
| 20 namespace content { | 20 namespace content { |
| 21 namespace { | 21 namespace { |
| 22 | 22 |
| 23 typedef std::map<int, RenderWidgetHelper*> WidgetHelperMap; | 23 typedef std::map<int, RenderWidgetHelper*> WidgetHelperMap; |
| 24 base::LazyInstance<WidgetHelperMap> g_widget_helpers = | 24 base::LazyInstance<WidgetHelperMap> g_widget_helpers = |
| 25 LAZY_INSTANCE_INITIALIZER; | 25 LAZY_INSTANCE_INITIALIZER; |
| 26 | 26 |
| 27 void AddWidgetHelper(int render_process_id, | 27 void AddWidgetHelper(int render_process_id, |
| 28 const scoped_refptr<RenderWidgetHelper>& widget_helper) { | 28 const scoped_refptr<RenderWidgetHelper>& widget_helper) { |
| 29 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); | 29 DCHECK_CURRENTLY_ON(BrowserThread::IO); |
| 30 // We don't care if RenderWidgetHelpers overwrite an existing process_id. Just | 30 // We don't care if RenderWidgetHelpers overwrite an existing process_id. Just |
| 31 // want this to be up to date. | 31 // want this to be up to date. |
| 32 g_widget_helpers.Get()[render_process_id] = widget_helper.get(); | 32 g_widget_helpers.Get()[render_process_id] = widget_helper.get(); |
| 33 } | 33 } |
| 34 | 34 |
| 35 } // namespace | 35 } // namespace |
| 36 | 36 |
| 37 // A helper used with DidReceiveBackingStoreMsg that we hold a pointer to in | 37 // A helper used with DidReceiveBackingStoreMsg that we hold a pointer to in |
| 38 // pending_paints_. | 38 // pending_paints_. |
| 39 class RenderWidgetHelper::BackingStoreMsgProxy { | 39 class RenderWidgetHelper::BackingStoreMsgProxy { |
| (...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 78 : render_process_id_(-1), | 78 : render_process_id_(-1), |
| 79 #if defined(OS_WIN) | 79 #if defined(OS_WIN) |
| 80 event_(CreateEvent(NULL, FALSE /* auto-reset */, FALSE, NULL)), | 80 event_(CreateEvent(NULL, FALSE /* auto-reset */, FALSE, NULL)), |
| 81 #elif defined(OS_POSIX) | 81 #elif defined(OS_POSIX) |
| 82 event_(false /* auto-reset */, false), | 82 event_(false /* auto-reset */, false), |
| 83 #endif | 83 #endif |
| 84 resource_dispatcher_host_(NULL) { | 84 resource_dispatcher_host_(NULL) { |
| 85 } | 85 } |
| 86 | 86 |
| 87 RenderWidgetHelper::~RenderWidgetHelper() { | 87 RenderWidgetHelper::~RenderWidgetHelper() { |
| 88 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); | 88 DCHECK_CURRENTLY_ON(BrowserThread::IO); |
| 89 | 89 |
| 90 // Delete this RWH from the map if it is found. | 90 // Delete this RWH from the map if it is found. |
| 91 WidgetHelperMap& widget_map = g_widget_helpers.Get(); | 91 WidgetHelperMap& widget_map = g_widget_helpers.Get(); |
| 92 WidgetHelperMap::iterator it = widget_map.find(render_process_id_); | 92 WidgetHelperMap::iterator it = widget_map.find(render_process_id_); |
| 93 if (it != widget_map.end() && it->second == this) | 93 if (it != widget_map.end() && it->second == this) |
| 94 widget_map.erase(it); | 94 widget_map.erase(it); |
| 95 | 95 |
| 96 // The elements of pending_paints_ each hold an owning reference back to this | 96 // The elements of pending_paints_ each hold an owning reference back to this |
| 97 // object, so we should not be destroyed unless pending_paints_ is empty! | 97 // object, so we should not be destroyed unless pending_paints_ is empty! |
| 98 DCHECK(pending_paints_.empty()); | 98 DCHECK(pending_paints_.empty()); |
| (...skipping 15 matching lines...) Expand all Loading... |
| 114 render_process_id_, make_scoped_refptr(this))); | 114 render_process_id_, make_scoped_refptr(this))); |
| 115 } | 115 } |
| 116 | 116 |
| 117 int RenderWidgetHelper::GetNextRoutingID() { | 117 int RenderWidgetHelper::GetNextRoutingID() { |
| 118 return next_routing_id_.GetNext() + 1; | 118 return next_routing_id_.GetNext() + 1; |
| 119 } | 119 } |
| 120 | 120 |
| 121 // static | 121 // static |
| 122 RenderWidgetHelper* RenderWidgetHelper::FromProcessHostID( | 122 RenderWidgetHelper* RenderWidgetHelper::FromProcessHostID( |
| 123 int render_process_host_id) { | 123 int render_process_host_id) { |
| 124 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); | 124 DCHECK_CURRENTLY_ON(BrowserThread::IO); |
| 125 WidgetHelperMap::const_iterator ci = g_widget_helpers.Get().find( | 125 WidgetHelperMap::const_iterator ci = g_widget_helpers.Get().find( |
| 126 render_process_host_id); | 126 render_process_host_id); |
| 127 return (ci == g_widget_helpers.Get().end())? NULL : ci->second; | 127 return (ci == g_widget_helpers.Get().end())? NULL : ci->second; |
| 128 } | 128 } |
| 129 | 129 |
| 130 void RenderWidgetHelper::ResumeDeferredNavigation( | 130 void RenderWidgetHelper::ResumeDeferredNavigation( |
| 131 const GlobalRequestID& request_id) { | 131 const GlobalRequestID& request_id) { |
| 132 BrowserThread::PostTask( | 132 BrowserThread::PostTask( |
| 133 BrowserThread::IO, FROM_HERE, | 133 BrowserThread::IO, FROM_HERE, |
| 134 base::Bind(&RenderWidgetHelper::OnResumeDeferredNavigation, | 134 base::Bind(&RenderWidgetHelper::OnResumeDeferredNavigation, |
| (...skipping 259 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 394 i = allocated_dibs_.begin(); i != allocated_dibs_.end(); ++i) { | 394 i = allocated_dibs_.begin(); i != allocated_dibs_.end(); ++i) { |
| 395 if (IGNORE_EINTR(close(i->second)) < 0) | 395 if (IGNORE_EINTR(close(i->second)) < 0) |
| 396 PLOG(ERROR) << "close: " << i->first; | 396 PLOG(ERROR) << "close: " << i->first; |
| 397 } | 397 } |
| 398 | 398 |
| 399 allocated_dibs_.clear(); | 399 allocated_dibs_.clear(); |
| 400 } | 400 } |
| 401 #endif | 401 #endif |
| 402 | 402 |
| 403 } // namespace content | 403 } // namespace content |
| OLD | NEW |