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

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

Issue 6930034: Print Preview: Print in the background. (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: '' Created 9 years, 7 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
Property Changes:
Added: svn:eol-style
+ LF
OLDNEW
(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/printing/print_preview_tab_controller.h"
9 #include "chrome/browser/tabs/tab_strip_model.h"
10 #include "chrome/browser/ui/browser_list.h"
11 #include "chrome/browser/ui/tab_contents/tab_contents_wrapper.h"
12 #include "content/browser/browser_thread.h"
13 #include "content/common/notification_details.h"
14 #include "content/common/notification_source.h"
15
16 namespace printing {
17
18 BackgroundPrintingManager::BackgroundPrintingManager() {
19 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
20 }
21
22 BackgroundPrintingManager::~BackgroundPrintingManager() {
23 DCHECK(CalledOnValidThread());
24 // The might be some TabContentsWrappers still in |printing_contents_| at
25 // this point. E.g. when the last remaining tab is a print preview tab and
26 // tries to print. In which case it will fail to print.
27 // TODO(thestig) handle this case better.
28 }
29
30 void BackgroundPrintingManager::OwnTabContents(TabContentsWrapper* contents) {
31 DCHECK(CalledOnValidThread());
32 DCHECK(printing::PrintPreviewTabController::IsPrintPreviewTab(
33 contents->tab_contents()));
34 CHECK(printing_contents_.find(contents) == printing_contents_.end());
35
36 printing_contents_.insert(contents);
37
38 registrar_.Add(this, NotificationType::PRINT_JOB_RELEASED,
39 Source<TabContents>(contents->tab_contents()));
40 registrar_.Add(this, NotificationType::TAB_CONTENTS_DESTROYED,
41 Source<TabContents>(contents->tab_contents()));
42
43 // Detach |contents| from its tab strip.
44 Browser* browser = BrowserList::FindBrowserWithID(
45 contents->controller().window_id().id());
46 TabStripModel* tabstrip = browser->tabstrip_model();
47 tabstrip->DetachTabContentsAt(tabstrip->GetIndexOfTabContents(contents));
48 }
49
50 void BackgroundPrintingManager::Observe(NotificationType type,
51 const NotificationSource& source,
52 const NotificationDetails& details) {
53 switch (type.value) {
54 case NotificationType::PRINT_JOB_RELEASED: {
55 // This might be happening in the middle of a RenderViewGone() loop.
56 // Deleting |contents| later so the RenderViewGone() loop can finish.
57 MessageLoop::current()->DeleteSoon(FROM_HERE,
58 Source<TabContents>(source).ptr());
59 break;
60 }
61 case NotificationType::TAB_CONTENTS_DESTROYED: {
62 TabContents* contents = Source<TabContents>(source).ptr();
63 registrar_.Remove(this, NotificationType::PRINT_JOB_RELEASED,
64 Source<TabContents>(contents));
65 registrar_.Remove(this, NotificationType::TAB_CONTENTS_DESTROYED,
66 Source<TabContents>(contents));
67 printing_contents_.erase(
68 TabContentsWrapper::GetCurrentWrapperForContents(contents));
69 break;
70 }
71 default: {
72 NOTREACHED();
73 break;
74 }
75 }
76 }
77
78 std::set<TabContentsWrapper*>::const_iterator
79 BackgroundPrintingManager::begin() {
80 return printing_contents_.begin();
81 }
82
83 std::set<TabContentsWrapper*>::const_iterator
84 BackgroundPrintingManager::end() {
85 return printing_contents_.end();
86 }
87
88 } // namespace printing
OLDNEW
« no previous file with comments | « chrome/browser/printing/background_printing_manager.h ('k') | chrome/browser/printing/print_view_manager.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698