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 "content/browser/browser_thread.h" | 14 #include "content/browser/browser_thread.h" |
14 #include "content/common/notification_details.h" | 15 #include "content/common/notification_details.h" |
15 #include "content/common/notification_source.h" | 16 #include "content/common/notification_source.h" |
16 | 17 |
17 namespace printing { | 18 namespace printing { |
18 | 19 |
19 BackgroundPrintingManager::BackgroundPrintingManager() { | 20 BackgroundPrintingManager::BackgroundPrintingManager() { |
20 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 21 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
21 } | 22 } |
22 | 23 |
23 BackgroundPrintingManager::~BackgroundPrintingManager() { | 24 BackgroundPrintingManager::~BackgroundPrintingManager() { |
24 DCHECK(CalledOnValidThread()); | 25 DCHECK(CalledOnValidThread()); |
25 // The might be some TabContentsWrappers still in |printing_contents_| at | 26 // The might be some TabContentsWrappers still in |printing_contents_| at |
26 // this point. E.g. when the last remaining tab is a print preview tab and | 27 // this point. E.g. when the last remaining tab is a print preview tab and |
27 // tries to print. In which case it will fail to print. | 28 // tries to print. In which case it will fail to print. |
28 // TODO(thestig) handle this case better. | 29 // TODO(thestig) handle this case better. |
29 } | 30 } |
30 | 31 |
31 void BackgroundPrintingManager::OwnTabContents(TabContentsWrapper* contents) { | 32 void BackgroundPrintingManager::OwnTabContents(TabContentsWrapper* contents) { |
32 DCHECK(CalledOnValidThread()); | 33 DCHECK(CalledOnValidThread()); |
33 DCHECK(printing::PrintPreviewTabController::IsPrintPreviewTab( | 34 DCHECK(printing::PrintPreviewTabController::IsPrintPreviewTab( |
34 contents->tab_contents())); | 35 contents->tab_contents())); |
35 CHECK(printing_contents_.find(contents) == printing_contents_.end()); | 36 CHECK(printing_contents_.find(contents) == printing_contents_.end()); |
36 | 37 |
37 printing_contents_.insert(contents); | 38 printing_contents_.insert(contents); |
38 | 39 |
39 registrar_.Add(this, NotificationType::PRINT_JOB_RELEASED, | 40 registrar_.Add(this, chrome::NOTIFICATION_PRINT_JOB_RELEASED, |
40 Source<TabContentsWrapper>(contents)); | 41 Source<TabContentsWrapper>(contents)); |
41 registrar_.Add(this, NotificationType::TAB_CONTENTS_DESTROYED, | 42 registrar_.Add(this, content::NOTIFICATION_TAB_CONTENTS_DESTROYED, |
42 Source<TabContents>(contents->tab_contents())); | 43 Source<TabContents>(contents->tab_contents())); |
43 | 44 |
44 // Detach |contents| from its tab strip. | 45 // Detach |contents| from its tab strip. |
45 Browser* browser = BrowserList::FindBrowserWithID( | 46 Browser* browser = BrowserList::FindBrowserWithID( |
46 contents->restore_tab_helper()->window_id().id()); | 47 contents->restore_tab_helper()->window_id().id()); |
47 DCHECK(browser); | 48 DCHECK(browser); |
48 | 49 |
49 TabStripModel* tabstrip = browser->tabstrip_model(); | 50 TabStripModel* tabstrip = browser->tabstrip_model(); |
50 tabstrip->DetachTabContentsAt(tabstrip->GetIndexOfTabContents(contents)); | 51 tabstrip->DetachTabContentsAt(tabstrip->GetIndexOfTabContents(contents)); |
51 | 52 |
52 // Activate the initiator tab. | 53 // Activate the initiator tab. |
53 printing::PrintPreviewTabController* tab_controller = | 54 printing::PrintPreviewTabController* tab_controller = |
54 printing::PrintPreviewTabController::GetInstance(); | 55 printing::PrintPreviewTabController::GetInstance(); |
55 if (!tab_controller) | 56 if (!tab_controller) |
56 return; | 57 return; |
57 TabContents* initiator_tab = tab_controller->GetInitiatorTab( | 58 TabContents* initiator_tab = tab_controller->GetInitiatorTab( |
58 contents->tab_contents()); | 59 contents->tab_contents()); |
59 if (!initiator_tab) | 60 if (!initiator_tab) |
60 return; | 61 return; |
61 initiator_tab->Activate(); | 62 initiator_tab->Activate(); |
62 } | 63 } |
63 | 64 |
64 void BackgroundPrintingManager::Observe(NotificationType type, | 65 void BackgroundPrintingManager::Observe(int type, |
65 const NotificationSource& source, | 66 const NotificationSource& source, |
66 const NotificationDetails& details) { | 67 const NotificationDetails& details) { |
67 switch (type.value) { | 68 switch (type) { |
68 case NotificationType::PRINT_JOB_RELEASED: { | 69 case chrome::NOTIFICATION_PRINT_JOB_RELEASED: { |
69 TabContentsWrapper* tab = Source<TabContentsWrapper>(source).ptr(); | 70 TabContentsWrapper* tab = Source<TabContentsWrapper>(source).ptr(); |
70 registrar_.Remove(this, NotificationType::PRINT_JOB_RELEASED, | 71 registrar_.Remove(this, chrome::NOTIFICATION_PRINT_JOB_RELEASED, |
71 Source<TabContentsWrapper>(tab)); | 72 Source<TabContentsWrapper>(tab)); |
72 | 73 |
73 // This might be happening in the middle of a RenderViewGone() loop. | 74 // This might be happening in the middle of a RenderViewGone() loop. |
74 // Deleting |contents| later so the RenderViewGone() loop can finish. | 75 // Deleting |contents| later so the RenderViewGone() loop can finish. |
75 MessageLoop::current()->DeleteSoon(FROM_HERE, tab); | 76 MessageLoop::current()->DeleteSoon(FROM_HERE, tab); |
76 break; | 77 break; |
77 } | 78 } |
78 case NotificationType::TAB_CONTENTS_DESTROYED: { | 79 case content::NOTIFICATION_TAB_CONTENTS_DESTROYED: { |
79 TabContentsWrapper* tab = | 80 TabContentsWrapper* tab = |
80 TabContentsWrapper::GetCurrentWrapperForContents( | 81 TabContentsWrapper::GetCurrentWrapperForContents( |
81 Source<TabContents>(source).ptr()); | 82 Source<TabContents>(source).ptr()); |
82 if (registrar_.IsRegistered(this, NotificationType::PRINT_JOB_RELEASED, | 83 if (registrar_.IsRegistered(this, chrome::NOTIFICATION_PRINT_JOB_RELEASED, |
83 Source<TabContentsWrapper>(tab))) { | 84 Source<TabContentsWrapper>(tab))) { |
84 registrar_.Remove(this, NotificationType::PRINT_JOB_RELEASED, | 85 registrar_.Remove(this, chrome::NOTIFICATION_PRINT_JOB_RELEASED, |
85 Source<TabContentsWrapper>(tab)); | 86 Source<TabContentsWrapper>(tab)); |
86 } | 87 } |
87 registrar_.Remove(this, NotificationType::TAB_CONTENTS_DESTROYED, | 88 registrar_.Remove(this, content::NOTIFICATION_TAB_CONTENTS_DESTROYED, |
88 Source<TabContents>(tab->tab_contents())); | 89 Source<TabContents>(tab->tab_contents())); |
89 printing_contents_.erase(tab); | 90 printing_contents_.erase(tab); |
90 break; | 91 break; |
91 } | 92 } |
92 default: { | 93 default: { |
93 NOTREACHED(); | 94 NOTREACHED(); |
94 break; | 95 break; |
95 } | 96 } |
96 } | 97 } |
97 } | 98 } |
98 | 99 |
99 std::set<TabContentsWrapper*>::const_iterator | 100 std::set<TabContentsWrapper*>::const_iterator |
100 BackgroundPrintingManager::begin() { | 101 BackgroundPrintingManager::begin() { |
101 return printing_contents_.begin(); | 102 return printing_contents_.begin(); |
102 } | 103 } |
103 | 104 |
104 std::set<TabContentsWrapper*>::const_iterator | 105 std::set<TabContentsWrapper*>::const_iterator |
105 BackgroundPrintingManager::end() { | 106 BackgroundPrintingManager::end() { |
106 return printing_contents_.end(); | 107 return printing_contents_.end(); |
107 } | 108 } |
108 | 109 |
109 bool BackgroundPrintingManager::HasTabContents(TabContentsWrapper* entry) { | 110 bool BackgroundPrintingManager::HasTabContents(TabContentsWrapper* entry) { |
110 return printing_contents_.find(entry) != printing_contents_.end(); | 111 return printing_contents_.find(entry) != printing_contents_.end(); |
111 } | 112 } |
112 | 113 |
113 } // namespace printing | 114 } // namespace printing |
OLD | NEW |