diff options
| author | evan@chromium.org <evan@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2011-01-28 18:27:17 +0000 | 
|---|---|---|
| committer | evan@chromium.org <evan@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2011-01-28 18:27:17 +0000 | 
| commit | 91243c39265d425a01aae6668fe7896598f566e0 (patch) | |
| tree | 555e39e750f669747a292fdc1d9c647a26a4a446 | |
| parent | 59bafea4d9c8d5b82f36a75254585a519833c9a2 (diff) | |
| download | chromium_src-91243c39265d425a01aae6668fe7896598f566e0.zip chromium_src-91243c39265d425a01aae6668fe7896598f566e0.tar.gz chromium_src-91243c39265d425a01aae6668fe7896598f566e0.tar.bz2 | |
importer: push more FilePath around to reduce conversions
BUG=69467
Review URL: http://codereview.chromium.org/6299021
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@72980 0039d316-1c4b-4281-b951-d872f2087c98
| -rw-r--r-- | chrome/browser/importer/firefox2_importer.cc | 6 | ||||
| -rw-r--r-- | chrome/browser/importer/firefox3_importer.cc | 18 | ||||
| -rw-r--r-- | chrome/browser/importer/firefox_importer_unittest.cc | 10 | ||||
| -rw-r--r-- | chrome/browser/importer/firefox_importer_unittest_messages_internal.h | 4 | ||||
| -rw-r--r-- | chrome/browser/importer/firefox_importer_unittest_utils.h | 10 | ||||
| -rw-r--r-- | chrome/browser/importer/firefox_importer_unittest_utils_mac.cc | 13 | ||||
| -rw-r--r-- | chrome/browser/importer/ie_importer.cc | 2 | ||||
| -rw-r--r-- | chrome/browser/importer/nss_decryptor_mac.h | 6 | ||||
| -rw-r--r-- | chrome/browser/importer/nss_decryptor_mac.mm | 13 | ||||
| -rw-r--r-- | chrome/browser/importer/nss_decryptor_null.h | 3 | ||||
| -rw-r--r-- | chrome/browser/importer/nss_decryptor_system_nss.cc | 6 | ||||
| -rw-r--r-- | chrome/browser/importer/nss_decryptor_system_nss.h | 3 | ||||
| -rw-r--r-- | chrome/browser/importer/nss_decryptor_win.cc | 11 | ||||
| -rw-r--r-- | chrome/browser/importer/nss_decryptor_win.h | 6 | 
14 files changed, 43 insertions, 68 deletions
| diff --git a/chrome/browser/importer/firefox2_importer.cc b/chrome/browser/importer/firefox2_importer.cc index 9a73f28..2ecccb0 100644 --- a/chrome/browser/importer/firefox2_importer.cc +++ b/chrome/browser/importer/firefox2_importer.cc @@ -335,10 +335,8 @@ void Firefox2Importer::ImportBookmarks() {  void Firefox2Importer::ImportPasswords() {    // Initializes NSS3.    NSSDecryptor decryptor; -  if (!decryptor.Init(source_path_.ToWStringHack(), -                      source_path_.ToWStringHack()) && -      !decryptor.Init(app_path_.ToWStringHack(), -                      source_path_.ToWStringHack())) { +  if (!decryptor.Init(source_path_, source_path_) && +      !decryptor.Init(app_path_, source_path_)) {      return;    } diff --git a/chrome/browser/importer/firefox3_importer.cc b/chrome/browser/importer/firefox3_importer.cc index 6ec18cc..38317be 100644 --- a/chrome/browser/importer/firefox3_importer.cc +++ b/chrome/browser/importer/firefox3_importer.cc @@ -114,10 +114,8 @@ void Firefox3Importer::ImportHistory() {      return;    sqlite3* sqlite; -  if (sqlite3_open(WideToUTF8(file.ToWStringHack()).c_str(), -                   &sqlite) != SQLITE_OK) { +  if (sqlite_utils::OpenSqliteDb(file, &sqlite) != SQLITE_OK)      return; -  }    sqlite_utils::scoped_sqlite_db_ptr db(sqlite);    SQLStatement s; @@ -163,10 +161,8 @@ void Firefox3Importer::ImportBookmarks() {      return;    sqlite3* sqlite; -  if (sqlite3_open(WideToUTF8(file.ToWStringHack()).c_str(), -                   &sqlite) != SQLITE_OK) { +  if (sqlite_utils::OpenSqliteDb(file, &sqlite) != SQLITE_OK)      return; -  }    sqlite_utils::scoped_sqlite_db_ptr db(sqlite);    // Get the bookmark folders that we are interested in. @@ -319,10 +315,8 @@ void Firefox3Importer::ImportBookmarks() {  void Firefox3Importer::ImportPasswords() {    // Initializes NSS3.    NSSDecryptor decryptor; -  if (!decryptor.Init(source_path_.ToWStringHack(), -                      source_path_.ToWStringHack()) && -      !decryptor.Init(app_path_.ToWStringHack(), -                      source_path_.ToWStringHack())) { +  if (!decryptor.Init(source_path_, source_path_) && +      !decryptor.Init(app_path_, source_path_)) {      return;    } @@ -375,10 +369,8 @@ void Firefox3Importer::GetSearchEnginesXMLFiles(      return;    sqlite3* sqlite; -  if (sqlite3_open(WideToUTF8(file.ToWStringHack()).c_str(), -                   &sqlite) != SQLITE_OK) { +  if (sqlite_utils::OpenSqliteDb(file, &sqlite) != SQLITE_OK)      return; -  }    sqlite_utils::scoped_sqlite_db_ptr db(sqlite);    SQLStatement s; diff --git a/chrome/browser/importer/firefox_importer_unittest.cc b/chrome/browser/importer/firefox_importer_unittest.cc index dc6d44d..12e75f4 100644 --- a/chrome/browser/importer/firefox_importer_unittest.cc +++ b/chrome/browser/importer/firefox_importer_unittest.cc @@ -33,10 +33,9 @@ TEST(FirefoxImporterTest, Firefox2NSS3Decryptor) {    db_path = db_path.AppendASCII("firefox2_profile");    FFUnitTestDecryptorProxy decryptor_proxy; -  ASSERT_TRUE(decryptor_proxy.Setup(nss_path.ToWStringHack())); +  ASSERT_TRUE(decryptor_proxy.Setup(nss_path)); -  EXPECT_TRUE(decryptor_proxy.DecryptorInit(nss_path.ToWStringHack(), -                                            db_path.ToWStringHack())); +  EXPECT_TRUE(decryptor_proxy.DecryptorInit(nss_path, db_path));    EXPECT_EQ(ASCIIToUTF16("hello"),        decryptor_proxy.Decrypt("MDIEEPgAAAAAAAAAAAAAAAAAAAEwFAYIKoZIhvcNAwcECBJ"                                "M63MpT9rtBAjMCm7qo/EhlA==")); @@ -59,10 +58,9 @@ TEST(FirefoxImporterTest, Firefox3NSS3Decryptor) {    db_path = db_path.AppendASCII("firefox3_profile");    FFUnitTestDecryptorProxy decryptor_proxy; -  ASSERT_TRUE(decryptor_proxy.Setup(nss_path.ToWStringHack())); +  ASSERT_TRUE(decryptor_proxy.Setup(nss_path)); -  EXPECT_TRUE(decryptor_proxy.DecryptorInit(nss_path.ToWStringHack(), -                                            db_path.ToWStringHack())); +  EXPECT_TRUE(decryptor_proxy.DecryptorInit(nss_path, db_path));    EXPECT_EQ(ASCIIToUTF16("hello"),        decryptor_proxy.Decrypt("MDIEEPgAAAAAAAAAAAAAAAAAAAEwFAYIKoZIhvcNAwcECKa"                                "jtRg4qFSHBAhv9luFkXgDJA==")); diff --git a/chrome/browser/importer/firefox_importer_unittest_messages_internal.h b/chrome/browser/importer/firefox_importer_unittest_messages_internal.h index fd70f7f..b0e25c2 100644 --- a/chrome/browser/importer/firefox_importer_unittest_messages_internal.h +++ b/chrome/browser/importer/firefox_importer_unittest_messages_internal.h @@ -11,8 +11,8 @@  // Server->Child: Initialize the decrytor with the following paramters.  IPC_MESSAGE_CONTROL2(Msg_Decryptor_Init, -                     std::wstring /* dll_path */, -                     std::wstring /* db_path */) +                     FilePath /* dll_path */, +                     FilePath /* db_path */)  // Child->Server: Return paramter from init call.  IPC_MESSAGE_CONTROL1(Msg_Decryptor_InitReturnCode,                       bool /* ret */) diff --git a/chrome/browser/importer/firefox_importer_unittest_utils.h b/chrome/browser/importer/firefox_importer_unittest_utils.h index 9a1df8d..9001f9a 100644 --- a/chrome/browser/importer/firefox_importer_unittest_utils.h +++ b/chrome/browser/importer/firefox_importer_unittest_utils.h @@ -35,10 +35,10 @@ class FFUnitTestDecryptorProxy {    // Initialize a decryptor, returns true if the object was    // constructed successfully. -  bool Setup(const std::wstring& nss_path); +  bool Setup(const FilePath& nss_path);    // This match the parallel functions in NSSDecryptor. -  bool DecryptorInit(const std::wstring& dll_path, const std::wstring& db_path); +  bool DecryptorInit(const FilePath& dll_path, const FilePath& db_path);    string16 Decrypt(const std::string& crypt);   private: @@ -68,12 +68,12 @@ FFUnitTestDecryptorProxy::FFUnitTestDecryptorProxy() {  FFUnitTestDecryptorProxy::~FFUnitTestDecryptorProxy() {  } -bool FFUnitTestDecryptorProxy::Setup(const std::wstring& /* nss_path */) { +bool FFUnitTestDecryptorProxy::Setup(const FilePath& nss_path) {    return true;  } -bool FFUnitTestDecryptorProxy::DecryptorInit(const std::wstring& dll_path, -    const std::wstring& db_path) { +bool FFUnitTestDecryptorProxy::DecryptorInit(const FilePath& dll_path, +                                             const FilePath& db_path) {    return decryptor_.Init(dll_path, db_path);  } diff --git a/chrome/browser/importer/firefox_importer_unittest_utils_mac.cc b/chrome/browser/importer/firefox_importer_unittest_utils_mac.cc index f27a53c..dbaf19a 100644 --- a/chrome/browser/importer/firefox_importer_unittest_utils_mac.cc +++ b/chrome/browser/importer/firefox_importer_unittest_utils_mac.cc @@ -29,19 +29,18 @@ const char kTestChannelID[] = "T1";  // |channel| - IPC Channel to use for communication.  // |handle| - On return, the process handle to use to communicate with the  // child. -bool LaunchNSSDecrypterChildProcess(const std::wstring& nss_path, +bool LaunchNSSDecrypterChildProcess(const FilePath& nss_path,      const IPC::Channel& channel, base::ProcessHandle* handle) {    CommandLine cl(*CommandLine::ForCurrentProcess());    cl.AppendSwitchASCII(switches::kTestChildProcess, "NSSDecrypterChildProcess"); -  FilePath ff_dylib_dir = FilePath::FromWStringHack(nss_path);    // Set env variable needed for FF encryption libs to load.    // See "chrome/browser/importer/nss_decryptor_mac.mm" for an explanation of    // why we need this.    base::environment_vector env;    std::pair<std::string, std::string> dyld_override;    dyld_override.first = "DYLD_FALLBACK_LIBRARY_PATH"; -  dyld_override.second = ff_dylib_dir.value(); +  dyld_override.second = nss_path.value();    env.push_back(dyld_override);    base::file_handle_mapping_vector fds_to_map; @@ -123,7 +122,7 @@ FFUnitTestDecryptorProxy::FFUnitTestDecryptorProxy()      : child_process_(0) {  } -bool FFUnitTestDecryptorProxy::Setup(const std::wstring& nss_path) { +bool FFUnitTestDecryptorProxy::Setup(const FilePath& nss_path) {    // Create a new message loop and spawn the child process.    message_loop_.reset(new MessageLoopForIO()); @@ -185,8 +184,8 @@ bool FFUnitTestDecryptorProxy::WaitForClientResponse() {    return ret;  } -bool FFUnitTestDecryptorProxy::DecryptorInit(const std::wstring& dll_path, -    const std::wstring& db_path) { +bool FFUnitTestDecryptorProxy::DecryptorInit(const FilePath& dll_path, +                                             const FilePath& db_path) {    channel_->Send(new Msg_Decryptor_Init(dll_path, db_path));    bool ok = WaitForClientResponse();    if (ok && listener_->got_result) { @@ -219,7 +218,7 @@ class FFDecryptorClientChannelListener : public IPC::Channel::Listener {      sender_ = sender;    } -  void OnDecryptor_Init(std::wstring dll_path, std::wstring db_path) { +  void OnDecryptor_Init(FilePath dll_path, FilePath db_path) {      bool ret = decryptor_.Init(dll_path, db_path);      sender_->Send(new Msg_Decryptor_InitReturnCode(ret));    } diff --git a/chrome/browser/importer/ie_importer.cc b/chrome/browser/importer/ie_importer.cc index 1d1a95b..d10453c0 100644 --- a/chrome/browser/importer/ie_importer.cc +++ b/chrome/browser/importer/ie_importer.cc @@ -75,7 +75,7 @@ void IEImporter::StartImport(const ProfileInfo& profile_info,                               uint16 items,                               ImporterBridge* bridge) {    bridge_ = bridge; -  source_path_ = profile_info.source_path.ToWStringHack(); +  source_path_ = profile_info.source_path.value();    bridge_->NotifyStarted(); diff --git a/chrome/browser/importer/nss_decryptor_mac.h b/chrome/browser/importer/nss_decryptor_mac.h index 5e0eeff..e88fd11 100644 --- a/chrome/browser/importer/nss_decryptor_mac.h +++ b/chrome/browser/importer/nss_decryptor_mac.h @@ -120,8 +120,7 @@ class NSSDecryptor {    ~NSSDecryptor();    // Initializes NSS if it hasn't already been initialized. -  bool Init(const std::wstring& /* dll_path */, -            const std::wstring& /* db_path */); +  bool Init(const FilePath& dll_path, const FilePath& db_path);    // Decrypts Firefox stored passwords. Before using this method,    // make sure Init() returns true. @@ -152,9 +151,6 @@ class NSSDecryptor {    PK11SDRDecryptFunc PK11SDR_Decrypt;    SECITEMFreeItemFunc SECITEM_FreeItem; -  // Libraries necessary for decrypting the passwords. -  static const wchar_t kNSS3Library[]; -    // True if NSS_Init() has been called    bool is_nss_initialized_; diff --git a/chrome/browser/importer/nss_decryptor_mac.mm b/chrome/browser/importer/nss_decryptor_mac.mm index 988ab56..d9d3d7a 100644 --- a/chrome/browser/importer/nss_decryptor_mac.mm +++ b/chrome/browser/importer/nss_decryptor_mac.mm @@ -13,25 +13,20 @@  #include "chrome/browser/importer/nss_decryptor_mac.h"  #include "chrome/browser/importer/firefox_importer_utils.h" -// static -const wchar_t NSSDecryptor::kNSS3Library[] = L"libnss3.dylib"; -  // Important!! : On OS X the nss3 libraries are compiled with depedencies  // on one another, referenced using dyld's @executable_path directive.  // To make a long story short in order to get the libraries to load, dyld's  // fallback path needs to be set to the directory containing the libraries.  // To do so, the process this function runs in must have the  // DYLD_FALLBACK_LIBRARY_PATH set on startup to said directory. -bool NSSDecryptor::Init(const std::wstring& dll_path, -                        const std::wstring& db_path) { +bool NSSDecryptor::Init(const FilePath& dll_path, const FilePath& db_path) {    if (getenv("DYLD_FALLBACK_LIBRARY_PATH") == NULL) {      LOG(ERROR) << "DYLD_FALLBACK_LIBRARY_PATH variable not set";      return false;    } -  FilePath dylib_file_path = FilePath::FromWStringHack(dll_path); -  FilePath nss3_path = dylib_file_path.Append("libnss3.dylib"); +  FilePath nss3_path = dll_path.Append("libnss3.dylib"); -  void *nss_3_lib = dlopen(nss3_path.value().c_str(), RTLD_LAZY); +  void* nss_3_lib = dlopen(nss3_path.value().c_str(), RTLD_LAZY);    if (!nss_3_lib) {      LOG(ERROR) << "Failed to load nss3 lib" << dlerror();      return false; @@ -56,7 +51,7 @@ bool NSSDecryptor::Init(const std::wstring& dll_path,      return false;    } -  SECStatus result = NSS_Init(base::SysWideToNativeMB(db_path).c_str()); +  SECStatus result = NSS_Init(db_path.value().c_str());    if (result != SECSuccess) {      LOG(ERROR) << "NSS_Init Failed returned: " << result; diff --git a/chrome/browser/importer/nss_decryptor_null.h b/chrome/browser/importer/nss_decryptor_null.h index 155f1e0..af725c1 100644 --- a/chrome/browser/importer/nss_decryptor_null.h +++ b/chrome/browser/importer/nss_decryptor_null.h @@ -23,8 +23,7 @@ struct PasswordForm;  class NSSDecryptor {   public:    NSSDecryptor() {} -  bool Init(const std::wstring& /* dll_path */, -            const std::wstring& db_path) { return false; } +  bool Init(const FilePath& dll_path, const FilePath& db_path) { return false; }    string16 Decrypt(const std::string& crypt) const { return string16(); }    void ParseSignons(const std::string& content,                      std::vector<webkit_glue::PasswordForm>* forms) {} diff --git a/chrome/browser/importer/nss_decryptor_system_nss.cc b/chrome/browser/importer/nss_decryptor_system_nss.cc index 06be5da..58ce34e 100644 --- a/chrome/browser/importer/nss_decryptor_system_nss.cc +++ b/chrome/browser/importer/nss_decryptor_system_nss.cc @@ -8,6 +8,7 @@  #include <pk11sdr.h>  #include "base/basictypes.h" +#include "base/file_path.h"  #include "base/nss_util.h"  #include "base/string_util.h"  #include "base/sys_string_conversions.h" @@ -23,13 +24,12 @@ NSSDecryptor::~NSSDecryptor() {    }  } -bool NSSDecryptor::Init(const std::wstring& /* dll_path */, -                        const std::wstring& db_path) { +bool NSSDecryptor::Init(const FilePath& dll_path, const FilePath& db_path) {    base::EnsureNSSInit();    is_nss_initialized_ = true;    const std::string modspec =        StringPrintf("configDir='%s' tokenDescription='Firefox NSS database' " -                   "flags=readOnly", base::SysWideToNativeMB(db_path).c_str()); +                   "flags=readOnly", db_path.value().c_str());    db_slot_ = SECMOD_OpenUserDB(modspec.c_str());    return db_slot_ != NULL;  } diff --git a/chrome/browser/importer/nss_decryptor_system_nss.h b/chrome/browser/importer/nss_decryptor_system_nss.h index c08496d..b4087d9 100644 --- a/chrome/browser/importer/nss_decryptor_system_nss.h +++ b/chrome/browser/importer/nss_decryptor_system_nss.h @@ -26,8 +26,7 @@ class NSSDecryptor {    ~NSSDecryptor();    // Initializes NSS if it hasn't already been initialized. -  bool Init(const std::wstring& /* dll_path */, -            const std::wstring& db_path); +  bool Init(const FilePath& dll_path, const FilePath& db_path);    // Decrypts Firefox stored passwords. Before using this method,    // make sure Init() returns true. diff --git a/chrome/browser/importer/nss_decryptor_win.cc b/chrome/browser/importer/nss_decryptor_win.cc index a7b5592..bb1b2d4 100644 --- a/chrome/browser/importer/nss_decryptor_win.cc +++ b/chrome/browser/importer/nss_decryptor_win.cc @@ -37,8 +37,7 @@ const wchar_t NSSDecryptor::kSoftokn3Library[] = L"softokn3.dll";  const wchar_t NSSDecryptor::kPLDS4Library[] = L"plds4.dll";  const wchar_t NSSDecryptor::kNSPR4Library[] = L"nspr4.dll"; -bool NSSDecryptor::Init(const std::wstring& dll_path, -                        const std::wstring& db_path) { +bool NSSDecryptor::Init(const FilePath& dll_path, const FilePath& db_path) {    // We call SetDllDirectory to work around a Purify bug (GetModuleHandle    // fails inside Purify under certain conditions).  SetDllDirectory only    // exists on Windows XP SP1 or later, so we look up its address at run time. @@ -50,7 +49,7 @@ bool NSSDecryptor::Init(const std::wstring& dll_path,    SetDllDirectoryCaller caller;    if (set_dll_directory != NULL) { -    if (!set_dll_directory(dll_path.c_str())) +    if (!set_dll_directory(dll_path.value().c_str()))        return false;      caller.set_func(set_dll_directory);      nss3_dll_ = LoadLibrary(kNSS3Library); @@ -60,7 +59,7 @@ bool NSSDecryptor::Init(const std::wstring& dll_path,      // Fall back on LoadLibraryEx if SetDllDirectory isn't available.  We      // actually prefer this method because it doesn't change the DLL search      // path, which is a process-wide property. -    FilePath path = FilePath(dll_path).Append(kNSS3Library); +    FilePath path = dll_path.Append(kNSS3Library);      nss3_dll_ = LoadLibraryEx(path.value().c_str(), NULL,                                LOAD_WITH_ALTERED_SEARCH_PATH);      if (nss3_dll_ == NULL) @@ -103,7 +102,7 @@ NSSDecryptor::~NSSDecryptor() {    Free();  } -bool NSSDecryptor::InitNSS(const std::wstring& db_path, +bool NSSDecryptor::InitNSS(const FilePath& db_path,                             base::NativeLibrary plds4_dll,                             base::NativeLibrary nspr4_dll) {    // NSPR DLLs are already loaded now. @@ -142,7 +141,7 @@ bool NSSDecryptor::InitNSS(const std::wstring& db_path,      return false;    } -  SECStatus result = NSS_Init(base::SysWideToNativeMB(db_path).c_str()); +  SECStatus result = NSS_Init(base::SysWideToNativeMB(db_path.value()).c_str());    if (result != SECSuccess) {      Free();      return false; diff --git a/chrome/browser/importer/nss_decryptor_win.h b/chrome/browser/importer/nss_decryptor_win.h index 0436323..23e7b1a 100644 --- a/chrome/browser/importer/nss_decryptor_win.h +++ b/chrome/browser/importer/nss_decryptor_win.h @@ -117,7 +117,7 @@ class NSSDecryptor {    // Loads NSS3 library and returns true if successful.    // |dll_path| indicates the location of NSS3 DLL files, and |db_path|    // is the location of the database file that stores the keys. -  bool Init(const std::wstring& dll_path, const std::wstring& db_path); +  bool Init(const FilePath& dll_path, const FilePath& db_path);    // Frees the libraries.    void Free(); @@ -139,8 +139,8 @@ class NSSDecryptor {                             std::vector<webkit_glue::PasswordForm>* forms);   private: -  // Performs tasks common across all platforms to initialize NSS. -  bool InitNSS(const std::wstring& db_path, +  // Call NSS initialization funcs. +  bool InitNSS(const FilePath& db_path,                 base::NativeLibrary plds4_dll,                 base::NativeLibrary nspr4_dll); | 
