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

Side by Side Diff: content/browser/loader/render_view_host_tracker.cc

Issue 12600018: ResourceScheduler should use renderer notifications instead of MRUCache to track renderers. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Switch to RenderViewHostObserver Created 7 years, 9 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
(Empty)
1 // Copyright (c) 2013 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4
5 #include "content/browser/loader/render_view_host_tracker.h"
6
7 #include "base/bind_helpers.h"
8 #include "base/stl_util.h"
9 #include "content/browser/loader/resource_dispatcher_host_impl.h"
10 #include "content/browser/loader/resource_scheduler.h"
11 #include "content/public/browser/browser_thread.h"
12 #include "content/public/browser/notification_service.h"
13 #include "content/public/browser/notification_types.h"
14 #include "content/public/browser/render_process_host.h"
15 #include "content/public/browser/render_view_host.h"
16
17 namespace content {
18
19 RenderViewHostTracker::RenderViewHostTracker() {
20 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
21 registrar_.Add(this, NOTIFICATION_RENDER_VIEW_HOST_CREATED,
22 NotificationService::AllSources());
23 registrar_.Add(this, NOTIFICATION_RENDER_VIEW_HOST_DELETED,
darin (slow to review) 2013/03/15 23:59:25 is this still needed?
24 NotificationService::AllSources());
25 }
26
27 RenderViewHostTracker::~RenderViewHostTracker() {
28 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
29 DCHECK(observers_.empty());
30 }
31
32 void RenderViewHostTracker::Observe(
33 int type,
34 const NotificationSource& source,
35 const NotificationDetails& details) {
36 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
37 RenderViewHost* rvh = content::Source<RenderViewHost>(source).ptr();
38 int child_id = rvh->GetProcess()->GetID();
39 int route_id = rvh->GetRoutingID();
40
41 switch (type) {
42 case NOTIFICATION_RENDER_VIEW_HOST_CREATED:
43 Observer* observer = new Observer(rvh, this);
44 observers_.insert(observer);
45 BrowserThread::PostTask(
46 BrowserThread::IO, FROM_HERE,
47 base::Bind(&ResourceDispatcherHostImpl::OnRenderViewHostCreated,
48 base::Unretained(ResourceDispatcherHostImpl::Get()),
49 child_id, route_id));
50 break;
51 }
52 }
53
54 void RenderViewHostTracker::RemoveObserver(Observer* observer) {
55 DCHECK(ContainsKey(observers_, observer));
56 observers_.erase(observer);
57 delete observer;
58 }
59
60 RenderViewHostTracker::Observer::Observer(RenderViewHost* rvh,
61 RenderViewHostTracker* tracker)
62 : RenderViewHostObserver(rvh),
63 tracker_(tracker) {
64 }
65
66 RenderViewHostTracker::Observer::~Observer() {
67 }
68
69 void RenderViewHostTracker::Observer::RenderViewHostDestroyed(
70 RenderViewHost* rvh) {
71 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
72 int child_id = rvh->GetProcess()->GetID();
73 int route_id = rvh->GetRoutingID();
74
75 BrowserThread::PostTask(
76 BrowserThread::IO, FROM_HERE,
77 base::Bind(&ResourceDispatcherHostImpl::OnRenderViewHostDeleted,
78 base::Unretained(ResourceDispatcherHostImpl::Get()),
79 child_id, route_id));
80
81 tracker_->RemoveObserver(this);
82 }
83
84 } // namespace content
OLDNEW
« no previous file with comments | « content/browser/loader/render_view_host_tracker.h ('k') | content/browser/loader/resource_dispatcher_host_impl.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698