Bug 1319423 - Part 2 - Switch away from std::ifstream to PRFileDesc in PrintTranslator; r=jrmuizel

MozReview-Commit-ID: 6ucwbGkqOQ0

--HG--
extra : rebase_source : ab0540e2b7d61108c8c550d8bf8b8a594364f90a
This commit is contained in:
Alex Gaynor 2017-10-03 13:23:57 -04:00
parent 41d8032290
commit b00c32c807
6 changed files with 26 additions and 7 deletions

View File

@ -23,6 +23,11 @@ RecordedEvent::LoadEventFromStream(std::istream &aStream, EventType aType) {
return LoadEvent(aStream, aType);
}
RecordedEvent *
RecordedEvent::LoadEventFromStream(EventStream& aStream, EventType aType) {
return LoadEvent(aStream, aType);
}
string
RecordedEvent::GetEventName(EventType aType)
{

View File

@ -210,6 +210,7 @@ struct MemStream {
class EventStream {
public:
virtual void write(const char* aData, size_t aSize) = 0;
virtual void read(char* aOut, size_t aSize) = 0;
};
class RecordedEvent {
@ -298,6 +299,7 @@ public:
template<class S>
static RecordedEvent *LoadEvent(S &aStream, EventType aType);
static RecordedEvent *LoadEventFromStream(std::istream &aStream, EventType aType);
static RecordedEvent *LoadEventFromStream(EventStream& aStream, EventType aType);
// An alternative to LoadEvent that avoids a heap allocation for the event.
// This accepts a callable `f' that will take a RecordedEvent* as a single parameter

View File

@ -15,11 +15,12 @@ namespace layout {
class PRFileDescStream : public mozilla::gfx::EventStream {
public:
PRFileDescStream() : mFd(nullptr) {}
PRFileDescStream() : mFd(nullptr), mGood(true) {}
void Open(const char* aFilename) {
MOZ_ASSERT(!IsOpen());
mFd = PR_Open(aFilename, PR_RDWR | PR_CREATE_FILE, PR_IRUSR | PR_IWUSR);
mGood = true;
}
void Close() {
@ -46,8 +47,18 @@ public:
}
}
void read(char* aOut, size_t aSize) {
PRInt32 res = PR_Read(mFd, static_cast<void*>(aOut), aSize);
mGood = res >= 0 && ((size_t)res == aSize);
}
bool good() {
return mGood;
}
private:
PRFileDesc* mFd;
bool mGood;
};
class DrawEventRecorderPRFileDesc : public gfx::DrawEventRecorderPrivate
@ -85,6 +96,7 @@ private:
};
}
}
#endif /* mozilla_layout_printing_DrawEventRecorder_h */

View File

@ -25,7 +25,7 @@ PrintTranslator::PrintTranslator(nsDeviceContext* aDeviceContext)
}
bool
PrintTranslator::TranslateRecording(std::istream& aRecording)
PrintTranslator::TranslateRecording(PRFileDescStream& aRecording)
{
uint32_t magicInt;
ReadElement(aRecording, magicInt);

View File

@ -35,7 +35,7 @@ class PrintTranslator final : public Translator
public:
explicit PrintTranslator(nsDeviceContext* aDeviceContext);
bool TranslateRecording(std::istream& aRecording);
bool TranslateRecording(PRFileDescStream& aRecording);
DrawTarget* LookupDrawTarget(ReferencePtr aRefPtr) final
{

View File

@ -124,7 +124,9 @@ RemotePrintJobParent::PrintPage(const nsCString& aPageFileName)
return rv;
}
std::ifstream recording(recordingPath.get(), std::ifstream::binary);
PRFileDescStream recording;
recording.Open(recordingPath.get());
MOZ_ASSERT(recording.IsOpen());
if (!mPrintTranslator->TranslateRecording(recording)) {
return NS_ERROR_FAILURE;
}
@ -134,7 +136,7 @@ RemotePrintJobParent::PrintPage(const nsCString& aPageFileName)
return rv;
}
recording.close();
recording.Close();
rv = recordingFile->Remove(/* recursive= */ false);
if (NS_WARN_IF(NS_FAILED(rv))) {
return rv;
@ -240,5 +242,3 @@ RemotePrintJobParent::ActorDestroy(ActorDestroyReason aWhy)
} // namespace layout
} // namespace mozilla