OLD | NEW |
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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/extensions/extension_tab_id_map.h" | 5 #include "chrome/browser/extensions/extension_tab_id_map.h" |
6 | 6 |
7 #include "chrome/browser/sessions/restore_tab_helper.h" | 7 #include "chrome/browser/sessions/restore_tab_helper.h" |
8 #include "chrome/browser/ui/tab_contents/tab_contents_wrapper.h" | 8 #include "chrome/browser/ui/tab_contents/tab_contents_wrapper.h" |
9 #include "content/browser/browser_thread.h" | 9 #include "content/browser/browser_thread.h" |
10 #include "content/browser/tab_contents/tab_contents.h" | 10 #include "content/browser/tab_contents/tab_contents.h" |
(...skipping 13 matching lines...) Expand all Loading... |
24 // This class listens for notifications about new and closed tabs on the UI | 24 // This class listens for notifications about new and closed tabs on the UI |
25 // thread, and notifies the ExtensionTabIdMap on the IO thread. It should only | 25 // thread, and notifies the ExtensionTabIdMap on the IO thread. It should only |
26 // ever be accessed on the UI thread. | 26 // ever be accessed on the UI thread. |
27 class ExtensionTabIdMap::TabObserver : public NotificationObserver { | 27 class ExtensionTabIdMap::TabObserver : public NotificationObserver { |
28 public: | 28 public: |
29 TabObserver(); | 29 TabObserver(); |
30 ~TabObserver(); | 30 ~TabObserver(); |
31 | 31 |
32 private: | 32 private: |
33 // NotificationObserver interface. | 33 // NotificationObserver interface. |
34 virtual void Observe(NotificationType type, | 34 virtual void Observe(int type, |
35 const NotificationSource& source, | 35 const NotificationSource& source, |
36 const NotificationDetails& details); | 36 const NotificationDetails& details); |
37 | 37 |
38 NotificationRegistrar registrar_; | 38 NotificationRegistrar registrar_; |
39 }; | 39 }; |
40 | 40 |
41 ExtensionTabIdMap::TabObserver::TabObserver() { | 41 ExtensionTabIdMap::TabObserver::TabObserver() { |
42 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 42 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
43 registrar_.Add(this, NotificationType::RENDER_VIEW_HOST_CREATED_FOR_TAB, | 43 registrar_.Add(this, content::NOTIFICATION_RENDER_VIEW_HOST_CREATED_FOR_TAB, |
44 NotificationService::AllSources()); | 44 NotificationService::AllSources()); |
45 registrar_.Add(this, NotificationType::RENDER_VIEW_HOST_DELETED, | 45 registrar_.Add(this, content::NOTIFICATION_RENDER_VIEW_HOST_DELETED, |
46 NotificationService::AllSources()); | 46 NotificationService::AllSources()); |
47 registrar_.Add(this, NotificationType::TAB_PARENTED, | 47 registrar_.Add(this, content::NOTIFICATION_TAB_PARENTED, |
48 NotificationService::AllSources()); | 48 NotificationService::AllSources()); |
49 } | 49 } |
50 | 50 |
51 ExtensionTabIdMap::TabObserver::~TabObserver() { | 51 ExtensionTabIdMap::TabObserver::~TabObserver() { |
52 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 52 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
53 } | 53 } |
54 | 54 |
55 void ExtensionTabIdMap::TabObserver::Observe( | 55 void ExtensionTabIdMap::TabObserver::Observe( |
56 NotificationType type, const NotificationSource& source, | 56 int type, const NotificationSource& source, |
57 const NotificationDetails& details) { | 57 const NotificationDetails& details) { |
58 switch (type.value) { | 58 switch (type) { |
59 case NotificationType::RENDER_VIEW_HOST_CREATED_FOR_TAB: { | 59 case content::NOTIFICATION_RENDER_VIEW_HOST_CREATED_FOR_TAB: { |
60 TabContents* contents = Source<TabContents>(source).ptr(); | 60 TabContents* contents = Source<TabContents>(source).ptr(); |
61 TabContentsWrapper* tab = | 61 TabContentsWrapper* tab = |
62 TabContentsWrapper::GetCurrentWrapperForContents(contents); | 62 TabContentsWrapper::GetCurrentWrapperForContents(contents); |
63 if (!tab) | 63 if (!tab) |
64 break; | 64 break; |
65 RenderViewHost* host = Details<RenderViewHost>(details).ptr(); | 65 RenderViewHost* host = Details<RenderViewHost>(details).ptr(); |
66 // TODO(mpcmoplete): How can we tell if window_id is bogus? It may not | 66 // TODO(mpcmoplete): How can we tell if window_id is bogus? It may not |
67 // have been set yet. | 67 // have been set yet. |
68 BrowserThread::PostTask( | 68 BrowserThread::PostTask( |
69 BrowserThread::IO, FROM_HERE, | 69 BrowserThread::IO, FROM_HERE, |
70 NewRunnableMethod( | 70 NewRunnableMethod( |
71 ExtensionTabIdMap::GetInstance(), | 71 ExtensionTabIdMap::GetInstance(), |
72 &ExtensionTabIdMap::SetTabAndWindowId, | 72 &ExtensionTabIdMap::SetTabAndWindowId, |
73 host->process()->id(), host->routing_id(), | 73 host->process()->id(), host->routing_id(), |
74 tab->restore_tab_helper()->session_id().id(), | 74 tab->restore_tab_helper()->session_id().id(), |
75 tab->restore_tab_helper()->window_id().id())); | 75 tab->restore_tab_helper()->window_id().id())); |
76 break; | 76 break; |
77 } | 77 } |
78 case NotificationType::TAB_PARENTED: { | 78 case content::NOTIFICATION_TAB_PARENTED: { |
79 TabContentsWrapper* tab = Source<TabContentsWrapper>(source).ptr(); | 79 TabContentsWrapper* tab = Source<TabContentsWrapper>(source).ptr(); |
80 RenderViewHost* host = tab->render_view_host(); | 80 RenderViewHost* host = tab->render_view_host(); |
81 BrowserThread::PostTask( | 81 BrowserThread::PostTask( |
82 BrowserThread::IO, FROM_HERE, | 82 BrowserThread::IO, FROM_HERE, |
83 NewRunnableMethod( | 83 NewRunnableMethod( |
84 ExtensionTabIdMap::GetInstance(), | 84 ExtensionTabIdMap::GetInstance(), |
85 &ExtensionTabIdMap::SetTabAndWindowId, | 85 &ExtensionTabIdMap::SetTabAndWindowId, |
86 host->process()->id(), host->routing_id(), | 86 host->process()->id(), host->routing_id(), |
87 tab->restore_tab_helper()->session_id().id(), | 87 tab->restore_tab_helper()->session_id().id(), |
88 tab->restore_tab_helper()->window_id().id())); | 88 tab->restore_tab_helper()->window_id().id())); |
89 break; | 89 break; |
90 } | 90 } |
91 case NotificationType::RENDER_VIEW_HOST_DELETED: { | 91 case content::NOTIFICATION_RENDER_VIEW_HOST_DELETED: { |
92 RenderViewHost* host = Source<RenderViewHost>(source).ptr(); | 92 RenderViewHost* host = Source<RenderViewHost>(source).ptr(); |
93 BrowserThread::PostTask( | 93 BrowserThread::PostTask( |
94 BrowserThread::IO, FROM_HERE, | 94 BrowserThread::IO, FROM_HERE, |
95 NewRunnableMethod( | 95 NewRunnableMethod( |
96 ExtensionTabIdMap::GetInstance(), | 96 ExtensionTabIdMap::GetInstance(), |
97 &ExtensionTabIdMap::ClearTabAndWindowId, | 97 &ExtensionTabIdMap::ClearTabAndWindowId, |
98 host->process()->id(), host->routing_id())); | 98 host->process()->id(), host->routing_id())); |
99 break; | 99 break; |
100 } | 100 } |
101 default: | 101 default: |
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
146 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); | 146 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); |
147 RenderId render_id(render_process_host_id, routing_id); | 147 RenderId render_id(render_process_host_id, routing_id); |
148 TabAndWindowIdMap::iterator iter = map_.find(render_id); | 148 TabAndWindowIdMap::iterator iter = map_.find(render_id); |
149 if (iter != map_.end()) { | 149 if (iter != map_.end()) { |
150 *tab_id = iter->second.first; | 150 *tab_id = iter->second.first; |
151 *window_id = iter->second.second; | 151 *window_id = iter->second.second; |
152 return true; | 152 return true; |
153 } | 153 } |
154 return false; | 154 return false; |
155 } | 155 } |
OLD | NEW |