diff --git a/utility/importer/brave_importer.cc b/utility/importer/brave_importer.cc index b24206a78561..960fab0ce1d7 100644 --- a/utility/importer/brave_importer.cc +++ b/utility/importer/brave_importer.cc @@ -41,11 +41,6 @@ #include "chrome/browser/password_manager/native_backend_kwallet_x.h" #include "chrome/browser/password_manager/password_store_x.h" #include "components/os_crypt/key_storage_util_linux.h" - -base::nix::DesktopEnvironment BraveImporter::GetDesktopEnvironment() { - std::unique_ptr env(base::Environment::Create()); - return base::nix::GetDesktopEnvironment(env.get()); -} #endif using base::Time; @@ -287,10 +282,6 @@ void BraveImporter::ImportBookmarks() { } } -double BraveImporter::chromeTimeToDouble(int64_t time) { - return ((time * 10 - 0x19DB1DED53E8000) / 10000) / 1000; -} - void BraveImporter::ImportPasswords() { #if !defined(USE_X11) base::FilePath passwords_path = @@ -380,61 +371,3 @@ void BraveImporter::ImportPasswords() { } #endif } - -void BraveImporter::ImportCookies() { - base::FilePath cookies_path = - source_path_.Append( - base::FilePath::StringType(FILE_PATH_LITERAL("Cookies"))); - if (!base::PathExists(cookies_path)) - return; - - sql::Connection db; - if (!db.Open(cookies_path)) - return; - - const char query[] = - "SELECT creation_utc, host_key, name, value, encrypted_value, path, " - "expires_utc, is_secure, is_httponly, firstpartyonly, last_access_utc, " - "has_expires, is_persistent, priority FROM cookies"; - - sql::Statement s(db.GetUniqueStatement(query)); - - net::CookieCryptoDelegate* delegate = - cookie_config::GetCookieCryptoDelegate(); -#if defined(OS_LINUX) - OSCrypt::SetConfig(std::make_unique()); -#endif - - std::vector cookies; - while (s.Step() && !cancelled()) { - std::string encrypted_value = s.ColumnString(4); - std::string value; - if (!encrypted_value.empty() && delegate) { - if (!delegate->DecryptString(encrypted_value, &value)) { - continue; - } - } else { - value = s.ColumnString(3); - } - - auto cookie = net::CanonicalCookie( - s.ColumnString(2), // name - value, // value - s.ColumnString(1), // domain - s.ColumnString(5), // path - Time::FromInternalValue(s.ColumnInt64(0)), // creation_utc - Time::FromInternalValue(s.ColumnInt64(6)), // expires_utc - Time::FromInternalValue(s.ColumnInt64(10)), // last_access_utc - s.ColumnBool(7), // secure - s.ColumnBool(8), // http_only - static_cast(s.ColumnInt(9)), // samesite - static_cast(s.ColumnInt(13))); // priority - if (cookie.IsCanonical()) { - cookies.push_back(cookie); - } - } - - if (!cookies.empty() && !cancelled()) { - bridge_->SetCookies(cookies); - } -} diff --git a/utility/importer/brave_importer.h b/utility/importer/brave_importer.h index 5fbb80727d44..e2f73a68e9b3 100644 --- a/utility/importer/brave_importer.h +++ b/utility/importer/brave_importer.h @@ -14,11 +14,11 @@ #include "base/macros.h" #include "base/nix/xdg_util.h" #include "base/values.h" +#include "brave/utility/importer/chrome_importer.h" #include "build/build_config.h" #include "chrome/common/importer/imported_bookmark_entry.h" -#include "chrome/utility/importer/importer.h" -class BraveImporter : public Importer { +class BraveImporter : public ChromeImporter { public: BraveImporter(); @@ -30,12 +30,9 @@ class BraveImporter : public Importer { private: ~BraveImporter() override; - static base::nix::DesktopEnvironment GetDesktopEnvironment(); - - void ImportHistory(); - void ImportBookmarks(); - void ImportPasswords(); - void ImportCookies(); + void ImportBookmarks() override; + void ImportHistory() override; + void ImportPasswords() override; void ParseBookmarks(std::vector* bookmarks); void RecursiveReadBookmarksFolder( @@ -48,10 +45,6 @@ class BraveImporter : public Importer { base::Value* bookmark_order_dict, std::vector* bookmarks); - double chromeTimeToDouble(int64_t time); - - base::FilePath source_path_; - DISALLOW_COPY_AND_ASSIGN(BraveImporter); }; diff --git a/utility/importer/chrome_importer.h b/utility/importer/chrome_importer.h index af7c37cbd9fd..21fe874d505a 100644 --- a/utility/importer/chrome_importer.h +++ b/utility/importer/chrome_importer.h @@ -38,16 +38,21 @@ class ChromeImporter : public Importer { uint16_t items, ImporterBridge* bridge) override; - private: + protected: ~ChromeImporter() override; static base::nix::DesktopEnvironment GetDesktopEnvironment(); - void ImportBookmarks(); - void ImportHistory(); - void ImportPasswords(); - void ImportCookies(); + virtual void ImportBookmarks(); + virtual void ImportHistory(); + virtual void ImportPasswords(); + virtual void ImportCookies(); + + double chromeTimeToDouble(int64_t time); + + base::FilePath source_path_; + private: // Multiple URLs can share the same favicon; this is a map // of URLs -> IconIDs that we load as a temporary step before // actually loading the icons. @@ -69,10 +74,6 @@ class ChromeImporter : public Importer { bool is_in_toolbar, std::vector* bookmarks); - double chromeTimeToDouble(int64_t time); - - base::FilePath source_path_; - DISALLOW_COPY_AND_ASSIGN(ChromeImporter); };