OLD | NEW |
---|---|
(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/resource_scheduler_view_observer.h" | |
6 | |
7 #include "content/browser/loader/resource_dispatcher_host_impl.h" | |
8 #include "content/browser/loader/resource_scheduler.h" | |
9 #include "content/public/browser/browser_thread.h" | |
10 #include "content/public/browser/notification_service.h" | |
11 #include "content/public/browser/notification_types.h" | |
12 #include "content/public/browser/render_process_host.h" | |
13 #include "content/public/browser/render_view_host.h" | |
14 | |
15 namespace content { | |
16 | |
17 ResourceSchedulerViewObserver::ResourceSchedulerViewObserver() { | |
18 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | |
19 registrar_.Add(this, NOTIFICATION_RENDER_VIEW_HOST_CREATED, | |
20 NotificationService::AllSources()); | |
21 registrar_.Add(this, NOTIFICATION_RENDER_VIEW_HOST_DELETED, | |
22 NotificationService::AllSources()); | |
23 } | |
24 | |
25 ResourceSchedulerViewObserver::~ResourceSchedulerViewObserver() { | |
darin (slow to review)
2013/03/13 00:12:27
do we need to make sure that this class is destroy
| |
26 } | |
27 | |
28 void OnRenderViewHostCreated(int child_id, int route_id) { | |
darin (slow to review)
2013/03/13 00:12:27
nit: these methods should be static or in an anon
| |
29 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); | |
30 ResourceDispatcherHostImpl::Get()->scheduler()->OnClientCreated( | |
31 child_id, route_id); | |
32 } | |
33 | |
34 void OnRenderViewHostDestroyed(int child_id, int route_id) { | |
35 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); | |
36 ResourceDispatcherHostImpl::Get()->scheduler()->OnClientDestroyed( | |
37 child_id, route_id); | |
38 } | |
39 | |
40 void ResourceSchedulerViewObserver::Observe( | |
41 int type, | |
42 const NotificationSource& source, | |
43 const NotificationDetails& details) { | |
44 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | |
45 RenderViewHost* rvh = content::Source<RenderViewHost>(source).ptr(); | |
46 int child_id = rvh->GetProcess()->GetID(); | |
47 int route_id = rvh->GetRoutingID(); | |
48 | |
49 switch (type) { | |
50 case NOTIFICATION_RENDER_VIEW_HOST_CREATED: | |
51 BrowserThread::PostTask( | |
52 BrowserThread::IO, FROM_HERE, | |
53 base::Bind(&OnRenderViewHostCreated, child_id, route_id)); | |
54 break; | |
55 | |
56 case NOTIFICATION_RENDER_VIEW_HOST_DELETED: | |
57 BrowserThread::PostTask( | |
58 BrowserThread::IO, FROM_HERE, | |
59 base::Bind(&OnRenderViewHostDestroyed, child_id, route_id)); | |
60 break; | |
61 } | |
62 } | |
63 | |
64 } // namespace content | |
OLD | NEW |