| 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/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 "base/stl_util.h" | 9 #include "base/stl_util.h" |
| 10 #include "printing/print_job_constants.h" | 10 #include "printing/print_job_constants.h" |
| (...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 56 } | 56 } |
| 57 | 57 |
| 58 private: | 58 private: |
| 59 friend class base::RefCounted<PrintPreviewDataStore>; | 59 friend class base::RefCounted<PrintPreviewDataStore>; |
| 60 | 60 |
| 61 // 1:1 relationship between page index and its associated preview data. | 61 // 1:1 relationship between page index and its associated preview data. |
| 62 // Key: Page index is zero-based and can be | 62 // Key: Page index is zero-based and can be |
| 63 // |printing::COMPLETE_PREVIEW_DOCUMENT_INDEX| to represent complete preview | 63 // |printing::COMPLETE_PREVIEW_DOCUMENT_INDEX| to represent complete preview |
| 64 // document. | 64 // document. |
| 65 // Value: Preview data. | 65 // Value: Preview data. |
| 66 typedef std::map<int, scoped_refptr<base::RefCountedBytes> > | 66 using PreviewPageDataMap = |
| 67 PreviewPageDataMap; | 67 std::map<int, scoped_refptr<base::RefCountedBytes>>; |
| 68 | 68 |
| 69 ~PrintPreviewDataStore() {} | 69 ~PrintPreviewDataStore() {} |
| 70 | 70 |
| 71 static bool IsInvalidIndex(int index) { | 71 static bool IsInvalidIndex(int index) { |
| 72 return (index != printing::COMPLETE_PREVIEW_DOCUMENT_INDEX && | 72 return (index != printing::COMPLETE_PREVIEW_DOCUMENT_INDEX && |
| 73 index < printing::FIRST_PAGE_INDEX); | 73 index < printing::FIRST_PAGE_INDEX); |
| 74 } | 74 } |
| 75 | 75 |
| 76 PreviewPageDataMap page_data_map_; | 76 PreviewPageDataMap page_data_map_; |
| 77 | 77 |
| 78 DISALLOW_COPY_AND_ASSIGN(PrintPreviewDataStore); | 78 DISALLOW_COPY_AND_ASSIGN(PrintPreviewDataStore); |
| 79 }; | 79 }; |
| 80 | 80 |
| 81 // static | 81 // static |
| 82 PrintPreviewDataService* PrintPreviewDataService::GetInstance() { | 82 PrintPreviewDataService* PrintPreviewDataService::GetInstance() { |
| 83 return Singleton<PrintPreviewDataService>::get(); | 83 return Singleton<PrintPreviewDataService>::get(); |
| 84 } | 84 } |
| 85 | 85 |
| 86 PrintPreviewDataService::PrintPreviewDataService() { | 86 PrintPreviewDataService::PrintPreviewDataService() { |
| 87 } | 87 } |
| 88 | 88 |
| 89 PrintPreviewDataService::~PrintPreviewDataService() { | 89 PrintPreviewDataService::~PrintPreviewDataService() { |
| 90 } | 90 } |
| 91 | 91 |
| 92 void PrintPreviewDataService::GetDataEntry( | 92 void PrintPreviewDataService::GetDataEntry( |
| 93 int32 preview_ui_id, | 93 int32_t preview_ui_id, |
| 94 int index, | 94 int index, |
| 95 scoped_refptr<base::RefCountedBytes>* data_bytes) { | 95 scoped_refptr<base::RefCountedBytes>* data_bytes) { |
| 96 *data_bytes = NULL; | 96 *data_bytes = nullptr; |
| 97 PreviewDataStoreMap::const_iterator it = data_store_map_.find(preview_ui_id); | 97 PreviewDataStoreMap::const_iterator it = data_store_map_.find(preview_ui_id); |
| 98 if (it != data_store_map_.end()) | 98 if (it != data_store_map_.end()) |
| 99 it->second->GetPreviewDataForIndex(index, data_bytes); | 99 it->second->GetPreviewDataForIndex(index, data_bytes); |
| 100 } | 100 } |
| 101 | 101 |
| 102 void PrintPreviewDataService::SetDataEntry( | 102 void PrintPreviewDataService::SetDataEntry( |
| 103 int32 preview_ui_id, | 103 int32_t preview_ui_id, |
| 104 int index, | 104 int index, |
| 105 const base::RefCountedBytes* data_bytes) { | 105 const base::RefCountedBytes* data_bytes) { |
| 106 if (!ContainsKey(data_store_map_, preview_ui_id)) | 106 if (!ContainsKey(data_store_map_, preview_ui_id)) |
| 107 data_store_map_[preview_ui_id] = new PrintPreviewDataStore(); | 107 data_store_map_[preview_ui_id] = new PrintPreviewDataStore(); |
| 108 | 108 |
| 109 data_store_map_[preview_ui_id]->SetPreviewDataForIndex(index, data_bytes); | 109 data_store_map_[preview_ui_id]->SetPreviewDataForIndex(index, data_bytes); |
| 110 } | 110 } |
| 111 | 111 |
| 112 void PrintPreviewDataService::RemoveEntry(int32 preview_ui_id) { | 112 void PrintPreviewDataService::RemoveEntry(int32_t preview_ui_id) { |
| 113 data_store_map_.erase(preview_ui_id); | 113 data_store_map_.erase(preview_ui_id); |
| 114 } | 114 } |
| 115 | 115 |
| 116 int PrintPreviewDataService::GetAvailableDraftPageCount(int32 preview_ui_id) { | 116 int PrintPreviewDataService::GetAvailableDraftPageCount(int32_t preview_ui_id) { |
| 117 PreviewDataStoreMap::const_iterator it = data_store_map_.find(preview_ui_id); | 117 PreviewDataStoreMap::const_iterator it = data_store_map_.find(preview_ui_id); |
| 118 return (it == data_store_map_.end()) ? | 118 return (it == data_store_map_.end()) ? |
| 119 0 : it->second->GetAvailableDraftPageCount(); | 119 0 : it->second->GetAvailableDraftPageCount(); |
| 120 } | 120 } |
| OLD | NEW |