Skip to content

Commit

Permalink
Removed the use of file_thread_task_runner across
Browse files Browse the repository at this point in the history
SerialIoHandler and BattOrAgent.

BUG=728448

Review-Url: https://codereview.chromium.org/2914173002
Cr-Commit-Position: refs/heads/master@{#481529}
  • Loading branch information
sujiths.s authored and Commit Bot committed Jun 22, 2017
1 parent 7ee677b commit 1f83b93
Show file tree
Hide file tree
Showing 17 changed files with 25 additions and 57 deletions.
3 changes: 1 addition & 2 deletions content/browser/tracing/power_tracing_agent.cc
Original file line number Diff line number Diff line change
Expand Up @@ -69,8 +69,7 @@ void PowerTracingAgent::StartAgentTracingOnIOThread(
DCHECK_CURRENTLY_ON(BrowserThread::IO);

battor_agent_.reset(new battor::BattOrAgent(
path, this, BrowserThread::GetTaskRunnerForThread(BrowserThread::FILE),
BrowserThread::GetTaskRunnerForThread(BrowserThread::UI)));
path, this, BrowserThread::GetTaskRunnerForThread(BrowserThread::UI)));

start_tracing_callback_ = callback;
battor_agent_->StartTracing();
Expand Down
20 changes: 10 additions & 10 deletions device/serial/serial_io_handler.cc
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@
#include "base/files/file_path.h"
#include "base/location.h"
#include "base/strings/string_util.h"
#include "base/task_scheduler/post_task.h"
#include "base/task_scheduler/task_traits.h"
#include "build/build_config.h"

#if defined(OS_CHROMEOS)
Expand All @@ -21,10 +23,8 @@
namespace device {

SerialIoHandler::SerialIoHandler(
scoped_refptr<base::SingleThreadTaskRunner> file_thread_task_runner,
scoped_refptr<base::SingleThreadTaskRunner> ui_thread_task_runner)
: file_thread_task_runner_(file_thread_task_runner),
ui_thread_task_runner_(ui_thread_task_runner) {
: ui_thread_task_runner_(ui_thread_task_runner) {
options_.bitrate = 9600;
options_.data_bits = serial::DataBits::EIGHT;
options_.parity_bit = serial::ParityBit::NO_PARITY;
Expand All @@ -44,7 +44,6 @@ void SerialIoHandler::Open(const std::string& port,
DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_);
DCHECK(open_complete_.is_null());
open_complete_ = callback;
DCHECK(file_thread_task_runner_.get());
DCHECK(ui_thread_task_runner_.get());
MergeConnectionOptions(options);
port_ = port;
Expand All @@ -63,9 +62,11 @@ void SerialIoHandler::Open(const std::string& port,
port, base::Bind(&SerialIoHandler::OnPathOpened, this, task_runner),
base::Bind(&SerialIoHandler::OnPathOpenError, this, task_runner)));
#else
file_thread_task_runner_->PostTask(
FROM_HERE, base::Bind(&SerialIoHandler::StartOpen, this, port,
base::ThreadTaskRunnerHandle::Get()));
base::PostTaskWithTraits(
FROM_HERE,
{base::MayBlock(), base::TaskShutdownBehavior::CONTINUE_ON_SHUTDOWN},
base::Bind(&SerialIoHandler::StartOpen, this, port,
base::ThreadTaskRunnerHandle::Get()));
#endif // defined(OS_CHROMEOS)
}

Expand Down Expand Up @@ -126,7 +127,6 @@ void SerialIoHandler::StartOpen(
const std::string& port,
scoped_refptr<base::SingleThreadTaskRunner> io_task_runner) {
DCHECK(!open_complete_.is_null());
DCHECK(file_thread_task_runner_->RunsTasksInCurrentSequence());
DCHECK(!file_.IsValid());
// It's the responsibility of the API wrapper around SerialIoHandler to
// validate the supplied path against the set of valid port names, and
Expand Down Expand Up @@ -170,9 +170,9 @@ bool SerialIoHandler::PostOpen() {

void SerialIoHandler::Close() {
if (file_.IsValid()) {
DCHECK(file_thread_task_runner_.get());
file_thread_task_runner_->PostTask(
base::PostTaskWithTraits(
FROM_HERE,
{base::MayBlock(), base::TaskShutdownBehavior::CONTINUE_ON_SHUTDOWN},
base::Bind(&SerialIoHandler::DoClose, Passed(std::move(file_))));
}
}
Expand Down
7 changes: 0 additions & 7 deletions device/serial/serial_io_handler.h
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,6 @@ class SerialIoHandler : public base::RefCountedThreadSafe<SerialIoHandler> {
public:
// Constructs an instance of some platform-specific subclass.
static scoped_refptr<SerialIoHandler> Create(
scoped_refptr<base::SingleThreadTaskRunner> file_thread_task_runner,
scoped_refptr<base::SingleThreadTaskRunner> ui_thread_task_runner);

typedef base::Callback<void(bool success)> OpenCompleteCallback;
Expand Down Expand Up @@ -112,7 +111,6 @@ class SerialIoHandler : public base::RefCountedThreadSafe<SerialIoHandler> {

protected:
explicit SerialIoHandler(
scoped_refptr<base::SingleThreadTaskRunner> file_thread_task_runner,
scoped_refptr<base::SingleThreadTaskRunner> ui_thread_task_runner);
virtual ~SerialIoHandler();

Expand Down Expand Up @@ -195,10 +193,6 @@ class SerialIoHandler : public base::RefCountedThreadSafe<SerialIoHandler> {
// Possibly fixes up a serial port path name in a platform-specific manner.
static std::string MaybeFixUpPortName(const std::string& port_name);

base::SingleThreadTaskRunner* file_thread_task_runner() const {
return file_thread_task_runner_.get();
}

base::SingleThreadTaskRunner* ui_thread_task_runner() const {
return ui_thread_task_runner_.get();
}
Expand Down Expand Up @@ -242,7 +236,6 @@ class SerialIoHandler : public base::RefCountedThreadSafe<SerialIoHandler> {
// Callback to handle the completion of a pending Open() request.
OpenCompleteCallback open_complete_;

scoped_refptr<base::SingleThreadTaskRunner> file_thread_task_runner_;
// On Chrome OS, PermissionBrokerClient should be called on the UI thread.
scoped_refptr<base::SingleThreadTaskRunner> ui_thread_task_runner_;

Expand Down
7 changes: 2 additions & 5 deletions device/serial/serial_io_handler_posix.cc
Original file line number Diff line number Diff line change
Expand Up @@ -113,10 +113,8 @@ namespace device {

// static
scoped_refptr<SerialIoHandler> SerialIoHandler::Create(
scoped_refptr<base::SingleThreadTaskRunner> file_thread_task_runner,
scoped_refptr<base::SingleThreadTaskRunner> ui_thread_task_runner) {
return new SerialIoHandlerPosix(file_thread_task_runner,
ui_thread_task_runner);
return new SerialIoHandlerPosix(ui_thread_task_runner);
}

void SerialIoHandlerPosix::ReadImpl() {
Expand Down Expand Up @@ -292,9 +290,8 @@ bool SerialIoHandlerPosix::PostOpen() {
}

SerialIoHandlerPosix::SerialIoHandlerPosix(
scoped_refptr<base::SingleThreadTaskRunner> file_thread_task_runner,
scoped_refptr<base::SingleThreadTaskRunner> ui_thread_task_runner)
: SerialIoHandler(file_thread_task_runner, ui_thread_task_runner) {}
: SerialIoHandler(ui_thread_task_runner) {}

SerialIoHandlerPosix::~SerialIoHandlerPosix() {
}
Expand Down
1 change: 0 additions & 1 deletion device/serial/serial_io_handler_posix.h
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,6 @@ class SerialIoHandlerPosix : public SerialIoHandler {
friend class SerialIoHandlerPosixTest;

SerialIoHandlerPosix(
scoped_refptr<base::SingleThreadTaskRunner> file_thread_task_runner,
scoped_refptr<base::SingleThreadTaskRunner> ui_thread_task_runner);
~SerialIoHandlerPosix() override;

Expand Down
2 changes: 1 addition & 1 deletion device/serial/serial_io_handler_posix_unittest.cc
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ class SerialIoHandlerPosixTest : public testing::Test {
SerialIoHandlerPosixTest() {}

void SetUp() override {
serial_io_handler_posix_ = new SerialIoHandlerPosix(nullptr, nullptr);
serial_io_handler_posix_ = new SerialIoHandlerPosix(nullptr);
}

void Initialize(bool parity_check_enabled,
Expand Down
6 changes: 2 additions & 4 deletions device/serial/serial_io_handler_win.cc
Original file line number Diff line number Diff line change
Expand Up @@ -151,9 +151,8 @@ bool GetCOMPort(const std::string friendly_name, std::string* com_port) {

// static
scoped_refptr<SerialIoHandler> SerialIoHandler::Create(
scoped_refptr<base::SingleThreadTaskRunner> file_thread_task_runner,
scoped_refptr<base::SingleThreadTaskRunner> ui_thread_task_runner) {
return new SerialIoHandlerWin(file_thread_task_runner, ui_thread_task_runner);
return new SerialIoHandlerWin(ui_thread_task_runner);
}

class SerialIoHandlerWin::UiThreadHelper final
Expand Down Expand Up @@ -359,9 +358,8 @@ bool SerialIoHandlerWin::ConfigurePortImpl() {
}

SerialIoHandlerWin::SerialIoHandlerWin(
scoped_refptr<base::SingleThreadTaskRunner> file_thread_task_runner,
scoped_refptr<base::SingleThreadTaskRunner> ui_thread_task_runner)
: SerialIoHandler(file_thread_task_runner, ui_thread_task_runner),
: SerialIoHandler(ui_thread_task_runner),
event_mask_(0),
is_comm_pending_(false),
helper_(nullptr),
Expand Down
1 change: 0 additions & 1 deletion device/serial/serial_io_handler_win.h
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,6 @@ class SerialIoHandlerWin : public SerialIoHandler,
friend class SerialIoHandler;

explicit SerialIoHandlerWin(
scoped_refptr<base::SingleThreadTaskRunner> file_thread_task_runner,
scoped_refptr<base::SingleThreadTaskRunner> ui_thread_task_runner);
~SerialIoHandlerWin() override;

Expand Down
5 changes: 2 additions & 3 deletions device/serial/test_serial_io_handler.cc
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,11 @@
namespace device {

TestSerialIoHandler::TestSerialIoHandler()
: SerialIoHandler(NULL, NULL),
: SerialIoHandler(NULL),
opened_(false),
dtr_(false),
rts_(false),
flushes_(0) {
}
flushes_(0) {}

scoped_refptr<SerialIoHandler> TestSerialIoHandler::Create() {
return scoped_refptr<SerialIoHandler>(new TestSerialIoHandler);
Expand Down
2 changes: 0 additions & 2 deletions extensions/browser/api/serial/serial_connection.cc
Original file line number Diff line number Diff line change
Expand Up @@ -167,8 +167,6 @@ SerialConnection::SerialConnection(const std::string& port,
send_timeout_(0),
paused_(false),
io_handler_(device::SerialIoHandler::Create(
content::BrowserThread::GetTaskRunnerForThread(
content::BrowserThread::FILE),
content::BrowserThread::GetTaskRunnerForThread(
content::BrowserThread::UI))) {
DCHECK_CURRENTLY_ON(BrowserThread::IO);
Expand Down
2 changes: 0 additions & 2 deletions tools/battor_agent/battor_agent.cc
Original file line number Diff line number Diff line change
Expand Up @@ -108,11 +108,9 @@ bool ParseSampleFrame(BattOrMessageType type,
BattOrAgent::BattOrAgent(
const std::string& path,
Listener* listener,
scoped_refptr<base::SingleThreadTaskRunner> file_thread_task_runner,
scoped_refptr<base::SingleThreadTaskRunner> ui_thread_task_runner)
: connection_(new BattOrConnectionImpl(path,
this,
file_thread_task_runner,
ui_thread_task_runner)),
listener_(listener),
last_action_(Action::INVALID),
Expand Down
1 change: 0 additions & 1 deletion tools/battor_agent/battor_agent.h
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,6 @@ class BattOrAgent : public BattOrConnection::Listener,
BattOrAgent(
const std::string& path,
Listener* listener,
scoped_refptr<base::SingleThreadTaskRunner> file_thread_task_runner,
scoped_refptr<base::SingleThreadTaskRunner> ui_thread_task_runner);
virtual ~BattOrAgent();

Expand Down
14 changes: 4 additions & 10 deletions tools/battor_agent/battor_agent_bin.cc
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@
#include "base/single_thread_task_runner.h"
#include "base/strings/string_tokenizer.h"
#include "base/strings/utf_string_conversions.h"
#include "base/task_scheduler/task_scheduler.h"
#include "base/threading/thread.h"
#include "base/threading/thread_task_runner_handle.h"
#include "tools/battor_agent/battor_agent.h"
Expand All @@ -60,7 +61,6 @@ namespace battor {
namespace {

const char kIoThreadName[] = "BattOr IO Thread";
const char kFileThreadName[] = "BattOr File Thread";

const char kUsage[] =
"Start the battor_agent shell with:\n"
Expand Down Expand Up @@ -111,7 +111,7 @@ std::vector<std::string> TokenizeString(std::string cmd) {
// use a BattOrAgent to communicate with a BattOr.
class BattOrAgentBin : public BattOrAgent::Listener {
public:
BattOrAgentBin() : io_thread_(kIoThreadName), file_thread_(kFileThreadName) {}
BattOrAgentBin() : io_thread_(kIoThreadName) {}

~BattOrAgentBin() { DCHECK(!agent_); }

Expand Down Expand Up @@ -305,13 +305,7 @@ class BattOrAgentBin : public BattOrAgent::Listener {
const std::string& path,
scoped_refptr<base::SingleThreadTaskRunner> ui_thread_task_runner,
base::WaitableEvent* done) {
// In Chrome, we already have a file thread running. Because the Chrome
// serial library relies on having it available, we have to spin up our own.
if (!file_thread_.Start())
ExitFromThreadStartFailure(kFileThreadName);

agent_.reset(new BattOrAgent(path, this, file_thread_.task_runner(),
ui_thread_task_runner));
agent_.reset(new BattOrAgent(path, this, ui_thread_task_runner));
done->Signal();
}

Expand All @@ -331,7 +325,6 @@ class BattOrAgentBin : public BattOrAgent::Listener {

// Threads needed for serial communication.
base::Thread io_thread_;
base::Thread file_thread_;

// The agent capable of asynchronously communicating with the BattOr.
std::unique_ptr<BattOrAgent> agent_;
Expand All @@ -345,5 +338,6 @@ int main(int argc, char* argv[]) {
base::AtExitManager exit_manager;
base::CommandLine::Init(argc, argv);
battor::BattOrAgentBin bin;
base::TaskScheduler::CreateAndStartWithDefaultParams("battor_agent");
return bin.Run(argc, argv);
}
2 changes: 1 addition & 1 deletion tools/battor_agent/battor_agent_unittest.cc
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ class MockBattOrConnection : public BattOrConnection {
class TestableBattOrAgent : public BattOrAgent {
public:
TestableBattOrAgent(BattOrAgent::Listener* listener)
: BattOrAgent("/dev/test", listener, nullptr, nullptr) {
: BattOrAgent("/dev/test", listener, nullptr) {
connection_ =
std::unique_ptr<BattOrConnection>(new MockBattOrConnection(this));
}
Expand Down
5 changes: 1 addition & 4 deletions tools/battor_agent/battor_connection_impl.cc
Original file line number Diff line number Diff line change
Expand Up @@ -61,11 +61,9 @@ size_t GetMaxBytesForMessageType(BattOrMessageType type) {
BattOrConnectionImpl::BattOrConnectionImpl(
const std::string& path,
BattOrConnection::Listener* listener,
scoped_refptr<base::SingleThreadTaskRunner> file_thread_task_runner,
scoped_refptr<base::SingleThreadTaskRunner> ui_thread_task_runner)
: BattOrConnection(listener),
path_(path),
file_thread_task_runner_(file_thread_task_runner),
ui_thread_task_runner_(ui_thread_task_runner) {
std::string serial_log_path =
base::CommandLine::ForCurrentProcess()->GetSwitchValueASCII(
Expand Down Expand Up @@ -193,8 +191,7 @@ void BattOrConnectionImpl::Flush() {
}

scoped_refptr<device::SerialIoHandler> BattOrConnectionImpl::CreateIoHandler() {
return device::SerialIoHandler::Create(file_thread_task_runner_,
ui_thread_task_runner_);
return device::SerialIoHandler::Create(ui_thread_task_runner_);
}

void BattOrConnectionImpl::BeginReadBytes(size_t max_bytes_to_read) {
Expand Down
2 changes: 0 additions & 2 deletions tools/battor_agent/battor_connection_impl.h
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,6 @@ class BattOrConnectionImpl
BattOrConnectionImpl(
const std::string& path,
BattOrConnection::Listener* listener,
scoped_refptr<base::SingleThreadTaskRunner> file_thread_task_runner,
scoped_refptr<base::SingleThreadTaskRunner> ui_thread_task_runner);
~BattOrConnectionImpl() override;

Expand Down Expand Up @@ -105,7 +104,6 @@ class BattOrConnectionImpl
size_t pending_write_length_;

// Threads needed for serial communication.
scoped_refptr<base::SingleThreadTaskRunner> file_thread_task_runner_;
scoped_refptr<base::SingleThreadTaskRunner> ui_thread_task_runner_;

std::fstream serial_log_;
Expand Down
2 changes: 1 addition & 1 deletion tools/battor_agent/battor_connection_impl_unittest.cc
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ namespace battor {
class TestableBattOrConnection : public BattOrConnectionImpl {
public:
TestableBattOrConnection(BattOrConnection::Listener* listener)
: BattOrConnectionImpl("/dev/test", listener, nullptr, nullptr) {}
: BattOrConnectionImpl("/dev/test", listener, nullptr) {}
scoped_refptr<device::SerialIoHandler> CreateIoHandler() override {
return device::TestSerialIoHandler::Create();
}
Expand Down

0 comments on commit 1f83b93

Please sign in to comment.