OLD | NEW |
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "chrome/browser/printing/print_preview_data_service.h" | 5 #include "chrome/browser/printing/print_preview_data_service.h" |
6 | 6 |
7 #include "base/memory/ref_counted_memory.h" | 7 #include "base/memory/ref_counted_memory.h" |
8 #include "base/memory/singleton.h" | 8 #include "base/memory/singleton.h" |
9 #include "printing/print_job_constants.h" | 9 #include "printing/print_job_constants.h" |
10 | 10 |
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
42 // Set/Update the preview data entry for the specified |index|. | 42 // Set/Update the preview data entry for the specified |index|. |
43 void SetPreviewDataForIndex(int index, const RefCountedBytes* data) { | 43 void SetPreviewDataForIndex(int index, const RefCountedBytes* data) { |
44 if (index != printing::COMPLETE_PREVIEW_DOCUMENT_INDEX && | 44 if (index != printing::COMPLETE_PREVIEW_DOCUMENT_INDEX && |
45 index < printing::FIRST_PAGE_INDEX) { | 45 index < printing::FIRST_PAGE_INDEX) { |
46 return; | 46 return; |
47 } | 47 } |
48 | 48 |
49 page_data_map_[index] = const_cast<RefCountedBytes*>(data); | 49 page_data_map_[index] = const_cast<RefCountedBytes*>(data); |
50 } | 50 } |
51 | 51 |
| 52 // Returns the available draft page count. |
| 53 int GetAvailableDraftPageCount() { |
| 54 int page_data_map_size = page_data_map_.size(); |
| 55 if (page_data_map_.find(printing::COMPLETE_PREVIEW_DOCUMENT_INDEX) != |
| 56 page_data_map_.end()) { |
| 57 page_data_map_size--; |
| 58 } |
| 59 return page_data_map_size; |
| 60 } |
| 61 |
52 private: | 62 private: |
53 friend class base::RefCounted<PrintPreviewDataStore>; | 63 friend class base::RefCounted<PrintPreviewDataStore>; |
54 | 64 |
55 // 1:1 relationship between page index and its associated preview data. | 65 // 1:1 relationship between page index and its associated preview data. |
56 // Key: Page index is zero-based and can be | 66 // Key: Page index is zero-based and can be |
57 // |printing::COMPLETE_PREVIEW_DOCUMENT_INDEX| to represent complete preview | 67 // |printing::COMPLETE_PREVIEW_DOCUMENT_INDEX| to represent complete preview |
58 // document. | 68 // document. |
59 // Value: Preview data. | 69 // Value: Preview data. |
60 typedef std::map<int, scoped_refptr<RefCountedBytes> > PreviewPageDataMap; | 70 typedef std::map<int, scoped_refptr<RefCountedBytes> > PreviewPageDataMap; |
61 | 71 |
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
98 data_store_map_[preview_ui_addr_str]->SetPreviewDataForIndex(index, | 108 data_store_map_[preview_ui_addr_str]->SetPreviewDataForIndex(index, |
99 data_bytes); | 109 data_bytes); |
100 } | 110 } |
101 | 111 |
102 void PrintPreviewDataService::RemoveEntry( | 112 void PrintPreviewDataService::RemoveEntry( |
103 const std::string& preview_ui_addr_str) { | 113 const std::string& preview_ui_addr_str) { |
104 PreviewDataStoreMap::iterator it = data_store_map_.find(preview_ui_addr_str); | 114 PreviewDataStoreMap::iterator it = data_store_map_.find(preview_ui_addr_str); |
105 if (it != data_store_map_.end()) | 115 if (it != data_store_map_.end()) |
106 data_store_map_.erase(it); | 116 data_store_map_.erase(it); |
107 } | 117 } |
| 118 |
| 119 int PrintPreviewDataService::GetAvailableDraftPageCount( |
| 120 const std::string& preview_ui_addr_str) { |
| 121 if (data_store_map_.find(preview_ui_addr_str) != data_store_map_.end()) |
| 122 return data_store_map_[preview_ui_addr_str]->GetAvailableDraftPageCount(); |
| 123 return 0; |
| 124 } |
OLD | NEW |