Update To 11.40.268.0
[platform/framework/web/crosswalk.git] / src / chrome / browser / printing / background_printing_manager.h
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 ConstrainedWebDialog.
26 // They get deleted when the printing finishes.
27 class BackgroundPrintingManager : public base::NonThreadSafe,
28                                   public content::NotificationObserver {
29  public:
30   class Observer;
31   typedef std::map<content::WebContents*, Observer*> WebContentsObserverMap;
32
33   BackgroundPrintingManager();
34   ~BackgroundPrintingManager() override;
35
36   // Takes ownership of |preview_dialog| and deletes it when |preview_dialog|
37   // finishes printing. This removes |preview_dialog| from its ConstrainedDialog
38   // and hides it from the user.
39   void OwnPrintPreviewDialog(content::WebContents* preview_dialog);
40
41   // Returns true if |printing_contents_map_| contains |preview_dialog|.
42   bool HasPrintPreviewDialog(content::WebContents* preview_dialog);
43
44   // Let others see the list of background printing contents.
45   std::set<content::WebContents*> CurrentContentSet();
46
47  private:
48   // content::NotificationObserver overrides:
49   void Observe(int type,
50                const content::NotificationSource& source,
51                const content::NotificationDetails& details) override;
52
53   // Schedule deletion of |preview_contents|.
54   void DeletePreviewContents(content::WebContents* preview_contents);
55
56   // A map from print preview WebContentses (managed by
57   // BackgroundPrintingManager) to the Observers that observe them.
58   WebContentsObserverMap printing_contents_map_;
59
60   content::NotificationRegistrar registrar_;
61
62   DISALLOW_COPY_AND_ASSIGN(BackgroundPrintingManager);
63 };
64
65 }  // namespace printing
66
67 #endif  // CHROME_BROWSER_PRINTING_BACKGROUND_PRINTING_MANAGER_H_