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

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

Issue 7800036: Print Preview: Hold on to tabs that do window.print(); window.close() until print preview finishes. (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: Created 9 years, 3 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
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 #ifndef CHROME_BROWSER_PRINTING_BACKGROUND_PRINTING_MANAGER_H_ 5 #ifndef CHROME_BROWSER_PRINTING_BACKGROUND_PRINTING_MANAGER_H_
6 #define CHROME_BROWSER_PRINTING_BACKGROUND_PRINTING_MANAGER_H_ 6 #define CHROME_BROWSER_PRINTING_BACKGROUND_PRINTING_MANAGER_H_
7 #pragma once 7 #pragma once
8 8
9 #include <map>
9 #include <set> 10 #include <set>
10 11
11 #include "base/compiler_specific.h" 12 #include "base/compiler_specific.h"
12 #include "base/threading/non_thread_safe.h" 13 #include "base/threading/non_thread_safe.h"
13 #include "content/common/notification_observer.h" 14 #include "content/common/notification_observer.h"
14 #include "content/common/notification_registrar.h" 15 #include "content/common/notification_registrar.h"
15 16
17 class RenderProcessHost;
16 class TabContentsWrapper; 18 class TabContentsWrapper;
17 19
18 namespace printing { 20 namespace printing {
19 21
20 // Manages hidden tabs that prints documents in the background. 22 // Manages hidden tabs that prints documents in the background.
21 // The hidden tabs are no longer part of any Browser / TabStripModel. 23 // The hidden tabs are no longer part of any Browser / TabStripModel.
22 // They get deleted when the tab finishes printing. 24 // They get deleted when the tab finishes printing.
23 class BackgroundPrintingManager : public base::NonThreadSafe, 25 class BackgroundPrintingManager : public base::NonThreadSafe,
24 public NotificationObserver { 26 public NotificationObserver {
25 public: 27 public:
26 typedef std::set<TabContentsWrapper*> TabContentsWrapperSet; 28 typedef std::set<TabContentsWrapper*> TabContentsWrapperSet;
27 29
28 BackgroundPrintingManager(); 30 BackgroundPrintingManager();
29 virtual ~BackgroundPrintingManager(); 31 virtual ~BackgroundPrintingManager();
30 32
31 // Takes ownership of |preview_tab| and deletes it when |preview_tab| finishes 33 // Takes ownership of |preview_tab| and deletes it when |preview_tab| finishes
32 // printing. This removes the TabContentsWrapper from its TabStrip and 34 // printing. This removes the TabContentsWrapper from its TabStrip and
33 // hides it from the user. 35 // hides it from the user.
34 void OwnPrintPreviewTab(TabContentsWrapper* preview_tab); 36 void OwnPrintPreviewTab(TabContentsWrapper* preview_tab);
35 37
38 // Takes ownership of |initiator_tab| and deletes it when its preview tab is
39 // destroyed by either being canceled, closed or finishing printing. This
40 // removes the TabContentsWrapper from its TabStrip and hides it from the
41 // user. Returns true if content has an associated print preview tab,
42 // otherwise, returns false and does not take ownership of |initiator_tab|.
43 bool OwnInitiatorTab(TabContentsWrapper* initiator_tab);
44
36 // Let others iterate over the list of background printing tabs. 45 // Let others iterate over the list of background printing tabs.
37 TabContentsWrapperSet::const_iterator begin(); 46 TabContentsWrapperSet::const_iterator begin();
38 TabContentsWrapperSet::const_iterator end(); 47 TabContentsWrapperSet::const_iterator end();
39 48
40 // Returns true if |printing_tabs_| contains |preview_tab|. 49 // Returns true if |printing_tabs_| contains |preview_tab|.
41 bool HasPrintPreviewTab(TabContentsWrapper* preview_tab); 50 bool HasPrintPreviewTab(TabContentsWrapper* preview_tab);
42 51
43 // NotificationObserver overrides: 52 // NotificationObserver overrides:
44 virtual void Observe(int type, 53 virtual void Observe(int type,
45 const NotificationSource& source, 54 const NotificationSource& source,
46 const NotificationDetails& details) OVERRIDE; 55 const NotificationDetails& details) OVERRIDE;
47 56
48 private: 57 private:
58 // Notifications handlers.
59 void OnRendererProcessClosed(RenderProcessHost* rph);
60 void OnPrintJobReleased(TabContentsWrapper* preview_tab);
61 void OnTabContentsDestroyed(TabContentsWrapper* preview_tab);
62
63 // Removes |tab| from its tab strip.
64 void RemoveFromTabStrip(TabContentsWrapper* tab);
65
49 // The set of print preview tabs managed by BackgroundPrintingManager. 66 // The set of print preview tabs managed by BackgroundPrintingManager.
50 TabContentsWrapperSet printing_tabs_; 67 TabContentsWrapperSet printing_tabs_;
51 68
69 // The set of initiator tabs managed by BackgroundPrintingManager.
70 TabContentsWrapperSet initiator_tabs_;
kmadhusu 2011/09/07 23:21:10 (repeating our in-person conversation): initiator_
Lei Zhang 2011/09/07 23:41:16 Done.
71
72 // 1:1 mapping between a print preview tab and an initiator tab in
73 // |initiator_tabs_|.
kmadhusu 2011/09/07 23:21:10 Document Key and Value.
Lei Zhang 2011/09/07 23:41:16 Done.
74 std::map<TabContentsWrapper*, TabContentsWrapper*> map_;
kmadhusu 2011/09/07 23:21:10 In the .cc file, I did not see any code to erase t
kmadhusu 2011/09/07 23:21:10 Add a comment explaining the scenario at which map
Lei Zhang 2011/09/07 23:41:16 Done.
Lei Zhang 2011/09/07 23:41:16 Done.
75
52 NotificationRegistrar registrar_; 76 NotificationRegistrar registrar_;
53 77
54 DISALLOW_COPY_AND_ASSIGN(BackgroundPrintingManager); 78 DISALLOW_COPY_AND_ASSIGN(BackgroundPrintingManager);
55 }; 79 };
56 80
57 } // namespace printing 81 } // namespace printing
58 82
59 #endif // CHROME_BROWSER_PRINTING_BACKGROUND_PRINTING_MANAGER_H_ 83 #endif // CHROME_BROWSER_PRINTING_BACKGROUND_PRINTING_MANAGER_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698