Skip to content

Commit

Permalink
Added import from Vivaldi (#13990)
Browse files Browse the repository at this point in the history
  • Loading branch information
spylogsster authored Jul 14, 2022
1 parent b72f2e2 commit 5aa6867
Show file tree
Hide file tree
Showing 21 changed files with 183 additions and 115 deletions.
11 changes: 8 additions & 3 deletions browser/importer/brave_external_process_importer_client.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
65 changes: 35 additions & 30 deletions browser/importer/brave_importer_p3a.cc
Original file line number Diff line number Diff line change
Expand Up @@ -11,53 +11,58 @@
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

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);
}
23 changes: 19 additions & 4 deletions chromium_src/chrome/browser/importer/importer_list.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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"

Expand Down Expand Up @@ -49,20 +50,34 @@ void DetectChromeProfiles(std::vector<importer::SourceProfile>* 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
Expand Down
14 changes: 14 additions & 0 deletions chromium_src/chrome/browser/importer/importer_uma.cc
Original file line number Diff line number Diff line change
@@ -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"
14 changes: 14 additions & 0 deletions chromium_src/chrome/common/importer/importer_type.h
Original file line number Diff line number Diff line change
@@ -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_
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_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)
Expand Down
20 changes: 9 additions & 11 deletions common/importer/chrome_importer_utils.cc
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,10 @@
#include <memory>
#include <utility>

#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"
Expand Down Expand Up @@ -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<base::Value> local_state =
Expand Down Expand Up @@ -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;
}

Expand Down
5 changes: 3 additions & 2 deletions common/importer/chrome_importer_utils.h
Original file line number Diff line number Diff line change
Expand Up @@ -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);
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 @@ -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))
Expand Down
5 changes: 5 additions & 0 deletions common/importer/chrome_importer_utils_mac.mm
Original file line number Diff line number Diff line change
Expand Up @@ -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");
Expand Down
26 changes: 26 additions & 0 deletions common/importer/chrome_importer_utils_unittest.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
Expand All @@ -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());
}
11 changes: 11 additions & 0 deletions common/importer/chrome_importer_utils_win.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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))
Expand Down
1 change: 1 addition & 0 deletions common/importer/importer_constants.h
Original file line number Diff line number Diff line change
Expand Up @@ -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_
2 changes: 1 addition & 1 deletion components/p3a/metric_names.h
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
17 changes: 0 additions & 17 deletions patches/chrome-browser-importer-importer_uma.cc.patch

This file was deleted.

21 changes: 0 additions & 21 deletions patches/chrome-common-importer-importer_type.h.patch

This file was deleted.

Loading

0 comments on commit 5aa6867

Please sign in to comment.