1 // Copyright (c) 2012 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 #ifndef CHROME_BROWSER_PRINTING_BACKGROUND_PRINTING_MANAGER_H_ 6 #define CHROME_BROWSER_PRINTING_BACKGROUND_PRINTING_MANAGER_H_ 7 8 #include <map> 9 #include <set> 10 11 #include "base/compiler_specific.h" 12 #include "base/threading/non_thread_safe.h" 13 #include "content/public/browser/notification_observer.h" 14 #include "content/public/browser/notification_registrar.h" 15 16 namespace content { 17 class RenderProcessHost; 18 class WebContents; 19 } 20 21 namespace printing { 22 23 // Manages hidden WebContents that prints documents in the background. 24 // The hidden WebContents are no longer part of any Browser / TabStripModel. 25 // The WebContents started life as a ConstrainedPrintPreview dialog. 26 // They get deleted when the printing finishes. 27 class BackgroundPrintingManager : public base::NonThreadSafe, 28 public content::NotificationObserver { 29 public: 30 typedef std::set<content::WebContents*> WebContentsSet; 31 32 BackgroundPrintingManager(); 33 virtual ~BackgroundPrintingManager(); 34 35 // Takes ownership of |preview_dialog| and deletes it when |preview_dialog| 36 // finishes printing. This removes |preview_dialog| from its ConstrainedDialog 37 // and hides it from the user. 38 void OwnPrintPreviewDialog(content::WebContents* preview_dialog); 39 40 // Returns true if |printing_contents_set_| contains |preview_dialog|. 41 bool HasPrintPreviewDialog(content::WebContents* preview_dialog); 42 43 // Let others iterate over the list of background printing contents. 44 WebContentsSet::const_iterator begin(); 45 WebContentsSet::const_iterator end(); 46 47 private: 48 // content::NotificationObserver overrides: 49 virtual void Observe(int type, 50 const content::NotificationSource& source, 51 const content::NotificationDetails& details) OVERRIDE; 52 53 // Notifications handlers. 54 void OnRendererProcessClosed(content::RenderProcessHost* rph); 55 void OnPrintJobReleased(content::WebContents* preview_contents); 56 void OnWebContentsDestroyed(content::WebContents* preview_contents); 57 58 // Add |preview_contents| to the pending deletion set and schedule deletion. 59 void DeletePreviewContents(content::WebContents* preview_contents); 60 61 // Check if any of the WebContentses in |set| share a RenderProcessHost 62 // with |tab|, excluding |tab|. 63 bool HasSharedRenderProcessHost(const WebContentsSet& set, 64 content::WebContents* preview_contents); 65 66 // The set of print preview WebContentses managed by 67 // BackgroundPrintingManager. 68 WebContentsSet printing_contents_set_; 69 70 // The set of print preview Webcontents managed by BackgroundPrintingManager 71 // that are pending deletion. 72 WebContentsSet printing_contents_pending_deletion_set_; 73 74 content::NotificationRegistrar registrar_; 75 76 DISALLOW_COPY_AND_ASSIGN(BackgroundPrintingManager); 77 }; 78 79 } // namespace printing 80 81 #endif // CHROME_BROWSER_PRINTING_BACKGROUND_PRINTING_MANAGER_H_ 82