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

Side by Side 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, 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 unified diff | Download patch
OLDNEW
(Empty)
1 // Copyright 2016 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4
5 #include "components/arc/print/arc_print_bridge.h"
6
7 #include <utility>
8
9 //#include "ash/new_window_delegate.h"
10 //#include "ash/shell.h"
11 //#include "ash/shell_delegate.h"
12 #include "base/files/file.h"
13 #include "base/files/scoped_file.h"
14 #include "base/logging.h"
15 #include "base/strings/utf_string_conversions.h"
16 #include "base/threading/thread_checker.h"
17 #include "components/arc/arc_bridge_service.h"
18 #include "mojo/edk/embedder/embedder.h"
19 #include "url/gurl.h"
20
21 namespace arc {
22
23 ArcPrintBridge::ArcPrintBridge(ArcBridgeService* bridge_service)
24 : ArcService(bridge_service), binding_(this) {
25 arc_bridge_service()->AddObserver(this);
26 }
27
28 ArcPrintBridge::~ArcPrintBridge() {
29 arc_bridge_service()->RemoveObserver(this);
30 }
31
32 void ArcPrintBridge::OnPrintInstanceReady() {
33 mojom::PrintInstance* print_instance = arc_bridge_service()->print_instance();
34 if (!print_instance) {
35 LOG(ERROR) << "OnPrintInstanceReady called, but no print instance found";
36 return;
37 }
38
39 print_instance->Init(binding_.CreateInterfacePtrAndBind());
40 }
41
42 void ArcPrintBridge::Print(mojo::ScopedHandle file) {
43 LOG(ERROR) << "Print called!!! " << file.get().value();
44
45 if (!file.is_valid()) {
46 LOG(ERROR) << "handle is invalid";
47 return;
48 }
49
50 mojo::edk::ScopedPlatformHandle scoped_platform_handle;
51 MojoResult mojo_result = mojo::edk::PassWrappedPlatformHandle(
52 file.release().value(), &scoped_platform_handle);
53 if (mojo_result != MOJO_RESULT_OK) {
54 LOG(ERROR) << "PassWrappedPlatformHandle failed: " << mojo_result;
55 return;
56 }
57
58 base::ScopedFD fd(scoped_platform_handle.release().handle);
59
60 base::FileDescriptor fn(fd.release(), true);
61 LOG(ERROR) << "File opened";
62 base::File fl(fn.fd);
63 LOG(ERROR) << "File length" << fl.GetLength();
64
65 base::FilePath filePath(FILE_PATH_LITERAL("/tmp/test.pdf"));
66 base::File out(filePath,
67 base::File::FLAG_CREATE_ALWAYS | base::File::FLAG_WRITE);
68
69 char buf[8192];
70 int bytes;
71 while ((bytes = read(fn.fd, buf, 8192)) > 0) {
72 LOG(ERROR) << "READ " << bytes;
73 out.WriteAtCurrentPos(buf, bytes);
74 }
75
76 LOG(ERROR) << "Result code: " << errno;
77
78 out.Flush();
79 out.Close();
80 // fd.release();
81
82 // GURL gurl("file:///tmp/test.pdf");
83 // ash::Shell::GetInstance()->delegate()->OpenUrl(gurl);
84
85 }
86
87 } // namespace arc
OLDNEW
« components/arc/common/arc_bridge.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