Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(343)

Side by Side Diff: chrome/browser/printing/print_preview_data_service.cc

Issue 1803263002: base: Make RefCountedBytes::TakeVector return ref ptr instead of raw ptr (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 4 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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 23 matching lines...) Expand all
34 scoped_refptr<base::RefCountedBytes>* data) { 34 scoped_refptr<base::RefCountedBytes>* data) {
35 if (IsInvalidIndex(index)) 35 if (IsInvalidIndex(index))
36 return; 36 return;
37 37
38 PreviewPageDataMap::iterator it = page_data_map_.find(index); 38 PreviewPageDataMap::iterator it = page_data_map_.find(index);
39 if (it != page_data_map_.end()) 39 if (it != page_data_map_.end())
40 *data = it->second.get(); 40 *data = it->second.get();
41 } 41 }
42 42
43 // Set/Update the preview data entry for the specified |index|. 43 // Set/Update the preview data entry for the specified |index|.
44 void SetPreviewDataForIndex(int index, const base::RefCountedBytes* data) { 44 void SetPreviewDataForIndex(int index,
45 scoped_refptr<base::RefCountedBytes> data) {
45 if (IsInvalidIndex(index)) 46 if (IsInvalidIndex(index))
46 return; 47 return;
47 48
48 page_data_map_[index] = const_cast<base::RefCountedBytes*>(data); 49 page_data_map_[index] = std::move(data);
49 } 50 }
50 51
51 // Returns the available draft page count. 52 // Returns the available draft page count.
52 int GetAvailableDraftPageCount() { 53 int GetAvailableDraftPageCount() {
53 int page_data_map_size = page_data_map_.size(); 54 int page_data_map_size = page_data_map_.size();
54 if (ContainsKey(page_data_map_, printing::COMPLETE_PREVIEW_DOCUMENT_INDEX)) 55 if (ContainsKey(page_data_map_, printing::COMPLETE_PREVIEW_DOCUMENT_INDEX))
55 page_data_map_size--; 56 page_data_map_size--;
56 return page_data_map_size; 57 return page_data_map_size;
57 } 58 }
58 59
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after
96 scoped_refptr<base::RefCountedBytes>* data_bytes) { 97 scoped_refptr<base::RefCountedBytes>* data_bytes) {
97 *data_bytes = nullptr; 98 *data_bytes = nullptr;
98 PreviewDataStoreMap::const_iterator it = data_store_map_.find(preview_ui_id); 99 PreviewDataStoreMap::const_iterator it = data_store_map_.find(preview_ui_id);
99 if (it != data_store_map_.end()) 100 if (it != data_store_map_.end())
100 it->second->GetPreviewDataForIndex(index, data_bytes); 101 it->second->GetPreviewDataForIndex(index, data_bytes);
101 } 102 }
102 103
103 void PrintPreviewDataService::SetDataEntry( 104 void PrintPreviewDataService::SetDataEntry(
104 int32_t preview_ui_id, 105 int32_t preview_ui_id,
105 int index, 106 int index,
106 const base::RefCountedBytes* data_bytes) { 107 scoped_refptr<base::RefCountedBytes> data_bytes) {
107 if (!ContainsKey(data_store_map_, preview_ui_id)) 108 if (!ContainsKey(data_store_map_, preview_ui_id)) {
108 data_store_map_[preview_ui_id] = new PrintPreviewDataStore(); 109 data_store_map_[preview_ui_id] =
110 make_scoped_refptr(new PrintPreviewDataStore());
111 }
109 112
110 data_store_map_[preview_ui_id]->SetPreviewDataForIndex(index, data_bytes); 113 data_store_map_[preview_ui_id]->SetPreviewDataForIndex(index,
114 std::move(data_bytes));
111 } 115 }
112 116
113 void PrintPreviewDataService::RemoveEntry(int32_t preview_ui_id) { 117 void PrintPreviewDataService::RemoveEntry(int32_t preview_ui_id) {
114 data_store_map_.erase(preview_ui_id); 118 data_store_map_.erase(preview_ui_id);
115 } 119 }
116 120
117 int PrintPreviewDataService::GetAvailableDraftPageCount(int32_t preview_ui_id) { 121 int PrintPreviewDataService::GetAvailableDraftPageCount(int32_t preview_ui_id) {
118 PreviewDataStoreMap::const_iterator it = data_store_map_.find(preview_ui_id); 122 PreviewDataStoreMap::const_iterator it = data_store_map_.find(preview_ui_id);
119 return (it == data_store_map_.end()) ? 123 return (it == data_store_map_.end()) ?
120 0 : it->second->GetAvailableDraftPageCount(); 124 0 : it->second->GetAvailableDraftPageCount();
121 } 125 }
OLDNEW
« no previous file with comments | « chrome/browser/printing/print_preview_data_service.h ('k') | chrome/browser/printing/print_preview_message_handler.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698