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( |
| 94 const std::vector<autofill::PasswordForm>& parsed_vector) { |
| 95 DCHECK(!got_result); |
| 96 result_vector = parsed_vector; |
| 97 got_result = true; |
| 98 base::MessageLoop::current()->Quit(); |
| 99 } |
| 100 |
93 void QuitClient() { | 101 void QuitClient() { |
94 if (sender_) | 102 if (sender_) |
95 sender_->Send(new Msg_Decryptor_Quit()); | 103 sender_->Send(new Msg_Decryptor_Quit()); |
96 } | 104 } |
97 | 105 |
98 virtual bool OnMessageReceived(const IPC::Message& msg) OVERRIDE { | 106 virtual bool OnMessageReceived(const IPC::Message& msg) OVERRIDE { |
99 bool handled = true; | 107 bool handled = true; |
100 IPC_BEGIN_MESSAGE_MAP(FFDecryptorServerChannelListener, msg) | 108 IPC_BEGIN_MESSAGE_MAP(FFDecryptorServerChannelListener, msg) |
101 IPC_MESSAGE_HANDLER(Msg_Decryptor_InitReturnCode, OnInitDecryptorResponse) | 109 IPC_MESSAGE_HANDLER(Msg_Decryptor_InitReturnCode, OnInitDecryptorResponse) |
102 IPC_MESSAGE_HANDLER(Msg_Decryptor_Response, OnDecryptedTextResonse) | 110 IPC_MESSAGE_HANDLER(Msg_Decryptor_Response, OnDecryptedTextResponse) |
| 111 IPC_MESSAGE_HANDLER(Msg_ParseSignons_Response, OnParseSignonsResponse) |
103 IPC_MESSAGE_UNHANDLED(handled = false) | 112 IPC_MESSAGE_UNHANDLED(handled = false) |
104 IPC_END_MESSAGE_MAP() | 113 IPC_END_MESSAGE_MAP() |
105 return handled; | 114 return handled; |
106 } | 115 } |
107 | 116 |
108 // If an error occured, just kill the message Loop. | 117 // If an error occured, just kill the message Loop. |
109 virtual void OnChannelError() OVERRIDE { | 118 virtual void OnChannelError() OVERRIDE { |
110 got_result = false; | 119 got_result = false; |
111 base::MessageLoop::current()->Quit(); | 120 base::MessageLoop::current()->Quit(); |
112 } | 121 } |
113 | 122 |
114 // Results of IPC calls. | 123 // Results of IPC calls. |
115 base::string16 result_string; | 124 base::string16 result_string; |
| 125 std::vector<autofill::PasswordForm> result_vector; |
116 bool result_bool; | 126 bool result_bool; |
117 // True if IPC call succeeded and data in above variables is valid. | 127 // True if IPC call succeeded and data in above variables is valid. |
118 bool got_result; | 128 bool got_result; |
119 | 129 |
120 private: | 130 private: |
121 IPC::Sender* sender_; // weak | 131 IPC::Sender* sender_; // weak |
122 }; | 132 }; |
123 | 133 |
124 FFUnitTestDecryptorProxy::FFUnitTestDecryptorProxy() | 134 FFUnitTestDecryptorProxy::FFUnitTestDecryptorProxy() |
125 : child_process_(0) { | 135 : 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) { | 213 base::string16 FFUnitTestDecryptorProxy::Decrypt(const std::string& crypt) { |
204 channel_->Send(new Msg_Decrypt(crypt)); | 214 channel_->Send(new Msg_Decrypt(crypt)); |
205 bool ok = WaitForClientResponse(); | 215 bool ok = WaitForClientResponse(); |
206 if (ok && listener_->got_result) { | 216 if (ok && listener_->got_result) { |
207 listener_->got_result = false; | 217 listener_->got_result = false; |
208 return listener_->result_string; | 218 return listener_->result_string; |
209 } | 219 } |
210 return base::string16(); | 220 return base::string16(); |
211 } | 221 } |
212 | 222 |
| 223 std::vector<autofill::PasswordForm> FFUnitTestDecryptorProxy::ParseSignons( |
| 224 const base::FilePath& signons_path) { |
| 225 channel_->Send(new Msg_ParseSignons(signons_path)); |
| 226 bool ok = WaitForClientResponse(); |
| 227 if (ok && listener_->got_result) { |
| 228 listener_->got_result = false; |
| 229 return listener_->result_vector; |
| 230 } |
| 231 return std::vector<autofill::PasswordForm>(); |
| 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 std::vector<autofill::PasswordForm> 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 |