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

Side by Side Diff: tools/battor_agent/battor_agent_bin.cc

Issue 2914173002: Removing file_thread_task_runner parameter from SerialIoHandler (Closed)
Patch Set: removed unused variable Created 3 years, 6 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 | « tools/battor_agent/battor_agent.cc ('k') | tools/battor_agent/battor_agent_unittest.cc » ('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 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 29 matching lines...) Expand all
40 #include "base/bind.h" 40 #include "base/bind.h"
41 #include "base/bind_helpers.h" 41 #include "base/bind_helpers.h"
42 #include "base/command_line.h" 42 #include "base/command_line.h"
43 #include "base/location.h" 43 #include "base/location.h"
44 #include "base/logging.h" 44 #include "base/logging.h"
45 #include "base/message_loop/message_loop.h" 45 #include "base/message_loop/message_loop.h"
46 #include "base/run_loop.h" 46 #include "base/run_loop.h"
47 #include "base/single_thread_task_runner.h" 47 #include "base/single_thread_task_runner.h"
48 #include "base/strings/string_tokenizer.h" 48 #include "base/strings/string_tokenizer.h"
49 #include "base/strings/utf_string_conversions.h" 49 #include "base/strings/utf_string_conversions.h"
50 #include "base/task_scheduler/task_scheduler.h"
50 #include "base/threading/thread.h" 51 #include "base/threading/thread.h"
51 #include "base/threading/thread_task_runner_handle.h" 52 #include "base/threading/thread_task_runner_handle.h"
52 #include "tools/battor_agent/battor_agent.h" 53 #include "tools/battor_agent/battor_agent.h"
53 #include "tools/battor_agent/battor_error.h" 54 #include "tools/battor_agent/battor_error.h"
54 #include "tools/battor_agent/battor_finder.h" 55 #include "tools/battor_agent/battor_finder.h"
55 56
56 using std::endl; 57 using std::endl;
57 58
58 namespace battor { 59 namespace battor {
59 60
60 namespace { 61 namespace {
61 62
62 const char kIoThreadName[] = "BattOr IO Thread"; 63 const char kIoThreadName[] = "BattOr IO Thread";
63 const char kFileThreadName[] = "BattOr File Thread";
64 64
65 const char kUsage[] = 65 const char kUsage[] =
66 "Start the battor_agent shell with:\n" 66 "Start the battor_agent shell with:\n"
67 "\n" 67 "\n"
68 " battor_agent <switches>\n" 68 " battor_agent <switches>\n"
69 "\n" 69 "\n"
70 "Switches: \n" 70 "Switches: \n"
71 " --battor-path=<path> Uses the specified BattOr path.\n" 71 " --battor-path=<path> Uses the specified BattOr path.\n"
72 "\n" 72 "\n"
73 "Once in the shell, you can issue the following commands:\n" 73 "Once in the shell, you can issue the following commands:\n"
(...skipping 30 matching lines...) Expand all
104 tokens.push_back(tokenizer.token()); 104 tokens.push_back(tokenizer.token());
105 return tokens; 105 return tokens;
106 } 106 }
107 107
108 } // namespace 108 } // namespace
109 109
110 // Wrapper class containing all state necessary for an independent binary to 110 // Wrapper class containing all state necessary for an independent binary to
111 // use a BattOrAgent to communicate with a BattOr. 111 // use a BattOrAgent to communicate with a BattOr.
112 class BattOrAgentBin : public BattOrAgent::Listener { 112 class BattOrAgentBin : public BattOrAgent::Listener {
113 public: 113 public:
114 BattOrAgentBin() : io_thread_(kIoThreadName), file_thread_(kFileThreadName) {} 114 BattOrAgentBin() : io_thread_(kIoThreadName) {}
115 115
116 ~BattOrAgentBin() { DCHECK(!agent_); } 116 ~BattOrAgentBin() { DCHECK(!agent_); }
117 117
118 // Starts the interactive BattOr agent shell and eventually returns an exit 118 // Starts the interactive BattOr agent shell and eventually returns an exit
119 // code. 119 // code.
120 int Run(int argc, char* argv[]) { 120 int Run(int argc, char* argv[]) {
121 // If we don't have any BattOr to use, exit. 121 // If we don't have any BattOr to use, exit.
122 std::string path = BattOrFinder::FindBattOr(); 122 std::string path = BattOrFinder::FindBattOr();
123 if (path.empty()) { 123 if (path.empty()) {
124 std::cout << "Unable to find a BattOr." << endl; 124 std::cout << "Unable to find a BattOr." << endl;
(...skipping 173 matching lines...) Expand 10 before | Expand all | Expand 10 after
298 PostRunNextCommand(); 298 PostRunNextCommand();
299 } 299 }
300 300
301 // Postable task for creating the BattOrAgent. Because the BattOrAgent has 301 // Postable task for creating the BattOrAgent. Because the BattOrAgent has
302 // uber thread safe dependencies, all interactions with it, including creating 302 // uber thread safe dependencies, all interactions with it, including creating
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 agent_.reset(new BattOrAgent(path, this, ui_thread_task_runner));
309 // serial library relies on having it available, we have to spin up our own.
310 if (!file_thread_.Start())
311 ExitFromThreadStartFailure(kFileThreadName);
312
313 agent_.reset(new BattOrAgent(path, this, file_thread_.task_runner(),
314 ui_thread_task_runner));
315 done->Signal(); 309 done->Signal();
316 } 310 }
317 311
318 // Postable task for deleting the BattOrAgent. See the comment for 312 // Postable task for deleting the BattOrAgent. See the comment for
319 // CreateAgent() above regarding why this is necessary. 313 // CreateAgent() above regarding why this is necessary.
320 void DeleteAgent(base::WaitableEvent* done) { 314 void DeleteAgent(base::WaitableEvent* done) {
321 agent_.reset(); 315 agent_.reset();
322 done->Signal(); 316 done->Signal();
323 } 317 }
324 318
325 private: 319 private:
326 // NOTE: ui_thread_message_loop_ must appear before ui_thread_run_loop_ here 320 // 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 321 // because ui_thread_run_loop_ checks for the current MessageLoop during
328 // initialization. 322 // initialization.
329 base::MessageLoopForUI ui_thread_message_loop_; 323 base::MessageLoopForUI ui_thread_message_loop_;
330 base::RunLoop ui_thread_run_loop_; 324 base::RunLoop ui_thread_run_loop_;
331 325
332 // Threads needed for serial communication. 326 // Threads needed for serial communication.
333 base::Thread io_thread_; 327 base::Thread io_thread_;
334 base::Thread file_thread_;
335 328
336 // The agent capable of asynchronously communicating with the BattOr. 329 // The agent capable of asynchronously communicating with the BattOr.
337 std::unique_ptr<BattOrAgent> agent_; 330 std::unique_ptr<BattOrAgent> agent_;
338 331
339 std::string trace_output_file_; 332 std::string trace_output_file_;
340 }; 333 };
341 334
342 } // namespace battor 335 } // namespace battor
343 336
344 int main(int argc, char* argv[]) { 337 int main(int argc, char* argv[]) {
345 base::AtExitManager exit_manager; 338 base::AtExitManager exit_manager;
346 base::CommandLine::Init(argc, argv); 339 base::CommandLine::Init(argc, argv);
347 battor::BattOrAgentBin bin; 340 battor::BattOrAgentBin bin;
341 base::TaskScheduler::CreateAndStartWithDefaultParams("battor_agent");
348 return bin.Run(argc, argv); 342 return bin.Run(argc, argv);
349 } 343 }
OLDNEW
« no previous file with comments | « tools/battor_agent/battor_agent.cc ('k') | tools/battor_agent/battor_agent_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698