- add sources.
[platform/framework/web/crosswalk.git] / src / chrome / browser / printing / print_preview_data_service.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_PRINT_PREVIEW_DATA_SERVICE_H_
6 #define CHROME_BROWSER_PRINTING_PRINT_PREVIEW_DATA_SERVICE_H_
7
8 #include <map>
9 #include <string>
10
11 #include "base/memory/ref_counted.h"
12
13 template<typename T> struct DefaultSingletonTraits;
14
15 class PrintPreviewDataStore;
16
17 namespace base {
18 class RefCountedBytes;
19 }
20
21 // PrintPreviewDataService manages data stores for chrome://print requests.
22 // It owns the data store object and is responsible for freeing it.
23 class PrintPreviewDataService {
24  public:
25   static PrintPreviewDataService* GetInstance();
26
27   // Get the data entry from PrintPreviewDataStore. |index| is zero-based or
28   // |printing::COMPLETE_PREVIEW_DOCUMENT_INDEX| to represent complete preview
29   // data. Use |index| to retrieve a specific preview page data. |data| is set
30   // to NULL if the requested page is not yet available.
31   void GetDataEntry(int32 preview_ui_id, int index,
32                     scoped_refptr<base::RefCountedBytes>* data);
33
34   // Set/Update the data entry in PrintPreviewDataStore. |index| is zero-based
35   // or |printing::COMPLETE_PREVIEW_DOCUMENT_INDEX| to represent complete
36   // preview data. Use |index| to set/update a specific preview page data.
37   // NOTE: PrintPreviewDataStore owns the data. Do not refcount |data| before
38   // calling this function. It will be refcounted in PrintPreviewDataStore.
39   void SetDataEntry(int32 preview_ui_id, int index,
40                     const base::RefCountedBytes* data);
41
42   // Remove the corresponding PrintPreviewUI entry from the map.
43   void RemoveEntry(int32 preview_ui_id);
44
45   // Returns the available draft page count.
46   int GetAvailableDraftPageCount(int32 preview_ui_id);
47
48  private:
49   friend struct DefaultSingletonTraits<PrintPreviewDataService>;
50
51   // 1:1 relationship between PrintPreviewUI and data store object.
52   // Key: PrintPreviewUI ID.
53   // Value: Print preview data store object.
54   typedef std::map<int32, scoped_refptr<PrintPreviewDataStore> >
55       PreviewDataStoreMap;
56
57   PrintPreviewDataService();
58   virtual ~PrintPreviewDataService();
59
60   PreviewDataStoreMap data_store_map_;
61
62   DISALLOW_COPY_AND_ASSIGN(PrintPreviewDataService);
63 };
64
65 #endif  // CHROME_BROWSER_PRINTING_PRINT_PREVIEW_DATA_SERVICE_H_