| 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/file_util.h" | 10 #include "base/file_util.h" |
| (...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 76 sender_ = sender; | 76 sender_ = sender; |
| 77 } | 77 } |
| 78 | 78 |
| 79 void OnInitDecryptorResponse(bool result) { | 79 void OnInitDecryptorResponse(bool result) { |
| 80 DCHECK(!got_result); | 80 DCHECK(!got_result); |
| 81 result_bool = result; | 81 result_bool = result; |
| 82 got_result = true; | 82 got_result = true; |
| 83 base::MessageLoop::current()->Quit(); | 83 base::MessageLoop::current()->Quit(); |
| 84 } | 84 } |
| 85 | 85 |
| 86 void OnDecryptedTextResonse(const base::string16& decrypted_text) { | 86 void OnDecryptedTextResponse(const base::string16& decrypted_text) { |
| 87 DCHECK(!got_result); | 87 DCHECK(!got_result); |
| 88 result_string = decrypted_text; | 88 result_string = decrypted_text; |
| 89 got_result = true; | 89 got_result = true; |
| 90 base::MessageLoop::current()->Quit(); | 90 base::MessageLoop::current()->Quit(); |
| 91 } | 91 } |
| 92 | 92 |
| 93 void OnParseSignonsResponse(const PasswordFormVector& parsed_vector) { |
| 94 DCHECK(!got_result); |
| 95 result_vector = parsed_vector; |
| 96 got_result = true; |
| 97 base::MessageLoop::current()->Quit(); |
| 98 } |
| 99 |
| 93 void QuitClient() { | 100 void QuitClient() { |
| 94 if (sender_) | 101 if (sender_) |
| 95 sender_->Send(new Msg_Decryptor_Quit()); | 102 sender_->Send(new Msg_Decryptor_Quit()); |
| 96 } | 103 } |
| 97 | 104 |
| 98 virtual bool OnMessageReceived(const IPC::Message& msg) OVERRIDE { | 105 virtual bool OnMessageReceived(const IPC::Message& msg) OVERRIDE { |
| 99 bool handled = true; | 106 bool handled = true; |
| 100 IPC_BEGIN_MESSAGE_MAP(FFDecryptorServerChannelListener, msg) | 107 IPC_BEGIN_MESSAGE_MAP(FFDecryptorServerChannelListener, msg) |
| 101 IPC_MESSAGE_HANDLER(Msg_Decryptor_InitReturnCode, OnInitDecryptorResponse) | 108 IPC_MESSAGE_HANDLER(Msg_Decryptor_InitReturnCode, OnInitDecryptorResponse) |
| 102 IPC_MESSAGE_HANDLER(Msg_Decryptor_Response, OnDecryptedTextResonse) | 109 IPC_MESSAGE_HANDLER(Msg_Decryptor_Response, OnDecryptedTextResponse) |
| 110 IPC_MESSAGE_HANDLER(Msg_ParseSignons_Response, OnParseSignonsResponse) |
| 103 IPC_MESSAGE_UNHANDLED(handled = false) | 111 IPC_MESSAGE_UNHANDLED(handled = false) |
| 104 IPC_END_MESSAGE_MAP() | 112 IPC_END_MESSAGE_MAP() |
| 105 return handled; | 113 return handled; |
| 106 } | 114 } |
| 107 | 115 |
| 108 // If an error occured, just kill the message Loop. | 116 // If an error occured, just kill the message Loop. |
| 109 virtual void OnChannelError() OVERRIDE { | 117 virtual void OnChannelError() OVERRIDE { |
| 110 got_result = false; | 118 got_result = false; |
| 111 base::MessageLoop::current()->Quit(); | 119 base::MessageLoop::current()->Quit(); |
| 112 } | 120 } |
| 113 | 121 |
| 114 // Results of IPC calls. | 122 // Results of IPC calls. |
| 115 base::string16 result_string; | 123 base::string16 result_string; |
| 124 PasswordFormVector result_vector; |
| 116 bool result_bool; | 125 bool result_bool; |
| 117 // True if IPC call succeeded and data in above variables is valid. | 126 // True if IPC call succeeded and data in above variables is valid. |
| 118 bool got_result; | 127 bool got_result; |
| 119 | 128 |
| 120 private: | 129 private: |
| 121 IPC::Sender* sender_; // weak | 130 IPC::Sender* sender_; // weak |
| 122 }; | 131 }; |
| 123 | 132 |
| 124 FFUnitTestDecryptorProxy::FFUnitTestDecryptorProxy() | 133 FFUnitTestDecryptorProxy::FFUnitTestDecryptorProxy() |
| 125 : child_process_(0) { | 134 : child_process_(0) { |
| (...skipping 77 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 203 base::string16 FFUnitTestDecryptorProxy::Decrypt(const std::string& crypt) { | 212 base::string16 FFUnitTestDecryptorProxy::Decrypt(const std::string& crypt) { |
| 204 channel_->Send(new Msg_Decrypt(crypt)); | 213 channel_->Send(new Msg_Decrypt(crypt)); |
| 205 bool ok = WaitForClientResponse(); | 214 bool ok = WaitForClientResponse(); |
| 206 if (ok && listener_->got_result) { | 215 if (ok && listener_->got_result) { |
| 207 listener_->got_result = false; | 216 listener_->got_result = false; |
| 208 return listener_->result_string; | 217 return listener_->result_string; |
| 209 } | 218 } |
| 210 return base::string16(); | 219 return base::string16(); |
| 211 } | 220 } |
| 212 | 221 |
| 222 PasswordFormVector FFUnitTestDecryptorProxy::ParseSignons( |
| 223 const base::FilePath& signons_path) { |
| 224 channel_->Send(new Msg_ParseSignons(signons_path)); |
| 225 bool ok = WaitForClientResponse(); |
| 226 if (ok && listener_->got_result) { |
| 227 listener_->got_result = false; |
| 228 return listener_->result_vector; |
| 229 } |
| 230 return PasswordFormVector(); |
| 231 } |
| 232 |
| 233 |
| 213 //---------------------------- Child Process ----------------------- | 234 //---------------------------- Child Process ----------------------- |
| 214 | 235 |
| 215 // Class to listen on the client side of the ipc channel, it calls through | 236 // Class to listen on the client side of the ipc channel, it calls through |
| 216 // to the NSSDecryptor and sends back a reply. | 237 // to the NSSDecryptor and sends back a reply. |
| 217 class FFDecryptorClientChannelListener : public IPC::Listener { | 238 class FFDecryptorClientChannelListener : public IPC::Listener { |
| 218 public: | 239 public: |
| 219 FFDecryptorClientChannelListener() | 240 FFDecryptorClientChannelListener() |
| 220 : sender_(NULL) {} | 241 : sender_(NULL) {} |
| 221 | 242 |
| 222 void SetSender(IPC::Sender* sender) { | 243 void SetSender(IPC::Sender* sender) { |
| 223 sender_ = sender; | 244 sender_ = sender; |
| 224 } | 245 } |
| 225 | 246 |
| 226 void OnDecryptor_Init(base::FilePath dll_path, base::FilePath db_path) { | 247 void OnDecryptor_Init(base::FilePath dll_path, base::FilePath db_path) { |
| 227 bool ret = decryptor_.Init(dll_path, db_path); | 248 bool ret = decryptor_.Init(dll_path, db_path); |
| 228 sender_->Send(new Msg_Decryptor_InitReturnCode(ret)); | 249 sender_->Send(new Msg_Decryptor_InitReturnCode(ret)); |
| 229 } | 250 } |
| 230 | 251 |
| 231 void OnDecrypt(std::string crypt) { | 252 void OnDecrypt(std::string crypt) { |
| 232 base::string16 unencrypted_str = decryptor_.Decrypt(crypt); | 253 base::string16 unencrypted_str = decryptor_.Decrypt(crypt); |
| 233 sender_->Send(new Msg_Decryptor_Response(unencrypted_str)); | 254 sender_->Send(new Msg_Decryptor_Response(unencrypted_str)); |
| 234 } | 255 } |
| 235 | 256 |
| 257 void OnParseSignons(base::FilePath signons_path) { |
| 258 PasswordFormVector forms; |
| 259 decryptor_.ReadAndParseSignons(signons_path, &forms); |
| 260 sender_->Send(new Msg_ParseSignons_Response(forms)); |
| 261 } |
| 262 |
| 236 void OnQuitRequest() { | 263 void OnQuitRequest() { |
| 237 base::MessageLoop::current()->Quit(); | 264 base::MessageLoop::current()->Quit(); |
| 238 } | 265 } |
| 239 | 266 |
| 240 virtual bool OnMessageReceived(const IPC::Message& msg) OVERRIDE { | 267 virtual bool OnMessageReceived(const IPC::Message& msg) OVERRIDE { |
| 241 bool handled = true; | 268 bool handled = true; |
| 242 IPC_BEGIN_MESSAGE_MAP(FFDecryptorClientChannelListener, msg) | 269 IPC_BEGIN_MESSAGE_MAP(FFDecryptorClientChannelListener, msg) |
| 243 IPC_MESSAGE_HANDLER(Msg_Decryptor_Init, OnDecryptor_Init) | 270 IPC_MESSAGE_HANDLER(Msg_Decryptor_Init, OnDecryptor_Init) |
| 244 IPC_MESSAGE_HANDLER(Msg_Decrypt, OnDecrypt) | 271 IPC_MESSAGE_HANDLER(Msg_Decrypt, OnDecrypt) |
| 272 IPC_MESSAGE_HANDLER(Msg_ParseSignons, OnParseSignons) |
| 245 IPC_MESSAGE_HANDLER(Msg_Decryptor_Quit, OnQuitRequest) | 273 IPC_MESSAGE_HANDLER(Msg_Decryptor_Quit, OnQuitRequest) |
| 246 IPC_MESSAGE_UNHANDLED(handled = false) | 274 IPC_MESSAGE_UNHANDLED(handled = false) |
| 247 IPC_END_MESSAGE_MAP() | 275 IPC_END_MESSAGE_MAP() |
| 248 return handled; | 276 return handled; |
| 249 } | 277 } |
| 250 | 278 |
| 251 virtual void OnChannelError() OVERRIDE { | 279 virtual void OnChannelError() OVERRIDE { |
| 252 base::MessageLoop::current()->Quit(); | 280 base::MessageLoop::current()->Quit(); |
| 253 } | 281 } |
| 254 | 282 |
| (...skipping 10 matching lines...) Expand all Loading... |
| 265 scoped_ptr<IPC::Channel> channel = IPC::Channel::CreateClient( | 293 scoped_ptr<IPC::Channel> channel = IPC::Channel::CreateClient( |
| 266 kTestChannelID, &listener); | 294 kTestChannelID, &listener); |
| 267 CHECK(channel->Connect()); | 295 CHECK(channel->Connect()); |
| 268 listener.SetSender(channel.get()); | 296 listener.SetSender(channel.get()); |
| 269 | 297 |
| 270 // run message loop | 298 // run message loop |
| 271 base::MessageLoop::current()->Run(); | 299 base::MessageLoop::current()->Run(); |
| 272 | 300 |
| 273 return 0; | 301 return 0; |
| 274 } | 302 } |
| OLD | NEW |