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

Unified Diff: components/arc/print/arc_print_bridge.cc

Issue 2115863002: Stub for ARC print Bridge (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Stub for ARC print Bridge Created 4 years, 6 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: components/arc/print/arc_print_bridge.cc
diff --git a/components/arc/print/arc_print_bridge.cc b/components/arc/print/arc_print_bridge.cc
new file mode 100644
index 0000000000000000000000000000000000000000..7b872ae7125ab78b9c4efe0fde2b0e87a584e968
--- /dev/null
+++ b/components/arc/print/arc_print_bridge.cc
@@ -0,0 +1,87 @@
+// Copyright 2016 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#include "components/arc/print/arc_print_bridge.h"
+
+#include <utility>
+
+//#include "ash/new_window_delegate.h"
+//#include "ash/shell.h"
+//#include "ash/shell_delegate.h"
+#include "base/files/file.h"
+#include "base/files/scoped_file.h"
+#include "base/logging.h"
+#include "base/strings/utf_string_conversions.h"
+#include "base/threading/thread_checker.h"
+#include "components/arc/arc_bridge_service.h"
+#include "mojo/edk/embedder/embedder.h"
+#include "url/gurl.h"
+
+namespace arc {
+
+ArcPrintBridge::ArcPrintBridge(ArcBridgeService* bridge_service)
+ : ArcService(bridge_service), binding_(this) {
+ arc_bridge_service()->AddObserver(this);
+}
+
+ArcPrintBridge::~ArcPrintBridge() {
+ arc_bridge_service()->RemoveObserver(this);
+}
+
+void ArcPrintBridge::OnPrintInstanceReady() {
+ mojom::PrintInstance* print_instance = arc_bridge_service()->print_instance();
+ if (!print_instance) {
+ LOG(ERROR) << "OnPrintInstanceReady called, but no print instance found";
+ return;
+ }
+
+ print_instance->Init(binding_.CreateInterfacePtrAndBind());
+}
+
+void ArcPrintBridge::Print(mojo::ScopedHandle file) {
+ LOG(ERROR) << "Print called!!! " << file.get().value();
+
+ if (!file.is_valid()) {
+ LOG(ERROR) << "handle is invalid";
+ return;
+ }
+
+ mojo::edk::ScopedPlatformHandle scoped_platform_handle;
+ MojoResult mojo_result = mojo::edk::PassWrappedPlatformHandle(
+ file.release().value(), &scoped_platform_handle);
+ if (mojo_result != MOJO_RESULT_OK) {
+ LOG(ERROR) << "PassWrappedPlatformHandle failed: " << mojo_result;
+ return;
+ }
+
+ base::ScopedFD fd(scoped_platform_handle.release().handle);
+
+ base::FileDescriptor fn(fd.release(), true);
+ LOG(ERROR) << "File opened";
+ base::File fl(fn.fd);
+ LOG(ERROR) << "File length" << fl.GetLength();
+
+ base::FilePath filePath(FILE_PATH_LITERAL("/tmp/test.pdf"));
+ base::File out(filePath,
+ base::File::FLAG_CREATE_ALWAYS | base::File::FLAG_WRITE);
+
+ char buf[8192];
+ int bytes;
+ while ((bytes = read(fn.fd, buf, 8192)) > 0) {
+ LOG(ERROR) << "READ " << bytes;
+ out.WriteAtCurrentPos(buf, bytes);
+ }
+
+ LOG(ERROR) << "Result code: " << errno;
+
+ out.Flush();
+ out.Close();
+// fd.release();
+
+// GURL gurl("file:///tmp/test.pdf");
+// ash::Shell::GetInstance()->delegate()->OpenUrl(gurl);
+
+}
+
+} // namespace arc
« components/arc/common/print.mojom ('K') | « components/arc/print/arc_print_bridge.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698