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

Side by Side Diff: chromeos/dbus/lorgnette_manager_client.cc

Issue 2081153002: No dbus::FileDescriptor in DebugDaemonClient (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Address comments Created 4 years, 3 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
« no previous file with comments | « chromeos/dbus/fake_debug_daemon_client.cc ('k') | chromeos/dbus/pipe_reader.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2014 The Chromium Authors. All rights reserved. 1 // Copyright 2014 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "chromeos/dbus/lorgnette_manager_client.h" 5 #include "chromeos/dbus/lorgnette_manager_client.h"
6 6
7 #include <memory> 7 #include <memory>
8 #include <string> 8 #include <string>
9 9
10 #include "base/bind.h" 10 #include "base/bind.h"
(...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after
65 false); 65 false);
66 } 66 }
67 67
68 void ScanImageToString( 68 void ScanImageToString(
69 std::string device_name, 69 std::string device_name,
70 const ScanProperties& properties, 70 const ScanProperties& properties,
71 const ScanImageToStringCallback& callback) override { 71 const ScanImageToStringCallback& callback) override {
72 // Owned by the callback created in scan_to_string_completion->Start(). 72 // Owned by the callback created in scan_to_string_completion->Start().
73 ScanToStringCompletion* scan_to_string_completion = 73 ScanToStringCompletion* scan_to_string_completion =
74 new ScanToStringCompletion(); 74 new ScanToStringCompletion();
75 base::File file; 75 base::ScopedFD fd;
76 ScanImageToFileCallback file_callback = 76 ScanImageToFileCallback file_callback =
77 scan_to_string_completion->Start(callback, &file); 77 scan_to_string_completion->Start(callback, &fd);
78 base::File file(fd.release());
78 ScanImageToFile(device_name, properties, file_callback, &file); 79 ScanImageToFile(device_name, properties, file_callback, &file);
79 } 80 }
80 81
81 protected: 82 protected:
82 void Init(dbus::Bus* bus) override { 83 void Init(dbus::Bus* bus) override {
83 lorgnette_daemon_proxy_ = 84 lorgnette_daemon_proxy_ =
84 bus->GetObjectProxy(lorgnette::kManagerServiceName, 85 bus->GetObjectProxy(lorgnette::kManagerServiceName,
85 dbus::ObjectPath(lorgnette::kManagerServicePath)); 86 dbus::ObjectPath(lorgnette::kManagerServicePath));
86 } 87 }
87 88
88 private: 89 private:
89 class ScanToStringCompletion { 90 class ScanToStringCompletion {
90 public: 91 public:
91 ScanToStringCompletion() {} 92 ScanToStringCompletion() {}
92 virtual ~ScanToStringCompletion() {} 93 virtual ~ScanToStringCompletion() {}
93 94
94 // Creates a file stream in |file| that will stream image data to 95 // Creates a file stream in |file| that will stream image data to
95 // a string that will be supplied to |callback|. Passes ownership 96 // a string that will be supplied to |callback|. Passes ownership
96 // of |this| to a returned callback that can be handed to a 97 // of |this| to a returned callback that can be handed to a
97 // ScanImageToFile invocation. 98 // ScanImageToFile invocation.
98 ScanImageToFileCallback Start(const ScanImageToStringCallback& callback, 99 ScanImageToFileCallback Start(const ScanImageToStringCallback& callback,
99 base::File *file) { 100 base::ScopedFD* fd) {
100 CHECK(!pipe_reader_.get()); 101 CHECK(!pipe_reader_.get());
101 const bool kTasksAreSlow = true; 102 const bool kTasksAreSlow = true;
102 scoped_refptr<base::TaskRunner> task_runner = 103 scoped_refptr<base::TaskRunner> task_runner =
103 base::WorkerPool::GetTaskRunner(kTasksAreSlow); 104 base::WorkerPool::GetTaskRunner(kTasksAreSlow);
104 pipe_reader_.reset( 105 pipe_reader_.reset(
105 new chromeos::PipeReaderForString( 106 new chromeos::PipeReaderForString(
106 task_runner, 107 task_runner,
107 base::Bind(&ScanToStringCompletion::OnScanToStringDataCompleted, 108 base::Bind(&ScanToStringCompletion::OnScanToStringDataCompleted,
108 base::Unretained(this)))); 109 base::Unretained(this))));
109 *file = pipe_reader_->StartIO(); 110 *fd = pipe_reader_->StartIO();
110 111
111 return base::Bind(&ScanToStringCompletion::OnScanToStringCompleted, 112 return base::Bind(&ScanToStringCompletion::OnScanToStringCompleted,
112 base::Owned(this), callback); 113 base::Owned(this), callback);
113 } 114 }
114 115
115 private: 116 private:
116 // Called when a |pipe_reader_| completes reading scan data to a string. 117 // Called when a |pipe_reader_| completes reading scan data to a string.
117 void OnScanToStringDataCompleted() { 118 void OnScanToStringDataCompleted() {
118 pipe_reader_->GetData(&scanned_image_data_string_); 119 pipe_reader_->GetData(&scanned_image_data_string_);
119 pipe_reader_.reset(); 120 pipe_reader_.reset();
(...skipping 136 matching lines...) Expand 10 before | Expand all | Expand 10 after
256 257
257 LorgnetteManagerClient::~LorgnetteManagerClient() { 258 LorgnetteManagerClient::~LorgnetteManagerClient() {
258 } 259 }
259 260
260 // static 261 // static
261 LorgnetteManagerClient* LorgnetteManagerClient::Create() { 262 LorgnetteManagerClient* LorgnetteManagerClient::Create() {
262 return new LorgnetteManagerClientImpl(); 263 return new LorgnetteManagerClientImpl();
263 } 264 }
264 265
265 } // namespace chromeos 266 } // namespace chromeos
OLDNEW
« no previous file with comments | « chromeos/dbus/fake_debug_daemon_client.cc ('k') | chromeos/dbus/pipe_reader.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698