Chromium Code Reviews| Index: chrome/browser/printing/background_printing_manager.cc |
| =================================================================== |
| --- chrome/browser/printing/background_printing_manager.cc (revision 0) |
| +++ chrome/browser/printing/background_printing_manager.cc (revision 0) |
| @@ -0,0 +1,80 @@ |
| +// Copyright (c) 2011 The Chromium Authors. All rights reserved. |
| +// Use of this source code is governed by a BSD-style license that can be |
| +// found in the LICENSE file. |
| + |
| +#include "chrome/browser/printing/background_printing_manager.h" |
| + |
| +#include "chrome/browser/printing/print_job.h" |
| +#include "chrome/browser/tabs/tab_strip_model.h" |
| +#include "chrome/browser/ui/browser_list.h" |
| +#include "chrome/browser/ui/tab_contents/tab_contents_wrapper.h" |
| +#include "content/browser/browser_thread.h" |
| +#include "content/common/notification_details.h" |
| +#include "content/common/notification_source.h" |
| + |
| +namespace printing { |
| + |
| +BackgroundPrintingManager::BackgroundPrintingManager() { |
| + DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| +} |
| + |
| +BackgroundPrintingManager::~BackgroundPrintingManager() { |
| + DCHECK_EQ(0U, printing_contents_.size()); |
|
sky
2011/05/06 16:37:55
Its the browsers that keep the process alive, not
Lei Zhang
2011/05/06 18:49:01
Indeed, thanks for mentioning this corner case. I'
|
| +} |
| + |
| +void BackgroundPrintingManager::HideTabContents(TabContentsWrapper* contents) { |
| + CHECK(printing_contents_.find(contents) == printing_contents_.end()); |
| + |
| + printing_contents_.insert(contents); |
| + |
| + registrar_.Add(this, NotificationType::PRINT_JOB_RELEASED, |
| + Source<TabContents>(contents->tab_contents())); |
| + registrar_.Add(this, NotificationType::TAB_CONTENTS_DESTROYED, |
| + Source<TabContents>(contents->tab_contents())); |
| + |
| + // Detach |contents| from its tab strip. |
| + Browser* browser = BrowserList::FindBrowserWithID( |
| + contents->controller().window_id().id()); |
| + TabStripModel* tabstrip = browser->tabstrip_model(); |
| + tabstrip->DetachTabContentsAt(tabstrip->GetIndexOfTabContents(contents)); |
| +} |
| + |
| +void BackgroundPrintingManager::Observe(NotificationType type, |
| + const NotificationSource& source, |
| + const NotificationDetails& details) { |
| + switch (type.value) { |
| + case NotificationType::PRINT_JOB_RELEASED: { |
| + // This might be happening in the middle of a RenderViewGone() loop. |
| + // Deleting |contents| later so the RenderViewGone() loop can finish. |
| + MessageLoop::current()->DeleteSoon(FROM_HERE, |
| + Source<TabContents>(source).ptr()); |
| + break; |
| + } |
| + case NotificationType::TAB_CONTENTS_DESTROYED: { |
| + TabContents* contents = Source<TabContents>(source).ptr(); |
| + registrar_.Remove(this, NotificationType::PRINT_JOB_RELEASED, |
| + Source<TabContents>(contents)); |
| + registrar_.Remove(this, NotificationType::TAB_CONTENTS_DESTROYED, |
| + Source<TabContents>(contents)); |
| + printing_contents_.erase( |
| + TabContentsWrapper::GetCurrentWrapperForContents(contents)); |
| + break; |
| + } |
| + default: { |
| + NOTREACHED(); |
| + break; |
| + } |
| + } |
| +} |
| + |
| +std::set<TabContentsWrapper*>::const_iterator |
| + BackgroundPrintingManager::begin() { |
| + return printing_contents_.begin(); |
| +} |
| + |
| +std::set<TabContentsWrapper*>::const_iterator |
| + BackgroundPrintingManager::end() { |
| + return printing_contents_.end(); |
| +} |
| + |
| +} // namespace printing |
| Property changes on: chrome/browser/printing/background_printing_manager.cc |
| ___________________________________________________________________ |
| Added: svn:eol-style |
| + LF |