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

Side by Side Diff: device/serial/serial_io_handler.cc

Issue 2291983002: chromeos: Remove dbus::FileDescriptor from PermissionBrokerClient (Closed)
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 | « device/serial/serial_io_handler.h ('k') | device/usb/usb_device_linux.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 "device/serial/serial_io_handler.h" 5 #include "device/serial/serial_io_handler.h"
6 6
7 #include <memory> 7 #include <memory>
8 #include <utility> 8 #include <utility>
9 9
10 #include "base/bind.h" 10 #include "base/bind.h"
11 #include "base/files/file_path.h" 11 #include "base/files/file_path.h"
12 #include "base/location.h" 12 #include "base/location.h"
13 #include "base/strings/string_util.h" 13 #include "base/strings/string_util.h"
14 #include "build/build_config.h" 14 #include "build/build_config.h"
15 15
16 #if defined(OS_CHROMEOS) 16 #if defined(OS_CHROMEOS)
17 #include "chromeos/dbus/dbus_thread_manager.h" 17 #include "chromeos/dbus/dbus_thread_manager.h"
18 #include "chromeos/dbus/permission_broker_client.h" 18 #include "chromeos/dbus/permission_broker_client.h"
19 #include "dbus/file_descriptor.h" // nogncheck
20 #endif // defined(OS_CHROMEOS) 19 #endif // defined(OS_CHROMEOS)
21 20
22 namespace device { 21 namespace device {
23 22
24 SerialIoHandler::SerialIoHandler( 23 SerialIoHandler::SerialIoHandler(
25 scoped_refptr<base::SingleThreadTaskRunner> file_thread_task_runner, 24 scoped_refptr<base::SingleThreadTaskRunner> file_thread_task_runner,
26 scoped_refptr<base::SingleThreadTaskRunner> ui_thread_task_runner) 25 scoped_refptr<base::SingleThreadTaskRunner> ui_thread_task_runner)
27 : file_thread_task_runner_(file_thread_task_runner), 26 : file_thread_task_runner_(file_thread_task_runner),
28 ui_thread_task_runner_(ui_thread_task_runner) { 27 ui_thread_task_runner_(ui_thread_task_runner) {
29 options_.bitrate = 9600; 28 options_.bitrate = 9600;
(...skipping 24 matching lines...) Expand all
54 chromeos::PermissionBrokerClient* client = 53 chromeos::PermissionBrokerClient* client =
55 chromeos::DBusThreadManager::Get()->GetPermissionBrokerClient(); 54 chromeos::DBusThreadManager::Get()->GetPermissionBrokerClient();
56 DCHECK(client) << "Could not get permission_broker client."; 55 DCHECK(client) << "Could not get permission_broker client.";
57 // PermissionBrokerClient should be called on the UI thread. 56 // PermissionBrokerClient should be called on the UI thread.
58 scoped_refptr<base::SingleThreadTaskRunner> task_runner = 57 scoped_refptr<base::SingleThreadTaskRunner> task_runner =
59 base::ThreadTaskRunnerHandle::Get(); 58 base::ThreadTaskRunnerHandle::Get();
60 ui_thread_task_runner_->PostTask( 59 ui_thread_task_runner_->PostTask(
61 FROM_HERE, 60 FROM_HERE,
62 base::Bind( 61 base::Bind(
63 &chromeos::PermissionBrokerClient::OpenPath, base::Unretained(client), 62 &chromeos::PermissionBrokerClient::OpenPath, base::Unretained(client),
64 port, base::Bind(&SerialIoHandler::OnPathOpened, this, 63 port, base::Bind(&SerialIoHandler::OnPathOpened, this, task_runner),
65 file_thread_task_runner_, task_runner),
66 base::Bind(&SerialIoHandler::OnPathOpenError, this, task_runner))); 64 base::Bind(&SerialIoHandler::OnPathOpenError, this, task_runner)));
67 #else 65 #else
68 file_thread_task_runner_->PostTask( 66 file_thread_task_runner_->PostTask(
69 FROM_HERE, base::Bind(&SerialIoHandler::StartOpen, this, port, 67 FROM_HERE, base::Bind(&SerialIoHandler::StartOpen, this, port,
70 base::ThreadTaskRunnerHandle::Get())); 68 base::ThreadTaskRunnerHandle::Get()));
71 #endif // defined(OS_CHROMEOS) 69 #endif // defined(OS_CHROMEOS)
72 } 70 }
73 71
74 #if defined(OS_CHROMEOS) 72 #if defined(OS_CHROMEOS)
75 73
76 void SerialIoHandler::OnPathOpened( 74 void SerialIoHandler::OnPathOpened(
77 scoped_refptr<base::SingleThreadTaskRunner> file_thread_task_runner,
78 scoped_refptr<base::SingleThreadTaskRunner> io_thread_task_runner, 75 scoped_refptr<base::SingleThreadTaskRunner> io_thread_task_runner,
79 dbus::FileDescriptor fd) { 76 base::ScopedFD fd) {
80 file_thread_task_runner->PostTask( 77 base::File file(fd.release());
81 FROM_HERE, base::Bind(&SerialIoHandler::ValidateOpenPort, this, 78 io_thread_task_runner->PostTask(
82 io_thread_task_runner, base::Passed(&fd))); 79 FROM_HERE,
80 base::Bind(&SerialIoHandler::FinishOpen, this, base::Passed(&file)));
83 } 81 }
84 82
85 void SerialIoHandler::OnPathOpenError( 83 void SerialIoHandler::OnPathOpenError(
86 scoped_refptr<base::SingleThreadTaskRunner> io_thread_task_runner, 84 scoped_refptr<base::SingleThreadTaskRunner> io_thread_task_runner,
87 const std::string& error_name, 85 const std::string& error_name,
88 const std::string& error_message) { 86 const std::string& error_message) {
89 io_thread_task_runner->PostTask( 87 io_thread_task_runner->PostTask(
90 FROM_HERE, base::Bind(&SerialIoHandler::ReportPathOpenError, this, 88 FROM_HERE, base::Bind(&SerialIoHandler::ReportPathOpenError, this,
91 error_name, error_message)); 89 error_name, error_message));
92 } 90 }
93 91
94 void SerialIoHandler::ValidateOpenPort(
95 scoped_refptr<base::SingleThreadTaskRunner> io_thread_task_runner,
96 dbus::FileDescriptor fd) {
97 base::File file;
98 fd.CheckValidity();
99 if (fd.is_valid()) {
100 file = base::File(fd.TakeValue());
101 }
102
103 io_thread_task_runner->PostTask(
104 FROM_HERE,
105 base::Bind(&SerialIoHandler::FinishOpen, this, base::Passed(&file)));
106 }
107
108 void SerialIoHandler::ReportPathOpenError(const std::string& error_name, 92 void SerialIoHandler::ReportPathOpenError(const std::string& error_name,
109 const std::string& error_message) { 93 const std::string& error_message) {
110 DCHECK(CalledOnValidThread()); 94 DCHECK(CalledOnValidThread());
111 DCHECK(!open_complete_.is_null()); 95 DCHECK(!open_complete_.is_null());
112 LOG(ERROR) << "Permission broker failed to open '" << port_ 96 LOG(ERROR) << "Permission broker failed to open '" << port_
113 << "': " << error_name << ": " << error_message; 97 << "': " << error_name << ": " << error_message;
114 OpenCompleteCallback callback = open_complete_; 98 OpenCompleteCallback callback = open_complete_;
115 open_complete_.Reset(); 99 open_complete_.Reset();
116 callback.Run(false); 100 callback.Run(false);
117 } 101 }
(...skipping 169 matching lines...) Expand 10 before | Expand all | Expand 10 after
287 } 271 }
288 272
289 void SerialIoHandler::QueueWriteCompleted(int bytes_written, 273 void SerialIoHandler::QueueWriteCompleted(int bytes_written,
290 serial::SendError error) { 274 serial::SendError error) {
291 base::ThreadTaskRunnerHandle::Get()->PostTask( 275 base::ThreadTaskRunnerHandle::Get()->PostTask(
292 FROM_HERE, 276 FROM_HERE,
293 base::Bind(&SerialIoHandler::WriteCompleted, this, bytes_written, error)); 277 base::Bind(&SerialIoHandler::WriteCompleted, this, bytes_written, error));
294 } 278 }
295 279
296 } // namespace device 280 } // namespace device
OLDNEW
« no previous file with comments | « device/serial/serial_io_handler.h ('k') | device/usb/usb_device_linux.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698