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

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

Issue 1681383002: Add path open errors from the permission broker to the device log. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@remove_request_access
Patch Set: Addresses stevenjb@'s comments. Created 4 years, 10 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_impl.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 <utility> 7 #include <utility>
8 8
9 #include "base/bind.h" 9 #include "base/bind.h"
10 #include "base/files/file_path.h" 10 #include "base/files/file_path.h"
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after
47 DCHECK(file_thread_task_runner_.get()); 47 DCHECK(file_thread_task_runner_.get());
48 DCHECK(ui_thread_task_runner_.get()); 48 DCHECK(ui_thread_task_runner_.get());
49 MergeConnectionOptions(options); 49 MergeConnectionOptions(options);
50 port_ = port; 50 port_ = port;
51 51
52 #if defined(OS_CHROMEOS) 52 #if defined(OS_CHROMEOS)
53 chromeos::PermissionBrokerClient* client = 53 chromeos::PermissionBrokerClient* client =
54 chromeos::DBusThreadManager::Get()->GetPermissionBrokerClient(); 54 chromeos::DBusThreadManager::Get()->GetPermissionBrokerClient();
55 DCHECK(client) << "Could not get permission_broker client."; 55 DCHECK(client) << "Could not get permission_broker client.";
56 // PermissionBrokerClient should be called on the UI thread. 56 // PermissionBrokerClient should be called on the UI thread.
57 scoped_refptr<base::SingleThreadTaskRunner> task_runner =
58 base::ThreadTaskRunnerHandle::Get();
57 ui_thread_task_runner_->PostTask( 59 ui_thread_task_runner_->PostTask(
58 FROM_HERE, base::Bind(&chromeos::PermissionBrokerClient::OpenPath, 60 FROM_HERE,
59 base::Unretained(client), port, 61 base::Bind(
60 base::Bind(&SerialIoHandler::OnPathOpened, this, 62 &chromeos::PermissionBrokerClient::OpenPath, base::Unretained(client),
61 file_thread_task_runner_, 63 port, base::Bind(&SerialIoHandler::OnPathOpened, this,
62 base::ThreadTaskRunnerHandle::Get()))); 64 file_thread_task_runner_, task_runner),
65 base::Bind(&SerialIoHandler::OnPathOpenError, this, task_runner)));
63 #else 66 #else
64 file_thread_task_runner_->PostTask( 67 file_thread_task_runner_->PostTask(
65 FROM_HERE, base::Bind(&SerialIoHandler::StartOpen, this, port, 68 FROM_HERE, base::Bind(&SerialIoHandler::StartOpen, this, port,
66 base::ThreadTaskRunnerHandle::Get())); 69 base::ThreadTaskRunnerHandle::Get()));
67 #endif // defined(OS_CHROMEOS) 70 #endif // defined(OS_CHROMEOS)
68 } 71 }
69 72
70 #if defined(OS_CHROMEOS) 73 #if defined(OS_CHROMEOS)
71 74
72 void SerialIoHandler::OnPathOpened( 75 void SerialIoHandler::OnPathOpened(
73 scoped_refptr<base::SingleThreadTaskRunner> file_thread_task_runner, 76 scoped_refptr<base::SingleThreadTaskRunner> file_thread_task_runner,
74 scoped_refptr<base::SingleThreadTaskRunner> io_thread_task_runner, 77 scoped_refptr<base::SingleThreadTaskRunner> io_thread_task_runner,
75 dbus::FileDescriptor fd) { 78 dbus::FileDescriptor fd) {
76 DCHECK(CalledOnValidThread());
77 file_thread_task_runner->PostTask( 79 file_thread_task_runner->PostTask(
78 FROM_HERE, base::Bind(&SerialIoHandler::ValidateOpenPort, this, 80 FROM_HERE, base::Bind(&SerialIoHandler::ValidateOpenPort, this,
79 io_thread_task_runner, base::Passed(&fd))); 81 io_thread_task_runner, base::Passed(&fd)));
80 } 82 }
81 83
84 void SerialIoHandler::OnPathOpenError(
85 scoped_refptr<base::SingleThreadTaskRunner> io_thread_task_runner,
86 const std::string& error_name,
87 const std::string& error_message) {
88 io_thread_task_runner->PostTask(
89 FROM_HERE, base::Bind(&SerialIoHandler::ReportPathOpenError, this,
90 error_name, error_message));
91 }
92
82 void SerialIoHandler::ValidateOpenPort( 93 void SerialIoHandler::ValidateOpenPort(
83 scoped_refptr<base::SingleThreadTaskRunner> io_thread_task_runner, 94 scoped_refptr<base::SingleThreadTaskRunner> io_thread_task_runner,
84 dbus::FileDescriptor fd) { 95 dbus::FileDescriptor fd) {
85 base::File file; 96 base::File file;
86 fd.CheckValidity(); 97 fd.CheckValidity();
87 if (fd.is_valid()) { 98 if (fd.is_valid()) {
88 file = base::File(fd.TakeValue()); 99 file = base::File(fd.TakeValue());
89 } 100 }
90 101
91 io_thread_task_runner->PostTask( 102 io_thread_task_runner->PostTask(
92 FROM_HERE, 103 FROM_HERE,
93 base::Bind(&SerialIoHandler::FinishOpen, this, base::Passed(&file))); 104 base::Bind(&SerialIoHandler::FinishOpen, this, base::Passed(&file)));
94 } 105 }
95 106
107 void SerialIoHandler::ReportPathOpenError(const std::string& error_name,
108 const std::string& error_message) {
109 DCHECK(CalledOnValidThread());
110 DCHECK(!open_complete_.is_null());
111 LOG(ERROR) << "Permission broker failed to open '" << port_
112 << "': " << error_name << ": " << error_message;
113 OpenCompleteCallback callback = open_complete_;
114 open_complete_.Reset();
115 callback.Run(false);
116 }
117
96 #endif 118 #endif
97 119
98 void SerialIoHandler::MergeConnectionOptions( 120 void SerialIoHandler::MergeConnectionOptions(
99 const serial::ConnectionOptions& options) { 121 const serial::ConnectionOptions& options) {
100 if (options.bitrate) { 122 if (options.bitrate) {
101 options_.bitrate = options.bitrate; 123 options_.bitrate = options.bitrate;
102 } 124 }
103 if (options.data_bits != serial::DataBits::NONE) { 125 if (options.data_bits != serial::DataBits::NONE) {
104 options_.data_bits = options.data_bits; 126 options_.data_bits = options.data_bits;
105 } 127 }
(...skipping 158 matching lines...) Expand 10 before | Expand all | Expand 10 after
264 } 286 }
265 287
266 void SerialIoHandler::QueueWriteCompleted(int bytes_written, 288 void SerialIoHandler::QueueWriteCompleted(int bytes_written,
267 serial::SendError error) { 289 serial::SendError error) {
268 base::MessageLoop::current()->PostTask( 290 base::MessageLoop::current()->PostTask(
269 FROM_HERE, 291 FROM_HERE,
270 base::Bind(&SerialIoHandler::WriteCompleted, this, bytes_written, error)); 292 base::Bind(&SerialIoHandler::WriteCompleted, this, bytes_written, error));
271 } 293 }
272 294
273 } // namespace device 295 } // namespace device
OLDNEW
« no previous file with comments | « device/serial/serial_io_handler.h ('k') | device/usb/usb_device_impl.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698