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/browser/importer/firefox_importer_unittest_utils.h" | 5 #include "chrome/browser/importer/firefox_importer_unittest_utils.h" |
6 | 6 |
7 #include "base/bind.h" | 7 #include "base/bind.h" |
8 #include "base/base_switches.h" | 8 #include "base/base_switches.h" |
9 #include "base/command_line.h" | 9 #include "base/command_line.h" |
10 #include "base/file_path.h" | 10 #include "base/file_path.h" |
(...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
63 } | 63 } |
64 | 64 |
65 } // namespace | 65 } // namespace |
66 | 66 |
67 //----------------------- Server -------------------- | 67 //----------------------- Server -------------------- |
68 | 68 |
69 // Class to communicate on the server side of the IPC Channel. | 69 // Class to communicate on the server side of the IPC Channel. |
70 // Method calls are sent over IPC and replies are read back into class | 70 // Method calls are sent over IPC and replies are read back into class |
71 // variables. | 71 // variables. |
72 // This class needs to be called on a single thread. | 72 // This class needs to be called on a single thread. |
73 class FFDecryptorServerChannelListener : public IPC::Channel::Listener { | 73 class FFDecryptorServerChannelListener : public IPC::Listener { |
74 public: | 74 public: |
75 FFDecryptorServerChannelListener() | 75 FFDecryptorServerChannelListener() |
76 : got_result(false), sender_(NULL) {} | 76 : got_result(false), sender_(NULL) {} |
77 | 77 |
78 void SetSender(IPC::Message::Sender* sender) { | 78 void SetSender(IPC::Sender* sender) { |
79 sender_ = sender; | 79 sender_ = sender; |
80 } | 80 } |
81 | 81 |
82 void OnInitDecryptorResponse(bool result) { | 82 void OnInitDecryptorResponse(bool result) { |
83 DCHECK(!got_result); | 83 DCHECK(!got_result); |
84 result_bool = result; | 84 result_bool = result; |
85 got_result = true; | 85 got_result = true; |
86 MessageLoop::current()->Quit(); | 86 MessageLoop::current()->Quit(); |
87 } | 87 } |
88 | 88 |
(...skipping 25 matching lines...) Expand all Loading... |
114 MessageLoop::current()->Quit(); | 114 MessageLoop::current()->Quit(); |
115 } | 115 } |
116 | 116 |
117 // Results of IPC calls. | 117 // Results of IPC calls. |
118 string16 result_string; | 118 string16 result_string; |
119 bool result_bool; | 119 bool result_bool; |
120 // True if IPC call succeeded and data in above variables is valid. | 120 // True if IPC call succeeded and data in above variables is valid. |
121 bool got_result; | 121 bool got_result; |
122 | 122 |
123 private: | 123 private: |
124 IPC::Message::Sender* sender_; // weak | 124 IPC::Sender* sender_; // weak |
125 }; | 125 }; |
126 | 126 |
127 FFUnitTestDecryptorProxy::FFUnitTestDecryptorProxy() | 127 FFUnitTestDecryptorProxy::FFUnitTestDecryptorProxy() |
128 : child_process_(0) { | 128 : child_process_(0) { |
129 } | 129 } |
130 | 130 |
131 bool FFUnitTestDecryptorProxy::Setup(const FilePath& nss_path) { | 131 bool FFUnitTestDecryptorProxy::Setup(const FilePath& nss_path) { |
132 // Create a new message loop and spawn the child process. | 132 // Create a new message loop and spawn the child process. |
133 message_loop_.reset(new MessageLoopForIO()); | 133 message_loop_.reset(new MessageLoopForIO()); |
134 | 134 |
(...skipping 77 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
212 listener_->got_result = false; | 212 listener_->got_result = false; |
213 return listener_->result_string; | 213 return listener_->result_string; |
214 } | 214 } |
215 return string16(); | 215 return string16(); |
216 } | 216 } |
217 | 217 |
218 //---------------------------- Child Process ----------------------- | 218 //---------------------------- Child Process ----------------------- |
219 | 219 |
220 // Class to listen on the client side of the ipc channel, it calls through | 220 // Class to listen on the client side of the ipc channel, it calls through |
221 // to the NSSDecryptor and sends back a reply. | 221 // to the NSSDecryptor and sends back a reply. |
222 class FFDecryptorClientChannelListener : public IPC::Channel::Listener { | 222 class FFDecryptorClientChannelListener : public IPC::Listener { |
223 public: | 223 public: |
224 FFDecryptorClientChannelListener() | 224 FFDecryptorClientChannelListener() |
225 : sender_(NULL) {} | 225 : sender_(NULL) {} |
226 | 226 |
227 void SetSender(IPC::Message::Sender* sender) { | 227 void SetSender(IPC::Sender* sender) { |
228 sender_ = sender; | 228 sender_ = sender; |
229 } | 229 } |
230 | 230 |
231 void OnDecryptor_Init(FilePath dll_path, FilePath db_path) { | 231 void OnDecryptor_Init(FilePath dll_path, FilePath db_path) { |
232 bool ret = decryptor_.Init(dll_path, db_path); | 232 bool ret = decryptor_.Init(dll_path, db_path); |
233 sender_->Send(new Msg_Decryptor_InitReturnCode(ret)); | 233 sender_->Send(new Msg_Decryptor_InitReturnCode(ret)); |
234 } | 234 } |
235 | 235 |
236 void OnDecrypt(std::string crypt) { | 236 void OnDecrypt(std::string crypt) { |
237 string16 unencrypted_str = decryptor_.Decrypt(crypt); | 237 string16 unencrypted_str = decryptor_.Decrypt(crypt); |
(...skipping 14 matching lines...) Expand all Loading... |
252 IPC_END_MESSAGE_MAP() | 252 IPC_END_MESSAGE_MAP() |
253 return handled; | 253 return handled; |
254 } | 254 } |
255 | 255 |
256 virtual void OnChannelError() { | 256 virtual void OnChannelError() { |
257 MessageLoop::current()->Quit(); | 257 MessageLoop::current()->Quit(); |
258 } | 258 } |
259 | 259 |
260 private: | 260 private: |
261 NSSDecryptor decryptor_; | 261 NSSDecryptor decryptor_; |
262 IPC::Message::Sender* sender_; | 262 IPC::Sender* sender_; |
263 }; | 263 }; |
264 | 264 |
265 // Entry function in child process. | 265 // Entry function in child process. |
266 MULTIPROCESS_TEST_MAIN(NSSDecrypterChildProcess) { | 266 MULTIPROCESS_TEST_MAIN(NSSDecrypterChildProcess) { |
267 MessageLoopForIO main_message_loop; | 267 MessageLoopForIO main_message_loop; |
268 FFDecryptorClientChannelListener listener; | 268 FFDecryptorClientChannelListener listener; |
269 | 269 |
270 IPC::Channel channel(kTestChannelID, IPC::Channel::MODE_CLIENT, &listener); | 270 IPC::Channel channel(kTestChannelID, IPC::Channel::MODE_CLIENT, &listener); |
271 CHECK(channel.Connect()); | 271 CHECK(channel.Connect()); |
272 listener.SetSender(&channel); | 272 listener.SetSender(&channel); |
273 | 273 |
274 // run message loop | 274 // run message loop |
275 MessageLoop::current()->Run(); | 275 MessageLoop::current()->Run(); |
276 | 276 |
277 return 0; | 277 return 0; |
278 } | 278 } |
OLD | NEW |