Fix building on Windows

This commit is contained in:
Cheng Zhao 2016-05-23 16:39:19 +09:00
parent 9d82041923
commit 44651656dd
4 changed files with 25 additions and 22 deletions

View file

@ -9,8 +9,7 @@
#include <vector> #include <vector>
#include "base/compiler_specific.h" #include "base/macros.h"
#include "base/memory/scoped_ptr.h"
namespace atom { namespace atom {

View file

@ -58,7 +58,7 @@ typedef std::unique_ptr<base::File, BrowserThread::DeleteOnFileThread>
class LazyEmf : public MetafilePlayer { class LazyEmf : public MetafilePlayer {
public: public:
LazyEmf(const scoped_refptr<RefCountedTempDir>& temp_dir, ScopedTempFile file) LazyEmf(const scoped_refptr<RefCountedTempDir>& temp_dir, ScopedTempFile file)
: temp_dir_(temp_dir), file_(file.Pass()) {} : temp_dir_(temp_dir), file_(std::move(file)) {}
virtual ~LazyEmf() { Close(); } virtual ~LazyEmf() { Close(); }
virtual bool SafePlayback(HDC hdc) const override; virtual bool SafePlayback(HDC hdc) const override;
@ -131,8 +131,8 @@ class PdfToEmfUtilityProcessHostClient
const PdfToEmfConverter::GetPageCallback& callback() const { const PdfToEmfConverter::GetPageCallback& callback() const {
return callback_; return callback_;
} }
ScopedTempFile emf() { return emf_.Pass(); } ScopedTempFile TakeEmf() { return std::move(emf_); }
void set_emf(ScopedTempFile emf) { emf_ = emf.Pass(); } void set_emf(ScopedTempFile emf) { emf_ = std::move(emf); }
private: private:
int page_number_; int page_number_;
@ -203,10 +203,10 @@ ScopedTempFile CreateTempFile(scoped_refptr<RefCountedTempDir>* temp_dir) {
*temp_dir = new RefCountedTempDir(); *temp_dir = new RefCountedTempDir();
ScopedTempFile file; ScopedTempFile file;
if (!(*temp_dir)->IsValid()) if (!(*temp_dir)->IsValid())
return file.Pass(); return file;
base::FilePath path; base::FilePath path;
if (!base::CreateTemporaryFileInDir((*temp_dir)->GetPath(), &path)) if (!base::CreateTemporaryFileInDir((*temp_dir)->GetPath(), &path))
return file.Pass(); return file;
file.reset(new base::File(path, file.reset(new base::File(path,
base::File::FLAG_CREATE_ALWAYS | base::File::FLAG_CREATE_ALWAYS |
base::File::FLAG_WRITE | base::File::FLAG_WRITE |
@ -215,7 +215,7 @@ ScopedTempFile CreateTempFile(scoped_refptr<RefCountedTempDir>* temp_dir) {
base::File::FLAG_TEMPORARY)); base::File::FLAG_TEMPORARY));
if (!file->IsValid()) if (!file->IsValid())
file.reset(); file.reset();
return file.Pass(); return file;
} }
ScopedTempFile CreateTempPdfFile( ScopedTempFile CreateTempPdfFile(
@ -230,7 +230,7 @@ ScopedTempFile CreateTempPdfFile(
pdf_file.reset(); pdf_file.reset();
} }
pdf_file->Seek(base::File::FROM_BEGIN, 0); pdf_file->Seek(base::File::FROM_BEGIN, 0);
return pdf_file.Pass(); return pdf_file;
} }
bool LazyEmf::SafePlayback(HDC hdc) const { bool LazyEmf::SafePlayback(HDC hdc) const {
@ -319,12 +319,11 @@ void PdfToEmfUtilityProcessHostClient::OnProcessStarted() {
void PdfToEmfUtilityProcessHostClient::OnTempPdfReady(ScopedTempFile pdf) { void PdfToEmfUtilityProcessHostClient::OnTempPdfReady(ScopedTempFile pdf) {
DCHECK_CURRENTLY_ON(BrowserThread::IO); DCHECK_CURRENTLY_ON(BrowserThread::IO);
if (!utility_process_host_) if (!utility_process_host_ || !pdf)
return OnFailed(); return OnFailed();
base::ProcessHandle process = utility_process_host_->GetData().handle;
// Should reply with OnPageCount(). // Should reply with OnPageCount().
Send(new ChromeUtilityMsg_RenderPDFPagesToMetafiles( Send(new ChromeUtilityMsg_RenderPDFPagesToMetafiles(
IPC::GetFileHandleForProcess(pdf->GetPlatformFile(), process, false), IPC::GetPlatformFileForTransit(pdf->GetPlatformFile(), false),
settings_)); settings_));
} }
@ -373,12 +372,11 @@ void PdfToEmfUtilityProcessHostClient::OnTempEmfReady(
GetPageCallbackData* callback_data, GetPageCallbackData* callback_data,
ScopedTempFile emf) { ScopedTempFile emf) {
DCHECK_CURRENTLY_ON(BrowserThread::IO); DCHECK_CURRENTLY_ON(BrowserThread::IO);
if (!utility_process_host_) if (!utility_process_host_ || !emf)
return OnFailed(); return OnFailed();
base::ProcessHandle process = utility_process_host_->GetData().handle;
IPC::PlatformFileForTransit transit = IPC::PlatformFileForTransit transit =
IPC::GetFileHandleForProcess(emf->GetPlatformFile(), process, false); IPC::GetPlatformFileForTransit(emf->GetPlatformFile(), false);
callback_data->set_emf(emf.Pass()); callback_data->set_emf(std::move(emf));
// Should reply with OnPageDone(). // Should reply with OnPageDone().
Send(new ChromeUtilityMsg_RenderPDFPagesToMetafiles_GetPage( Send(new ChromeUtilityMsg_RenderPDFPagesToMetafiles_GetPage(
callback_data->page_number(), transit)); callback_data->page_number(), transit));
@ -389,10 +387,16 @@ void PdfToEmfUtilityProcessHostClient::OnPageDone(bool success,
DCHECK_CURRENTLY_ON(BrowserThread::IO); DCHECK_CURRENTLY_ON(BrowserThread::IO);
if (get_page_callbacks_.empty()) if (get_page_callbacks_.empty())
return OnFailed(); return OnFailed();
std::unique_ptr<MetafilePlayer> emf;
GetPageCallbackData& data = get_page_callbacks_.front(); GetPageCallbackData& data = get_page_callbacks_.front();
if (success) std::unique_ptr<MetafilePlayer> emf;
emf.reset(new LazyEmf(temp_dir_, data.emf().Pass()));
if (success) {
ScopedTempFile temp_emf = data.TakeEmf();
if (!temp_emf) // Unexpected message from utility process.
return OnFailed();
emf.reset(new LazyEmf(temp_dir_, std::move(temp_emf)));
}
BrowserThread::PostTask(BrowserThread::UI, BrowserThread::PostTask(BrowserThread::UI,
FROM_HERE, FROM_HERE,
base::Bind(&PdfToEmfConverterImpl::RunCallback, base::Bind(&PdfToEmfConverterImpl::RunCallback,

View file

@ -306,7 +306,7 @@ void PrintJob::OnPdfToEmfPageConverted(int page_number,
// Update the rendered document. It will send notifications to the listener. // Update the rendered document. It will send notifications to the listener.
document_->SetPage(page_number, document_->SetPage(page_number,
emf.Pass(), std::move(emf),
scale_factor, scale_factor,
ptd_to_emf_state_->page_size(), ptd_to_emf_state_->page_size(),
ptd_to_emf_state_->content_area()); ptd_to_emf_state_->content_area());

View file

@ -53,7 +53,7 @@ void PrintingHandlerWin::OnRenderPDFPagesToMetafile(
const PdfRenderSettings& settings) { const PdfRenderSettings& settings) {
pdf_rendering_settings_ = settings; pdf_rendering_settings_ = settings;
base::File pdf_file = IPC::PlatformFileForTransitToFile(pdf_transit); base::File pdf_file = IPC::PlatformFileForTransitToFile(pdf_transit);
int page_count = LoadPDF(pdf_file.Pass()); int page_count = LoadPDF(std::move(pdf_file));
//int page_count = 1; //int page_count = 1;
Send( Send(
new ChromeUtilityHostMsg_RenderPDFPagesToMetafiles_PageCount(page_count)); new ChromeUtilityHostMsg_RenderPDFPagesToMetafiles_PageCount(page_count));
@ -65,7 +65,7 @@ void PrintingHandlerWin::OnRenderPDFPagesToMetafileGetPage(
base::File emf_file = IPC::PlatformFileForTransitToFile(output_file); base::File emf_file = IPC::PlatformFileForTransitToFile(output_file);
float scale_factor = 1.0f; float scale_factor = 1.0f;
bool success = bool success =
RenderPdfPageToMetafile(page_number, emf_file.Pass(), &scale_factor); RenderPdfPageToMetafile(page_number, std::move(emf_file), &scale_factor);
Send(new ChromeUtilityHostMsg_RenderPDFPagesToMetafiles_PageDone( Send(new ChromeUtilityHostMsg_RenderPDFPagesToMetafiles_PageDone(
success, scale_factor)); success, scale_factor));
} }