summaryrefslogtreecommitdiffstats
path: root/chromium/chrome/browser/printing/pdf_nup_converter_client.h
blob: 3efc158496fc53fcd56c9dcc8d4cf6b0833c9a60 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
// Copyright 2018 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#ifndef CHROME_BROWSER_PRINTING_PDF_NUP_CONVERTER_CLIENT_H_
#define CHROME_BROWSER_PRINTING_PDF_NUP_CONVERTER_CLIENT_H_

#include <map>
#include <memory>

#include "chrome/services/printing/public/mojom/pdf_nup_converter.mojom.h"
#include "content/public/browser/web_contents_user_data.h"
#include "services/service_manager/public/cpp/connector.h"

namespace printing {

// Class to manage print requests and their communication with pdf N-up
// converter service.
// Each N-up conversion request has a separate interface pointer to connect
// with remote service. The request and its printing results are tracked by its
// document cookie.
class PdfNupConverterClient
    : public content::WebContentsUserData<PdfNupConverterClient> {
 public:
  explicit PdfNupConverterClient(content::WebContents* web_contents);
  ~PdfNupConverterClient() override;

  void DoNupPdfConvert(
      int document_cookie,
      uint32_t pages_per_sheet,
      const gfx::Size& page_size,
      const gfx::Rect& printable_area,
      std::vector<base::ReadOnlySharedMemoryRegion> pdf_page_regions,
      mojom::PdfNupConverter::NupPageConvertCallback callback);
  void DoNupPdfDocumentConvert(
      int document_cookie,
      uint32_t pages_per_sheet,
      const gfx::Size& page_size,
      const gfx::Rect& printable_area,
      base::ReadOnlySharedMemoryRegion src_pdf_document,
      mojom::PdfNupConverter::NupDocumentConvertCallback callback);

 private:
  friend class content::WebContentsUserData<PdfNupConverterClient>;
  void OnDidNupPdfDocumentConvert(
      int document_cookie,
      mojom::PdfNupConverter::NupDocumentConvertCallback callback,
      mojom::PdfNupConverter::Status status,
      base::ReadOnlySharedMemoryRegion region);

  // Get the request or create a new one if none exists.
  mojom::PdfNupConverterPtr& GetPdfNupConverterRequest(int cookie);

  // Remove an existing request from |pdf_nup_converter_map_|.
  void RemovePdfNupConverterRequest(int cookie);

  mojom::PdfNupConverterPtr CreatePdfNupConverterRequest();

  std::unique_ptr<service_manager::Connector> connector_;

  // Stores the mapping between document cookies and their corresponding
  // requests.
  std::map<int, mojom::PdfNupConverterPtr> pdf_nup_converter_map_;

  content::WebContents* web_contents_;

  WEB_CONTENTS_USER_DATA_KEY_DECL();

  DISALLOW_COPY_AND_ASSIGN(PdfNupConverterClient);
};

}  // namespace printing

#endif  // CHROME_BROWSER_PRINTING_PDF_NUP_CONVERTER_CLIENT_H_