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

Side by Side Diff: content/browser/renderer_host/render_widget_host_impl.cc

Issue 16431010: Refactor RenderProcessHost to use IPC::Listener instead of RenderWidgetHost (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Rebase on top of hash_pair move. Created 7 years, 6 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
OLDNEW
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_host_impl.h" 5 #include "content/browser/renderer_host/render_widget_host_impl.h"
6 6
7 #include <math.h> 7 #include <math.h>
8 #include <utility> 8 #include <utility>
9 9
10 #include "base/auto_reset.h" 10 #include "base/auto_reset.h"
11 #include "base/bind.h" 11 #include "base/bind.h"
12 #include "base/command_line.h" 12 #include "base/command_line.h"
13 #include "base/containers/hash_tables.h"
13 #include "base/debug/trace_event.h" 14 #include "base/debug/trace_event.h"
14 #include "base/i18n/rtl.h" 15 #include "base/i18n/rtl.h"
15 #include "base/lazy_instance.h" 16 #include "base/lazy_instance.h"
16 #include "base/message_loop.h" 17 #include "base/message_loop.h"
17 #include "base/metrics/field_trial.h" 18 #include "base/metrics/field_trial.h"
18 #include "base/metrics/histogram.h" 19 #include "base/metrics/histogram.h"
19 #include "base/strings/string_number_conversions.h" 20 #include "base/strings/string_number_conversions.h"
20 #include "base/strings/utf_string_conversions.h" 21 #include "base/strings/utf_string_conversions.h"
21 #include "cc/output/compositor_frame.h" 22 #include "cc/output/compositor_frame.h"
22 #include "cc/output/compositor_frame_ack.h" 23 #include "cc/output/compositor_frame_ack.h"
(...skipping 87 matching lines...) Expand 10 before | Expand all | Expand 10 after
110 return 1.f; 111 return 1.f;
111 return unaccelerated_delta / accelerated_delta; 112 return unaccelerated_delta / accelerated_delta;
112 } 113 }
113 114
114 base::LazyInstance<std::vector<RenderWidgetHost::CreatedCallback> > 115 base::LazyInstance<std::vector<RenderWidgetHost::CreatedCallback> >
115 g_created_callbacks = LAZY_INSTANCE_INITIALIZER; 116 g_created_callbacks = LAZY_INSTANCE_INITIALIZER;
116 117
117 } // namespace 118 } // namespace
118 119
119 120
121 typedef std::pair<int32, int32> RenderWidgetHostID;
122 typedef base::hash_map<RenderWidgetHostID, RenderWidgetHostImpl*>
123 RoutingIDWidgetMap;
124 static base::LazyInstance<RoutingIDWidgetMap> g_routing_id_widget_map =
125 LAZY_INSTANCE_INITIALIZER;
126
120 // static 127 // static
121 void RenderWidgetHost::RemoveAllBackingStores() { 128 void RenderWidgetHost::RemoveAllBackingStores() {
122 BackingStoreManager::RemoveAllBackingStores(); 129 BackingStoreManager::RemoveAllBackingStores();
123 } 130 }
124 131
125 // static 132 // static
126 size_t RenderWidgetHost::BackingStoreMemorySize() { 133 size_t RenderWidgetHost::BackingStoreMemorySize() {
127 return BackingStoreManager::MemorySize(); 134 return BackingStoreManager::MemorySize();
128 } 135 }
129 136
(...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after
189 // problem, for example by tracking in the RenderWidgetHelper the routing id 196 // problem, for example by tracking in the RenderWidgetHelper the routing id
190 // (and surface id) that have been created, but whose RWH haven't yet. 197 // (and surface id) that have been created, but whose RWH haven't yet.
191 surface_id_ = GpuSurfaceTracker::Get()->LookupSurfaceForRenderer( 198 surface_id_ = GpuSurfaceTracker::Get()->LookupSurfaceForRenderer(
192 process_->GetID(), 199 process_->GetID(),
193 routing_id_); 200 routing_id_);
194 DCHECK(surface_id_); 201 DCHECK(surface_id_);
195 } 202 }
196 203
197 is_threaded_compositing_enabled_ = IsThreadedCompositingEnabled(); 204 is_threaded_compositing_enabled_ = IsThreadedCompositingEnabled();
198 205
199 process_->Attach(this, routing_id_); 206 g_routing_id_widget_map.Get().insert(std::make_pair(
207 RenderWidgetHostID(process->GetID(), routing_id_), this));
208 process_->AddRoute(routing_id_, this);
200 // Because the widget initializes as is_hidden_ == false, 209 // Because the widget initializes as is_hidden_ == false,
201 // tell the process host that we're alive. 210 // tell the process host that we're alive.
202 process_->WidgetRestored(); 211 process_->WidgetRestored();
203 212
204 accessibility_mode_ = 213 accessibility_mode_ =
205 BrowserAccessibilityStateImpl::GetInstance()->accessibility_mode(); 214 BrowserAccessibilityStateImpl::GetInstance()->accessibility_mode();
206 215
207 for (size_t i = 0; i < g_created_callbacks.Get().size(); i++) 216 for (size_t i = 0; i < g_created_callbacks.Get().size(); i++)
208 g_created_callbacks.Get().at(i).Run(this); 217 g_created_callbacks.Get().at(i).Run(this);
209 218
210 #if defined(USE_AURA) 219 #if defined(USE_AURA)
211 bool overscroll_enabled = CommandLine::ForCurrentProcess()-> 220 bool overscroll_enabled = CommandLine::ForCurrentProcess()->
212 GetSwitchValueASCII(switches::kOverscrollHistoryNavigation) != "0"; 221 GetSwitchValueASCII(switches::kOverscrollHistoryNavigation) != "0";
213 SetOverscrollControllerEnabled(overscroll_enabled); 222 SetOverscrollControllerEnabled(overscroll_enabled);
214 #endif 223 #endif
215 } 224 }
216 225
217 RenderWidgetHostImpl::~RenderWidgetHostImpl() { 226 RenderWidgetHostImpl::~RenderWidgetHostImpl() {
218 SetView(NULL); 227 SetView(NULL);
219 228
220 // Clear our current or cached backing store if either remains. 229 // Clear our current or cached backing store if either remains.
221 BackingStoreManager::RemoveBackingStore(this); 230 BackingStoreManager::RemoveBackingStore(this);
222 231
223 GpuSurfaceTracker::Get()->RemoveSurface(surface_id_); 232 GpuSurfaceTracker::Get()->RemoveSurface(surface_id_);
224 surface_id_ = 0; 233 surface_id_ = 0;
225 234
226 process_->Release(routing_id_); 235 process_->RemoveRoute(routing_id_);
236 g_routing_id_widget_map.Get().erase(
237 RenderWidgetHostID(process_->GetID(), routing_id_));
227 238
228 if (delegate_) 239 if (delegate_)
229 delegate_->RenderWidgetDeleted(this); 240 delegate_->RenderWidgetDeleted(this);
230 } 241 }
231 242
232 // static 243 // static
244 RenderWidgetHost* RenderWidgetHost::FromID(
245 int32 process_id,
246 int32 routing_id) {
247 return RenderWidgetHostImpl::FromID(process_id, routing_id);
248 }
249
250 // static
251 RenderWidgetHostImpl* RenderWidgetHostImpl::FromID(
252 int32 process_id,
253 int32 routing_id) {
254 RoutingIDWidgetMap* widgets = g_routing_id_widget_map.Pointer();
255 RoutingIDWidgetMap::iterator it = widgets->find(
256 RenderWidgetHostID(process_id, routing_id));
257 return it == widgets->end() ? NULL : it->second;
258 }
259
260 // static
261 std::vector<RenderWidgetHost*> RenderWidgetHost::GetRenderWidgetHosts() {
262 std::vector<RenderWidgetHost*> hosts;
263 RoutingIDWidgetMap* widgets = g_routing_id_widget_map.Pointer();
264 for (RoutingIDWidgetMap::const_iterator it = widgets->begin();
265 it != widgets->end();
266 ++it) {
267 hosts.push_back(it->second);
268 }
269 return hosts;
270 }
271
272 // static
233 RenderWidgetHostImpl* RenderWidgetHostImpl::From(RenderWidgetHost* rwh) { 273 RenderWidgetHostImpl* RenderWidgetHostImpl::From(RenderWidgetHost* rwh) {
234 return rwh->AsRenderWidgetHostImpl(); 274 return rwh->AsRenderWidgetHostImpl();
235 } 275 }
236 276
237 // static 277 // static
238 void RenderWidgetHost::AddCreatedCallback(const CreatedCallback& callback) { 278 void RenderWidgetHost::AddCreatedCallback(const CreatedCallback& callback) {
239 g_created_callbacks.Get().push_back(callback); 279 g_created_callbacks.Get().push_back(callback);
240 } 280 }
241 281
242 // static 282 // static
(...skipping 2304 matching lines...) Expand 10 before | Expand all | Expand 10 after
2547 const ui::LatencyInfo& latency_info) { 2587 const ui::LatencyInfo& latency_info) {
2548 for (ui::LatencyInfo::LatencyMap::const_iterator b = 2588 for (ui::LatencyInfo::LatencyMap::const_iterator b =
2549 latency_info.latency_components.begin(); 2589 latency_info.latency_components.begin();
2550 b != latency_info.latency_components.end(); 2590 b != latency_info.latency_components.end();
2551 ++b) { 2591 ++b) {
2552 if (b->first.first != ui::INPUT_EVENT_LATENCY_RWH_COMPONENT) 2592 if (b->first.first != ui::INPUT_EVENT_LATENCY_RWH_COMPONENT)
2553 continue; 2593 continue;
2554 // Matches with GetLatencyComponentId 2594 // Matches with GetLatencyComponentId
2555 int routing_id = b->first.second & 0xffffffff; 2595 int routing_id = b->first.second & 0xffffffff;
2556 int process_id = (b->first.second >> 32) & 0xffffffff; 2596 int process_id = (b->first.second >> 32) & 0xffffffff;
2557 RenderProcessHost* host = RenderProcessHost::FromID(process_id); 2597 RenderWidgetHost* rwh =
2558 if (!host) 2598 RenderWidgetHost::FromID(process_id, routing_id);
2559 continue;
2560 RenderWidgetHost* rwh = host->GetRenderWidgetHostByID(routing_id);
2561 if (!rwh) 2599 if (!rwh)
2562 continue; 2600 continue;
2563 RenderWidgetHostImpl::From(rwh)->FrameSwapped(latency_info); 2601 RenderWidgetHostImpl::From(rwh)->FrameSwapped(latency_info);
2564 } 2602 }
2565 } 2603 }
2566 2604
2567 } // namespace content 2605 } // namespace content
OLDNEW
« no previous file with comments | « content/browser/renderer_host/render_widget_host_impl.h ('k') | content/browser/worker_host/worker_service_impl.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698