Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 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 // This file provides a thin binary wrapper around the BattOr Agent | 5 // This file provides a thin binary wrapper around the BattOr Agent |
| 6 // library. This binary wrapper provides a means for non-C++ tracing | 6 // library. This binary wrapper provides a means for non-C++ tracing |
| 7 // controllers, such as Telemetry and Android Systrace, to issue high-level | 7 // controllers, such as Telemetry and Android Systrace, to issue high-level |
| 8 // tracing commands to the BattOr through an interactive shell. | 8 // tracing commands to the BattOr through an interactive shell. |
| 9 // | 9 // |
| 10 // Example usage of how an external trace controller might use this binary: | 10 // Example usage of how an external trace controller might use this binary: |
| (...skipping 123 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 134 } | 134 } |
| 135 | 135 |
| 136 // Performs any setup necessary for the BattOr binary to run. | 136 // Performs any setup necessary for the BattOr binary to run. |
| 137 void SetUp(const std::string& path) { | 137 void SetUp(const std::string& path) { |
| 138 base::Thread::Options io_thread_options; | 138 base::Thread::Options io_thread_options; |
| 139 io_thread_options.message_loop_type = base::MessageLoopForIO::TYPE_IO; | 139 io_thread_options.message_loop_type = base::MessageLoopForIO::TYPE_IO; |
| 140 if (!io_thread_.StartWithOptions(io_thread_options)) { | 140 if (!io_thread_.StartWithOptions(io_thread_options)) { |
| 141 ExitFromThreadStartFailure(kIoThreadName); | 141 ExitFromThreadStartFailure(kIoThreadName); |
| 142 } | 142 } |
| 143 | 143 |
| 144 base::WaitableEvent done(base::WaitableEvent::ResetPolicy::AUTOMATIC, | |
| 145 base::WaitableEvent::InitialState::NOT_SIGNALED); | |
|
aschulman
2016/06/15 14:51:03
I'd like to see a comment explaining why this part
| |
| 144 io_thread_.task_runner()->PostTask( | 146 io_thread_.task_runner()->PostTask( |
| 145 FROM_HERE, | 147 FROM_HERE, |
| 146 base::Bind(&BattOrAgentBin::CreateAgent, base::Unretained(this), path, | 148 base::Bind(&BattOrAgentBin::CreateAgent, base::Unretained(this), path, |
| 147 base::ThreadTaskRunnerHandle::Get())); | 149 base::ThreadTaskRunnerHandle::Get(), &done)); |
| 150 done.Wait(); | |
| 148 } | 151 } |
| 149 | 152 |
| 150 // Performs any cleanup necessary after the BattOr binary is done running. | 153 // Performs any cleanup necessary after the BattOr binary is done running. |
| 151 void TearDown() { | 154 void TearDown() { |
| 152 base::WaitableEvent done(base::WaitableEvent::ResetPolicy::AUTOMATIC, | 155 base::WaitableEvent done(base::WaitableEvent::ResetPolicy::AUTOMATIC, |
| 153 base::WaitableEvent::InitialState::NOT_SIGNALED); | 156 base::WaitableEvent::InitialState::NOT_SIGNALED); |
| 154 io_thread_.task_runner()->PostTask( | 157 io_thread_.task_runner()->PostTask( |
| 155 FROM_HERE, base::Bind(&BattOrAgentBin::DeleteAgent, | 158 FROM_HERE, base::Bind(&BattOrAgentBin::DeleteAgent, |
| 156 base::Unretained(this), &done)); | 159 base::Unretained(this), &done)); |
| 157 done.Wait(); | 160 done.Wait(); |
| (...skipping 107 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 265 HandleError(error); | 268 HandleError(error); |
| 266 | 269 |
| 267 PostRunNextCommand(); | 270 PostRunNextCommand(); |
| 268 } | 271 } |
| 269 | 272 |
| 270 // Postable task for creating the BattOrAgent. Because the BattOrAgent has | 273 // Postable task for creating the BattOrAgent. Because the BattOrAgent has |
| 271 // uber thread safe dependencies, all interactions with it, including creating | 274 // uber thread safe dependencies, all interactions with it, including creating |
| 272 // and deleting it, MUST happen on the IO thread. | 275 // and deleting it, MUST happen on the IO thread. |
| 273 void CreateAgent( | 276 void CreateAgent( |
| 274 const std::string& path, | 277 const std::string& path, |
| 275 scoped_refptr<base::SingleThreadTaskRunner> ui_thread_task_runner) { | 278 scoped_refptr<base::SingleThreadTaskRunner> ui_thread_task_runner, |
| 279 base::WaitableEvent* done) { | |
| 276 // In Chrome, we already have a file thread running. Because the Chrome | 280 // In Chrome, we already have a file thread running. Because the Chrome |
| 277 // serial library relies on having it available, we have to spin up our own. | 281 // serial library relies on having it available, we have to spin up our own. |
| 278 if (!file_thread_.Start()) | 282 if (!file_thread_.Start()) |
| 279 ExitFromThreadStartFailure(kFileThreadName); | 283 ExitFromThreadStartFailure(kFileThreadName); |
| 280 | 284 |
| 281 agent_.reset(new BattOrAgent(path, this, file_thread_.task_runner(), | 285 agent_.reset(new BattOrAgent(path, this, file_thread_.task_runner(), |
| 282 ui_thread_task_runner)); | 286 ui_thread_task_runner)); |
| 287 done->Signal(); | |
| 283 } | 288 } |
| 284 | 289 |
| 285 // Postable task for deleting the BattOrAgent. See the comment for | 290 // Postable task for deleting the BattOrAgent. See the comment for |
| 286 // CreateAgent() above regarding why this is necessary. | 291 // CreateAgent() above regarding why this is necessary. |
| 287 void DeleteAgent(base::WaitableEvent* done) { | 292 void DeleteAgent(base::WaitableEvent* done) { |
| 288 agent_.reset(); | 293 agent_.reset(); |
| 289 done->Signal(); | 294 done->Signal(); |
| 290 } | 295 } |
| 291 | 296 |
| 292 private: | 297 private: |
| (...skipping 14 matching lines...) Expand all Loading... | |
| 307 }; | 312 }; |
| 308 | 313 |
| 309 } // namespace battor | 314 } // namespace battor |
| 310 | 315 |
| 311 int main(int argc, char* argv[]) { | 316 int main(int argc, char* argv[]) { |
| 312 base::AtExitManager exit_manager; | 317 base::AtExitManager exit_manager; |
| 313 base::CommandLine::Init(argc, argv); | 318 base::CommandLine::Init(argc, argv); |
| 314 battor::BattOrAgentBin bin; | 319 battor::BattOrAgentBin bin; |
| 315 return bin.Run(argc, argv); | 320 return bin.Run(argc, argv); |
| 316 } | 321 } |
| OLD | NEW |