diff --git a/browser/importer/brave_external_process_importer_client.cc b/browser/importer/brave_external_process_importer_client.cc index 07c2f4d06cb5..a0375276def3 100644 --- a/browser/importer/brave_external_process_importer_client.cc +++ b/browser/importer/brave_external_process_importer_client.cc @@ -14,9 +14,14 @@ namespace { bool ShouldUseBraveImporter(importer::ImporterType type) { - if (type == importer::TYPE_CHROME || type == importer::TYPE_EDGE_CHROMIUM) - return true; - + switch (type) { + case importer::TYPE_CHROME: + case importer::TYPE_EDGE_CHROMIUM: + case importer::TYPE_VIVALDI: + return true; + default: + return false; + } return false; } } // namespace diff --git a/browser/importer/brave_importer_p3a.cc b/browser/importer/brave_importer_p3a.cc index f88f83e997e8..9d066d5b7654 100644 --- a/browser/importer/brave_importer_p3a.cc +++ b/browser/importer/brave_importer_p3a.cc @@ -11,16 +11,18 @@ namespace { // Note: append-only enumeration! Never remove any existing values, as this enum // is used to bucket a UMA histogram, and removing values breaks that. +// +// If changes are absolutely required, we can version the histogram (ex .2, .3). +// We need to let folks from stats know so we can update the server side also. enum class ImporterSource { kNone, - kBrave, + kBookmarksHTMLFile, kChrome, kFirefox, - kBookmarksHTMLFile, + kMicrosoft, // includes IE, Legacy Edge, Chromium Edge + kOpera, kSafari, - kIE, - kEdge, - kEdgeChromium, + kOther, // includes Vivaldi and can include others kSize }; } // namespace @@ -28,36 +30,39 @@ enum class ImporterSource { void RecordImporterP3A(importer::ImporterType type) { ImporterSource metric; switch (type) { - case importer::TYPE_UNKNOWN: - metric = ImporterSource::kNone; - break; + case importer::TYPE_UNKNOWN: + metric = ImporterSource::kNone; + break; #if BUILDFLAG(IS_WIN) - case importer::TYPE_IE: - metric = ImporterSource::kIE; - break; - case importer::TYPE_EDGE: - metric = ImporterSource::kEdge; - break; + case importer::TYPE_IE: + metric = ImporterSource::kMicrosoft; + break; + case importer::TYPE_EDGE: + metric = ImporterSource::kMicrosoft; + break; #endif - case importer::TYPE_FIREFOX: - metric = ImporterSource::kFirefox; - break; + case importer::TYPE_FIREFOX: + metric = ImporterSource::kFirefox; + break; #if BUILDFLAG(IS_MAC) - case importer::TYPE_SAFARI: - metric = ImporterSource::kSafari; - break; + case importer::TYPE_SAFARI: + metric = ImporterSource::kSafari; + break; #endif - case importer::TYPE_BOOKMARKS_FILE: - metric = ImporterSource::kBookmarksHTMLFile; - break; - case importer::TYPE_CHROME: - metric = ImporterSource::kChrome; - break; - case importer::TYPE_EDGE_CHROMIUM: - metric = ImporterSource::kEdgeChromium; - break; + case importer::TYPE_BOOKMARKS_FILE: + metric = ImporterSource::kBookmarksHTMLFile; + break; + case importer::TYPE_CHROME: + metric = ImporterSource::kChrome; + break; + case importer::TYPE_EDGE_CHROMIUM: + metric = ImporterSource::kMicrosoft; + break; + case importer::TYPE_VIVALDI: + metric = ImporterSource::kOther; + break; } - UMA_HISTOGRAM_ENUMERATION("Brave.Importer.ImporterSource", metric, + UMA_HISTOGRAM_ENUMERATION("Brave.Importer.ImporterSource.2", metric, ImporterSource::kSize); } diff --git a/chromium_src/chrome/browser/importer/importer_list.cc b/chromium_src/chrome/browser/importer/importer_list.cc index 0e90e68a2eda..9812cf4cf627 100644 --- a/chromium_src/chrome/browser/importer/importer_list.cc +++ b/chromium_src/chrome/browser/importer/importer_list.cc @@ -10,6 +10,7 @@ #include "base/values.h" #include "brave/common/importer/chrome_importer_utils.h" #include "brave/grit/brave_generated_resources.h" +#include "chrome/common/importer/importer_type.h" #include "chrome/grit/generated_resources.h" #include "ui/base/l10n/l10n_util.h" @@ -49,20 +50,34 @@ void DetectChromeProfiles(std::vector* profiles) { base::ScopedBlockingCall scoped_blocking_call(FROM_HERE, base::BlockingType::WILL_BLOCK); AddChromeToProfiles( - profiles, GetChromeSourceProfiles(GetChromeUserDataFolder()), + profiles, + GetChromeSourceProfiles(GetChromeUserDataFolder().Append( + base::FilePath::StringType(FILE_PATH_LITERAL("Local State")))), GetChromeUserDataFolder(), "Chrome ", importer::TYPE_CHROME); #if !BUILDFLAG(IS_LINUX) AddChromeToProfiles( - profiles, GetChromeSourceProfiles(GetCanaryUserDataFolder()), + profiles, + GetChromeSourceProfiles(GetCanaryUserDataFolder().Append( + base::FilePath::StringType(FILE_PATH_LITERAL("Local State")))), GetCanaryUserDataFolder(), "Chrome Canary ", importer::TYPE_CHROME); #endif AddChromeToProfiles( - profiles, GetChromeSourceProfiles(GetChromiumUserDataFolder()), + profiles, + GetChromeSourceProfiles(GetChromiumUserDataFolder().Append( + base::FilePath::StringType(FILE_PATH_LITERAL("Local State")))), GetChromiumUserDataFolder(), "Chromium ", importer::TYPE_CHROME); AddChromeToProfiles( - profiles, GetChromeSourceProfiles(GetEdgeUserDataFolder()), + profiles, + GetChromeSourceProfiles(GetEdgeUserDataFolder().Append( + base::FilePath::StringType(FILE_PATH_LITERAL("Local State")))), GetEdgeUserDataFolder(), "Microsoft Edge ", importer::TYPE_EDGE_CHROMIUM); + + AddChromeToProfiles( + profiles, + GetChromeSourceProfiles(GetVivaldiUserDataFolder().Append( + base::FilePath::StringType(FILE_PATH_LITERAL("Local State")))), + GetVivaldiUserDataFolder(), "Vivaldi ", importer::TYPE_VIVALDI); } } // namespace diff --git a/chromium_src/chrome/browser/importer/importer_uma.cc b/chromium_src/chrome/browser/importer/importer_uma.cc new file mode 100644 index 000000000000..51815a836913 --- /dev/null +++ b/chromium_src/chrome/browser/importer/importer_uma.cc @@ -0,0 +1,14 @@ +/* Copyright 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/. */ + +#include "chrome/browser/importer/importer_uma.h" + +#define TYPE_FIREFOX \ + TYPE_CHROME: \ + case TYPE_EDGE_CHROMIUM: \ + case TYPE_VIVALDI: \ + break; \ + case TYPE_FIREFOX +#include "src/chrome/browser/importer/importer_uma.cc" diff --git a/chromium_src/chrome/common/importer/importer_type.h b/chromium_src/chrome/common/importer/importer_type.h new file mode 100644 index 000000000000..e872c728dd07 --- /dev/null +++ b/chromium_src/chrome/common/importer/importer_type.h @@ -0,0 +1,14 @@ +/* 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/. */ + +#ifndef BRAVE_CHROMIUM_SRC_CHROME_COMMON_IMPORTER_IMPORTER_TYPE_H_ +#define BRAVE_CHROMIUM_SRC_CHROME_COMMON_IMPORTER_IMPORTER_TYPE_H_ + +#define TYPE_FIREFOX \ + TYPE_CHROME = 1, TYPE_EDGE_CHROMIUM = 10, TYPE_VIVALDI = 11, TYPE_FIREFOX +#include "src/chrome/common/importer/importer_type.h" +#undef TYPE_FIREFOX + +#endif // BRAVE_CHROMIUM_SRC_CHROME_COMMON_IMPORTER_IMPORTER_TYPE_H_ diff --git a/chromium_src/chrome/common/importer/profile_import_process_param_traits_macros.h b/chromium_src/chrome/common/importer/profile_import_process_param_traits_macros.h index 1443cfdb197b..1d738d0537ca 100644 --- a/chromium_src/chrome/common/importer/profile_import_process_param_traits_macros.h +++ b/chromium_src/chrome/common/importer/profile_import_process_param_traits_macros.h @@ -10,9 +10,9 @@ #include "chrome/common/importer/importer_type.h" #if !BUILDFLAG(IS_WIN) -#define TYPE_BOOKMARKS_FILE TYPE_EDGE_CHROMIUM +#define TYPE_BOOKMARKS_FILE TYPE_VIVALDI #else -#define TYPE_EDGE TYPE_EDGE_CHROMIUM +#define TYPE_EDGE TYPE_VIVALDI #endif #include "src/chrome/common/importer/profile_import_process_param_traits_macros.h" #if !BUILDFLAG(IS_WIN) diff --git a/common/importer/chrome_importer_utils.cc b/common/importer/chrome_importer_utils.cc index 91523e4160c1..90831a36631e 100644 --- a/common/importer/chrome_importer_utils.cc +++ b/common/importer/chrome_importer_utils.cc @@ -8,10 +8,10 @@ #include #include -#include "base/values.h" #include "base/files/file_path.h" #include "base/files/file_util.h" #include "base/json/json_reader.h" +#include "base/values.h" #include "brave/common/importer/importer_constants.h" #include "brave/common/importer/scoped_copy_file.h" #include "chrome/common/importer/importer_data_types.h" @@ -72,17 +72,9 @@ bool HasPaymentMethods(const base::FilePath& payments_path) { } // namespace base::Value::List GetChromeSourceProfiles( - const base::FilePath& user_data_folder) { + const base::FilePath& local_state_path) { base::Value::List profiles; - base::FilePath local_state_path = - user_data_folder.Append( - base::FilePath::StringType(FILE_PATH_LITERAL("Local State"))); - if (!base::PathExists(local_state_path)) { - base::Value::Dict entry; - entry.Set("id", "Default"); - entry.Set("name", "Default"); - profiles.Append(std::move(entry)); - } else { + if (base::PathExists(local_state_path)) { std::string local_state_content; base::ReadFileToString(local_state_path, &local_state_content); absl::optional local_state = @@ -113,6 +105,12 @@ base::Value::List GetChromeSourceProfiles( } } } + if (profiles.empty()) { + base::Value::Dict entry; + entry.Set("id", "Default"); + entry.Set("name", "Default"); + profiles.Append(std::move(entry)); + } return profiles; } diff --git a/common/importer/chrome_importer_utils.h b/common/importer/chrome_importer_utils.h index cbfe2a7aeb7d..7b28cd6bf75c 100644 --- a/common/importer/chrome_importer_utils.h +++ b/common/importer/chrome_importer_utils.h @@ -25,8 +25,9 @@ base::FilePath GetChromiumUserDataFolder(); base::FilePath GetEdgeUserDataFolder(); -base::Value::List GetChromeSourceProfiles( - const base::FilePath& user_data_folder); +base::FilePath GetVivaldiUserDataFolder(); + +base::Value::List GetChromeSourceProfiles(const base::FilePath& local_state); bool ChromeImporterCanImport(const base::FilePath& profile, uint16_t* services_supported); diff --git a/common/importer/chrome_importer_utils_linux.cc b/common/importer/chrome_importer_utils_linux.cc index 0addfde5a0b2..8e55cde10bd2 100644 --- a/common/importer/chrome_importer_utils_linux.cc +++ b/common/importer/chrome_importer_utils_linux.cc @@ -21,6 +21,17 @@ base::FilePath GetChromeUserDataFolder() { return result; } +base::FilePath GetVivaldiUserDataFolder() { + base::FilePath result; + if (!base::PathService::Get(base::DIR_HOME, &result)) + return base::FilePath(); + + result = result.Append(".config"); + result = result.Append("vivaldi"); + + return result; +} + base::FilePath GetChromiumUserDataFolder() { base::FilePath result; if (!base::PathService::Get(base::DIR_HOME, &result)) diff --git a/common/importer/chrome_importer_utils_mac.mm b/common/importer/chrome_importer_utils_mac.mm index c512914178fe..0d30f090f784 100644 --- a/common/importer/chrome_importer_utils_mac.mm +++ b/common/importer/chrome_importer_utils_mac.mm @@ -15,6 +15,11 @@ return result.Append("Application Support/Google/Chrome"); } +base::FilePath GetVivaldiUserDataFolder() { + base::FilePath result = base::mac::GetUserLibraryPath(); + return result.Append("Application Support/Vivaldi"); +} + base::FilePath GetCanaryUserDataFolder() { base::FilePath result = base::mac::GetUserLibraryPath(); return result.Append("Application Support/Google/Chrome Canary"); diff --git a/common/importer/chrome_importer_utils_unittest.cc b/common/importer/chrome_importer_utils_unittest.cc index 46f736b14f83..7e0d4a72ed01 100644 --- a/common/importer/chrome_importer_utils_unittest.cc +++ b/common/importer/chrome_importer_utils_unittest.cc @@ -13,6 +13,12 @@ #include "testing/gtest/include/gtest/gtest.h" namespace { +base::FilePath GetTestProfilePath() { + base::FilePath test_dir; + base::PathService::Get(brave::DIR_TEST_DATA, &test_dir); + return test_dir.AppendASCII("import").AppendASCII("chrome").AppendASCII( + "default"); +} // This sample prefs file is fetched after installing two extensions and one // theme from webstore with fresh profile. base::FilePath GetTestPreferencesPath() { @@ -39,3 +45,23 @@ TEST(ChromeImporterUtilsTest, BasicTest) { // We don't import theme, pre-installed extensions and installed by default. EXPECT_EQ(2UL, extensions_list.size()); } + +TEST(ChromeImporterUtilsTest, GetChromeUserDataFolder) { + EXPECT_EQ(GetChromeSourceProfiles(base::FilePath(FILE_PATH_LITERAL("fake"))), + base::JSONReader::Read(R"([{"id": "Default", "name": "Default" }])") + ->GetList()); + + EXPECT_EQ(GetChromeSourceProfiles(GetTestProfilePath().Append( + base::FilePath::StringType(FILE_PATH_LITERAL("Local State")))), + base::JSONReader::Read(R"([ + {"id": "Default", "name": "Profile 1"}, + {"id": "Profile 2", "name": "Profile 2"} + ])") + ->GetList()); + + EXPECT_EQ(GetChromeSourceProfiles( + GetTestProfilePath().Append(base::FilePath::StringType( + FILE_PATH_LITERAL("No Profile Local State")))), + base::JSONReader::Read(R"([{"id": "Default", "name": "Default" }])") + ->GetList()); +} diff --git a/common/importer/chrome_importer_utils_win.cc b/common/importer/chrome_importer_utils_win.cc index dd2ef824918c..ba39210ccd16 100644 --- a/common/importer/chrome_importer_utils_win.cc +++ b/common/importer/chrome_importer_utils_win.cc @@ -20,6 +20,17 @@ base::FilePath GetChromeUserDataFolder() { return result; } +base::FilePath GetVivaldiUserDataFolder() { + base::FilePath result; + if (!base::PathService::Get(base::DIR_LOCAL_APP_DATA, &result)) + return base::FilePath(); + + result = result.AppendASCII("Vivaldi"); + result = result.AppendASCII("User Data"); + + return result; +} + base::FilePath GetCanaryUserDataFolder() { base::FilePath result; if (!base::PathService::Get(base::DIR_LOCAL_APP_DATA, &result)) diff --git a/common/importer/importer_constants.h b/common/importer/importer_constants.h index c91f81dacb71..92c91d71b114 100644 --- a/common/importer/importer_constants.h +++ b/common/importer/importer_constants.h @@ -16,5 +16,6 @@ constexpr char kChromeExtensionsPreferencesFile[] = "Secure Preferences"; #endif constexpr char kChromeExtensionsListPath[] = "extensions.settings"; +constexpr char kChromeLocalStateFile[] = "Local State"; #endif // BRAVE_COMMON_IMPORTER_IMPORTER_CONSTANTS_H_ diff --git a/components/p3a/metric_names.h b/components/p3a/metric_names.h index 920be2a584c6..74243f2ca3f1 100644 --- a/components/p3a/metric_names.h +++ b/components/p3a/metric_names.h @@ -32,7 +32,7 @@ constexpr inline auto kCollectedHistograms = "Brave.Core.TabCount", "Brave.Core.TorEverUsed", "Brave.Core.WindowCount.2", - "Brave.Importer.ImporterSource", + "Brave.Importer.ImporterSource.2", "Brave.NTP.CustomizeUsageStatus", "Brave.NTP.NewTabsCreated", "Brave.NTP.SponsoredImagesEnabled", diff --git a/patches/chrome-browser-importer-importer_uma.cc.patch b/patches/chrome-browser-importer-importer_uma.cc.patch deleted file mode 100644 index 17c127c6c744..000000000000 --- a/patches/chrome-browser-importer-importer_uma.cc.patch +++ /dev/null @@ -1,17 +0,0 @@ -diff --git a/chrome/browser/importer/importer_uma.cc b/chrome/browser/importer/importer_uma.cc -index d858676745103908f16a41392c0da42c3683c555..ebdd7bdf2c893dacba09bea9c174ce4f5bb176eb 100644 ---- a/chrome/browser/importer/importer_uma.cc -+++ b/chrome/browser/importer/importer_uma.cc -@@ -59,6 +59,12 @@ void LogImporterUseToMetrics(const std::string& metric_postfix, - case TYPE_BOOKMARKS_FILE: - metrics_type = IMPORTER_METRICS_BOOKMARKS_FILE; - break; -+ case TYPE_CHROME: -+ // TODO: Wire this up if we want to record metrics on users who import from Chrome -+ break; -+ case TYPE_EDGE_CHROMIUM: -+ // TODO: Wire this up if we want to record metrics on users who import from Chrome -+ break; - } - - // Note: This leaks memory, which is the expected behavior as the factory diff --git a/patches/chrome-common-importer-importer_type.h.patch b/patches/chrome-common-importer-importer_type.h.patch deleted file mode 100644 index 33e09434bb8a..000000000000 --- a/patches/chrome-common-importer-importer_type.h.patch +++ /dev/null @@ -1,21 +0,0 @@ -diff --git a/chrome/common/importer/importer_type.h b/chrome/common/importer/importer_type.h -index 783aeeb86b265b9abf6c1d5c8a77c726daea277d..e7f580e9136ffa37b24a08336ae7f8cdcee353f7 100644 ---- a/chrome/common/importer/importer_type.h -+++ b/chrome/common/importer/importer_type.h -@@ -19,6 +19,8 @@ enum ImporterType { - TYPE_IE = 0, - #endif - // Value 1 was the (now deleted) Firefox 2 profile importer. -+ // We use it for the Chrome profile importer now. -+ TYPE_CHROME = 1, - TYPE_FIREFOX = 2, - #if BUILDFLAG(IS_MAC) - TYPE_SAFARI = 3, -@@ -28,6 +30,7 @@ enum ImporterType { - #if BUILDFLAG(IS_WIN) - TYPE_EDGE = 6, - #endif -+ TYPE_EDGE_CHROMIUM = 10 - }; - - } // namespace importer diff --git a/test/data/import/chrome/default/Local State b/test/data/import/chrome/default/Local State new file mode 100644 index 000000000000..2b1f686877c2 --- /dev/null +++ b/test/data/import/chrome/default/Local State @@ -0,0 +1,18 @@ +{ + "profile": + { + "info_cache": + { + "Default": + { + + "name": "Profile 1" + }, + "Profile 2": + { + + "name": "Profile 2" + } + } + } +} \ No newline at end of file diff --git a/test/data/import/chrome/default/No Profile Local State b/test/data/import/chrome/default/No Profile Local State new file mode 100644 index 000000000000..0db3279e44b0 --- /dev/null +++ b/test/data/import/chrome/default/No Profile Local State @@ -0,0 +1,3 @@ +{ + +} diff --git a/utility/importer/brave_profile_import_impl.cc b/utility/importer/brave_profile_import_impl.cc index d66c5e389efa..145cfdc47846 100644 --- a/utility/importer/brave_profile_import_impl.cc +++ b/utility/importer/brave_profile_import_impl.cc @@ -17,7 +17,6 @@ #include "base/threading/thread_task_runner_handle.h" #include "brave/utility/importer/brave_external_process_importer_bridge.h" #include "brave/utility/importer/chrome_importer.h" -#include "brave/utility/importer/edge_importer.h" #include "build/build_config.h" #include "chrome/common/importer/profile_import.mojom.h" #include "chrome/utility/importer/external_process_importer_bridge.h" @@ -33,7 +32,9 @@ scoped_refptr CreateImporterByType(importer::ImporterType type) { case importer::TYPE_CHROME: return new ChromeImporter(); case importer::TYPE_EDGE_CHROMIUM: - return new EdgeImporter(); + return new ChromeImporter(); + case importer::TYPE_VIVALDI: + return new ChromeImporter(); default: NOTREACHED(); return nullptr; diff --git a/utility/importer/edge_importer.h b/utility/importer/edge_importer.h deleted file mode 100644 index 8a5abb2ae5f3..000000000000 --- a/utility/importer/edge_importer.h +++ /dev/null @@ -1,21 +0,0 @@ -/* 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/. */ - -#ifndef BRAVE_UTILITY_IMPORTER_EDGE_IMPORTER_H_ -#define BRAVE_UTILITY_IMPORTER_EDGE_IMPORTER_H_ - -#include "brave/utility/importer/chrome_importer.h" - -class EdgeImporter : public ChromeImporter { - public: - EdgeImporter() = default; - EdgeImporter(const EdgeImporter&) = delete; - EdgeImporter& operator=(const EdgeImporter&) = delete; - - protected: - ~EdgeImporter() override {} -}; - -#endif // BRAVE_UTILITY_IMPORTER_EDGE_IMPORTER_H_ diff --git a/utility/importer/sources.gni b/utility/importer/sources.gni index 4d2f572a6a49..0c7ff56eb0e6 100644 --- a/utility/importer/sources.gni +++ b/utility/importer/sources.gni @@ -16,7 +16,6 @@ if (!is_android) { "//brave/utility/importer/brave_profile_import_impl.h", "//brave/utility/importer/chrome_importer.cc", "//brave/utility/importer/chrome_importer.h", - "//brave/utility/importer/edge_importer.h", ] brave_utility_importer_deps += [