Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Try to import chrome data w/o warning dialog #5336

Merged
merged 3 commits into from
May 14, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 0 additions & 7 deletions app/brave_generated_resources.grd
Original file line number Diff line number Diff line change
Expand Up @@ -174,13 +174,6 @@
<message name="IDS_EXTENSION_CANT_INSTALL_ON_BRAVE" desc="Error message when user tries to install an extension that is not allowed in Brave.">
<ph name="EXTENSION_NAME">$1</ph> (extension ID "<ph name="EXTENSION_ID">$2<ex>abacabadabacabaeabacabadabacabaf</ex></ph>") is not allowed in Brave.
</message>
<!-- Importer Lock Dialog -->
<message name="IDS_CHROME_IMPORTER_LOCK_TITLE" desc="Dialog title for Chrome importer lock dialog">
Close Chrome
</message>
<message name="IDS_CHROME_IMPORTER_LOCK_TEXT" desc="The message to be displayed in the Chrome importer lock dialog">
To finish importing, close all Chrome windows.
</message>
<message name="IDS_SETTINGS_IMPORT_EXTENSIONS_CHECKBOX" desc="Checkbox for importing extensions list">
Extensions
</message>
Expand Down
4 changes: 0 additions & 4 deletions browser/importer/BUILD.gn
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,8 @@ source_set("importer") {
sources = [
"brave_external_process_importer_host.cc",
"brave_external_process_importer_host.h",
"brave_importer_lock_dialog.h",
"brave_importer_p3a.cc",
"brave_importer_p3a.h",
"browser_profile_lock.h",
"chrome_profile_lock.cc",
"chrome_profile_lock.h",
]

deps = [
Expand Down
65 changes: 3 additions & 62 deletions browser/importer/brave_external_process_importer_host.cc
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,15 @@

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

#include <memory>
#include <string>

#include "base/bind.h"
#include "base/files/file_util.h"
#include "base/json/json_reader.h"
#include "base/task/post_task.h"
#include "base/task/task_traits.h"
#include "brave/browser/importer/brave_importer_lock_dialog.h"
#include "brave/browser/importer/brave_importer_p3a.h"
#include "brave/browser/importer/chrome_profile_lock.h"
#include "brave/common/importer/chrome_importer_utils.h"
#include "brave/common/importer/importer_constants.h"

Expand Down Expand Up @@ -65,66 +66,6 @@ BraveExternalProcessImporterHost::BraveExternalProcessImporterHost()
weak_ptr_factory_(this) {}
BraveExternalProcessImporterHost::~BraveExternalProcessImporterHost() = default;

void BraveExternalProcessImporterHost::ShowWarningDialog() {
DCHECK(!headless_);
brave::importer::ShowImportLockDialog(
parent_window_, source_profile_,
base::Bind(&BraveExternalProcessImporterHost::OnImportLockDialogEnd,
weak_ptr_factory_.GetWeakPtr()));
}

void BraveExternalProcessImporterHost::OnImportLockDialogEnd(bool is_continue) {
if (is_continue) {
// User chose to continue, then we check the lock again to make sure that
// the other browser has been closed. Try to import the settings if
// successful. Otherwise, show a warning dialog.
browser_lock_->Lock();
if (browser_lock_->HasAcquired()) {
is_source_readable_ = true;
LaunchImportIfReady();
} else {
ShowWarningDialog();
}
} else {
NotifyImportEnded();
}
}
bool BraveExternalProcessImporterHost::CheckForFirefoxLock(
const importer::SourceProfile& source_profile) {
if (!ExternalProcessImporterHost::CheckForFirefoxLock(source_profile))
return false;

return CheckForChromeLock(source_profile);
}

bool BraveExternalProcessImporterHost::CheckForChromeLock(
const importer::SourceProfile& source_profile) {
if (source_profile.importer_type != importer::TYPE_CHROME)
return true;

DCHECK(!browser_lock_.get());

// Extract the user data directory from the path of the profile to be
// imported, because we can only lock/unlock the entire user directory with
// ProcessSingleton.
base::FilePath user_data_dir = source_profile.source_path.DirName();
browser_lock_.reset(new ChromeProfileLock(user_data_dir));

browser_lock_->Lock();
if (browser_lock_->HasAcquired())
return true;

// If fail to acquire the lock, we set the source unreadable and
// show a warning dialog, unless running without UI (in which case the import
// must be aborted).
is_source_readable_ = false;
if (headless_)
return false;

ShowWarningDialog();
return true;
}

#if BUILDFLAG(ENABLE_EXTENSIONS)
void BraveExternalProcessImporterHost::LaunchExtensionsImport() {
DCHECK_EQ(importer::TYPE_CHROME, source_profile_.importer_type);
Expand Down
24 changes: 0 additions & 24 deletions browser/importer/brave_external_process_importer_host.h
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,6 @@
#ifndef BRAVE_BROWSER_IMPORTER_BRAVE_EXTERNAL_PROCESS_IMPORTER_HOST_H_
#define BRAVE_BROWSER_IMPORTER_BRAVE_EXTERNAL_PROCESS_IMPORTER_HOST_H_

#include <memory>
#include <string>

#include "base/memory/weak_ptr.h"
#include "base/optional.h"
#include "base/values.h"
Expand All @@ -28,33 +25,12 @@ class BraveExternalProcessImporterHost : public ExternalProcessImporterHost {

// ExternalProcessImporterHost overrides:
void NotifyImportEnded() override;
bool CheckForFirefoxLock(
const importer::SourceProfile& source_profile) override;
// Make sure that Chrome isn't running, if import browser is Chrome
// or Brave. Show to the user a dialog that notifies that is necessary to
// close Chrome prior to continuing the import. Returns false iff
// import should be aborted.
bool CheckForChromeLock(
const importer::SourceProfile& source_profile);

// ShowWarningDialog() asks user to close the application that is owning the
// lock. They can retry or skip the importing process.
// This method should not be called if the importer is in headless mode.
void ShowWarningDialog();

// This is called when when user ends the lock dialog by clicking on either
// the "Skip" or "Continue" buttons. |is_continue| is true when user clicked
// the "Continue" button.
void OnImportLockDialogEnd(bool is_continue);

#if BUILDFLAG(ENABLE_EXTENSIONS)
void LaunchExtensionsImport();
void OnGetChromeExtensionsList(base::Optional<base::Value> extensions_list);
#endif

// Chrome profile lock.
std::unique_ptr<BrowserProfileLock> browser_lock_;

// Vends weak pointers for the importer to call us back.
base::WeakPtrFactory<BraveExternalProcessImporterHost> weak_ptr_factory_;

Expand Down
25 changes: 0 additions & 25 deletions browser/importer/brave_importer_lock_dialog.h

This file was deleted.

21 changes: 0 additions & 21 deletions browser/importer/browser_profile_lock.h

This file was deleted.

51 changes: 0 additions & 51 deletions browser/importer/chrome_profile_lock.cc

This file was deleted.

37 changes: 0 additions & 37 deletions browser/importer/chrome_profile_lock.h

This file was deleted.

Loading