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 true if the draft pages is available. |
| 53 bool IsDraftPagesAvailable(int draft_page_count) { |
| 54 int page_data_map_size = page_data_map_.size(); |
| 55 return (page_data_map_size > draft_page_count || |
| 56 (page_data_map_size == draft_page_count && |
| 57 (page_data_map_.find(printing::COMPLETE_PREVIEW_DOCUMENT_INDEX) == |
| 58 page_data_map_.end()))); |
| 59 } |
| 60 |
52 private: | 61 private: |
53 friend class base::RefCounted<PrintPreviewDataStore>; | 62 friend class base::RefCounted<PrintPreviewDataStore>; |
54 | 63 |
55 // 1:1 relationship between page index and its associated preview data. | 64 // 1:1 relationship between page index and its associated preview data. |
56 // Key: Page index is zero-based and can be | 65 // Key: Page index is zero-based and can be |
57 // |printing::COMPLETE_PREVIEW_DOCUMENT_INDEX| to represent complete preview | 66 // |printing::COMPLETE_PREVIEW_DOCUMENT_INDEX| to represent complete preview |
58 // document. | 67 // document. |
59 // Value: Preview data. | 68 // Value: Preview data. |
60 typedef std::map<int, scoped_refptr<RefCountedBytes> > PreviewPageDataMap; | 69 typedef std::map<int, scoped_refptr<RefCountedBytes> > PreviewPageDataMap; |
61 | 70 |
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
98 data_store_map_[preview_ui_addr_str]->SetPreviewDataForIndex(index, | 107 data_store_map_[preview_ui_addr_str]->SetPreviewDataForIndex(index, |
99 data_bytes); | 108 data_bytes); |
100 } | 109 } |
101 | 110 |
102 void PrintPreviewDataService::RemoveEntry( | 111 void PrintPreviewDataService::RemoveEntry( |
103 const std::string& preview_ui_addr_str) { | 112 const std::string& preview_ui_addr_str) { |
104 PreviewDataStoreMap::iterator it = data_store_map_.find(preview_ui_addr_str); | 113 PreviewDataStoreMap::iterator it = data_store_map_.find(preview_ui_addr_str); |
105 if (it != data_store_map_.end()) | 114 if (it != data_store_map_.end()) |
106 data_store_map_.erase(it); | 115 data_store_map_.erase(it); |
107 } | 116 } |
| 117 |
| 118 bool PrintPreviewDataService::IsDraftPagesAvailable( |
| 119 const std::string& preview_ui_addr_str, |
| 120 int draft_page_count) { |
| 121 if (data_store_map_.find(preview_ui_addr_str) != data_store_map_.end()) { |
| 122 return data_store_map_[preview_ui_addr_str]->IsDraftPagesAvailable( |
| 123 draft_page_count); |
| 124 } |
| 125 return false; |
| 126 } |
OLD | NEW |