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

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

Issue 10890023: Miscellaneous cleanups from several months ago I never got around to landing. (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: Created 8 years, 3 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) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 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/ui/browser_list.h" 9 #include "chrome/browser/ui/browser_list.h"
10 #include "chrome/browser/ui/tab_contents/tab_contents.h" 10 #include "chrome/browser/ui/tab_contents/tab_contents.h"
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after
49 chrome::NOTIFICATION_TAB_CONTENTS_DESTROYED, preview_source)) { 49 chrome::NOTIFICATION_TAB_CONTENTS_DESTROYED, preview_source)) {
50 registrar_.Add(this, chrome::NOTIFICATION_TAB_CONTENTS_DESTROYED, 50 registrar_.Add(this, chrome::NOTIFICATION_TAB_CONTENTS_DESTROYED,
51 preview_source); 51 preview_source);
52 } 52 }
53 53
54 // If a tab that is printing crashes, the user cannot destroy it since it is 54 // If a tab that is printing crashes, the user cannot destroy it since it is
55 // not in any tab strip. Thus listen for crashes here and delete the tab. 55 // not in any tab strip. Thus listen for crashes here and delete the tab.
56 // 56 //
57 // Multiple sites may share the same RenderProcessHost, so check if this 57 // Multiple sites may share the same RenderProcessHost, so check if this
58 // notification has already been added. 58 // notification has already been added.
59 content::RenderProcessHost* rph = 59 content::Source<content::RenderProcessHost> rph_source(
60 preview_tab->web_contents()->GetRenderProcessHost(); 60 preview_tab->web_contents()->GetRenderProcessHost());
61 if (!registrar_.IsRegistered(this, 61 if (!registrar_.IsRegistered(this,
62 content::NOTIFICATION_RENDERER_PROCESS_CLOSED, 62 content::NOTIFICATION_RENDERER_PROCESS_CLOSED, rph_source)) {
63 content::Source<content::RenderProcessHost>(
64 rph))) {
65 registrar_.Add(this, content::NOTIFICATION_RENDERER_PROCESS_CLOSED, 63 registrar_.Add(this, content::NOTIFICATION_RENDERER_PROCESS_CLOSED,
66 content::Source<content::RenderProcessHost>(rph)); 64 rph_source);
67 } 65 }
68 66
69 // Activate the initiator tab. 67 // Activate the initiator tab.
70 PrintPreviewTabController* tab_controller = 68 PrintPreviewTabController* tab_controller =
71 PrintPreviewTabController::GetInstance(); 69 PrintPreviewTabController::GetInstance();
72 if (!tab_controller) 70 if (!tab_controller)
73 return; 71 return;
74 TabContents* initiator_tab = tab_controller->GetInitiatorTab(preview_tab); 72 TabContents* initiator_tab = tab_controller->GetInitiatorTab(preview_tab);
75 if (!initiator_tab) 73 if (!initiator_tab)
76 return; 74 return;
77 WebContents* web_contents = initiator_tab->web_contents(); 75 WebContents* web_contents = initiator_tab->web_contents();
78 web_contents->GetDelegate()->ActivateContents(web_contents); 76 web_contents->GetDelegate()->ActivateContents(web_contents);
79 } 77 }
80 78
81 void BackgroundPrintingManager::Observe( 79 void BackgroundPrintingManager::Observe(
82 int type, 80 int type,
83 const content::NotificationSource& source, 81 const content::NotificationSource& source,
84 const content::NotificationDetails& details) { 82 const content::NotificationDetails& details) {
85 switch (type) { 83 if (type == content::NOTIFICATION_RENDERER_PROCESS_CLOSED) {
86 case content::NOTIFICATION_RENDERER_PROCESS_CLOSED: { 84 OnRendererProcessClosed(
87 OnRendererProcessClosed( 85 content::Source<content::RenderProcessHost>(source).ptr());
88 content::Source<content::RenderProcessHost>(source).ptr()); 86 } else if (type == chrome::NOTIFICATION_PRINT_JOB_RELEASED) {
89 break; 87 OnPrintJobReleased(content::Source<TabContents>(source).ptr());
90 } 88 } else {
91 case chrome::NOTIFICATION_PRINT_JOB_RELEASED: { 89 DCHECK_EQ(chrome::NOTIFICATION_TAB_CONTENTS_DESTROYED, type);
92 OnPrintJobReleased(content::Source<TabContents>(source).ptr()); 90 OnTabContentsDestroyed(content::Source<TabContents>(source).ptr());
93 break;
94 }
95 case chrome::NOTIFICATION_TAB_CONTENTS_DESTROYED: {
96 OnTabContentsDestroyed(content::Source<TabContents>(source).ptr());
97 break;
98 }
99 default: {
100 NOTREACHED();
101 break;
102 }
103 } 91 }
104 } 92 }
105 93
106 void BackgroundPrintingManager::OnRendererProcessClosed( 94 void BackgroundPrintingManager::OnRendererProcessClosed(
107 content::RenderProcessHost* rph) { 95 content::RenderProcessHost* rph) {
108 TabContentsSet preview_tabs_pending_deletion; 96 TabContentsSet preview_tabs_pending_deletion;
109 TabContentsSet::const_iterator it; 97 TabContentsSet::const_iterator it;
110 for (it = begin(); it != end(); ++it) { 98 for (it = begin(); it != end(); ++it) {
111 TabContents* preview_tab = *it; 99 TabContents* preview_tab = *it;
112 if (preview_tab->web_contents()->GetRenderProcessHost() == rph) { 100 if (preview_tab->web_contents()->GetRenderProcessHost() == rph) {
(...skipping 79 matching lines...) Expand 10 before | Expand all | Expand 10 after
192 180
193 bool BackgroundPrintingManager::HasPrintPreviewTab( 181 bool BackgroundPrintingManager::HasPrintPreviewTab(
194 TabContents* preview_tab) { 182 TabContents* preview_tab) {
195 if (printing_tabs_.find(preview_tab) != printing_tabs_.end()) 183 if (printing_tabs_.find(preview_tab) != printing_tabs_.end())
196 return true; 184 return true;
197 return printing_tabs_pending_deletion_.find(preview_tab) != 185 return printing_tabs_pending_deletion_.find(preview_tab) !=
198 printing_tabs_pending_deletion_.end(); 186 printing_tabs_pending_deletion_.end();
199 } 187 }
200 188
201 } // namespace printing 189 } // namespace printing
OLDNEW
« no previous file with comments | « chrome/browser/download/download_request_limiter.cc ('k') | chrome/browser/printing/print_preview_tab_controller.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698