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

Unified Diff: chrome/browser/printing/print_preview_data_service.cc

Issue 10873097: Merge 153342 - Print preview: Use an ID instead of memory pointer string in WebUI. (Closed) Base URL: svn://svn.chromium.org/chrome/branches/1229/src/
Patch Set: Created 8 years, 4 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 side-by-side diff with in-line comments
Download patch
Index: chrome/browser/printing/print_preview_data_service.cc
===================================================================
--- chrome/browser/printing/print_preview_data_service.cc (revision 153583)
+++ chrome/browser/printing/print_preview_data_service.cc (working copy)
@@ -6,6 +6,7 @@
#include "base/memory/ref_counted_memory.h"
#include "base/memory/singleton.h"
+#include "base/stl_util.h"
#include "printing/print_job_constants.h"
// PrintPreviewDataStore stores data for preview workflow and preview printing
@@ -30,10 +31,8 @@
// Get the preview page for the specified |index|.
void GetPreviewDataForIndex(int index,
scoped_refptr<base::RefCountedBytes>* data) {
- if (index != printing::COMPLETE_PREVIEW_DOCUMENT_INDEX &&
- index < printing::FIRST_PAGE_INDEX) {
+ if (IsInvalidIndex(index))
return;
- }
PreviewPageDataMap::iterator it = page_data_map_.find(index);
if (it != page_data_map_.end())
@@ -42,10 +41,8 @@
// Set/Update the preview data entry for the specified |index|.
void SetPreviewDataForIndex(int index, const base::RefCountedBytes* data) {
- if (index != printing::COMPLETE_PREVIEW_DOCUMENT_INDEX &&
- index < printing::FIRST_PAGE_INDEX) {
+ if (IsInvalidIndex(index))
return;
- }
page_data_map_[index] = const_cast<base::RefCountedBytes*>(data);
}
@@ -53,10 +50,8 @@
// Returns the available draft page count.
int GetAvailableDraftPageCount() {
int page_data_map_size = page_data_map_.size();
- if (page_data_map_.find(printing::COMPLETE_PREVIEW_DOCUMENT_INDEX) !=
- page_data_map_.end()) {
+ if (ContainsKey(page_data_map_, printing::COMPLETE_PREVIEW_DOCUMENT_INDEX))
page_data_map_size--;
- }
return page_data_map_size;
}
@@ -73,6 +68,11 @@
~PrintPreviewDataStore() {}
+ static bool IsInvalidIndex(int index) {
+ return (index != printing::COMPLETE_PREVIEW_DOCUMENT_INDEX &&
+ index < printing::FIRST_PAGE_INDEX);
+ }
+
PreviewPageDataMap page_data_map_;
DISALLOW_COPY_AND_ASSIGN(PrintPreviewDataStore);
@@ -90,37 +90,31 @@
}
void PrintPreviewDataService::GetDataEntry(
- const std::string& preview_ui_addr_str,
+ int32 preview_ui_id,
int index,
scoped_refptr<base::RefCountedBytes>* data_bytes) {
*data_bytes = NULL;
- PreviewDataStoreMap::iterator it = data_store_map_.find(preview_ui_addr_str);
+ PreviewDataStoreMap::const_iterator it = data_store_map_.find(preview_ui_id);
if (it != data_store_map_.end())
it->second->GetPreviewDataForIndex(index, data_bytes);
}
void PrintPreviewDataService::SetDataEntry(
- const std::string& preview_ui_addr_str,
+ int32 preview_ui_id,
int index,
const base::RefCountedBytes* data_bytes) {
- PreviewDataStoreMap::iterator it = data_store_map_.find(preview_ui_addr_str);
- if (it == data_store_map_.end())
- data_store_map_[preview_ui_addr_str] = new PrintPreviewDataStore();
+ if (!ContainsKey(data_store_map_, preview_ui_id))
+ data_store_map_[preview_ui_id] = new PrintPreviewDataStore();
- data_store_map_[preview_ui_addr_str]->SetPreviewDataForIndex(index,
- data_bytes);
+ data_store_map_[preview_ui_id]->SetPreviewDataForIndex(index, data_bytes);
}
-void PrintPreviewDataService::RemoveEntry(
- const std::string& preview_ui_addr_str) {
- PreviewDataStoreMap::iterator it = data_store_map_.find(preview_ui_addr_str);
- if (it != data_store_map_.end())
- data_store_map_.erase(it);
+void PrintPreviewDataService::RemoveEntry(int32 preview_ui_id) {
+ data_store_map_.erase(preview_ui_id);
}
-int PrintPreviewDataService::GetAvailableDraftPageCount(
- const std::string& preview_ui_addr_str) {
- if (data_store_map_.find(preview_ui_addr_str) != data_store_map_.end())
- return data_store_map_[preview_ui_addr_str]->GetAvailableDraftPageCount();
- return 0;
+int PrintPreviewDataService::GetAvailableDraftPageCount(int32 preview_ui_id) {
+ PreviewDataStoreMap::const_iterator it = data_store_map_.find(preview_ui_id);
+ return (it == data_store_map_.end()) ?
+ 0 : it->second->GetAvailableDraftPageCount();
}
« no previous file with comments | « chrome/browser/printing/print_preview_data_service.h ('k') | chrome/browser/printing/printing_message_filter.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698