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 292 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 303 // and deleting it, MUST happen on the IO thread. | 303 // and deleting it, MUST happen on the IO thread. |
| 304 void CreateAgent( | 304 void CreateAgent( |
| 305 const std::string& path, | 305 const std::string& path, |
| 306 scoped_refptr<base::SingleThreadTaskRunner> ui_thread_task_runner, | 306 scoped_refptr<base::SingleThreadTaskRunner> ui_thread_task_runner, |
| 307 base::WaitableEvent* done) { | 307 base::WaitableEvent* done) { |
| 308 // In Chrome, we already have a file thread running. Because the Chrome | 308 // In Chrome, we already have a file thread running. Because the Chrome |
| 309 // serial library relies on having it available, we have to spin up our own. | 309 // serial library relies on having it available, we have to spin up our own. |
| 310 if (!file_thread_.Start()) | 310 if (!file_thread_.Start()) |
| 311 ExitFromThreadStartFailure(kFileThreadName); | 311 ExitFromThreadStartFailure(kFileThreadName); |
| 312 | 312 |
| 313 agent_.reset(new BattOrAgent(path, this, file_thread_.task_runner(), | 313 agent_.reset(new BattOrAgent(path, this, ui_thread_task_runner)); |
| 314 ui_thread_task_runner)); | |
| 315 done->Signal(); | 314 done->Signal(); |
| 316 } | 315 } |
| 317 | 316 |
| 318 // Postable task for deleting the BattOrAgent. See the comment for | 317 // Postable task for deleting the BattOrAgent. See the comment for |
| 319 // CreateAgent() above regarding why this is necessary. | 318 // CreateAgent() above regarding why this is necessary. |
| 320 void DeleteAgent(base::WaitableEvent* done) { | 319 void DeleteAgent(base::WaitableEvent* done) { |
| 321 agent_.reset(); | 320 agent_.reset(); |
| 322 done->Signal(); | 321 done->Signal(); |
| 323 } | 322 } |
| 324 | 323 |
| 325 private: | 324 private: |
| 326 // NOTE: ui_thread_message_loop_ must appear before ui_thread_run_loop_ here | 325 // NOTE: ui_thread_message_loop_ must appear before ui_thread_run_loop_ here |
| 327 // because ui_thread_run_loop_ checks for the current MessageLoop during | 326 // because ui_thread_run_loop_ checks for the current MessageLoop during |
| 328 // initialization. | 327 // initialization. |
| 329 base::MessageLoopForUI ui_thread_message_loop_; | 328 base::MessageLoopForUI ui_thread_message_loop_; |
| 330 base::RunLoop ui_thread_run_loop_; | 329 base::RunLoop ui_thread_run_loop_; |
| 331 | 330 |
| 332 // Threads needed for serial communication. | 331 // Threads needed for serial communication. |
| 333 base::Thread io_thread_; | 332 base::Thread io_thread_; |
| 334 base::Thread file_thread_; | 333 base::Thread file_thread_; |
|
Reilly Grant (use Gerrit)
2017/06/07 15:48:56
This field should be replaced with a call to base:
sujith
2017/06/08 06:36:38
Done.
| |
| 335 | 334 |
| 336 // The agent capable of asynchronously communicating with the BattOr. | 335 // The agent capable of asynchronously communicating with the BattOr. |
| 337 std::unique_ptr<BattOrAgent> agent_; | 336 std::unique_ptr<BattOrAgent> agent_; |
| 338 | 337 |
| 339 std::string trace_output_file_; | 338 std::string trace_output_file_; |
| 340 }; | 339 }; |
| 341 | 340 |
| 342 } // namespace battor | 341 } // namespace battor |
| 343 | 342 |
| 344 int main(int argc, char* argv[]) { | 343 int main(int argc, char* argv[]) { |
| 345 base::AtExitManager exit_manager; | 344 base::AtExitManager exit_manager; |
| 346 base::CommandLine::Init(argc, argv); | 345 base::CommandLine::Init(argc, argv); |
| 347 battor::BattOrAgentBin bin; | 346 battor::BattOrAgentBin bin; |
| 348 return bin.Run(argc, argv); | 347 return bin.Run(argc, argv); |
| 349 } | 348 } |
| OLD | NEW |