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

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

Issue 7104074: Attempt at fixing crash. It looks like the printing code can delete (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Another comment tweak Created 9 years, 6 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
« no previous file with comments | « no previous file | chrome/browser/printing/print_view_manager.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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/tabs/tab_strip_model.h" 9 #include "chrome/browser/tabs/tab_strip_model.h"
10 #include "chrome/browser/ui/browser_list.h" 10 #include "chrome/browser/ui/browser_list.h"
(...skipping 18 matching lines...) Expand all
29 29
30 void BackgroundPrintingManager::OwnTabContents(TabContentsWrapper* contents) { 30 void BackgroundPrintingManager::OwnTabContents(TabContentsWrapper* contents) {
31 DCHECK(CalledOnValidThread()); 31 DCHECK(CalledOnValidThread());
32 DCHECK(printing::PrintPreviewTabController::IsPrintPreviewTab( 32 DCHECK(printing::PrintPreviewTabController::IsPrintPreviewTab(
33 contents->tab_contents())); 33 contents->tab_contents()));
34 CHECK(printing_contents_.find(contents) == printing_contents_.end()); 34 CHECK(printing_contents_.find(contents) == printing_contents_.end());
35 35
36 printing_contents_.insert(contents); 36 printing_contents_.insert(contents);
37 37
38 registrar_.Add(this, NotificationType::PRINT_JOB_RELEASED, 38 registrar_.Add(this, NotificationType::PRINT_JOB_RELEASED,
39 Source<TabContents>(contents->tab_contents())); 39 Source<TabContentsWrapper>(contents));
40 registrar_.Add(this, NotificationType::TAB_CONTENTS_DESTROYED, 40 registrar_.Add(this, NotificationType::TAB_CONTENTS_DESTROYED,
41 Source<TabContents>(contents->tab_contents())); 41 Source<TabContents>(contents->tab_contents()));
42 42
43 // Detach |contents| from its tab strip. 43 // Detach |contents| from its tab strip.
44 Browser* browser = BrowserList::FindBrowserWithID( 44 Browser* browser = BrowserList::FindBrowserWithID(
45 contents->controller().window_id().id()); 45 contents->controller().window_id().id());
46 TabStripModel* tabstrip = browser->tabstrip_model(); 46 TabStripModel* tabstrip = browser->tabstrip_model();
47 tabstrip->DetachTabContentsAt(tabstrip->GetIndexOfTabContents(contents)); 47 tabstrip->DetachTabContentsAt(tabstrip->GetIndexOfTabContents(contents));
48 48
49 // Activate the initiator tab. 49 // Activate the initiator tab.
50 printing::PrintPreviewTabController* tab_controller = 50 printing::PrintPreviewTabController* tab_controller =
51 printing::PrintPreviewTabController::GetInstance(); 51 printing::PrintPreviewTabController::GetInstance();
52 if (!tab_controller) 52 if (!tab_controller)
53 return; 53 return;
54 TabContents* initiator_tab = tab_controller->GetInitiatorTab( 54 TabContents* initiator_tab = tab_controller->GetInitiatorTab(
55 contents->tab_contents()); 55 contents->tab_contents());
56 if (!initiator_tab) 56 if (!initiator_tab)
57 return; 57 return;
58 initiator_tab->Activate(); 58 initiator_tab->Activate();
59 } 59 }
60 60
61 void BackgroundPrintingManager::Observe(NotificationType type, 61 void BackgroundPrintingManager::Observe(NotificationType type,
62 const NotificationSource& source, 62 const NotificationSource& source,
63 const NotificationDetails& details) { 63 const NotificationDetails& details) {
64 switch (type.value) { 64 switch (type.value) {
65 case NotificationType::PRINT_JOB_RELEASED: { 65 case NotificationType::PRINT_JOB_RELEASED: {
66 // This might be happening in the middle of a RenderViewGone() loop. 66 // This might be happening in the middle of a RenderViewGone() loop.
67 // Deleting |contents| later so the RenderViewGone() loop can finish. 67 // Deleting |contents| later so the RenderViewGone() loop can finish.
68 MessageLoop::current()->DeleteSoon(FROM_HERE, 68 MessageLoop::current()->DeleteSoon(
69 Source<TabContents>(source).ptr()); 69 FROM_HERE,
70 Source<TabContentsWrapper>(source).ptr());
70 break; 71 break;
71 } 72 }
72 case NotificationType::TAB_CONTENTS_DESTROYED: { 73 case NotificationType::TAB_CONTENTS_DESTROYED: {
73 TabContents* contents = Source<TabContents>(source).ptr(); 74 TabContentsWrapper* tab =
75 TabContentsWrapper::GetCurrentWrapperForContents(
76 Source<TabContents>(source).ptr());
74 registrar_.Remove(this, NotificationType::PRINT_JOB_RELEASED, 77 registrar_.Remove(this, NotificationType::PRINT_JOB_RELEASED,
75 Source<TabContents>(contents)); 78 Source<TabContentsWrapper>(tab));
76 registrar_.Remove(this, NotificationType::TAB_CONTENTS_DESTROYED, 79 registrar_.Remove(this, NotificationType::TAB_CONTENTS_DESTROYED,
77 Source<TabContents>(contents)); 80 Source<TabContents>(tab->tab_contents()));
78 printing_contents_.erase( 81 printing_contents_.erase(tab);
79 TabContentsWrapper::GetCurrentWrapperForContents(contents));
80 break; 82 break;
81 } 83 }
82 default: { 84 default: {
83 NOTREACHED(); 85 NOTREACHED();
84 break; 86 break;
85 } 87 }
86 } 88 }
87 } 89 }
88 90
89 std::set<TabContentsWrapper*>::const_iterator 91 std::set<TabContentsWrapper*>::const_iterator
90 BackgroundPrintingManager::begin() { 92 BackgroundPrintingManager::begin() {
91 return printing_contents_.begin(); 93 return printing_contents_.begin();
92 } 94 }
93 95
94 std::set<TabContentsWrapper*>::const_iterator 96 std::set<TabContentsWrapper*>::const_iterator
95 BackgroundPrintingManager::end() { 97 BackgroundPrintingManager::end() {
96 return printing_contents_.end(); 98 return printing_contents_.end();
97 } 99 }
98 100
99 } // namespace printing 101 } // namespace printing
OLDNEW
« no previous file with comments | « no previous file | chrome/browser/printing/print_view_manager.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698