Skip to content

Commit

Permalink
Add import from Yandex browser
Browse files Browse the repository at this point in the history
  • Loading branch information
spylogsster committed Dec 21, 2022
1 parent 8f562a7 commit aa83abf
Show file tree
Hide file tree
Showing 14 changed files with 62 additions and 18 deletions.
5 changes: 3 additions & 2 deletions browser/importer/brave_external_process_importer_client.cc
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/* Copyright 2020 The Brave Authors. All rights reserved.
/* Copyright (c) 2020 The Brave Authors. All rights reserved.
* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this file,
* You can obtain one at http://mozilla.org/MPL/2.0/. */
* You can obtain one at https://mozilla.org/MPL/2.0/. */

#include "brave/browser/importer/brave_external_process_importer_client.h"

Expand All @@ -19,6 +19,7 @@ bool ShouldUseBraveImporter(importer::ImporterType type) {
case importer::TYPE_EDGE_CHROMIUM:
case importer::TYPE_VIVALDI:
case importer::TYPE_OPERA:
case importer::TYPE_YANDEX:
return true;
default:
return false;
Expand Down
2 changes: 0 additions & 2 deletions browser/importer/brave_external_process_importer_host.cc
Original file line number Diff line number Diff line change
Expand Up @@ -76,8 +76,6 @@ BraveExternalProcessImporterHost::~BraveExternalProcessImporterHost() = default;

#if BUILDFLAG(ENABLE_EXTENSIONS)
void BraveExternalProcessImporterHost::LaunchExtensionsImport() {
DCHECK_EQ(importer::TYPE_CHROME, source_profile_.importer_type);

const base::FilePath pref_file = source_profile_.source_path.AppendASCII(
kChromeExtensionsPreferencesFile);
base::ThreadPool::PostTaskAndReplyWithResult(
Expand Down
7 changes: 4 additions & 3 deletions browser/importer/brave_importer_p3a.cc
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/* Copyright 2019 The Brave Authors. All rights reserved.
/* Copyright (c) 2019 The Brave Authors. All rights reserved.
* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this file,
* You can obtain one at http://mozilla.org/MPL/2.0/. */
* You can obtain one at https://mozilla.org/MPL/2.0/. */

#include "brave/browser/importer/brave_importer_p3a.h"

Expand All @@ -22,7 +22,7 @@ enum class ImporterSource {
kMicrosoft, // includes IE, Legacy Edge, Chromium Edge
kOpera,
kSafari,
kOther, // includes Vivaldi and can include others
kOther, // includes Vivaldi, Yandex and can include others
kSize
};
} // namespace
Expand Down Expand Up @@ -59,6 +59,7 @@ void RecordImporterP3A(importer::ImporterType type) {
metric = ImporterSource::kMicrosoft;
break;
case importer::TYPE_VIVALDI:
case importer::TYPE_YANDEX:
metric = ImporterSource::kOther;
break;
case importer::TYPE_OPERA:
Expand Down
4 changes: 2 additions & 2 deletions browser/ui/webui/settings/brave_import_data_handler.cc
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@
#include <string>
#include <unordered_map>

#include "brave/browser/importer/brave_external_process_importer_host.h"
#include "brave/browser/ui/webui/settings/import_feature.h"
#include "chrome/browser/importer/external_process_importer_host.h"
#include "chrome/browser/importer/profile_writer.h"
#include "chrome/browser/profiles/profile.h"
#include "content/public/browser/browser_task_traits.h"
Expand Down Expand Up @@ -90,7 +90,7 @@ void BraveImportDataHandler::StartImportImpl(
import_observers_.erase(source_profile.source_path);

// Using weak pointers because it destroys itself when finshed.
auto* importer_host = new ExternalProcessImporterHost();
auto* importer_host = new BraveExternalProcessImporterHost();
import_observers_[source_profile.source_path] =
std::make_unique<BraveImporterObserver>(
importer_host, source_profile, imported_items,
Expand Down
10 changes: 8 additions & 2 deletions chromium_src/chrome/browser/importer/importer_list.cc
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/* Copyright 2019 The Brave Authors. All rights reserved.
/* Copyright (c) 2019 The Brave Authors. All rights reserved.
* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this file,
* You can obtain one at http://mozilla.org/MPL/2.0/. */
* You can obtain one at https://mozilla.org/MPL/2.0/. */

#include "chrome/browser/importer/importer_list.h"
#include "base/files/file_path.h"
Expand Down Expand Up @@ -95,6 +95,12 @@ void DetectChromeProfiles(std::vector<importer::SourceProfile>* profiles) {
base::FilePath::StringType(FILE_PATH_LITERAL("Local State")))),
GetOperaUserDataFolder(), "Opera ", importer::TYPE_OPERA);

AddChromeToProfiles(
profiles,
GetChromeSourceProfiles(GetYandexUserDataFolder().Append(
base::FilePath::StringType(FILE_PATH_LITERAL("Local State")))),
GetYandexUserDataFolder(), "Yandex ", importer::TYPE_YANDEX);

#if BUILDFLAG(IS_LINUX)
// Installed via snap Opera has different profile path.
AddChromeToProfiles(
Expand Down
5 changes: 3 additions & 2 deletions chromium_src/chrome/browser/importer/importer_uma.cc
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/* Copyright 2022 The Brave Authors. All rights reserved.
/* Copyright (c) 2022 The Brave Authors. All rights reserved.
* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this file,
* You can obtain one at http://mozilla.org/MPL/2.0/. */
* You can obtain one at https://mozilla.org/MPL/2.0/. */

#include "chrome/browser/importer/importer_uma.h"

Expand All @@ -10,6 +10,7 @@
case TYPE_EDGE_CHROMIUM: \
case TYPE_VIVALDI: \
case TYPE_OPERA: \
case TYPE_YANDEX: \
break; \
case TYPE_FIREFOX
#include "src/chrome/browser/importer/importer_uma.cc"
2 changes: 1 addition & 1 deletion chromium_src/chrome/common/importer/importer_type.h
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@

#define TYPE_FIREFOX \
TYPE_CHROME = 1, TYPE_EDGE_CHROMIUM = 10, TYPE_VIVALDI = 11, \
TYPE_OPERA = 12, TYPE_FIREFOX
TYPE_OPERA = 12, TYPE_YANDEX = 13, TYPE_FIREFOX
#include "src/chrome/common/importer/importer_type.h"
#undef TYPE_FIREFOX

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,9 @@
#include "chrome/common/importer/importer_type.h"

#if !BUILDFLAG(IS_WIN)
#define TYPE_BOOKMARKS_FILE TYPE_OPERA
#define TYPE_BOOKMARKS_FILE TYPE_YANDEX
#else
#define TYPE_EDGE TYPE_OPERA
#define TYPE_EDGE TYPE_YANDEX
#endif
#include "src/chrome/common/importer/profile_import_process_param_traits_macros.h"
#if !BUILDFLAG(IS_WIN)
Expand Down
3 changes: 3 additions & 0 deletions chromium_src/components/os_crypt/keychain_password_mac.mm
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,9 @@
if (command_line->HasSwitch("import-edge")) {
service_name = std::string("Microsoft Edge Safe Storage");
account_name = std::string("Microsoft Edge");
} else if (command_line->HasSwitch("import-yandex")) {
service_name = std::string("Yandex Safe Storage");
account_name = std::string("Yandex");
} else if (command_line->HasSwitch("import-chrome")) {
service_name = std::string("Chrome Safe Storage");
account_name = std::string("Chrome");
Expand Down
1 change: 1 addition & 0 deletions common/importer/chrome_importer_utils.h
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ base::FilePath GetEdgeUserDataFolder();

base::FilePath GetVivaldiUserDataFolder();
base::FilePath GetOperaUserDataFolder();
base::FilePath GetYandexUserDataFolder();

#if BUILDFLAG(IS_LINUX)
base::FilePath GetOperaSnapUserDataFolder();
Expand Down
11 changes: 11 additions & 0 deletions common/importer/chrome_importer_utils_linux.cc
Original file line number Diff line number Diff line change
Expand Up @@ -100,3 +100,14 @@ base::FilePath GetOperaSnapUserDataFolder() {

return result;
}

base::FilePath GetYandexUserDataFolder() {
base::FilePath result;
if (!base::PathService::Get(base::DIR_HOME, &result))
return base::FilePath();

result = result.Append(".config");
result = result.Append("yandex-browser");

return result;
}
10 changes: 8 additions & 2 deletions common/importer/chrome_importer_utils_mac.mm
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
/* This Source Code Form is subject to the terms of the Mozilla Public
/* Copyright (c) 2018 The Brave Authors. All rights reserved.
* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this file,
* You can obtain one at http://mozilla.org/MPL/2.0/. */
* You can obtain one at https://mozilla.org/MPL/2.0/. */

#include <Cocoa/Cocoa.h>
#include <sys/param.h>
Expand Down Expand Up @@ -49,3 +50,8 @@
base::FilePath result = base::mac::GetUserLibraryPath();
return result.Append("Application Support/com.operasoftware.Opera");
}

base::FilePath GetYandexUserDataFolder() {
base::FilePath result = base::mac::GetUserLibraryPath();
return result.Append("Application Support/Yandex/YandexBrowser");
}
12 changes: 12 additions & 0 deletions common/importer/chrome_importer_utils_win.cc
Original file line number Diff line number Diff line change
Expand Up @@ -99,3 +99,15 @@ base::FilePath GetOperaUserDataFolder() {

return result;
}

base::FilePath GetYandexUserDataFolder() {
base::FilePath result;
if (!base::PathService::Get(base::DIR_LOCAL_APP_DATA, &result))
return base::FilePath();

result = result.AppendASCII("Yandex");
result = result.AppendASCII("YandexBrowser");
result = result.AppendASCII("User Data");

return result;
}
4 changes: 4 additions & 0 deletions utility/importer/brave_profile_import_impl.cc
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,8 @@ scoped_refptr<Importer> CreateImporterByType(importer::ImporterType type) {
return new ChromeImporter();
case importer::TYPE_OPERA:
return new ChromeImporter();
case importer::TYPE_YANDEX:
return new ChromeImporter();
default:
NOTREACHED();
return nullptr;
Expand Down Expand Up @@ -71,6 +73,8 @@ void BraveProfileImportImpl::StartImport(
command_line->AppendSwitch("import-chromium");
} else if (source_profile.importer_type == importer::TYPE_OPERA) {
command_line->AppendSwitch("import-opera");
} else if (source_profile.importer_type == importer::TYPE_YANDEX) {
command_line->AppendSwitch("import-yandex");
} else if (source_profile.importer_type == importer::TYPE_VIVALDI) {
command_line->AppendSwitch("import-vivaldi");
}
Expand Down

0 comments on commit aa83abf

Please sign in to comment.