Skip to content

Commit

Permalink
Revert "[Printing] Write file to file descriptor directly on Android"
Browse files Browse the repository at this point in the history
This reverts commit 9c078ea.

Reason for revert: The fix isn't memory efficient enough.

Original change's description:
> [Printing] Write file to file descriptor directly on Android
> 
> Android's policy doesn't allow to exchange file ownership. It should be
> caught by our test but we don't have up-to-date bots setup in Chromium
> yet.
> 
> Bug: 1050064
> Change-Id: I26c82e538817e68fd49f40c0c7c414c5a76078b8
> Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2048271
> Commit-Queue: Shimi Zhang <ctzsm@chromium.org>
> Reviewed-by: Lei Zhang <thestig@chromium.org>
> Cr-Commit-Position: refs/heads/master@{#740491}

TBR=thestig@chromium.org,ctzsm@chromium.org

Change-Id: Ie33bf740f4221072059e2cd82eedc53c1974286f
No-Presubmit: true
No-Tree-Checks: true
No-Try: true
Bug: 1050064
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2049836
Reviewed-by: Shimi Zhang <ctzsm@chromium.org>
Commit-Queue: Shimi Zhang <ctzsm@chromium.org>
Cr-Commit-Position: refs/heads/master@{#740753}
  • Loading branch information
Shimi Zhang authored and Commit Bot committed Feb 12, 2020
1 parent a18bf4d commit dc94dca
Show file tree
Hide file tree
Showing 3 changed files with 4 additions and 28 deletions.
13 changes: 0 additions & 13 deletions printing/metafile.cc
Original file line number Diff line number Diff line change
Expand Up @@ -45,17 +45,4 @@ bool Metafile::SaveTo(base::File* file) const {
return true;
}

#if defined(OS_ANDROID)
bool Metafile::SaveToFileDescriptor(int fd) const {
if (fd == base::kInvalidFd)
return false;

std::vector<char> buffer;
if (!GetDataAsVector(&buffer))
return false;

return base::WriteFileDescriptor(fd, buffer.data(), buffer.size());
}
#endif // defined(OS_ANDROID)

} // namespace printing
14 changes: 0 additions & 14 deletions printing/metafile.h
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,6 @@
#include <ApplicationServices/ApplicationServices.h>
#include <CoreFoundation/CoreFoundation.h>
#include "base/mac/scoped_cftyperef.h"
#elif defined(OS_ANDROID)
#include "base/file_descriptor_posix.h"
#include "base/files/file_util.h"
#endif

namespace base {
Expand Down Expand Up @@ -96,14 +93,6 @@ class PRINTING_EXPORT MetafilePlayer {
// called after the metafile is closed. Returns true if writing succeeded.
virtual bool SaveTo(base::File* file) const = 0;

#if defined(OS_ANDROID)
// Similar to bool SaveTo(base::File* file) const, but write the data to the
// file descriptor directly. This is because Android doesn't allow file
// ownership exchange. This function should ONLY be called after the metafile
// is closed. Returns true if writing succeeded.
virtual bool SaveToFileDescriptor(int fd) const = 0;
#endif // defined(OS_ANDROID)

private:
DISALLOW_COPY_AND_ASSIGN(MetafilePlayer);
};
Expand Down Expand Up @@ -171,9 +160,6 @@ class PRINTING_EXPORT Metafile : public MetafilePlayer {
// MetfilePlayer
bool GetDataAsVector(std::vector<char>* buffer) const override;
bool SaveTo(base::File* file) const override;
#if defined(OS_ANDROID)
bool SaveToFileDescriptor(int fd) const override;
#endif // defined(OS_ANDROID)

private:
DISALLOW_COPY_AND_ASSIGN(Metafile);
Expand Down
5 changes: 4 additions & 1 deletion printing/printing_context_android.cc
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
#include "base/android/jni_android.h"
#include "base/android/jni_array.h"
#include "base/android/jni_string.h"
#include "base/files/file.h"
#include "base/logging.h"
#include "base/memory/ptr_util.h"
#include "base/strings/string_number_conversions.h"
Expand Down Expand Up @@ -158,7 +159,9 @@ void PrintingContextAndroid::ShowSystemDialogDone(
void PrintingContextAndroid::PrintDocument(const MetafilePlayer& metafile) {
DCHECK(is_file_descriptor_valid());

metafile.SaveToFileDescriptor(fd_);
base::File file(fd_);
metafile.SaveTo(&file);
file.TakePlatformFile();
}

PrintingContext::Result PrintingContextAndroid::UseDefaultSettings() {
Expand Down

0 comments on commit dc94dca

Please sign in to comment.