| OLD | NEW |
| (Empty) | |
| 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 |
| 3 // found in the LICENSE file. |
| 4 |
| 5 #include "chrome/browser/printing/background_printing_manager.h" |
| 6 |
| 7 #include "chrome/browser/printing/print_job.h" |
| 8 #include "chrome/browser/tabs/tab_strip_model.h" |
| 9 #include "chrome/browser/ui/browser_list.h" |
| 10 #include "chrome/browser/ui/tab_contents/tab_contents_wrapper.h" |
| 11 #include "content/browser/browser_thread.h" |
| 12 #include "content/common/notification_details.h" |
| 13 #include "content/common/notification_source.h" |
| 14 |
| 15 namespace printing { |
| 16 |
| 17 BackgroundPrintingManager::BackgroundPrintingManager() { |
| 18 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| 19 } |
| 20 |
| 21 BackgroundPrintingManager::~BackgroundPrintingManager() { |
| 22 DCHECK_EQ(0U, printing_contents_.size()); |
| 23 } |
| 24 |
| 25 void BackgroundPrintingManager::HideTabContents(TabContentsWrapper* contents) { |
| 26 CHECK(printing_contents_.find(contents) == printing_contents_.end()); |
| 27 |
| 28 printing_contents_.insert(contents); |
| 29 |
| 30 registrar_.Add(this, NotificationType::PRINT_JOB_RELEASED, |
| 31 Source<TabContents>(contents->tab_contents())); |
| 32 registrar_.Add(this, NotificationType::TAB_CONTENTS_DESTROYED, |
| 33 Source<TabContents>(contents->tab_contents())); |
| 34 |
| 35 // Detach |contents| from its tab strip. |
| 36 Browser* browser = BrowserList::FindBrowserWithID( |
| 37 contents->controller().window_id().id()); |
| 38 TabStripModel* tabstrip = browser->tabstrip_model(); |
| 39 tabstrip->DetachTabContentsAt(tabstrip->GetIndexOfTabContents(contents)); |
| 40 } |
| 41 |
| 42 void BackgroundPrintingManager::Observe(NotificationType type, |
| 43 const NotificationSource& source, |
| 44 const NotificationDetails& details) { |
| 45 switch (type.value) { |
| 46 case NotificationType::PRINT_JOB_RELEASED: { |
| 47 // This might be happening in the middle of a RenderViewGone() loop. |
| 48 // Deleting |contents| later so the RenderViewGone() loop can finish. |
| 49 MessageLoop::current()->DeleteSoon(FROM_HERE, |
| 50 Source<TabContents>(source).ptr()); |
| 51 break; |
| 52 } |
| 53 case NotificationType::TAB_CONTENTS_DESTROYED: { |
| 54 TabContents* contents = Source<TabContents>(source).ptr(); |
| 55 registrar_.Remove(this, NotificationType::PRINT_JOB_RELEASED, |
| 56 Source<TabContents>(contents)); |
| 57 registrar_.Remove(this, NotificationType::TAB_CONTENTS_DESTROYED, |
| 58 Source<TabContents>(contents)); |
| 59 printing_contents_.erase( |
| 60 TabContentsWrapper::GetCurrentWrapperForContents(contents)); |
| 61 break; |
| 62 } |
| 63 default: { |
| 64 NOTREACHED(); |
| 65 break; |
| 66 } |
| 67 } |
| 68 } |
| 69 |
| 70 std::set<TabContentsWrapper*>::const_iterator |
| 71 BackgroundPrintingManager::begin() { |
| 72 return printing_contents_.begin(); |
| 73 } |
| 74 |
| 75 std::set<TabContentsWrapper*>::const_iterator |
| 76 BackgroundPrintingManager::end() { |
| 77 return printing_contents_.end(); |
| 78 } |
| 79 |
| 80 } // namespace printing |
| OLD | NEW |