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