summaryrefslogtreecommitdiffstats
path: root/chrome/browser/printing/print_preview_data_service.h
blob: 3642876365e6b8b3164193dac1a7ae48dbd3ec46 (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
// Copyright (c) 2011 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_PRINT_PREVIEW_DATA_SERVICE_H_
#define CHROME_BROWSER_PRINTING_PRINT_PREVIEW_DATA_SERVICE_H_
#pragma once

#include <map>
#include <string>

#include "base/memory/ref_counted.h"

template<typename T> struct DefaultSingletonTraits;

class PrintPreviewDataStore;
class RefCountedBytes;

// PrintPreviewDataService manages data stores for chrome://print requests.
// It owns the data store object and is responsible for freeing it.
class PrintPreviewDataService {
 public:
  static PrintPreviewDataService* GetInstance();

  // Get the data entry from PrintPreviewDataStore. |index| is zero-based or
  // |printing::COMPLETE_PREVIEW_DOCUMENT_INDEX| to represent complete preview
  // data. Use |index| to retrieve a specific preview page data. |data| is set
  // to NULL if the requested page is not yet available.
  void GetDataEntry(const std::string& preview_ui_addr_str, int index,
                    scoped_refptr<RefCountedBytes>* data);

  // Set/Update the data entry in PrintPreviewDataStore. |index| is zero-based
  // or |printing::COMPLETE_PREVIEW_DOCUMENT_INDEX| to represent complete
  // preview data. Use |index| to set/update a specific preview page data.
  // NOTE: PrintPreviewDataStore owns the data. Do not refcount |data| before
  // calling this function. It will be refcounted in PrintPreviewDataStore.
  void SetDataEntry(const std::string& preview_ui_addr_str, int index,
                    const RefCountedBytes* data);

  // Remove the corresponding PrintPreviewUI entry from the map.
  void RemoveEntry(const std::string& preview_ui_addr_str);

  // Returns the available draft page count.
  int GetAvailableDraftPageCount(const std::string& preview_ui_addr_str);

 private:
  friend struct DefaultSingletonTraits<PrintPreviewDataService>;

  // 1:1 relationship between PrintPreviewUI and data store object.
  // Key: Print preview UI address string.
  // Value: Print preview data store object.
  typedef std::map<std::string, scoped_refptr<PrintPreviewDataStore> >
      PreviewDataStoreMap;

  PrintPreviewDataService();
  virtual ~PrintPreviewDataService();

  PreviewDataStoreMap data_store_map_;

  DISALLOW_COPY_AND_ASSIGN(PrintPreviewDataService);
};

#endif  // CHROME_BROWSER_PRINTING_PRINT_PREVIEW_DATA_SERVICE_H_