Chromium Code Reviews| 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/utility/importer/firefox_importer_unittest_utils.h" | 5 #include "chrome/utility/importer/firefox_importer_unittest_utils.h" |
| 6 | 6 |
| 7 #include "base/base_switches.h" | 7 #include "base/base_switches.h" |
| 8 #include "base/bind.h" | 8 #include "base/bind.h" |
| 9 #include "base/command_line.h" | 9 #include "base/command_line.h" |
| 10 #include "base/files/file_path.h" | 10 #include "base/files/file_path.h" |
| (...skipping 161 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 172 listener_->QuitClient(); | 172 listener_->QuitClient(); |
| 173 channel_->Close(); | 173 channel_->Close(); |
| 174 | 174 |
| 175 if (child_process_.IsValid()) { | 175 if (child_process_.IsValid()) { |
| 176 int exit_code; | 176 int exit_code; |
| 177 child_process_.WaitForExitWithTimeout(base::TimeDelta::FromSeconds(5), | 177 child_process_.WaitForExitWithTimeout(base::TimeDelta::FromSeconds(5), |
| 178 &exit_code); | 178 &exit_code); |
| 179 } | 179 } |
| 180 } | 180 } |
| 181 | 181 |
| 182 // A message_loop task that quits the message loop when invoked, setting cancel | |
| 183 // causes the task to do nothing when invoked. | |
| 184 class CancellableQuitMsgLoop : public base::RefCounted<CancellableQuitMsgLoop> { | |
| 185 public: | |
| 186 CancellableQuitMsgLoop() : cancelled_(false) {} | |
| 187 void QuitNow() { | |
| 188 if (!cancelled_) | |
| 189 base::MessageLoop::current()->QuitWhenIdle(); | |
| 190 } | |
| 191 bool cancelled_; | |
| 192 | |
| 193 private: | |
| 194 friend class base::RefCounted<CancellableQuitMsgLoop>; | |
| 195 ~CancellableQuitMsgLoop() {} | |
| 196 }; | |
| 197 | |
| 198 // Spin until either a client response arrives or a timeout occurs. | 182 // Spin until either a client response arrives or a timeout occurs. |
| 199 bool FFUnitTestDecryptorProxy::WaitForClientResponse() { | 183 bool FFUnitTestDecryptorProxy::WaitForClientResponse() { |
| 200 // What we're trying to do here is to wait for an RPC message to go over the | 184 // What we're trying to do here is to wait for an RPC message to go over the |
| 201 // wire and the client to reply. If the client does not reply by a given | 185 // wire and the client to reply. If the client does not reply by a given |
| 202 // timeout we kill the message loop. | 186 // timeout we kill the message loop. |
| 203 // The way we do this is to post a CancellableQuitMsgLoop for 3 seconds in | |
| 204 // the future and cancel it if an RPC message comes back earlier. | |
| 205 // This relies on the IPC listener class to quit the message loop itself when | 187 // This relies on the IPC listener class to quit the message loop itself when |
| 206 // a message comes in. | 188 // a message comes in. |
| 207 scoped_refptr<CancellableQuitMsgLoop> quit_task( | 189 base::RunLoop run_loop; |
| 208 new CancellableQuitMsgLoop()); | |
| 209 base::ThreadTaskRunnerHandle::Get()->PostDelayedTask( | 190 base::ThreadTaskRunnerHandle::Get()->PostDelayedTask( |
| 210 FROM_HERE, base::Bind(&CancellableQuitMsgLoop::QuitNow, quit_task.get()), | 191 FROM_HERE, run_loop.QuitWhenIdleClosure(), |
| 211 TestTimeouts::action_max_timeout()); | 192 TestTimeouts::action_max_timeout()); |
| 212 | 193 run_loop.Run(); |
| 213 message_loop_->Run(); | 194 return true; |
|
jochen (gone - plz use gerrit)
2016/09/26 15:11:32
just make the method void()
fdoray
2016/09/26 17:26:00
Done.
| |
| 214 bool ret = !quit_task->cancelled_; | |
| 215 quit_task->cancelled_ = false; | |
| 216 return ret; | |
| 217 } | 195 } |
| 218 | 196 |
| 219 bool FFUnitTestDecryptorProxy::DecryptorInit(const base::FilePath& dll_path, | 197 bool FFUnitTestDecryptorProxy::DecryptorInit(const base::FilePath& dll_path, |
| 220 const base::FilePath& db_path) { | 198 const base::FilePath& db_path) { |
| 221 channel_->Send(new Msg_Decryptor_Init(dll_path, db_path)); | 199 channel_->Send(new Msg_Decryptor_Init(dll_path, db_path)); |
| 222 bool ok = WaitForClientResponse(); | 200 WaitForClientResponse(); |
| 223 if (ok && listener_->got_result) { | 201 if (listener_->got_result) { |
| 224 listener_->got_result = false; | 202 listener_->got_result = false; |
| 225 return listener_->result_bool; | 203 return listener_->result_bool; |
| 226 } | 204 } |
| 227 return false; | 205 return false; |
| 228 } | 206 } |
| 229 | 207 |
| 230 base::string16 FFUnitTestDecryptorProxy::Decrypt(const std::string& crypt) { | 208 base::string16 FFUnitTestDecryptorProxy::Decrypt(const std::string& crypt) { |
| 231 channel_->Send(new Msg_Decrypt(crypt)); | 209 channel_->Send(new Msg_Decrypt(crypt)); |
| 232 bool ok = WaitForClientResponse(); | 210 WaitForClientResponse(); |
| 233 if (ok && listener_->got_result) { | 211 if (listener_->got_result) { |
| 234 listener_->got_result = false; | 212 listener_->got_result = false; |
| 235 return listener_->result_string; | 213 return listener_->result_string; |
| 236 } | 214 } |
| 237 return base::string16(); | 215 return base::string16(); |
| 238 } | 216 } |
| 239 | 217 |
| 240 std::vector<autofill::PasswordForm> FFUnitTestDecryptorProxy::ParseSignons( | 218 std::vector<autofill::PasswordForm> FFUnitTestDecryptorProxy::ParseSignons( |
| 241 const base::FilePath& signons_path) { | 219 const base::FilePath& signons_path) { |
| 242 channel_->Send(new Msg_ParseSignons(signons_path)); | 220 channel_->Send(new Msg_ParseSignons(signons_path)); |
| 243 bool ok = WaitForClientResponse(); | 221 WaitForClientResponse(); |
| 244 if (ok && listener_->got_result) { | 222 if (listener_->got_result) { |
| 245 listener_->got_result = false; | 223 listener_->got_result = false; |
| 246 return listener_->result_vector; | 224 return listener_->result_vector; |
| 247 } | 225 } |
| 248 return std::vector<autofill::PasswordForm>(); | 226 return std::vector<autofill::PasswordForm>(); |
| 249 } | 227 } |
| 250 | 228 |
| 251 //---------------------------- Child Process ----------------------- | 229 //---------------------------- Child Process ----------------------- |
| 252 | 230 |
| 253 // Class to listen on the client side of the ipc channel, it calls through | 231 // Class to listen on the client side of the ipc channel, it calls through |
| 254 // to the NSSDecryptor and sends back a reply. | 232 // to the NSSDecryptor and sends back a reply. |
| (...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 316 std::unique_ptr<IPC::Channel> channel = | 294 std::unique_ptr<IPC::Channel> channel = |
| 317 IPC::Channel::CreateClient(mojo_handle.release(), &listener); | 295 IPC::Channel::CreateClient(mojo_handle.release(), &listener); |
| 318 CHECK(channel->Connect()); | 296 CHECK(channel->Connect()); |
| 319 listener.SetSender(channel.get()); | 297 listener.SetSender(channel.get()); |
| 320 | 298 |
| 321 // run message loop | 299 // run message loop |
| 322 base::RunLoop().Run(); | 300 base::RunLoop().Run(); |
| 323 | 301 |
| 324 return 0; | 302 return 0; |
| 325 } | 303 } |
| OLD | NEW |