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

Side by Side Diff: chrome/browser/printing/background_printing_manager.cc

Issue 9030032: Get rid of a bunch of tab_contents.h includes from chrome. These are all trivial changes to use W... (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: fix cros Created 8 years, 11 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
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/browser/renderer_host/render_view_host_delegate.h"
16 #include "content/public/browser/browser_thread.h" 16 #include "content/public/browser/browser_thread.h"
17 #include "content/public/browser/notification_details.h" 17 #include "content/public/browser/notification_details.h"
18 #include "content/public/browser/notification_source.h" 18 #include "content/public/browser/notification_source.h"
19 #include "content/public/browser/web_contents.h"
19 20
20 using content::BrowserThread; 21 using content::BrowserThread;
21 using content::WebContents; 22 using content::WebContents;
22 23
23 namespace printing { 24 namespace printing {
24 25
25 BackgroundPrintingManager::BackgroundPrintingManager() { 26 BackgroundPrintingManager::BackgroundPrintingManager() {
26 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 27 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
27 } 28 }
28 29
(...skipping 10 matching lines...) Expand all
39 DCHECK(CalledOnValidThread()); 40 DCHECK(CalledOnValidThread());
40 DCHECK(PrintPreviewTabController::IsPrintPreviewTab(preview_tab)); 41 DCHECK(PrintPreviewTabController::IsPrintPreviewTab(preview_tab));
41 CHECK(!HasPrintPreviewTab(preview_tab)); 42 CHECK(!HasPrintPreviewTab(preview_tab));
42 43
43 printing_tabs_.insert(preview_tab); 44 printing_tabs_.insert(preview_tab);
44 45
45 registrar_.Add(this, chrome::NOTIFICATION_PRINT_JOB_RELEASED, 46 registrar_.Add(this, chrome::NOTIFICATION_PRINT_JOB_RELEASED,
46 content::Source<TabContentsWrapper>(preview_tab)); 47 content::Source<TabContentsWrapper>(preview_tab));
47 48
48 // OwnInitiatorTabContents() may have already added this notification. 49 // OwnInitiatorTabContents() may have already added this notification.
49 TabContents* preview_contents = preview_tab->tab_contents(); 50 WebContents* preview_contents = preview_tab->web_contents();
50 if (!registrar_.IsRegistered( 51 if (!registrar_.IsRegistered(
51 this, 52 this,
52 content::NOTIFICATION_WEB_CONTENTS_DESTROYED, 53 content::NOTIFICATION_WEB_CONTENTS_DESTROYED,
53 content::Source<WebContents>(preview_contents))) { 54 content::Source<WebContents>(preview_contents))) {
54 registrar_.Add(this, content::NOTIFICATION_WEB_CONTENTS_DESTROYED, 55 registrar_.Add(this, content::NOTIFICATION_WEB_CONTENTS_DESTROYED,
55 content::Source<WebContents>(preview_contents)); 56 content::Source<WebContents>(preview_contents));
56 } 57 }
57 58
58 // If a tab that is printing crashes, the user cannot destroy it since it is 59 // If a tab that is printing crashes, the user cannot destroy it since it is
59 // not in any tab strip. Thus listen for crashes here and delete the tab. 60 // not in any tab strip. Thus listen for crashes here and delete the tab.
60 // 61 //
61 // Multiple sites may share the same RenderProcessHost, so check if this 62 // Multiple sites may share the same RenderProcessHost, so check if this
62 // notification has already been added. 63 // notification has already been added.
63 content::RenderProcessHost* rph = 64 content::RenderProcessHost* rph =
64 preview_tab->tab_contents()->GetRenderProcessHost(); 65 preview_tab->web_contents()->GetRenderProcessHost();
65 if (!registrar_.IsRegistered(this, 66 if (!registrar_.IsRegistered(this,
66 content::NOTIFICATION_RENDERER_PROCESS_CLOSED, 67 content::NOTIFICATION_RENDERER_PROCESS_CLOSED,
67 content::Source<content::RenderProcessHost>( 68 content::Source<content::RenderProcessHost>(
68 rph))) { 69 rph))) {
69 registrar_.Add(this, content::NOTIFICATION_RENDERER_PROCESS_CLOSED, 70 registrar_.Add(this, content::NOTIFICATION_RENDERER_PROCESS_CLOSED,
70 content::Source<content::RenderProcessHost>(rph)); 71 content::Source<content::RenderProcessHost>(rph));
71 } 72 }
72 73
73 // Activate the initiator tab. 74 // Activate the initiator tab.
74 PrintPreviewTabController* tab_controller = 75 PrintPreviewTabController* tab_controller =
75 PrintPreviewTabController::GetInstance(); 76 PrintPreviewTabController::GetInstance();
76 if (!tab_controller) 77 if (!tab_controller)
77 return; 78 return;
78 TabContentsWrapper* initiator_tab = 79 TabContentsWrapper* initiator_tab =
79 tab_controller->GetInitiatorTab(preview_tab); 80 tab_controller->GetInitiatorTab(preview_tab);
80 if (!initiator_tab) 81 if (!initiator_tab)
81 return; 82 return;
82 static_cast<RenderViewHostDelegate*>( 83 initiator_tab->web_contents()->GetRenderViewHost()->delegate()->Activate();
83 initiator_tab->tab_contents())->Activate();
84 } 84 }
85 85
86 void BackgroundPrintingManager::Observe( 86 void BackgroundPrintingManager::Observe(
87 int type, 87 int type,
88 const content::NotificationSource& source, 88 const content::NotificationSource& source,
89 const content::NotificationDetails& details) { 89 const content::NotificationDetails& details) {
90 switch (type) { 90 switch (type) {
91 case content::NOTIFICATION_RENDERER_PROCESS_CLOSED: { 91 case content::NOTIFICATION_RENDERER_PROCESS_CLOSED: {
92 OnRendererProcessClosed( 92 OnRendererProcessClosed(
93 content::Source<content::RenderProcessHost>(source).ptr()); 93 content::Source<content::RenderProcessHost>(source).ptr());
(...skipping 15 matching lines...) Expand all
109 } 109 }
110 } 110 }
111 } 111 }
112 112
113 void BackgroundPrintingManager::OnRendererProcessClosed( 113 void BackgroundPrintingManager::OnRendererProcessClosed(
114 content::RenderProcessHost* rph) { 114 content::RenderProcessHost* rph) {
115 TabContentsWrapperSet preview_tabs_pending_deletion; 115 TabContentsWrapperSet preview_tabs_pending_deletion;
116 TabContentsWrapperSet::const_iterator it; 116 TabContentsWrapperSet::const_iterator it;
117 for (it = begin(); it != end(); ++it) { 117 for (it = begin(); it != end(); ++it) {
118 TabContentsWrapper* preview_tab = *it; 118 TabContentsWrapper* preview_tab = *it;
119 if (preview_tab->tab_contents()->GetRenderProcessHost() == rph) { 119 if (preview_tab->web_contents()->GetRenderProcessHost() == rph) {
120 preview_tabs_pending_deletion.insert(preview_tab); 120 preview_tabs_pending_deletion.insert(preview_tab);
121 } 121 }
122 } 122 }
123 for (it = preview_tabs_pending_deletion.begin(); 123 for (it = preview_tabs_pending_deletion.begin();
124 it != preview_tabs_pending_deletion.end(); 124 it != preview_tabs_pending_deletion.end();
125 ++it) { 125 ++it) {
126 DeletePreviewTab(*it); 126 DeletePreviewTab(*it);
127 } 127 }
128 } 128 }
129 129
130 void BackgroundPrintingManager::OnPrintJobReleased( 130 void BackgroundPrintingManager::OnPrintJobReleased(
131 TabContentsWrapper* preview_tab) { 131 TabContentsWrapper* preview_tab) {
132 DeletePreviewTab(preview_tab); 132 DeletePreviewTab(preview_tab);
133 } 133 }
134 134
135 void BackgroundPrintingManager::OnTabContentsDestroyed( 135 void BackgroundPrintingManager::OnTabContentsDestroyed(
136 TabContentsWrapper* preview_tab) { 136 TabContentsWrapper* preview_tab) {
137 // Always need to remove this notification since the tab is gone. 137 // Always need to remove this notification since the tab is gone.
138 registrar_.Remove(this, content::NOTIFICATION_WEB_CONTENTS_DESTROYED, 138 registrar_.Remove(this, content::NOTIFICATION_WEB_CONTENTS_DESTROYED,
139 content::Source<WebContents>(preview_tab->tab_contents())); 139 content::Source<WebContents>(preview_tab->web_contents()));
140 140
141 if (!HasPrintPreviewTab(preview_tab)) { 141 if (!HasPrintPreviewTab(preview_tab)) {
142 NOTREACHED(); 142 NOTREACHED();
143 return; 143 return;
144 } 144 }
145 145
146 // Remove NOTIFICATION_RENDERER_PROCESS_CLOSED if |preview_tab| is the last 146 // Remove NOTIFICATION_RENDERER_PROCESS_CLOSED if |preview_tab| is the last
147 // TabContents associated with |rph|. 147 // TabContents associated with |rph|.
148 bool shared_rph = HasSharedRenderProcessHost(printing_tabs_, preview_tab) || 148 bool shared_rph = HasSharedRenderProcessHost(printing_tabs_, preview_tab) ||
149 HasSharedRenderProcessHost(printing_tabs_pending_deletion_, preview_tab); 149 HasSharedRenderProcessHost(printing_tabs_pending_deletion_, preview_tab);
150 if (!shared_rph) { 150 if (!shared_rph) {
151 content::RenderProcessHost* rph = 151 content::RenderProcessHost* rph =
152 preview_tab->tab_contents()->GetRenderProcessHost(); 152 preview_tab->web_contents()->GetRenderProcessHost();
153 registrar_.Remove(this, content::NOTIFICATION_RENDERER_PROCESS_CLOSED, 153 registrar_.Remove(this, content::NOTIFICATION_RENDERER_PROCESS_CLOSED,
154 content::Source<content::RenderProcessHost>(rph)); 154 content::Source<content::RenderProcessHost>(rph));
155 } 155 }
156 156
157 // Remove other notifications and remove the tab from its 157 // Remove other notifications and remove the tab from its
158 // TabContentsWrapperSet. 158 // TabContentsWrapperSet.
159 if (printing_tabs_.find(preview_tab) != printing_tabs_.end()) { 159 if (printing_tabs_.find(preview_tab) != printing_tabs_.end()) {
160 registrar_.Remove(this, chrome::NOTIFICATION_PRINT_JOB_RELEASED, 160 registrar_.Remove(this, chrome::NOTIFICATION_PRINT_JOB_RELEASED,
161 content::Source<TabContentsWrapper>(preview_tab)); 161 content::Source<TabContentsWrapper>(preview_tab));
162 printing_tabs_.erase(preview_tab); 162 printing_tabs_.erase(preview_tab);
163 } else { 163 } else {
164 // DeletePreviewTab already deleted the notification. 164 // DeletePreviewTab already deleted the notification.
165 printing_tabs_pending_deletion_.erase(preview_tab); 165 printing_tabs_pending_deletion_.erase(preview_tab);
166 } 166 }
167 } 167 }
168 168
169 void BackgroundPrintingManager::DeletePreviewTab(TabContentsWrapper* tab) { 169 void BackgroundPrintingManager::DeletePreviewTab(TabContentsWrapper* tab) {
170 registrar_.Remove(this, chrome::NOTIFICATION_PRINT_JOB_RELEASED, 170 registrar_.Remove(this, chrome::NOTIFICATION_PRINT_JOB_RELEASED,
171 content::Source<TabContentsWrapper>(tab)); 171 content::Source<TabContentsWrapper>(tab));
172 printing_tabs_.erase(tab); 172 printing_tabs_.erase(tab);
173 printing_tabs_pending_deletion_.insert(tab); 173 printing_tabs_pending_deletion_.insert(tab);
174 MessageLoop::current()->DeleteSoon(FROM_HERE, tab); 174 MessageLoop::current()->DeleteSoon(FROM_HERE, tab);
175 } 175 }
176 176
177 bool BackgroundPrintingManager::HasSharedRenderProcessHost( 177 bool BackgroundPrintingManager::HasSharedRenderProcessHost(
178 const TabContentsWrapperSet& set, 178 const TabContentsWrapperSet& set,
179 TabContentsWrapper* tab) { 179 TabContentsWrapper* tab) {
180 content::RenderProcessHost* rph = tab->tab_contents()->GetRenderProcessHost(); 180 content::RenderProcessHost* rph = tab->web_contents()->GetRenderProcessHost();
181 for (TabContentsWrapperSet::const_iterator it = set.begin(); 181 for (TabContentsWrapperSet::const_iterator it = set.begin();
182 it != set.end(); 182 it != set.end();
183 ++it) { 183 ++it) {
184 TabContentsWrapper* iter_tab = *it; 184 TabContentsWrapper* iter_tab = *it;
185 if ((iter_tab != tab) && 185 if ((iter_tab != tab) &&
186 (iter_tab->tab_contents()->GetRenderProcessHost() == rph)) { 186 (iter_tab->web_contents()->GetRenderProcessHost() == rph)) {
187 return true; 187 return true;
188 } 188 }
189 } 189 }
190 return false; 190 return false;
191 } 191 }
192 192
193 BackgroundPrintingManager::TabContentsWrapperSet::const_iterator 193 BackgroundPrintingManager::TabContentsWrapperSet::const_iterator
194 BackgroundPrintingManager::begin() { 194 BackgroundPrintingManager::begin() {
195 return printing_tabs_.begin(); 195 return printing_tabs_.begin();
196 } 196 }
197 197
198 BackgroundPrintingManager::TabContentsWrapperSet::const_iterator 198 BackgroundPrintingManager::TabContentsWrapperSet::const_iterator
199 BackgroundPrintingManager::end() { 199 BackgroundPrintingManager::end() {
200 return printing_tabs_.end(); 200 return printing_tabs_.end();
201 } 201 }
202 202
203 bool BackgroundPrintingManager::HasPrintPreviewTab( 203 bool BackgroundPrintingManager::HasPrintPreviewTab(
204 TabContentsWrapper* preview_tab) { 204 TabContentsWrapper* preview_tab) {
205 if (printing_tabs_.find(preview_tab) != printing_tabs_.end()) 205 if (printing_tabs_.find(preview_tab) != printing_tabs_.end())
206 return true; 206 return true;
207 return printing_tabs_pending_deletion_.find(preview_tab) != 207 return printing_tabs_pending_deletion_.find(preview_tab) !=
208 printing_tabs_pending_deletion_.end(); 208 printing_tabs_pending_deletion_.end();
209 } 209 }
210 210
211 } // namespace printing 211 } // namespace printing
OLDNEW
« no previous file with comments | « chrome/browser/prerender/prerender_tab_helper.cc ('k') | chrome/browser/printing/print_preview_message_handler.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698