OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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 "chrome/test/chromedriver/commands.h" | 5 #include "chrome/test/chromedriver/commands.h" |
6 | 6 |
7 #include <algorithm> | 7 #include <algorithm> |
8 #include <list> | 8 #include <list> |
9 #include <utility> | 9 #include <utility> |
10 | 10 |
11 #include "base/bind.h" | 11 #include "base/bind.h" |
12 #include "base/bind_helpers.h" | 12 #include "base/bind_helpers.h" |
| 13 #include "base/location.h" |
13 #include "base/logging.h" | 14 #include "base/logging.h" |
14 #include "base/memory/linked_ptr.h" | 15 #include "base/memory/linked_ptr.h" |
15 #include "base/message_loop/message_loop.h" | 16 #include "base/message_loop/message_loop.h" |
16 #include "base/message_loop/message_loop_proxy.h" | |
17 #include "base/run_loop.h" | 17 #include "base/run_loop.h" |
| 18 #include "base/single_thread_task_runner.h" |
18 #include "base/strings/stringprintf.h" | 19 #include "base/strings/stringprintf.h" |
19 #include "base/sys_info.h" | 20 #include "base/sys_info.h" |
| 21 #include "base/thread_task_runner_handle.h" |
20 #include "base/values.h" | 22 #include "base/values.h" |
21 #include "chrome/test/chromedriver/capabilities.h" | 23 #include "chrome/test/chromedriver/capabilities.h" |
22 #include "chrome/test/chromedriver/chrome/browser_info.h" | 24 #include "chrome/test/chromedriver/chrome/browser_info.h" |
23 #include "chrome/test/chromedriver/chrome/chrome.h" | 25 #include "chrome/test/chromedriver/chrome/chrome.h" |
24 #include "chrome/test/chromedriver/chrome/status.h" | 26 #include "chrome/test/chromedriver/chrome/status.h" |
25 #include "chrome/test/chromedriver/logging.h" | 27 #include "chrome/test/chromedriver/logging.h" |
26 #include "chrome/test/chromedriver/session.h" | 28 #include "chrome/test/chromedriver/session.h" |
27 #include "chrome/test/chromedriver/session_thread_map.h" | 29 #include "chrome/test/chromedriver/session_thread_map.h" |
28 #include "chrome/test/chromedriver/util.h" | 30 #include "chrome/test/chromedriver/util.h" |
29 | 31 |
(...skipping 28 matching lines...) Expand all Loading... |
58 scoped_ptr<Session> session(new Session(new_id)); | 60 scoped_ptr<Session> session(new Session(new_id)); |
59 scoped_ptr<base::Thread> thread(new base::Thread(new_id)); | 61 scoped_ptr<base::Thread> thread(new base::Thread(new_id)); |
60 if (!thread->Start()) { | 62 if (!thread->Start()) { |
61 callback.Run( | 63 callback.Run( |
62 Status(kUnknownError, "failed to start a thread for the new session"), | 64 Status(kUnknownError, "failed to start a thread for the new session"), |
63 scoped_ptr<base::Value>(), | 65 scoped_ptr<base::Value>(), |
64 std::string()); | 66 std::string()); |
65 return; | 67 return; |
66 } | 68 } |
67 | 69 |
68 thread->message_loop()->PostTask( | 70 thread->task_runner()->PostTask( |
69 FROM_HERE, base::Bind(&SetThreadLocalSession, base::Passed(&session))); | 71 FROM_HERE, base::Bind(&SetThreadLocalSession, base::Passed(&session))); |
70 session_thread_map | 72 session_thread_map |
71 ->insert(std::make_pair(new_id, make_linked_ptr(thread.release()))); | 73 ->insert(std::make_pair(new_id, make_linked_ptr(thread.release()))); |
72 init_session_cmd.Run(params, new_id, callback); | 74 init_session_cmd.Run(params, new_id, callback); |
73 } | 75 } |
74 | 76 |
75 namespace { | 77 namespace { |
76 | 78 |
77 void OnGetSession(const base::WeakPtr<size_t>& session_remaining_count, | 79 void OnGetSession(const base::WeakPtr<size_t>& session_remaining_count, |
78 const base::Closure& all_get_session_func, | 80 const base::Closure& all_get_session_func, |
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
119 iter != session_thread_map->end(); | 121 iter != session_thread_map->end(); |
120 ++iter) { | 122 ++iter) { |
121 session_capabilities_command.Run(params, | 123 session_capabilities_command.Run(params, |
122 iter->first, | 124 iter->first, |
123 base::Bind( | 125 base::Bind( |
124 &OnGetSession, | 126 &OnGetSession, |
125 weak_ptr_factory.GetWeakPtr(), | 127 weak_ptr_factory.GetWeakPtr(), |
126 run_loop.QuitClosure(), | 128 run_loop.QuitClosure(), |
127 session_list.get())); | 129 session_list.get())); |
128 } | 130 } |
129 base::MessageLoop::current()->PostDelayedTask( | 131 base::ThreadTaskRunnerHandle::Get()->PostDelayedTask( |
130 FROM_HERE, | 132 FROM_HERE, run_loop.QuitClosure(), base::TimeDelta::FromSeconds(10)); |
131 run_loop.QuitClosure(), | |
132 base::TimeDelta::FromSeconds(10)); | |
133 base::MessageLoop::current()->SetNestableTasksAllowed(true); | 133 base::MessageLoop::current()->SetNestableTasksAllowed(true); |
134 run_loop.Run(); | 134 run_loop.Run(); |
135 | 135 |
136 callback.Run(Status(kOk), session_list.Pass(), session_id); | 136 callback.Run(Status(kOk), session_list.Pass(), session_id); |
137 } | 137 } |
138 | 138 |
139 namespace { | 139 namespace { |
140 | 140 |
141 void OnSessionQuit(const base::WeakPtr<size_t>& quit_remaining_count, | 141 void OnSessionQuit(const base::WeakPtr<size_t>& quit_remaining_count, |
142 const base::Closure& all_quit_func, | 142 const base::Closure& all_quit_func, |
(...skipping 26 matching lines...) Expand all Loading... |
169 base::RunLoop run_loop; | 169 base::RunLoop run_loop; |
170 for (SessionThreadMap::const_iterator iter = session_thread_map->begin(); | 170 for (SessionThreadMap::const_iterator iter = session_thread_map->begin(); |
171 iter != session_thread_map->end(); | 171 iter != session_thread_map->end(); |
172 ++iter) { | 172 ++iter) { |
173 quit_command.Run(params, | 173 quit_command.Run(params, |
174 iter->first, | 174 iter->first, |
175 base::Bind(&OnSessionQuit, | 175 base::Bind(&OnSessionQuit, |
176 weak_ptr_factory.GetWeakPtr(), | 176 weak_ptr_factory.GetWeakPtr(), |
177 run_loop.QuitClosure())); | 177 run_loop.QuitClosure())); |
178 } | 178 } |
179 base::MessageLoop::current()->PostDelayedTask( | 179 base::ThreadTaskRunnerHandle::Get()->PostDelayedTask( |
180 FROM_HERE, run_loop.QuitClosure(), base::TimeDelta::FromSeconds(10)); | 180 FROM_HERE, run_loop.QuitClosure(), base::TimeDelta::FromSeconds(10)); |
181 // Uses a nested run loop to block this thread until all the quit | 181 // Uses a nested run loop to block this thread until all the quit |
182 // commands have executed, or the timeout expires. | 182 // commands have executed, or the timeout expires. |
183 base::MessageLoop::current()->SetNestableTasksAllowed(true); | 183 base::MessageLoop::current()->SetNestableTasksAllowed(true); |
184 run_loop.Run(); | 184 run_loop.Run(); |
185 callback.Run(Status(kOk), scoped_ptr<base::Value>(), session_id); | 185 callback.Run(Status(kOk), scoped_ptr<base::Value>(), session_id); |
186 } | 186 } |
187 | 187 |
188 namespace { | 188 namespace { |
189 | 189 |
(...skipping 106 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
296 const SessionCommand& command, | 296 const SessionCommand& command, |
297 bool return_ok_without_session, | 297 bool return_ok_without_session, |
298 const base::DictionaryValue& params, | 298 const base::DictionaryValue& params, |
299 const std::string& session_id, | 299 const std::string& session_id, |
300 const CommandCallback& callback) { | 300 const CommandCallback& callback) { |
301 SessionThreadMap::iterator iter = session_thread_map->find(session_id); | 301 SessionThreadMap::iterator iter = session_thread_map->find(session_id); |
302 if (iter == session_thread_map->end()) { | 302 if (iter == session_thread_map->end()) { |
303 Status status(return_ok_without_session ? kOk : kNoSuchSession); | 303 Status status(return_ok_without_session ? kOk : kNoSuchSession); |
304 callback.Run(status, scoped_ptr<base::Value>(), session_id); | 304 callback.Run(status, scoped_ptr<base::Value>(), session_id); |
305 } else { | 305 } else { |
306 iter->second->message_loop() | 306 iter->second->task_runner()->PostTask( |
307 ->PostTask(FROM_HERE, | 307 FROM_HERE, base::Bind(&ExecuteSessionCommandOnSessionThread, |
308 base::Bind(&ExecuteSessionCommandOnSessionThread, | 308 command_name, command, return_ok_without_session, |
309 command_name, | |
310 command, | |
311 return_ok_without_session, | |
312 base::Passed(make_scoped_ptr(params.DeepCopy())), | 309 base::Passed(make_scoped_ptr(params.DeepCopy())), |
313 base::MessageLoopProxy::current(), | 310 base::ThreadTaskRunnerHandle::Get(), callback, |
314 callback, | |
315 base::Bind(&TerminateSessionThreadOnCommandThread, | 311 base::Bind(&TerminateSessionThreadOnCommandThread, |
316 session_thread_map, | 312 session_thread_map, session_id))); |
317 session_id))); | |
318 } | 313 } |
319 } | 314 } |
320 | 315 |
321 namespace internal { | 316 namespace internal { |
322 | 317 |
323 void CreateSessionOnSessionThreadForTesting(const std::string& id) { | 318 void CreateSessionOnSessionThreadForTesting(const std::string& id) { |
324 SetThreadLocalSession(make_scoped_ptr(new Session(id))); | 319 SetThreadLocalSession(make_scoped_ptr(new Session(id))); |
325 } | 320 } |
326 | 321 |
327 } // namespace internal | 322 } // namespace internal |
OLD | NEW |