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" |
11 #include "chrome/browser/ui/browser_list.h" | 11 #include "chrome/browser/ui/browser_list.h" |
12 #include "chrome/browser/ui/tab_contents/tab_contents_wrapper.h" | 12 #include "chrome/browser/ui/tab_contents/tab_contents_wrapper.h" |
13 #include "chrome/common/chrome_notification_types.h" | 13 #include "chrome/common/chrome_notification_types.h" |
14 #include "content/browser/renderer_host/render_view_host.h" | 14 #include "content/browser/renderer_host/render_view_host.h" |
| 15 #include "content/browser/tab_contents/tab_contents.h" |
15 #include "content/public/browser/browser_thread.h" | 16 #include "content/public/browser/browser_thread.h" |
16 #include "content/public/browser/notification_details.h" | 17 #include "content/public/browser/notification_details.h" |
17 #include "content/public/browser/notification_source.h" | 18 #include "content/public/browser/notification_source.h" |
18 | 19 |
19 using content::BrowserThread; | 20 using content::BrowserThread; |
20 | 21 |
21 namespace printing { | 22 namespace printing { |
22 | 23 |
23 BackgroundPrintingManager::BackgroundPrintingManager() { | 24 BackgroundPrintingManager::BackgroundPrintingManager() { |
24 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 25 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
(...skipping 26 matching lines...) Expand all Loading... |
51 content::Source<TabContents>(preview_contents))) { | 52 content::Source<TabContents>(preview_contents))) { |
52 registrar_.Add(this, content::NOTIFICATION_TAB_CONTENTS_DESTROYED, | 53 registrar_.Add(this, content::NOTIFICATION_TAB_CONTENTS_DESTROYED, |
53 content::Source<TabContents>(preview_contents)); | 54 content::Source<TabContents>(preview_contents)); |
54 } | 55 } |
55 | 56 |
56 // If a tab that is printing crashes, the user cannot destroy it since it is | 57 // 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. | 58 // not in any tab strip. Thus listen for crashes here and delete the tab. |
58 // | 59 // |
59 // Multiple sites may share the same RenderProcessHost, so check if this | 60 // Multiple sites may share the same RenderProcessHost, so check if this |
60 // notification has already been added. | 61 // notification has already been added. |
61 content::RenderProcessHost* rph = preview_tab->render_view_host()->process(); | 62 content::RenderProcessHost* rph = |
| 63 preview_tab->tab_contents()->render_view_host()->process(); |
62 if (!registrar_.IsRegistered(this, | 64 if (!registrar_.IsRegistered(this, |
63 content::NOTIFICATION_RENDERER_PROCESS_CLOSED, | 65 content::NOTIFICATION_RENDERER_PROCESS_CLOSED, |
64 content::Source<content::RenderProcessHost>( | 66 content::Source<content::RenderProcessHost>( |
65 rph))) { | 67 rph))) { |
66 registrar_.Add(this, content::NOTIFICATION_RENDERER_PROCESS_CLOSED, | 68 registrar_.Add(this, content::NOTIFICATION_RENDERER_PROCESS_CLOSED, |
67 content::Source<content::RenderProcessHost>(rph)); | 69 content::Source<content::RenderProcessHost>(rph)); |
68 } | 70 } |
69 | 71 |
70 // Activate the initiator tab. | 72 // Activate the initiator tab. |
71 PrintPreviewTabController* tab_controller = | 73 PrintPreviewTabController* tab_controller = |
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
106 } | 108 } |
107 } | 109 } |
108 } | 110 } |
109 | 111 |
110 void BackgroundPrintingManager::OnRendererProcessClosed( | 112 void BackgroundPrintingManager::OnRendererProcessClosed( |
111 content::RenderProcessHost* rph) { | 113 content::RenderProcessHost* rph) { |
112 TabContentsWrapperSet preview_tabs_pending_deletion; | 114 TabContentsWrapperSet preview_tabs_pending_deletion; |
113 TabContentsWrapperSet::const_iterator it; | 115 TabContentsWrapperSet::const_iterator it; |
114 for (it = begin(); it != end(); ++it) { | 116 for (it = begin(); it != end(); ++it) { |
115 TabContentsWrapper* preview_tab = *it; | 117 TabContentsWrapper* preview_tab = *it; |
116 if (preview_tab->render_view_host()->process() == rph) { | 118 if (preview_tab->tab_contents()->render_view_host()->process() == rph) { |
117 preview_tabs_pending_deletion.insert(preview_tab); | 119 preview_tabs_pending_deletion.insert(preview_tab); |
118 } | 120 } |
119 } | 121 } |
120 for (it = preview_tabs_pending_deletion.begin(); | 122 for (it = preview_tabs_pending_deletion.begin(); |
121 it != preview_tabs_pending_deletion.end(); | 123 it != preview_tabs_pending_deletion.end(); |
122 ++it) { | 124 ++it) { |
123 DeletePreviewTab(*it); | 125 DeletePreviewTab(*it); |
124 } | 126 } |
125 } | 127 } |
126 | 128 |
(...skipping 12 matching lines...) Expand all Loading... |
139 NOTREACHED(); | 141 NOTREACHED(); |
140 return; | 142 return; |
141 } | 143 } |
142 | 144 |
143 // Remove NOTIFICATION_RENDERER_PROCESS_CLOSED if |preview_tab| is the last | 145 // Remove NOTIFICATION_RENDERER_PROCESS_CLOSED if |preview_tab| is the last |
144 // TabContents associated with |rph|. | 146 // TabContents associated with |rph|. |
145 bool shared_rph = HasSharedRenderProcessHost(printing_tabs_, preview_tab) || | 147 bool shared_rph = HasSharedRenderProcessHost(printing_tabs_, preview_tab) || |
146 HasSharedRenderProcessHost(printing_tabs_pending_deletion_, preview_tab); | 148 HasSharedRenderProcessHost(printing_tabs_pending_deletion_, preview_tab); |
147 if (!shared_rph) { | 149 if (!shared_rph) { |
148 content::RenderProcessHost* rph = | 150 content::RenderProcessHost* rph = |
149 preview_tab->render_view_host()->process(); | 151 preview_tab->tab_contents()->render_view_host()->process(); |
150 registrar_.Remove(this, content::NOTIFICATION_RENDERER_PROCESS_CLOSED, | 152 registrar_.Remove(this, content::NOTIFICATION_RENDERER_PROCESS_CLOSED, |
151 content::Source<content::RenderProcessHost>(rph)); | 153 content::Source<content::RenderProcessHost>(rph)); |
152 } | 154 } |
153 | 155 |
154 // Remove other notifications and remove the tab from its | 156 // Remove other notifications and remove the tab from its |
155 // TabContentsWrapperSet. | 157 // TabContentsWrapperSet. |
156 if (printing_tabs_.find(preview_tab) != printing_tabs_.end()) { | 158 if (printing_tabs_.find(preview_tab) != printing_tabs_.end()) { |
157 registrar_.Remove(this, chrome::NOTIFICATION_PRINT_JOB_RELEASED, | 159 registrar_.Remove(this, chrome::NOTIFICATION_PRINT_JOB_RELEASED, |
158 content::Source<TabContentsWrapper>(preview_tab)); | 160 content::Source<TabContentsWrapper>(preview_tab)); |
159 printing_tabs_.erase(preview_tab); | 161 printing_tabs_.erase(preview_tab); |
160 } else { | 162 } else { |
161 // DeletePreviewTab already deleted the notification. | 163 // DeletePreviewTab already deleted the notification. |
162 printing_tabs_pending_deletion_.erase(preview_tab); | 164 printing_tabs_pending_deletion_.erase(preview_tab); |
163 } | 165 } |
164 } | 166 } |
165 | 167 |
166 void BackgroundPrintingManager::DeletePreviewTab(TabContentsWrapper* tab) { | 168 void BackgroundPrintingManager::DeletePreviewTab(TabContentsWrapper* tab) { |
167 registrar_.Remove(this, chrome::NOTIFICATION_PRINT_JOB_RELEASED, | 169 registrar_.Remove(this, chrome::NOTIFICATION_PRINT_JOB_RELEASED, |
168 content::Source<TabContentsWrapper>(tab)); | 170 content::Source<TabContentsWrapper>(tab)); |
169 printing_tabs_.erase(tab); | 171 printing_tabs_.erase(tab); |
170 printing_tabs_pending_deletion_.insert(tab); | 172 printing_tabs_pending_deletion_.insert(tab); |
171 MessageLoop::current()->DeleteSoon(FROM_HERE, tab); | 173 MessageLoop::current()->DeleteSoon(FROM_HERE, tab); |
172 } | 174 } |
173 | 175 |
174 bool BackgroundPrintingManager::HasSharedRenderProcessHost( | 176 bool BackgroundPrintingManager::HasSharedRenderProcessHost( |
175 const TabContentsWrapperSet& set, | 177 const TabContentsWrapperSet& set, |
176 TabContentsWrapper* tab) { | 178 TabContentsWrapper* tab) { |
177 content::RenderProcessHost* rph = tab->render_view_host()->process(); | 179 content::RenderProcessHost* rph = |
| 180 tab->tab_contents()->render_view_host()->process(); |
178 for (TabContentsWrapperSet::const_iterator it = set.begin(); | 181 for (TabContentsWrapperSet::const_iterator it = set.begin(); |
179 it != set.end(); | 182 it != set.end(); |
180 ++it) { | 183 ++it) { |
181 TabContentsWrapper* iter_tab = *it; | 184 TabContentsWrapper* iter_tab = *it; |
182 if ((iter_tab != tab) && | 185 if ((iter_tab != tab) && |
183 (iter_tab->render_view_host()->process() == rph)) { | 186 (iter_tab->tab_contents()->render_view_host()->process() == rph)) { |
184 return true; | 187 return true; |
185 } | 188 } |
186 } | 189 } |
187 return false; | 190 return false; |
188 } | 191 } |
189 | 192 |
190 BackgroundPrintingManager::TabContentsWrapperSet::const_iterator | 193 BackgroundPrintingManager::TabContentsWrapperSet::const_iterator |
191 BackgroundPrintingManager::begin() { | 194 BackgroundPrintingManager::begin() { |
192 return printing_tabs_.begin(); | 195 return printing_tabs_.begin(); |
193 } | 196 } |
194 | 197 |
195 BackgroundPrintingManager::TabContentsWrapperSet::const_iterator | 198 BackgroundPrintingManager::TabContentsWrapperSet::const_iterator |
196 BackgroundPrintingManager::end() { | 199 BackgroundPrintingManager::end() { |
197 return printing_tabs_.end(); | 200 return printing_tabs_.end(); |
198 } | 201 } |
199 | 202 |
200 bool BackgroundPrintingManager::HasPrintPreviewTab( | 203 bool BackgroundPrintingManager::HasPrintPreviewTab( |
201 TabContentsWrapper* preview_tab) { | 204 TabContentsWrapper* preview_tab) { |
202 if (printing_tabs_.find(preview_tab) != printing_tabs_.end()) | 205 if (printing_tabs_.find(preview_tab) != printing_tabs_.end()) |
203 return true; | 206 return true; |
204 return printing_tabs_pending_deletion_.find(preview_tab) != | 207 return printing_tabs_pending_deletion_.find(preview_tab) != |
205 printing_tabs_pending_deletion_.end(); | 208 printing_tabs_pending_deletion_.end(); |
206 } | 209 } |
207 | 210 |
208 } // namespace printing | 211 } // namespace printing |
OLD | NEW |