Commit 5551bc6c authored by Lei Zhang's avatar Lei Zhang Committed by Commit Bot

Change printing code to take base::RefCountedMemory.

This is in preparation for adding and using base::RefCountedShm to avoid
copying data from base::SharedMemory. All the printing code being
changed only needs the generic base::RefCountedMemory interface and do
not specifically need base::RefCountedBytes.

Also fix most lint errors.

Change-Id: I4071b869e75350d922bcb7077aeda269df59ee12
Reviewed-on: https://chromium-review.googlesource.com/978649
Commit-Queue: Lei Zhang <thestig@chromium.org>
Reviewed-by: default avatarRebekah Potter <rbpotter@chromium.org>
Reviewed-by: default avatarWei Li <weili@chromium.org>
Cr-Commit-Position: refs/heads/master@{#545685}
parent 773a51f0
...@@ -13,7 +13,7 @@ ...@@ -13,7 +13,7 @@
#include "net/base/host_port_pair.h" #include "net/base/host_port_pair.h"
namespace base { namespace base {
class RefCountedBytes; class RefCountedMemory;
} }
namespace gfx { namespace gfx {
...@@ -156,10 +156,10 @@ class PrivetLocalPrintOperation { ...@@ -156,10 +156,10 @@ class PrivetLocalPrintOperation {
virtual void Start() = 0; virtual void Start() = 0;
// Required print data. MUST be called before calling |Start()|. // Required print data. MUST be called before calling Start().
virtual void SetData(const scoped_refptr<base::RefCountedBytes>& data) = 0; virtual void SetData(const scoped_refptr<base::RefCountedMemory>& data) = 0;
// Optional attributes for /submitdoc. Call before calling |Start()| // Optional attributes for /submitdoc. Call before calling Start().
// |ticket| should be in CJT format. // |ticket| should be in CJT format.
virtual void SetTicket(const std::string& ticket) = 0; virtual void SetTicket(const std::string& ticket) = 0;
......
...@@ -605,7 +605,7 @@ void PrivetLocalPrintOperationImpl::OnNeedPrivetToken( ...@@ -605,7 +605,7 @@ void PrivetLocalPrintOperationImpl::OnNeedPrivetToken(
} }
void PrivetLocalPrintOperationImpl::SetData( void PrivetLocalPrintOperationImpl::SetData(
const scoped_refptr<base::RefCountedBytes>& data) { const scoped_refptr<base::RefCountedMemory>& data) {
DCHECK(!started_); DCHECK(!started_);
data_ = data; data_ = data;
} }
......
...@@ -154,7 +154,7 @@ class PrivetLocalPrintOperationImpl ...@@ -154,7 +154,7 @@ class PrivetLocalPrintOperationImpl
// PrivetLocalPrintOperation: // PrivetLocalPrintOperation:
void Start() override; void Start() override;
void SetData(const scoped_refptr<base::RefCountedBytes>& data) override; void SetData(const scoped_refptr<base::RefCountedMemory>& data) override;
void SetTicket(const std::string& ticket) override; void SetTicket(const std::string& ticket) override;
void SetCapabilities(const std::string& capabilities) override; void SetCapabilities(const std::string& capabilities) override;
void SetUsername(const std::string& user) override; void SetUsername(const std::string& user) override;
...@@ -199,7 +199,7 @@ class PrivetLocalPrintOperationImpl ...@@ -199,7 +199,7 @@ class PrivetLocalPrintOperationImpl
cloud_devices::CloudDeviceDescription ticket_; cloud_devices::CloudDeviceDescription ticket_;
cloud_devices::CloudDeviceDescription capabilities_; cloud_devices::CloudDeviceDescription capabilities_;
scoped_refptr<base::RefCountedBytes> data_; scoped_refptr<base::RefCountedMemory> data_;
base::FilePath pwg_file_path_; base::FilePath pwg_file_path_;
bool use_pdf_ = false; bool use_pdf_ = false;
......
...@@ -4,6 +4,8 @@ ...@@ -4,6 +4,8 @@
#include "chrome/browser/printing/print_preview_data_service.h" #include "chrome/browser/printing/print_preview_data_service.h"
#include <utility>
#include "base/macros.h" #include "base/macros.h"
#include "base/memory/ptr_util.h" #include "base/memory/ptr_util.h"
#include "base/memory/ref_counted_memory.h" #include "base/memory/ref_counted_memory.h"
...@@ -34,7 +36,7 @@ class PrintPreviewDataStore { ...@@ -34,7 +36,7 @@ class PrintPreviewDataStore {
// Get the preview page for the specified |index|. // Get the preview page for the specified |index|.
void GetPreviewDataForIndex( void GetPreviewDataForIndex(
int index, int index,
scoped_refptr<base::RefCountedBytes>* data) const { scoped_refptr<base::RefCountedMemory>* data) const {
if (IsInvalidIndex(index)) if (IsInvalidIndex(index))
return; return;
...@@ -45,7 +47,7 @@ class PrintPreviewDataStore { ...@@ -45,7 +47,7 @@ class PrintPreviewDataStore {
// Set/Update the preview data entry for the specified |index|. // Set/Update the preview data entry for the specified |index|.
void SetPreviewDataForIndex(int index, void SetPreviewDataForIndex(int index,
scoped_refptr<base::RefCountedBytes> data) { scoped_refptr<base::RefCountedMemory> data) {
if (IsInvalidIndex(index)) if (IsInvalidIndex(index))
return; return;
...@@ -68,7 +70,7 @@ class PrintPreviewDataStore { ...@@ -68,7 +70,7 @@ class PrintPreviewDataStore {
// document. // document.
// Value: Preview data. // Value: Preview data.
using PreviewPageDataMap = using PreviewPageDataMap =
std::map<int, scoped_refptr<base::RefCountedBytes>>; std::map<int, scoped_refptr<base::RefCountedMemory>>;
static bool IsInvalidIndex(int index) { static bool IsInvalidIndex(int index) {
return (index != printing::COMPLETE_PREVIEW_DOCUMENT_INDEX && return (index != printing::COMPLETE_PREVIEW_DOCUMENT_INDEX &&
...@@ -94,7 +96,7 @@ PrintPreviewDataService::~PrintPreviewDataService() { ...@@ -94,7 +96,7 @@ PrintPreviewDataService::~PrintPreviewDataService() {
void PrintPreviewDataService::GetDataEntry( void PrintPreviewDataService::GetDataEntry(
int32_t preview_ui_id, int32_t preview_ui_id,
int index, int index,
scoped_refptr<base::RefCountedBytes>* data_bytes) const { scoped_refptr<base::RefCountedMemory>* data_bytes) const {
*data_bytes = nullptr; *data_bytes = nullptr;
PreviewDataStoreMap::const_iterator it = data_store_map_.find(preview_ui_id); PreviewDataStoreMap::const_iterator it = data_store_map_.find(preview_ui_id);
if (it != data_store_map_.end()) if (it != data_store_map_.end())
...@@ -104,7 +106,7 @@ void PrintPreviewDataService::GetDataEntry( ...@@ -104,7 +106,7 @@ void PrintPreviewDataService::GetDataEntry(
void PrintPreviewDataService::SetDataEntry( void PrintPreviewDataService::SetDataEntry(
int32_t preview_ui_id, int32_t preview_ui_id,
int index, int index,
scoped_refptr<base::RefCountedBytes> data_bytes) { scoped_refptr<base::RefCountedMemory> data_bytes) {
if (!base::ContainsKey(data_store_map_, preview_ui_id)) if (!base::ContainsKey(data_store_map_, preview_ui_id))
data_store_map_[preview_ui_id] = std::make_unique<PrintPreviewDataStore>(); data_store_map_[preview_ui_id] = std::make_unique<PrintPreviewDataStore>();
data_store_map_[preview_ui_id]->SetPreviewDataForIndex(index, data_store_map_[preview_ui_id]->SetPreviewDataForIndex(index,
......
...@@ -19,7 +19,7 @@ class PrintPreviewDataStore; ...@@ -19,7 +19,7 @@ class PrintPreviewDataStore;
namespace base { namespace base {
template <typename T> template <typename T>
struct DefaultSingletonTraits; struct DefaultSingletonTraits;
class RefCountedBytes; class RefCountedMemory;
} }
// PrintPreviewDataService manages data stores for chrome://print requests. // PrintPreviewDataService manages data stores for chrome://print requests.
...@@ -34,7 +34,7 @@ class PrintPreviewDataService { ...@@ -34,7 +34,7 @@ class PrintPreviewDataService {
// to NULL if the requested page is not yet available. // to NULL if the requested page is not yet available.
void GetDataEntry(int32_t preview_ui_id, void GetDataEntry(int32_t preview_ui_id,
int index, int index,
scoped_refptr<base::RefCountedBytes>* data) const; scoped_refptr<base::RefCountedMemory>* data) const;
// Set/Update the data entry in PrintPreviewDataStore. |index| is zero-based // Set/Update the data entry in PrintPreviewDataStore. |index| is zero-based
// or |printing::COMPLETE_PREVIEW_DOCUMENT_INDEX| to represent complete // or |printing::COMPLETE_PREVIEW_DOCUMENT_INDEX| to represent complete
...@@ -43,7 +43,7 @@ class PrintPreviewDataService { ...@@ -43,7 +43,7 @@ class PrintPreviewDataService {
// calling this function. It will be refcounted in PrintPreviewDataStore. // calling this function. It will be refcounted in PrintPreviewDataStore.
void SetDataEntry(int32_t preview_ui_id, void SetDataEntry(int32_t preview_ui_id,
int index, int index,
scoped_refptr<base::RefCountedBytes> data); scoped_refptr<base::RefCountedMemory> data);
// Remove the corresponding PrintPreviewUI entry from the map. // Remove the corresponding PrintPreviewUI entry from the map.
void RemoveEntry(int32_t preview_ui_id); void RemoveEntry(int32_t preview_ui_id);
......
...@@ -58,11 +58,10 @@ void StopWorker(int document_cookie) { ...@@ -58,11 +58,10 @@ void StopWorker(int document_cookie) {
} }
} }
scoped_refptr<base::RefCountedBytes> GetDataFromHandle( scoped_refptr<base::RefCountedMemory> GetDataFromHandle(
base::SharedMemoryHandle handle, base::SharedMemoryHandle handle,
uint32_t data_size) { uint32_t data_size) {
std::unique_ptr<base::SharedMemory> shared_buf( auto shared_buf = std::make_unique<base::SharedMemory>(handle, true);
new base::SharedMemory(handle, true));
if (!shared_buf->Map(data_size)) { if (!shared_buf->Map(data_size)) {
NOTREACHED(); NOTREACHED();
return nullptr; return nullptr;
...@@ -240,7 +239,7 @@ void PrintPreviewMessageHandler::OnSetOptionsFromDocument( ...@@ -240,7 +239,7 @@ void PrintPreviewMessageHandler::OnSetOptionsFromDocument(
void PrintPreviewMessageHandler::NotifyUIPreviewPageReady( void PrintPreviewMessageHandler::NotifyUIPreviewPageReady(
int page_number, int page_number,
int request_id, int request_id,
scoped_refptr<base::RefCountedBytes> data_bytes) { scoped_refptr<base::RefCountedMemory> data_bytes) {
DCHECK(data_bytes); DCHECK(data_bytes);
PrintPreviewUI* print_preview_ui = GetPrintPreviewUI(); PrintPreviewUI* print_preview_ui = GetPrintPreviewUI();
...@@ -254,7 +253,7 @@ void PrintPreviewMessageHandler::NotifyUIPreviewPageReady( ...@@ -254,7 +253,7 @@ void PrintPreviewMessageHandler::NotifyUIPreviewPageReady(
void PrintPreviewMessageHandler::NotifyUIPreviewDocumentReady( void PrintPreviewMessageHandler::NotifyUIPreviewDocumentReady(
int page_count, int page_count,
int request_id, int request_id,
scoped_refptr<base::RefCountedBytes> data_bytes) { scoped_refptr<base::RefCountedMemory> data_bytes) {
if (!data_bytes || !data_bytes->size()) if (!data_bytes || !data_bytes->size())
return; return;
......
...@@ -78,11 +78,11 @@ class PrintPreviewMessageHandler ...@@ -78,11 +78,11 @@ class PrintPreviewMessageHandler
void NotifyUIPreviewPageReady( void NotifyUIPreviewPageReady(
int page_number, int page_number,
int request_id, int request_id,
scoped_refptr<base::RefCountedBytes> data_bytes); scoped_refptr<base::RefCountedMemory> data_bytes);
void NotifyUIPreviewDocumentReady( void NotifyUIPreviewDocumentReady(
int page_count, int page_count,
int request_id, int request_id,
scoped_refptr<base::RefCountedBytes> data_bytes); scoped_refptr<base::RefCountedMemory> data_bytes);
// Callbacks for pdf compositor client. // Callbacks for pdf compositor client.
void OnCompositePdfPageDone(int page_number, void OnCompositePdfPageDone(int page_number,
......
...@@ -11,6 +11,7 @@ ...@@ -11,6 +11,7 @@
#include "base/bind.h" #include "base/bind.h"
#include "base/location.h" #include "base/location.h"
#include "base/memory/ptr_util.h" #include "base/memory/ptr_util.h"
#include "base/memory/ref_counted_memory.h"
#include "base/memory/shared_memory.h" #include "base/memory/shared_memory.h"
#include "base/message_loop/message_loop.h" #include "base/message_loop/message_loop.h"
#include "base/run_loop.h" #include "base/run_loop.h"
...@@ -143,7 +144,7 @@ bool PrintViewManagerBase::PrintNow(content::RenderFrameHost* rfh) { ...@@ -143,7 +144,7 @@ bool PrintViewManagerBase::PrintNow(content::RenderFrameHost* rfh) {
#if BUILDFLAG(ENABLE_PRINT_PREVIEW) #if BUILDFLAG(ENABLE_PRINT_PREVIEW)
void PrintViewManagerBase::PrintForPrintPreview( void PrintViewManagerBase::PrintForPrintPreview(
std::unique_ptr<base::DictionaryValue> job_settings, std::unique_ptr<base::DictionaryValue> job_settings,
const scoped_refptr<base::RefCountedBytes>& print_data, const scoped_refptr<base::RefCountedMemory>& print_data,
content::RenderFrameHost* rfh, content::RenderFrameHost* rfh,
PrinterHandler::PrintCallback callback) { PrinterHandler::PrintCallback callback) {
DCHECK_CURRENTLY_ON(content::BrowserThread::UI); DCHECK_CURRENTLY_ON(content::BrowserThread::UI);
...@@ -164,7 +165,7 @@ void PrintViewManagerBase::PrintForPrintPreview( ...@@ -164,7 +165,7 @@ void PrintViewManagerBase::PrintForPrintPreview(
void PrintViewManagerBase::PrintDocument( void PrintViewManagerBase::PrintDocument(
PrintedDocument* document, PrintedDocument* document,
const scoped_refptr<base::RefCountedBytes>& print_data, const scoped_refptr<base::RefCountedMemory>& print_data,
const gfx::Size& page_size, const gfx::Size& page_size,
const gfx::Rect& content_area, const gfx::Rect& content_area,
const gfx::Point& offsets) { const gfx::Point& offsets) {
...@@ -210,7 +211,7 @@ void PrintViewManagerBase::PrintDocument( ...@@ -210,7 +211,7 @@ void PrintViewManagerBase::PrintDocument(
#if BUILDFLAG(ENABLE_PRINT_PREVIEW) #if BUILDFLAG(ENABLE_PRINT_PREVIEW)
void PrintViewManagerBase::OnPrintSettingsDone( void PrintViewManagerBase::OnPrintSettingsDone(
const scoped_refptr<base::RefCountedBytes>& print_data, const scoped_refptr<base::RefCountedMemory>& print_data,
int page_count, int page_count,
PrinterHandler::PrintCallback callback, PrinterHandler::PrintCallback callback,
scoped_refptr<printing::PrinterQuery> printer_query) { scoped_refptr<printing::PrinterQuery> printer_query) {
...@@ -249,7 +250,7 @@ void PrintViewManagerBase::OnPrintSettingsDone( ...@@ -249,7 +250,7 @@ void PrintViewManagerBase::OnPrintSettingsDone(
} }
void PrintViewManagerBase::StartLocalPrintJob( void PrintViewManagerBase::StartLocalPrintJob(
const scoped_refptr<base::RefCountedBytes>& print_data, const scoped_refptr<base::RefCountedMemory>& print_data,
int page_count, int page_count,
scoped_refptr<printing::PrinterQuery> printer_query, scoped_refptr<printing::PrinterQuery> printer_query,
PrinterHandler::PrintCallback callback) { PrinterHandler::PrintCallback callback) {
...@@ -587,7 +588,7 @@ bool PrintViewManagerBase::CreateNewPrintJob(PrintJobWorkerOwner* job) { ...@@ -587,7 +588,7 @@ bool PrintViewManagerBase::CreateNewPrintJob(PrintJobWorkerOwner* job) {
if (!job) if (!job)
return false; return false;
print_job_ = new PrintJob(); print_job_ = base::MakeRefCounted<PrintJob>();
print_job_->Initialize(job, RenderSourceName(), number_pages_); print_job_->Initialize(job, RenderSourceName(), number_pages_);
registrar_.Add(this, chrome::NOTIFICATION_PRINT_JOB_EVENT, registrar_.Add(this, chrome::NOTIFICATION_PRINT_JOB_EVENT,
content::Source<PrintJob>(print_job_.get())); content::Source<PrintJob>(print_job_.get()));
......
...@@ -8,7 +8,7 @@ ...@@ -8,7 +8,7 @@
#include <memory> #include <memory>
#include "base/macros.h" #include "base/macros.h"
#include "base/memory/ref_counted.h" #include "base/memory/scoped_refptr.h"
#include "base/memory/weak_ptr.h" #include "base/memory/weak_ptr.h"
#include "base/strings/string16.h" #include "base/strings/string16.h"
#include "build/build_config.h" #include "build/build_config.h"
...@@ -24,7 +24,7 @@ ...@@ -24,7 +24,7 @@
struct PrintHostMsg_DidPrintDocument_Params; struct PrintHostMsg_DidPrintDocument_Params;
namespace base { namespace base {
class RefCountedBytes; class RefCountedMemory;
} }
namespace content { namespace content {
...@@ -60,7 +60,7 @@ class PrintViewManagerBase : public content::NotificationObserver, ...@@ -60,7 +60,7 @@ class PrintViewManagerBase : public content::NotificationObserver,
// frame host for the preview initiator contents respectively. // frame host for the preview initiator contents respectively.
void PrintForPrintPreview( void PrintForPrintPreview(
std::unique_ptr<base::DictionaryValue> job_settings, std::unique_ptr<base::DictionaryValue> job_settings,
const scoped_refptr<base::RefCountedBytes>& print_data, const scoped_refptr<base::RefCountedMemory>& print_data,
content::RenderFrameHost* rfh, content::RenderFrameHost* rfh,
PrinterHandler::PrintCallback callback); PrinterHandler::PrintCallback callback);
#endif #endif
...@@ -117,13 +117,13 @@ class PrintViewManagerBase : public content::NotificationObserver, ...@@ -117,13 +117,13 @@ class PrintViewManagerBase : public content::NotificationObserver,
// Helpers for PrintForPrintPreview(); // Helpers for PrintForPrintPreview();
#if BUILDFLAG(ENABLE_PRINT_PREVIEW) #if BUILDFLAG(ENABLE_PRINT_PREVIEW)
void OnPrintSettingsDone( void OnPrintSettingsDone(
const scoped_refptr<base::RefCountedBytes>& print_data, const scoped_refptr<base::RefCountedMemory>& print_data,
int page_count, int page_count,
PrinterHandler::PrintCallback callback, PrinterHandler::PrintCallback callback,
scoped_refptr<printing::PrinterQuery> printer_query); scoped_refptr<printing::PrinterQuery> printer_query);
void StartLocalPrintJob( void StartLocalPrintJob(
const scoped_refptr<base::RefCountedBytes>& print_data, const scoped_refptr<base::RefCountedMemory>& print_data,
int page_count, int page_count,
scoped_refptr<printing::PrinterQuery> printer_query, scoped_refptr<printing::PrinterQuery> printer_query,
PrinterHandler::PrintCallback callback); PrinterHandler::PrintCallback callback);
...@@ -144,7 +144,7 @@ class PrintViewManagerBase : public content::NotificationObserver, ...@@ -144,7 +144,7 @@ class PrintViewManagerBase : public content::NotificationObserver,
// Starts printing |document| with the given |print_data|. This method assumes // Starts printing |document| with the given |print_data|. This method assumes
// |print_data| contains valid data. // |print_data| contains valid data.
void PrintDocument(PrintedDocument* document, void PrintDocument(PrintedDocument* document,
const scoped_refptr<base::RefCountedBytes>& print_data, const scoped_refptr<base::RefCountedMemory>& print_data,
const gfx::Size& page_size, const gfx::Size& page_size,
const gfx::Rect& content_area, const gfx::Rect& content_area,
const gfx::Point& offsets); const gfx::Point& offsets);
......
...@@ -185,7 +185,7 @@ void ExtensionPrinterHandler::StartPrint( ...@@ -185,7 +185,7 @@ void ExtensionPrinterHandler::StartPrint(
const base::string16& job_title, const base::string16& job_title,
const std::string& ticket_json, const std::string& ticket_json,
const gfx::Size& page_size, const gfx::Size& page_size,
const scoped_refptr<base::RefCountedBytes>& print_data, const scoped_refptr<base::RefCountedMemory>& print_data,
PrintCallback callback) { PrintCallback callback) {
auto print_job = std::make_unique<extensions::PrinterProviderPrintJob>(); auto print_job = std::make_unique<extensions::PrinterProviderPrintJob>();
print_job->printer_id = destination_id; print_job->printer_id = destination_id;
......
...@@ -18,7 +18,6 @@ ...@@ -18,7 +18,6 @@
namespace base { namespace base {
class DictionaryValue; class DictionaryValue;
class ListValue; class ListValue;
class RefCountedBytes;
class RefCountedMemory; class RefCountedMemory;
} }
...@@ -63,7 +62,7 @@ class ExtensionPrinterHandler : public PrinterHandler { ...@@ -63,7 +62,7 @@ class ExtensionPrinterHandler : public PrinterHandler {
const base::string16& job_title, const base::string16& job_title,
const std::string& ticket_json, const std::string& ticket_json,
const gfx::Size& page_size, const gfx::Size& page_size,
const scoped_refptr<base::RefCountedBytes>& print_data, const scoped_refptr<base::RefCountedMemory>& print_data,
PrintCallback callback) override; PrintCallback callback) override;
void StartGrantPrinterAccess(const std::string& printer_id, void StartGrantPrinterAccess(const std::string& printer_id,
GetPrinterInfoCallback callback) override; GetPrinterInfoCallback callback) override;
......
...@@ -202,7 +202,7 @@ void LocalPrinterHandlerChromeos::StartPrint( ...@@ -202,7 +202,7 @@ void LocalPrinterHandlerChromeos::StartPrint(
const base::string16& job_title, const base::string16& job_title,
const std::string& ticket_json, const std::string& ticket_json,
const gfx::Size& page_size, const gfx::Size& page_size,
const scoped_refptr<base::RefCountedBytes>& print_data, const scoped_refptr<base::RefCountedMemory>& print_data,
PrintCallback callback) { PrintCallback callback) {
printing::StartLocalPrint(ticket_json, print_data, preview_web_contents_, printing::StartLocalPrint(ticket_json, print_data, preview_web_contents_,
std::move(callback)); std::move(callback));
......
...@@ -41,7 +41,7 @@ class LocalPrinterHandlerChromeos : public PrinterHandler { ...@@ -41,7 +41,7 @@ class LocalPrinterHandlerChromeos : public PrinterHandler {
const base::string16& job_title, const base::string16& job_title,
const std::string& ticket_json, const std::string& ticket_json,
const gfx::Size& page_size, const gfx::Size& page_size,
const scoped_refptr<base::RefCountedBytes>& print_data, const scoped_refptr<base::RefCountedMemory>& print_data,
PrintCallback callback) override; PrintCallback callback) override;
private: private:
......
...@@ -108,7 +108,7 @@ void LocalPrinterHandlerDefault::StartPrint( ...@@ -108,7 +108,7 @@ void LocalPrinterHandlerDefault::StartPrint(
const base::string16& job_title, const base::string16& job_title,
const std::string& ticket_json, const std::string& ticket_json,
const gfx::Size& page_size, const gfx::Size& page_size,
const scoped_refptr<base::RefCountedBytes>& print_data, const scoped_refptr<base::RefCountedMemory>& print_data,
PrintCallback callback) { PrintCallback callback) {
printing::StartLocalPrint(ticket_json, print_data, preview_web_contents_, printing::StartLocalPrint(ticket_json, print_data, preview_web_contents_,
std::move(callback)); std::move(callback));
......
...@@ -36,7 +36,7 @@ class LocalPrinterHandlerDefault : public PrinterHandler { ...@@ -36,7 +36,7 @@ class LocalPrinterHandlerDefault : public PrinterHandler {
const base::string16& job_title, const base::string16& job_title,
const std::string& ticket_json, const std::string& ticket_json,
const gfx::Size& page_size, const gfx::Size& page_size,
const scoped_refptr<base::RefCountedBytes>& print_data, const scoped_refptr<base::RefCountedMemory>& print_data,
PrintCallback callback) override; PrintCallback callback) override;
private: private:
......
...@@ -111,7 +111,7 @@ std::unique_ptr<base::DictionaryValue> GetPdfCapabilities( ...@@ -111,7 +111,7 @@ std::unique_ptr<base::DictionaryValue> GetPdfCapabilities(
} }
// Callback that stores a PDF file on disk. // Callback that stores a PDF file on disk.
void PrintToPdfCallback(const scoped_refptr<base::RefCountedBytes>& data, void PrintToPdfCallback(const scoped_refptr<base::RefCountedMemory>& data,
const base::FilePath& path, const base::FilePath& path,
const base::Closure& pdf_file_saved_closure) { const base::Closure& pdf_file_saved_closure) {
base::File file(path, base::File file(path,
...@@ -184,7 +184,7 @@ void PdfPrinterHandler::StartPrint( ...@@ -184,7 +184,7 @@ void PdfPrinterHandler::StartPrint(
const base::string16& job_title, const base::string16& job_title,
const std::string& ticket_json, const std::string& ticket_json,
const gfx::Size& page_size, const gfx::Size& page_size,
const scoped_refptr<base::RefCountedBytes>& print_data, const scoped_refptr<base::RefCountedMemory>& print_data,
PrintCallback callback) { PrintCallback callback) {
print_data_ = print_data; print_data_ = print_data;
if (!print_to_pdf_path_.empty()) { if (!print_to_pdf_path_.empty()) {
......
...@@ -17,7 +17,7 @@ ...@@ -17,7 +17,7 @@
#include "ui/shell_dialogs/select_file_dialog.h" #include "ui/shell_dialogs/select_file_dialog.h"
namespace base { namespace base {
class RefCountedBytes; class RefCountedMemory;
} }
namespace content { namespace content {
...@@ -56,7 +56,7 @@ class PdfPrinterHandler : public PrinterHandler, ...@@ -56,7 +56,7 @@ class PdfPrinterHandler : public PrinterHandler,
const base::string16& job_title, const base::string16& job_title,
const std::string& ticket_json, const std::string& ticket_json,
const gfx::Size& page_size, const gfx::Size& page_size,
const scoped_refptr<base::RefCountedBytes>& print_data, const scoped_refptr<base::RefCountedMemory>& print_data,
PrintCallback callback) override; PrintCallback callback) override;
// SelectFileDialog::Listener implementation. // SelectFileDialog::Listener implementation.
...@@ -108,7 +108,7 @@ class PdfPrinterHandler : public PrinterHandler, ...@@ -108,7 +108,7 @@ class PdfPrinterHandler : public PrinterHandler,
base::Closure pdf_file_saved_closure_; base::Closure pdf_file_saved_closure_;
// The data to print // The data to print
scoped_refptr<base::RefCountedBytes> print_data_; scoped_refptr<base::RefCountedMemory> print_data_;
// The callback to call when complete. // The callback to call when complete.
PrintCallback print_callback_; PrintCallback print_callback_;
......
...@@ -720,7 +720,7 @@ void PrintPreviewHandler::HandlePrint(const base::ListValue* args) { ...@@ -720,7 +720,7 @@ void PrintPreviewHandler::HandlePrint(const base::ListValue* args) {
ReportUserActionHistogram(PRINT_WITH_CLOUD_PRINT); ReportUserActionHistogram(PRINT_WITH_CLOUD_PRINT);
} }
scoped_refptr<base::RefCountedBytes> data; scoped_refptr<base::RefCountedMemory> data;
print_preview_ui()->GetPrintPreviewDataForIndex( print_preview_ui()->GetPrintPreviewDataForIndex(
printing::COMPLETE_PREVIEW_DOCUMENT_INDEX, &data); printing::COMPLETE_PREVIEW_DOCUMENT_INDEX, &data);
if (!data) { if (!data) {
...@@ -1044,11 +1044,11 @@ void PrintPreviewHandler::SendCloudPrintEnabled() { ...@@ -1044,11 +1044,11 @@ void PrintPreviewHandler::SendCloudPrintEnabled() {
} }
} }
void PrintPreviewHandler::SendCloudPrintJob(const std::string& callback_id, void PrintPreviewHandler::SendCloudPrintJob(
const base::RefCountedBytes* data) { const std::string& callback_id,
const base::RefCountedMemory* data) {
// BASE64 encode the job data. // BASE64 encode the job data.
const base::StringPiece raw_data(reinterpret_cast<const char*>(data->front()), const base::StringPiece raw_data(data->front_as<char>(), data->size());
data->size());
std::string base64_data; std::string base64_data;
base::Base64Encode(raw_data, &base64_data); base::Base64Encode(raw_data, &base64_data);
......
...@@ -27,7 +27,7 @@ class PrintPreviewUI; ...@@ -27,7 +27,7 @@ class PrintPreviewUI;
namespace base { namespace base {
class DictionaryValue; class DictionaryValue;
class RefCountedBytes; class RefCountedMemory;
} }
namespace content { namespace content {
...@@ -246,7 +246,7 @@ class PrintPreviewHandler ...@@ -246,7 +246,7 @@ class PrintPreviewHandler
// Send the PDF data to the cloud to print. // Send the PDF data to the cloud to print.
void SendCloudPrintJob(const std::string& callback_id, void SendCloudPrintJob(const std::string& callback_id,
const base::RefCountedBytes* data); const base::RefCountedMemory* data);
// Closes the preview dialog. // Closes the preview dialog.
void ClosePreviewDialog(); void ClosePreviewDialog();
......
...@@ -4,6 +4,10 @@ ...@@ -4,6 +4,10 @@
#include "chrome/browser/ui/webui/print_preview/print_preview_handler.h" #include "chrome/browser/ui/webui/print_preview/print_preview_handler.h"
#include <map>
#include <utility>
#include <vector>
#include "base/base64.h" #include "base/base64.h"
#include "base/containers/flat_set.h" #include "base/containers/flat_set.h"
#include "base/json/json_writer.h" #include "base/json/json_writer.h"
...@@ -203,7 +207,7 @@ class TestPrinterHandler : public PrinterHandler { ...@@ -203,7 +207,7 @@ class TestPrinterHandler : public PrinterHandler {
const base::string16& job_title, const base::string16& job_title,
const std::string& ticket_json, const std::string& ticket_json,
const gfx::Size& page_size, const gfx::Size& page_size,
const scoped_refptr<base::RefCountedBytes>& print_data, const scoped_refptr<base::RefCountedMemory>& print_data,
PrintCallback callback) override { PrintCallback callback) override {
std::move(callback).Run(base::Value()); std::move(callback).Run(base::Value());
} }
...@@ -239,8 +243,8 @@ class FakePrintPreviewUI : public PrintPreviewUI { ...@@ -239,8 +243,8 @@ class FakePrintPreviewUI : public PrintPreviewUI {
void GetPrintPreviewDataForIndex( void GetPrintPreviewDataForIndex(
int index, int index,
scoped_refptr<base::RefCountedBytes>* data) const override { scoped_refptr<base::RefCountedMemory>* data) const override {
*data = base::MakeRefCounted<base::RefCountedBytes>( *data = base::MakeRefCounted<base::RefCountedStaticMemory>(
reinterpret_cast<const unsigned char*>(kTestData), reinterpret_cast<const unsigned char*>(kTestData),
sizeof(kTestData) - 1); sizeof(kTestData) - 1);
} }
......
...@@ -5,7 +5,7 @@ ...@@ -5,7 +5,7 @@
#include "chrome/browser/ui/webui/print_preview/print_preview_ui.h" #include "chrome/browser/ui/webui/print_preview/print_preview_ui.h"
#include <map> #include <map>
#include <memory> #include <string>
#include <utility> #include <utility>
#include <vector> #include <vector>
...@@ -150,7 +150,7 @@ bool HandleRequestCallback( ...@@ -150,7 +150,7 @@ bool HandleRequestCallback(
return false; return false;
// Print Preview data. // Print Preview data.
scoped_refptr<base::RefCountedBytes> data; scoped_refptr<base::RefCountedMemory> data;
std::vector<std::string> url_substr = base::SplitString( std::vector<std::string> url_substr = base::SplitString(
path, "/", base::TRIM_WHITESPACE, base::SPLIT_WANT_ALL); path, "/", base::TRIM_WHITESPACE, base::SPLIT_WANT_ALL);
int preview_ui_id = -1; int preview_ui_id = -1;
...@@ -599,13 +599,13 @@ PrintPreviewUI::~PrintPreviewUI() { ...@@ -599,13 +599,13 @@ PrintPreviewUI::~PrintPreviewUI() {
void PrintPreviewUI::GetPrintPreviewDataForIndex( void PrintPreviewUI::GetPrintPreviewDataForIndex(
int index, int index,
scoped_refptr<base::RefCountedBytes>* data) const { scoped_refptr<base::RefCountedMemory>* data) const {
PrintPreviewDataService::GetInstance()->GetDataEntry(id_, index, data); PrintPreviewDataService::GetInstance()->GetDataEntry(id_, index, data);
} }
void PrintPreviewUI::SetPrintPreviewDataForIndex( void PrintPreviewUI::SetPrintPreviewDataForIndex(
int index, int index,
scoped_refptr<base::RefCountedBytes> data) { scoped_refptr<base::RefCountedMemory> data) {
PrintPreviewDataService::GetInstance()->SetDataEntry(id_, index, PrintPreviewDataService::GetInstance()->SetDataEntry(id_, index,
std::move(data)); std::move(data));
} }
......
...@@ -7,7 +7,7 @@ ...@@ -7,7 +7,7 @@
#include <stdint.h> #include <stdint.h>
#include <string> #include <memory>
#include "base/callback_forward.h" #include "base/callback_forward.h"
#include "base/gtest_prod_util.h" #include "base/gtest_prod_util.h"
...@@ -25,7 +25,7 @@ struct PrintHostMsg_SetOptionsFromDocument_Params; ...@@ -25,7 +25,7 @@ struct PrintHostMsg_SetOptionsFromDocument_Params;
namespace base { namespace base {
class DictionaryValue; class DictionaryValue;
class FilePath; class FilePath;
class RefCountedBytes; class RefCountedMemory;
} }
namespace gfx { namespace gfx {
...@@ -47,13 +47,13 @@ class PrintPreviewUI : public ConstrainedWebDialogUI { ...@@ -47,13 +47,13 @@ class PrintPreviewUI : public ConstrainedWebDialogUI {
// document. // document.
virtual void GetPrintPreviewDataForIndex( virtual void GetPrintPreviewDataForIndex(
int index, int index,
scoped_refptr<base::RefCountedBytes>* data) const; scoped_refptr<base::RefCountedMemory>* data) const;
// Sets the print preview |data|. |index| is zero-based, and can be // Sets the print preview |data|. |index| is zero-based, and can be
// |printing::COMPLETE_PREVIEW_DOCUMENT_INDEX| to set the entire preview // |printing::COMPLETE_PREVIEW_DOCUMENT_INDEX| to set the entire preview
// document. // document.
void SetPrintPreviewDataForIndex(int index, void SetPrintPreviewDataForIndex(int index,
scoped_refptr<base::RefCountedBytes> data); scoped_refptr<base::RefCountedMemory> data);
// Clear the existing print preview data. // Clear the existing print preview data.
void ClearAllPreviewData(); void ClearAllPreviewData();
......
...@@ -85,13 +85,13 @@ TEST_F(PrintPreviewUIUnitTest, PrintPreviewData) { ...@@ -85,13 +85,13 @@ TEST_F(PrintPreviewUIUnitTest, PrintPreviewData) {
PrintPreviewUI* preview_ui = static_cast<PrintPreviewUI*>( PrintPreviewUI* preview_ui = static_cast<PrintPreviewUI*>(
preview_dialog->GetWebUI()->GetController()); preview_dialog->GetWebUI()->GetController());
ASSERT_TRUE(preview_ui != NULL); ASSERT_TRUE(preview_ui);
scoped_refptr<base::RefCountedBytes> data; scoped_refptr<base::RefCountedMemory> data;
preview_ui->GetPrintPreviewDataForIndex( preview_ui->GetPrintPreviewDataForIndex(
printing::COMPLETE_PREVIEW_DOCUMENT_INDEX, printing::COMPLETE_PREVIEW_DOCUMENT_INDEX,
&data); &data);
EXPECT_EQ(NULL, data.get()); EXPECT_FALSE(data);
scoped_refptr<base::RefCountedBytes> dummy_data = CreateTestData(); scoped_refptr<base::RefCountedBytes> dummy_data = CreateTestData();
...@@ -115,7 +115,7 @@ TEST_F(PrintPreviewUIUnitTest, PrintPreviewData) { ...@@ -115,7 +115,7 @@ TEST_F(PrintPreviewUIUnitTest, PrintPreviewData) {
preview_ui->GetPrintPreviewDataForIndex( preview_ui->GetPrintPreviewDataForIndex(
printing::COMPLETE_PREVIEW_DOCUMENT_INDEX, printing::COMPLETE_PREVIEW_DOCUMENT_INDEX,
&data); &data);
EXPECT_EQ(NULL, data.get()); EXPECT_FALSE(data);
} }
// Set and get the individual draft pages. // Set and get the individual draft pages.
...@@ -138,11 +138,11 @@ TEST_F(PrintPreviewUIUnitTest, PrintPreviewDraftPages) { ...@@ -138,11 +138,11 @@ TEST_F(PrintPreviewUIUnitTest, PrintPreviewDraftPages) {
PrintPreviewUI* preview_ui = static_cast<PrintPreviewUI*>( PrintPreviewUI* preview_ui = static_cast<PrintPreviewUI*>(
preview_dialog->GetWebUI()->GetController()); preview_dialog->GetWebUI()->GetController());
ASSERT_TRUE(preview_ui != NULL); ASSERT_TRUE(preview_ui);
scoped_refptr<base::RefCountedBytes> data; scoped_refptr<base::RefCountedMemory> data;
preview_ui->GetPrintPreviewDataForIndex(printing::FIRST_PAGE_INDEX, &data); preview_ui->GetPrintPreviewDataForIndex(printing::FIRST_PAGE_INDEX, &data);
EXPECT_EQ(NULL, data.get()); EXPECT_FALSE(data);
scoped_refptr<base::RefCountedBytes> dummy_data = CreateTestData(); scoped_refptr<base::RefCountedBytes> dummy_data = CreateTestData();
...@@ -163,7 +163,7 @@ TEST_F(PrintPreviewUIUnitTest, PrintPreviewDraftPages) { ...@@ -163,7 +163,7 @@ TEST_F(PrintPreviewUIUnitTest, PrintPreviewDraftPages) {
// Get the second page data. // Get the second page data.
preview_ui->GetPrintPreviewDataForIndex(printing::FIRST_PAGE_INDEX + 1, preview_ui->GetPrintPreviewDataForIndex(printing::FIRST_PAGE_INDEX + 1,
&data); &data);
EXPECT_EQ(NULL, data.get()); EXPECT_FALSE(data);
preview_ui->SetPrintPreviewDataForIndex(printing::FIRST_PAGE_INDEX + 1, preview_ui->SetPrintPreviewDataForIndex(printing::FIRST_PAGE_INDEX + 1,
dummy_data.get()); dummy_data.get());
...@@ -175,7 +175,7 @@ TEST_F(PrintPreviewUIUnitTest, PrintPreviewDraftPages) { ...@@ -175,7 +175,7 @@ TEST_F(PrintPreviewUIUnitTest, PrintPreviewDraftPages) {
// Clear the preview data. // Clear the preview data.
preview_ui->ClearAllPreviewData(); preview_ui->ClearAllPreviewData();
preview_ui->GetPrintPreviewDataForIndex(printing::FIRST_PAGE_INDEX, &data); preview_ui->GetPrintPreviewDataForIndex(printing::FIRST_PAGE_INDEX, &data);
EXPECT_EQ(NULL, data.get()); EXPECT_FALSE(data);
} }
// Test the browser-side print preview cancellation functionality. // Test the browser-side print preview cancellation functionality.
...@@ -198,7 +198,7 @@ TEST_F(PrintPreviewUIUnitTest, GetCurrentPrintPreviewStatus) { ...@@ -198,7 +198,7 @@ TEST_F(PrintPreviewUIUnitTest, GetCurrentPrintPreviewStatus) {
PrintPreviewUI* preview_ui = static_cast<PrintPreviewUI*>( PrintPreviewUI* preview_ui = static_cast<PrintPreviewUI*>(
preview_dialog->GetWebUI()->GetController()); preview_dialog->GetWebUI()->GetController());
ASSERT_TRUE(preview_ui != NULL); ASSERT_TRUE(preview_ui);
// Test with invalid |preview_ui_addr|. // Test with invalid |preview_ui_addr|.
bool cancel = false; bool cancel = false;
......
...@@ -181,7 +181,7 @@ void ConvertPrinterListForCallback( ...@@ -181,7 +181,7 @@ void ConvertPrinterListForCallback(
} }
void StartLocalPrint(const std::string& ticket_json, void StartLocalPrint(const std::string& ticket_json,
const scoped_refptr<base::RefCountedBytes>& print_data, const scoped_refptr<base::RefCountedMemory>& print_data,
content::WebContents* preview_web_contents, content::WebContents* preview_web_contents,
PrinterHandler::PrintCallback callback) { PrinterHandler::PrintCallback callback) {
std::unique_ptr<base::DictionaryValue> job_settings = std::unique_ptr<base::DictionaryValue> job_settings =
......
...@@ -43,7 +43,7 @@ std::unique_ptr<base::DictionaryValue> ValidateCddForPrintPreview( ...@@ -43,7 +43,7 @@ std::unique_ptr<base::DictionaryValue> ValidateCddForPrintPreview(
// Starts a local print of |print_data| with print settings dictionary // Starts a local print of |print_data| with print settings dictionary
// |ticket_json|. Runs |callback| on failure or success. // |ticket_json|. Runs |callback| on failure or success.
void StartLocalPrint(const std::string& ticket_json, void StartLocalPrint(const std::string& ticket_json,
const scoped_refptr<base::RefCountedBytes>& print_data, const scoped_refptr<base::RefCountedMemory>& print_data,
content::WebContents* preview_web_contents, content::WebContents* preview_web_contents,
PrinterHandler::PrintCallback callback); PrinterHandler::PrintCallback callback);
......
...@@ -16,7 +16,7 @@ ...@@ -16,7 +16,7 @@
namespace base { namespace base {
class DictionaryValue; class DictionaryValue;
class ListValue; class ListValue;
class RefCountedBytes; class RefCountedMemory;
class Value; class Value;
} }
...@@ -127,7 +127,7 @@ class PrinterHandler { ...@@ -127,7 +127,7 @@ class PrinterHandler {
const base::string16& job_title, const base::string16& job_title,
const std::string& ticket_json, const std::string& ticket_json,
const gfx::Size& page_size, const gfx::Size& page_size,
const scoped_refptr<base::RefCountedBytes>& print_data, const scoped_refptr<base::RefCountedMemory>& print_data,
PrintCallback callback) = 0; PrintCallback callback) = 0;
}; };
......
...@@ -6,6 +6,7 @@ ...@@ -6,6 +6,7 @@
#include <memory> #include <memory>
#include <string> #include <string>
#include <utility>
#include "base/bind.h" #include "base/bind.h"
#include "base/callback.h" #include "base/callback.h"
...@@ -85,7 +86,7 @@ void PrivetPrinterHandler::StartPrint( ...@@ -85,7 +86,7 @@ void PrivetPrinterHandler::StartPrint(
const base::string16& job_title, const base::string16& job_title,
const std::string& ticket_json, const std::string& ticket_json,
const gfx::Size& page_size, const gfx::Size& page_size,
const scoped_refptr<base::RefCountedBytes>& print_data, const scoped_refptr<base::RefCountedMemory>& print_data,
PrintCallback callback) { PrintCallback callback) {
DCHECK(!print_callback_); DCHECK(!print_callback_);
print_callback_ = std::move(callback); print_callback_ = std::move(callback);
...@@ -205,7 +206,7 @@ void PrivetPrinterHandler::OnGotCapabilities( ...@@ -205,7 +206,7 @@ void PrivetPrinterHandler::OnGotCapabilities(
void PrivetPrinterHandler::PrintUpdateClient( void PrivetPrinterHandler::PrintUpdateClient(
const base::string16& job_title, const base::string16& job_title,
const scoped_refptr<base::RefCountedBytes>& print_data, const scoped_refptr<base::RefCountedMemory>& print_data,
const std::string& print_ticket, const std::string& print_ticket,
const std::string& capabilities, const std::string& capabilities,
const gfx::Size& page_size, const gfx::Size& page_size,
...@@ -237,7 +238,7 @@ bool PrivetPrinterHandler::UpdateClient( ...@@ -237,7 +238,7 @@ bool PrivetPrinterHandler::UpdateClient(
void PrivetPrinterHandler::StartPrint( void PrivetPrinterHandler::StartPrint(
const base::string16& job_title, const base::string16& job_title,
const scoped_refptr<base::RefCountedBytes>& print_data, const scoped_refptr<base::RefCountedMemory>& print_data,
const std::string& print_ticket, const std::string& print_ticket,
const std::string& capabilities, const std::string& capabilities,
const gfx::Size& page_size) { const gfx::Size& page_size) {
......
...@@ -19,7 +19,7 @@ ...@@ -19,7 +19,7 @@
namespace base { namespace base {
class DictionaryValue; class DictionaryValue;
class OneShotTimer; class OneShotTimer;
class RefCountedBytes; class RefCountedMemory;
} // namespace base } // namespace base
namespace gfx { namespace gfx {
...@@ -48,7 +48,7 @@ class PrivetPrinterHandler ...@@ -48,7 +48,7 @@ class PrivetPrinterHandler
const base::string16& job_title, const base::string16& job_title,
const std::string& ticket_json, const std::string& ticket_json,
const gfx::Size& page_size, const gfx::Size& page_size,
const scoped_refptr<base::RefCountedBytes>& print_data, const scoped_refptr<base::RefCountedMemory>& print_data,
PrintCallback callback) override; PrintCallback callback) override;
// PrivetLocalPrinterLister::Delegate implementation. // PrivetLocalPrinterLister::Delegate implementation.
...@@ -76,14 +76,14 @@ class PrivetPrinterHandler ...@@ -76,14 +76,14 @@ class PrivetPrinterHandler
void OnGotCapabilities(const base::DictionaryValue* capabilities); void OnGotCapabilities(const base::DictionaryValue* capabilities);
void PrintUpdateClient( void PrintUpdateClient(
const base::string16& job_title, const base::string16& job_title,
const scoped_refptr<base::RefCountedBytes>& print_data, const scoped_refptr<base::RefCountedMemory>& print_data,
const std::string& print_ticket, const std::string& print_ticket,
const std::string& capabilities, const std::string& capabilities,
const gfx::Size& page_size, const gfx::Size& page_size,
std::unique_ptr<cloud_print::PrivetHTTPClient> http_client); std::unique_ptr<cloud_print::PrivetHTTPClient> http_client);
bool UpdateClient(std::unique_ptr<cloud_print::PrivetHTTPClient> http_client); bool UpdateClient(std::unique_ptr<cloud_print::PrivetHTTPClient> http_client);
void StartPrint(const base::string16& job_title, void StartPrint(const base::string16& job_title,
const scoped_refptr<base::RefCountedBytes>& print_data, const scoped_refptr<base::RefCountedMemory>& print_data,
const std::string& print_ticket, const std::string& print_ticket,
const std::string& capabilities, const std::string& capabilities,
const gfx::Size& page_size); const gfx::Size& page_size);
......
...@@ -4,6 +4,8 @@ ...@@ -4,6 +4,8 @@
#include "components/printing/service/public/cpp/pdf_service_mojo_utils.h" #include "components/printing/service/public/cpp/pdf_service_mojo_utils.h"
#include <utility>
#include "base/memory/ref_counted_memory.h" #include "base/memory/ref_counted_memory.h"
#include "base/memory/shared_memory.h" #include "base/memory/shared_memory.h"
#include "mojo/public/cpp/system/platform_handle.h" #include "mojo/public/cpp/system/platform_handle.h"
...@@ -20,8 +22,8 @@ std::unique_ptr<base::SharedMemory> GetShmFromMojoHandle( ...@@ -20,8 +22,8 @@ std::unique_ptr<base::SharedMemory> GetShmFromMojoHandle(
std::move(handle), &memory_handle, &memory_size, &protection); std::move(handle), &memory_handle, &memory_size, &protection);
if (result != MOJO_RESULT_OK) if (result != MOJO_RESULT_OK)
return nullptr; return nullptr;
DCHECK_GT(memory_size, 0u);
DCHECK_GT(memory_size, 0u);
const bool read_only = const bool read_only =
protection == mojo::UnwrappedSharedMemoryHandleProtection::kReadOnly; protection == mojo::UnwrappedSharedMemoryHandleProtection::kReadOnly;
std::unique_ptr<base::SharedMemory> shm = std::unique_ptr<base::SharedMemory> shm =
...@@ -33,7 +35,7 @@ std::unique_ptr<base::SharedMemory> GetShmFromMojoHandle( ...@@ -33,7 +35,7 @@ std::unique_ptr<base::SharedMemory> GetShmFromMojoHandle(
return shm; return shm;
} }
scoped_refptr<base::RefCountedBytes> GetDataFromMojoHandle( scoped_refptr<base::RefCountedMemory> GetDataFromMojoHandle(
mojo::ScopedSharedBufferHandle handle) { mojo::ScopedSharedBufferHandle handle) {
std::unique_ptr<base::SharedMemory> shm = std::unique_ptr<base::SharedMemory> shm =
GetShmFromMojoHandle(std::move(handle)); GetShmFromMojoHandle(std::move(handle));
......
...@@ -11,7 +11,7 @@ ...@@ -11,7 +11,7 @@
#include "mojo/public/cpp/system/buffer.h" #include "mojo/public/cpp/system/buffer.h"
namespace base { namespace base {
class RefCountedBytes; class RefCountedMemory;
class SharedMemory; class SharedMemory;
} // namespace base } // namespace base
...@@ -20,7 +20,7 @@ namespace printing { ...@@ -20,7 +20,7 @@ namespace printing {
std::unique_ptr<base::SharedMemory> GetShmFromMojoHandle( std::unique_ptr<base::SharedMemory> GetShmFromMojoHandle(
mojo::ScopedSharedBufferHandle handle); mojo::ScopedSharedBufferHandle handle);
scoped_refptr<base::RefCountedBytes> GetDataFromMojoHandle( scoped_refptr<base::RefCountedMemory> GetDataFromMojoHandle(
mojo::ScopedSharedBufferHandle handle); mojo::ScopedSharedBufferHandle handle);
} // namespace printing } // namespace printing
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment