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
ash / webui / print_preview_cros / backend / print_preview_pdf_store.h [blame]
// Copyright 2024 The Chromium Authors
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#ifndef ASH_WEBUI_PRINT_PREVIEW_CROS_BACKEND_PRINT_PREVIEW_PDF_STORE_H_
#define ASH_WEBUI_PRINT_PREVIEW_CROS_BACKEND_PRINT_PREVIEW_PDF_STORE_H_
#include <map>
#include "base/memory/ref_counted_memory.h"
#include "base/memory/scoped_refptr.h"
#include "base/unguessable_token.h"
namespace ash::printing::print_preview {
// PrintPreviewPdfStore is the singleton class responsible for in-memory storage
// of PDF data for CrOS Print Preview. When fetching PDFs to display in the UI,
// only untrusted WebUI access is expected.
class PrintPreviewPdfStore {
public:
static PrintPreviewPdfStore* GetInstance();
PrintPreviewPdfStore();
PrintPreviewPdfStore(const PrintPreviewPdfStore&) = delete;
PrintPreviewPdfStore& operator=(const PrintPreviewPdfStore&) = delete;
~PrintPreviewPdfStore();
// `token` specifies the instance of Print Preview. `page_index` is the
// zero-based index of the PDF page to store. Returns NULLPTR if either
// `token` or `page_index` is not found.
void InsertPdfData(const base::UnguessableToken& token,
int page_index,
scoped_refptr<base::RefCountedMemory> data);
// `token` specifies the instance of Print Preview. `page_index` is the
// zero-based index of the PDF page to retrieve.
scoped_refptr<base::RefCountedMemory> GetPdfData(
const base::UnguessableToken& token,
int page_index) const;
private:
// Data map keyed by UnguessableToken to specify the Print Preview instance,
// and int for the zero-based page index.
std::map<base::UnguessableToken,
std::map<int, scoped_refptr<base::RefCountedMemory>>>
pdf_data_map_;
};
} // namespace ash::printing::print_preview
#endif // ASH_WEBUI_PRINT_PREVIEW_CROS_BACKEND_PRINT_PREVIEW_PDF_STORE_H_