Chromium Code Reviews| OLD | NEW |
|---|---|
| (Empty) | |
| 1 // Copyright (c) 2009 The Chromium Authors. All rights reserved. | |
| 2 // Use of this source code is governed by a BSD-style license that can be | |
| 3 // found in the LICENSE file. | |
| 4 | |
| 5 #ifndef CHROME_BROWSER_IMPORTER_UNITTEST_UTILS_H_ | |
|
John Grabowski
2009/08/21 01:13:18
CHROME_BROWSER_IMPORTER_UNITTEST_UTILS_H_ -->
CHRO
| |
| 6 #define CHROME_BROWSER_IMPORTER_UNITTEST_UTILS_H_ | |
| 7 | |
| 8 #include "base/basictypes.h" | |
| 9 #include "base/process_util.h" | |
| 10 #include "base/scoped_ptr.h" | |
| 11 #include "chrome/browser/importer/nss_decryptor.h" | |
| 12 | |
| 13 class FFDecryptorServerChannelListener; | |
| 14 namespace IPC { | |
| 15 class Channel; | |
| 16 } // namespace IPC | |
| 17 class MessageLoopForIO; | |
| 18 | |
| 19 // On OS X NSSDecryptor needs to run in a separate process, to allow us to use | |
|
John Grabowski
2009/08/21 01:13:18
More comments would be nice. E.g. brief example o
| |
| 20 // the same uni test on all platforms we use a proxy class which spawns a | |
|
John Grabowski
2009/08/21 01:13:18
uni test --> unit test (and run on sentence)
| |
| 21 // child process to do decryption on OS X, and calls through directly | |
| 22 // to NSSDecryptor on other platforms. | |
| 23 class FFUnitTestDecryptorProxy { | |
| 24 public: | |
| 25 // Initialize a decryptor, on return |success| is true if the object was | |
| 26 // constructed successfully. | |
| 27 FFUnitTestDecryptorProxy(std::wstring &nss_path, bool* success); | |
|
John Grabowski
2009/08/21 01:13:18
We don't use C++ exceptions so constructors in gen
| |
| 28 virtual ~FFUnitTestDecryptorProxy(); | |
| 29 | |
| 30 // This match the parallel functions in NSSDecryptor. | |
| 31 bool Init(const std::wstring& dll_path, const std::wstring& db_path); | |
| 32 std::wstring Decrypt(const std::string& crypt); | |
| 33 | |
| 34 private: | |
| 35 #if defined(OS_MACOSX) | |
| 36 // Blocks until either a timeout is reached, or until the client process | |
| 37 // responds to an IPC message. | |
| 38 // Returns true if a reply was recieved successfully and false if the | |
| 39 // the operation timed out. | |
| 40 bool WaitForClientResponse(); | |
| 41 | |
| 42 base::ProcessHandle child_process_; | |
| 43 scoped_ptr<IPC::Channel> channel_; | |
| 44 scoped_ptr<FFDecryptorServerChannelListener> listener_; | |
| 45 scoped_ptr<MessageLoopForIO> message_loop_; | |
| 46 #else | |
| 47 NSSDecrypter decryptor_; | |
| 48 #endif // !OS_MACOSX | |
| 49 DISALLOW_COPY_AND_ASSIGN(FFUnitTestDecryptorProxy); | |
| 50 }; | |
| 51 | |
| 52 // On Non-OSX platforms FFUnitTestDecryptorProxy simply calls through to | |
| 53 // NSSDecryptor. | |
| 54 #if !defined(OS_MACOSX) | |
| 55 FFUnitTestDecryptorProxy::FFUnitTestDecryptorProxy(std::wstring& /* nss_path */, | |
| 56 bool* success) { | |
| 57 *success = true; | |
| 58 } | |
| 59 | |
| 60 FFUnitTestDecryptorProxy::~FFUnitTestDecryptorProxy() { | |
| 61 } | |
| 62 | |
| 63 bool FFUnitTestDecryptorProxy::Init(const std::wstring& dll_path, | |
| 64 const std::wstring& db_path) { | |
| 65 return decryptor_.Init(dll_path, db_path); | |
| 66 } | |
| 67 | |
| 68 std::wstring FFUnitTestDecryptorProxy::Decrypt(const std::string& crypt) { | |
| 69 return decryptor_.Decrypt(crypt); | |
| 70 } | |
| 71 #endif // !OS_MACOSX | |
| 72 | |
| 73 #endif // CHROME_BROWSER_IMPORTER_UNITTEST_UTILS_H_ | |
| OLD | NEW |