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/printing/background_printing_manager.h" | 5 #include "chrome/browser/printing/background_printing_manager.h" |
6 | 6 |
7 #include "chrome/browser/printing/print_job.h" | 7 #include "chrome/browser/printing/print_job.h" |
8 #include "chrome/browser/printing/print_preview_tab_controller.h" | 8 #include "chrome/browser/printing/print_preview_tab_controller.h" |
9 #include "chrome/browser/sessions/restore_tab_helper.h" | 9 #include "chrome/browser/sessions/restore_tab_helper.h" |
10 #include "chrome/browser/tabs/tab_strip_model.h" | 10 #include "chrome/browser/tabs/tab_strip_model.h" |
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
51 content::Source<TabContents>(preview_contents))) { | 51 content::Source<TabContents>(preview_contents))) { |
52 registrar_.Add(this, content::NOTIFICATION_TAB_CONTENTS_DESTROYED, | 52 registrar_.Add(this, content::NOTIFICATION_TAB_CONTENTS_DESTROYED, |
53 content::Source<TabContents>(preview_contents)); | 53 content::Source<TabContents>(preview_contents)); |
54 } | 54 } |
55 | 55 |
56 // If a tab that is printing crashes, the user cannot destroy it since it is | 56 // If a tab that is printing crashes, the user cannot destroy it since it is |
57 // not in any tab strip. Thus listen for crashes here and delete the tab. | 57 // not in any tab strip. Thus listen for crashes here and delete the tab. |
58 // | 58 // |
59 // Multiple sites may share the same RenderProcessHost, so check if this | 59 // Multiple sites may share the same RenderProcessHost, so check if this |
60 // notification has already been added. | 60 // notification has already been added. |
61 RenderProcessHost* rph = preview_tab->render_view_host()->process(); | 61 content::RenderProcessHost* rph = preview_tab->render_view_host()->process(); |
62 if (!registrar_.IsRegistered(this, | 62 if (!registrar_.IsRegistered(this, |
63 content::NOTIFICATION_RENDERER_PROCESS_CLOSED, | 63 content::NOTIFICATION_RENDERER_PROCESS_CLOSED, |
64 content::Source<RenderProcessHost>(rph))) { | 64 content::Source<content::RenderProcessHost>( |
| 65 rph))) { |
65 registrar_.Add(this, content::NOTIFICATION_RENDERER_PROCESS_CLOSED, | 66 registrar_.Add(this, content::NOTIFICATION_RENDERER_PROCESS_CLOSED, |
66 content::Source<RenderProcessHost>(rph)); | 67 content::Source<content::RenderProcessHost>(rph)); |
67 } | 68 } |
68 | 69 |
69 // Activate the initiator tab. | 70 // Activate the initiator tab. |
70 PrintPreviewTabController* tab_controller = | 71 PrintPreviewTabController* tab_controller = |
71 PrintPreviewTabController::GetInstance(); | 72 PrintPreviewTabController::GetInstance(); |
72 if (!tab_controller) | 73 if (!tab_controller) |
73 return; | 74 return; |
74 TabContentsWrapper* initiator_tab = | 75 TabContentsWrapper* initiator_tab = |
75 tab_controller->GetInitiatorTab(preview_tab); | 76 tab_controller->GetInitiatorTab(preview_tab); |
76 if (!initiator_tab) | 77 if (!initiator_tab) |
77 return; | 78 return; |
78 static_cast<RenderViewHostDelegate*>( | 79 static_cast<RenderViewHostDelegate*>( |
79 initiator_tab->tab_contents())->Activate(); | 80 initiator_tab->tab_contents())->Activate(); |
80 } | 81 } |
81 | 82 |
82 void BackgroundPrintingManager::Observe( | 83 void BackgroundPrintingManager::Observe( |
83 int type, | 84 int type, |
84 const content::NotificationSource& source, | 85 const content::NotificationSource& source, |
85 const content::NotificationDetails& details) { | 86 const content::NotificationDetails& details) { |
86 switch (type) { | 87 switch (type) { |
87 case content::NOTIFICATION_RENDERER_PROCESS_CLOSED: { | 88 case content::NOTIFICATION_RENDERER_PROCESS_CLOSED: { |
88 OnRendererProcessClosed(content::Source<RenderProcessHost>(source).ptr()); | 89 OnRendererProcessClosed( |
| 90 content::Source<content::RenderProcessHost>(source).ptr()); |
89 break; | 91 break; |
90 } | 92 } |
91 case chrome::NOTIFICATION_PRINT_JOB_RELEASED: { | 93 case chrome::NOTIFICATION_PRINT_JOB_RELEASED: { |
92 OnPrintJobReleased(content::Source<TabContentsWrapper>(source).ptr()); | 94 OnPrintJobReleased(content::Source<TabContentsWrapper>(source).ptr()); |
93 break; | 95 break; |
94 } | 96 } |
95 case content::NOTIFICATION_TAB_CONTENTS_DESTROYED: { | 97 case content::NOTIFICATION_TAB_CONTENTS_DESTROYED: { |
96 OnTabContentsDestroyed( | 98 OnTabContentsDestroyed( |
97 TabContentsWrapper::GetCurrentWrapperForContents( | 99 TabContentsWrapper::GetCurrentWrapperForContents( |
98 content::Source<TabContents>(source).ptr())); | 100 content::Source<TabContents>(source).ptr())); |
99 break; | 101 break; |
100 } | 102 } |
101 default: { | 103 default: { |
102 NOTREACHED(); | 104 NOTREACHED(); |
103 break; | 105 break; |
104 } | 106 } |
105 } | 107 } |
106 } | 108 } |
107 | 109 |
108 void BackgroundPrintingManager::OnRendererProcessClosed( | 110 void BackgroundPrintingManager::OnRendererProcessClosed( |
109 RenderProcessHost* rph) { | 111 content::RenderProcessHost* rph) { |
110 TabContentsWrapperSet preview_tabs_pending_deletion; | 112 TabContentsWrapperSet preview_tabs_pending_deletion; |
111 TabContentsWrapperSet::const_iterator it; | 113 TabContentsWrapperSet::const_iterator it; |
112 for (it = begin(); it != end(); ++it) { | 114 for (it = begin(); it != end(); ++it) { |
113 TabContentsWrapper* preview_tab = *it; | 115 TabContentsWrapper* preview_tab = *it; |
114 if (preview_tab->render_view_host()->process() == rph) { | 116 if (preview_tab->render_view_host()->process() == rph) { |
115 preview_tabs_pending_deletion.insert(preview_tab); | 117 preview_tabs_pending_deletion.insert(preview_tab); |
116 } | 118 } |
117 } | 119 } |
118 for (it = preview_tabs_pending_deletion.begin(); | 120 for (it = preview_tabs_pending_deletion.begin(); |
119 it != preview_tabs_pending_deletion.end(); | 121 it != preview_tabs_pending_deletion.end(); |
(...skipping 16 matching lines...) Expand all Loading... |
136 if (!HasPrintPreviewTab(preview_tab)) { | 138 if (!HasPrintPreviewTab(preview_tab)) { |
137 NOTREACHED(); | 139 NOTREACHED(); |
138 return; | 140 return; |
139 } | 141 } |
140 | 142 |
141 // Remove NOTIFICATION_RENDERER_PROCESS_CLOSED if |preview_tab| is the last | 143 // Remove NOTIFICATION_RENDERER_PROCESS_CLOSED if |preview_tab| is the last |
142 // TabContents associated with |rph|. | 144 // TabContents associated with |rph|. |
143 bool shared_rph = HasSharedRenderProcessHost(printing_tabs_, preview_tab) || | 145 bool shared_rph = HasSharedRenderProcessHost(printing_tabs_, preview_tab) || |
144 HasSharedRenderProcessHost(printing_tabs_pending_deletion_, preview_tab); | 146 HasSharedRenderProcessHost(printing_tabs_pending_deletion_, preview_tab); |
145 if (!shared_rph) { | 147 if (!shared_rph) { |
146 RenderProcessHost* rph = preview_tab->render_view_host()->process(); | 148 content::RenderProcessHost* rph = |
| 149 preview_tab->render_view_host()->process(); |
147 registrar_.Remove(this, content::NOTIFICATION_RENDERER_PROCESS_CLOSED, | 150 registrar_.Remove(this, content::NOTIFICATION_RENDERER_PROCESS_CLOSED, |
148 content::Source<RenderProcessHost>(rph)); | 151 content::Source<content::RenderProcessHost>(rph)); |
149 } | 152 } |
150 | 153 |
151 // Remove other notifications and remove the tab from its | 154 // Remove other notifications and remove the tab from its |
152 // TabContentsWrapperSet. | 155 // TabContentsWrapperSet. |
153 if (printing_tabs_.find(preview_tab) != printing_tabs_.end()) { | 156 if (printing_tabs_.find(preview_tab) != printing_tabs_.end()) { |
154 registrar_.Remove(this, chrome::NOTIFICATION_PRINT_JOB_RELEASED, | 157 registrar_.Remove(this, chrome::NOTIFICATION_PRINT_JOB_RELEASED, |
155 content::Source<TabContentsWrapper>(preview_tab)); | 158 content::Source<TabContentsWrapper>(preview_tab)); |
156 printing_tabs_.erase(preview_tab); | 159 printing_tabs_.erase(preview_tab); |
157 } else { | 160 } else { |
158 // DeletePreviewTab already deleted the notification. | 161 // DeletePreviewTab already deleted the notification. |
159 printing_tabs_pending_deletion_.erase(preview_tab); | 162 printing_tabs_pending_deletion_.erase(preview_tab); |
160 } | 163 } |
161 } | 164 } |
162 | 165 |
163 void BackgroundPrintingManager::DeletePreviewTab(TabContentsWrapper* tab) { | 166 void BackgroundPrintingManager::DeletePreviewTab(TabContentsWrapper* tab) { |
164 registrar_.Remove(this, chrome::NOTIFICATION_PRINT_JOB_RELEASED, | 167 registrar_.Remove(this, chrome::NOTIFICATION_PRINT_JOB_RELEASED, |
165 content::Source<TabContentsWrapper>(tab)); | 168 content::Source<TabContentsWrapper>(tab)); |
166 printing_tabs_.erase(tab); | 169 printing_tabs_.erase(tab); |
167 printing_tabs_pending_deletion_.insert(tab); | 170 printing_tabs_pending_deletion_.insert(tab); |
168 MessageLoop::current()->DeleteSoon(FROM_HERE, tab); | 171 MessageLoop::current()->DeleteSoon(FROM_HERE, tab); |
169 } | 172 } |
170 | 173 |
171 bool BackgroundPrintingManager::HasSharedRenderProcessHost( | 174 bool BackgroundPrintingManager::HasSharedRenderProcessHost( |
172 const TabContentsWrapperSet& set, | 175 const TabContentsWrapperSet& set, |
173 TabContentsWrapper* tab) { | 176 TabContentsWrapper* tab) { |
174 RenderProcessHost* rph = tab->render_view_host()->process(); | 177 content::RenderProcessHost* rph = tab->render_view_host()->process(); |
175 for (TabContentsWrapperSet::const_iterator it = set.begin(); | 178 for (TabContentsWrapperSet::const_iterator it = set.begin(); |
176 it != set.end(); | 179 it != set.end(); |
177 ++it) { | 180 ++it) { |
178 TabContentsWrapper* iter_tab = *it; | 181 TabContentsWrapper* iter_tab = *it; |
179 if ((iter_tab != tab) && | 182 if ((iter_tab != tab) && |
180 (iter_tab->render_view_host()->process() == rph)) { | 183 (iter_tab->render_view_host()->process() == rph)) { |
181 return true; | 184 return true; |
182 } | 185 } |
183 } | 186 } |
184 return false; | 187 return false; |
(...skipping 11 matching lines...) Expand all Loading... |
196 | 199 |
197 bool BackgroundPrintingManager::HasPrintPreviewTab( | 200 bool BackgroundPrintingManager::HasPrintPreviewTab( |
198 TabContentsWrapper* preview_tab) { | 201 TabContentsWrapper* preview_tab) { |
199 if (printing_tabs_.find(preview_tab) != printing_tabs_.end()) | 202 if (printing_tabs_.find(preview_tab) != printing_tabs_.end()) |
200 return true; | 203 return true; |
201 return printing_tabs_pending_deletion_.find(preview_tab) != | 204 return printing_tabs_pending_deletion_.find(preview_tab) != |
202 printing_tabs_pending_deletion_.end(); | 205 printing_tabs_pending_deletion_.end(); |
203 } | 206 } |
204 | 207 |
205 } // namespace printing | 208 } // namespace printing |
OLD | NEW |