OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 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 | 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/macros.h" | 7 #include "base/macros.h" |
8 #include "base/memory/ref_counted_memory.h" | 8 #include "base/memory/ref_counted_memory.h" |
9 #include "base/memory/singleton.h" | 9 #include "base/memory/singleton.h" |
10 #include "base/stl_util.h" | 10 #include "base/stl_util.h" |
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
45 scoped_refptr<base::RefCountedBytes> data) { | 45 scoped_refptr<base::RefCountedBytes> data) { |
46 if (IsInvalidIndex(index)) | 46 if (IsInvalidIndex(index)) |
47 return; | 47 return; |
48 | 48 |
49 page_data_map_[index] = std::move(data); | 49 page_data_map_[index] = std::move(data); |
50 } | 50 } |
51 | 51 |
52 // Returns the available draft page count. | 52 // Returns the available draft page count. |
53 int GetAvailableDraftPageCount() { | 53 int GetAvailableDraftPageCount() { |
54 int page_data_map_size = page_data_map_.size(); | 54 int page_data_map_size = page_data_map_.size(); |
55 if (ContainsKey(page_data_map_, printing::COMPLETE_PREVIEW_DOCUMENT_INDEX)) | 55 if (base::ContainsKey(page_data_map_, |
| 56 printing::COMPLETE_PREVIEW_DOCUMENT_INDEX)) |
56 page_data_map_size--; | 57 page_data_map_size--; |
57 return page_data_map_size; | 58 return page_data_map_size; |
58 } | 59 } |
59 | 60 |
60 private: | 61 private: |
61 friend class base::RefCounted<PrintPreviewDataStore>; | 62 friend class base::RefCounted<PrintPreviewDataStore>; |
62 | 63 |
63 // 1:1 relationship between page index and its associated preview data. | 64 // 1:1 relationship between page index and its associated preview data. |
64 // Key: Page index is zero-based and can be | 65 // Key: Page index is zero-based and can be |
65 // |printing::COMPLETE_PREVIEW_DOCUMENT_INDEX| to represent complete preview | 66 // |printing::COMPLETE_PREVIEW_DOCUMENT_INDEX| to represent complete preview |
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
98 *data_bytes = nullptr; | 99 *data_bytes = nullptr; |
99 PreviewDataStoreMap::const_iterator it = data_store_map_.find(preview_ui_id); | 100 PreviewDataStoreMap::const_iterator it = data_store_map_.find(preview_ui_id); |
100 if (it != data_store_map_.end()) | 101 if (it != data_store_map_.end()) |
101 it->second->GetPreviewDataForIndex(index, data_bytes); | 102 it->second->GetPreviewDataForIndex(index, data_bytes); |
102 } | 103 } |
103 | 104 |
104 void PrintPreviewDataService::SetDataEntry( | 105 void PrintPreviewDataService::SetDataEntry( |
105 int32_t preview_ui_id, | 106 int32_t preview_ui_id, |
106 int index, | 107 int index, |
107 scoped_refptr<base::RefCountedBytes> data_bytes) { | 108 scoped_refptr<base::RefCountedBytes> data_bytes) { |
108 if (!ContainsKey(data_store_map_, preview_ui_id)) { | 109 if (!base::ContainsKey(data_store_map_, preview_ui_id)) { |
109 data_store_map_[preview_ui_id] = | 110 data_store_map_[preview_ui_id] = |
110 make_scoped_refptr(new PrintPreviewDataStore()); | 111 make_scoped_refptr(new PrintPreviewDataStore()); |
111 } | 112 } |
112 | 113 |
113 data_store_map_[preview_ui_id]->SetPreviewDataForIndex(index, | 114 data_store_map_[preview_ui_id]->SetPreviewDataForIndex(index, |
114 std::move(data_bytes)); | 115 std::move(data_bytes)); |
115 } | 116 } |
116 | 117 |
117 void PrintPreviewDataService::RemoveEntry(int32_t preview_ui_id) { | 118 void PrintPreviewDataService::RemoveEntry(int32_t preview_ui_id) { |
118 data_store_map_.erase(preview_ui_id); | 119 data_store_map_.erase(preview_ui_id); |
119 } | 120 } |
120 | 121 |
121 int PrintPreviewDataService::GetAvailableDraftPageCount(int32_t preview_ui_id) { | 122 int PrintPreviewDataService::GetAvailableDraftPageCount(int32_t preview_ui_id) { |
122 PreviewDataStoreMap::const_iterator it = data_store_map_.find(preview_ui_id); | 123 PreviewDataStoreMap::const_iterator it = data_store_map_.find(preview_ui_id); |
123 return (it == data_store_map_.end()) ? | 124 return (it == data_store_map_.end()) ? |
124 0 : it->second->GetAvailableDraftPageCount(); | 125 0 : it->second->GetAvailableDraftPageCount(); |
125 } | 126 } |
OLD | NEW |