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

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: arc_bridge.mojom version update Created 4 years, 5 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
« no previous file with comments | « components/arc/print/arc_print_bridge.h ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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..dc2ac8dd2527b0746205cd8db0012ac3f406b24b
--- /dev/null
+++ b/components/arc/print/arc_print_bridge.cc
@@ -0,0 +1,88 @@
+// 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/common/shell_delegate.h"
+#include "ash/common/wm_shell.h"
+#include "ash/new_window_delegate.h"
+#include "ash/shell.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) {
Luis Héctor Chávez 2016/07/11 18:27:53 This function runs in the UI thread, which shouldn
Sergey Poromov 2016/07/13 16:58:42 Done.
+ LOG(ERROR) << "Print called!!! " << file.get().value();
Luis Héctor Chávez 2016/07/11 18:27:53 Try to keep debugging statements to a minimum. If
Sergey Poromov 2016/07/13 16:58:42 Done.
+
+ 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);
Luis Héctor Chávez 2016/07/11 18:27:53 This seems unnecessary. You can use |fd.get()| ins
Sergey Poromov 2016/07/13 16:58:42 Done.
+ LOG(ERROR) << "File opened";
+ base::File fl(fn.fd);
Luis Héctor Chávez 2016/07/11 18:27:53 This also feels unnecessary. Plus it will double-c
Sergey Poromov 2016/07/13 16:58:42 Done.
+ LOG(ERROR) << "File length" << fl.GetLength();
Luis Héctor Chávez 2016/07/11 18:27:53 Huh, I was not expecting this would work with pipe
Sergey Poromov 2016/07/13 16:58:42 Done.
+
+ base::FilePath filePath(FILE_PATH_LITERAL("/tmp/test.pdf"));
Luis Héctor Chávez 2016/07/11 18:27:53 Can you use base::CreateTemporaryFile instead? Als
Sergey Poromov 2016/07/13 16:58:42 Done.
+ base::File out(filePath,
+ base::File::FLAG_CREATE_ALWAYS | base::File::FLAG_WRITE);
+
+ char buf[8192];
+ int bytes;
Luis Héctor Chávez 2016/07/11 18:27:53 size_t
Sergey Poromov 2016/07/13 16:58:42 Done.
+ while ((bytes = read(fn.fd, buf, 8192)) > 0) {
Luis Héctor Chávez 2016/07/11 18:27:53 Try to model this after base::ReadFromFD. This doe
Sergey Poromov 2016/07/13 16:58:42 ReadFromFD doesn't return amount of read bytes. We
+ LOG(ERROR) << "READ " << bytes;
+ out.WriteAtCurrentPos(buf, bytes);
+ }
+
+ LOG(ERROR) << "Result code: " << errno;
Luis Héctor Chávez 2016/07/11 18:27:53 VPLOG(2)? That'll convert errno into its string re
Sergey Poromov 2016/07/13 16:58:42 Done.
+
+ out.Flush();
+ out.Close();
Luis Héctor Chávez 2016/07/11 18:27:53 You can just do { base::File out(...); // Wri
Sergey Poromov 2016/07/13 16:58:42 Done.
+ fd.release();
Luis Héctor Chávez 2016/07/11 18:27:53 This is unnecessary.
Sergey Poromov 2016/07/13 16:58:42 Done.
+
+ GURL gurl("file:///tmp/test.pdf");
+ ash::WmShell::Get()->delegate()->OpenUrl(gurl);
+
+}
+
+} // namespace arc
« no previous file with comments | « 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