Skip to content

Commit

Permalink
Just warning if browser detect chrome is running while importing
Browse files Browse the repository at this point in the history
With this warning dialog, user will close chrome windows.
After that user clicks continue button, browser will not check lock again aind
will try to import chrome's settings.
Even if chrome is still running, importing will be done because
importing is done with temporarily copied db files.
  • Loading branch information
simonhong committed Apr 24, 2020
1 parent 4b8cb48 commit 13c0db1
Show file tree
Hide file tree
Showing 5 changed files with 47 additions and 23 deletions.
5 changes: 4 additions & 1 deletion app/brave_generated_resources.grd
Original file line number Diff line number Diff line change
Expand Up @@ -179,7 +179,10 @@
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.
To continue importing, close all Chrome windows.
</message>
<message name="IDS_CHROME_IMPORTER_LOCK_OK" desc="The text to be displayed in the OK button">
Continue
</message>
<message name="IDS_SETTINGS_IMPORT_EXTENSIONS_CHECKBOX" desc="Checkbox for importing extensions list">
Extensions
Expand Down
15 changes: 5 additions & 10 deletions browser/importer/brave_external_process_importer_host.cc
Original file line number Diff line number Diff line change
Expand Up @@ -75,20 +75,15 @@ void BraveExternalProcessImporterHost::ShowWarningDialog() {

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();
}
// User chose to continue, then try to import the settings.
is_source_readable_ = true;
LaunchImportIfReady();
} else {
cancelled_ = true;
NotifyImportEnded();
}
}

bool BraveExternalProcessImporterHost::CheckForFirefoxLock(
const importer::SourceProfile& source_profile) {
if (!ExternalProcessImporterHost::CheckForFirefoxLock(source_profile))
Expand Down
4 changes: 2 additions & 2 deletions browser/importer/brave_external_process_importer_host.h
Original file line number Diff line number Diff line change
Expand Up @@ -38,11 +38,11 @@ class BraveExternalProcessImporterHost : public ExternalProcessImporterHost {
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.
// lock. They can continue 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
// This is called when when user ends the warning 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);
Expand Down
6 changes: 2 additions & 4 deletions browser/ui/views/importer/brave_import_lock_dialog_view.cc
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,6 @@
#include "chrome/browser/importer/importer_lock_dialog.h"
#include "chrome/browser/ui/browser_dialogs.h"
#include "chrome/browser/ui/views/chrome_layout_provider.h"
#include "chrome/grit/chromium_strings.h"
#include "chrome/grit/generated_resources.h"
#include "chrome/grit/locale_settings.h"
#include "ui/base/l10n/l10n_util.h"
#include "ui/base/buildflags.h"
#include "ui/views/border.h"
Expand Down Expand Up @@ -57,7 +54,8 @@ ImportLockDialogView::ImportLockDialogView(
SetLayoutManager(std::make_unique<views::FillLayout>());

DialogDelegate::set_button_label(
ui::DIALOG_BUTTON_OK, l10n_util::GetStringUTF16(IDS_IMPORTER_LOCK_OK));
ui::DIALOG_BUTTON_OK,
l10n_util::GetStringUTF16(IDS_CHROME_IMPORTER_LOCK_OK));

views::Label* description_label;
DCHECK_EQ(::importer::TYPE_CHROME, source_profile_.importer_type);
Expand Down
40 changes: 34 additions & 6 deletions utility/importer/chrome_importer.cc
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,27 @@ bool SetEncryptionKeyForPasswordImporting(
}
#endif

class CreateCopyFile {
public:
explicit CreateCopyFile(const base::FilePath& original_file_path) {
DCHECK(base::PathExists(original_file_path));
if (base::CreateTemporaryFile(&copied_file_path_))
base::CopyFile(original_file_path, copied_file_path_);
}

~CreateCopyFile() {
base::DeleteFile(copied_file_path_, false);
}

CreateCopyFile(const CreateCopyFile&) = delete;
CreateCopyFile& operator=(const CreateCopyFile&) = delete;

base::FilePath copied_file_path() const { return copied_file_path_; }

private:
base::FilePath copied_file_path_;
};

} // namespace

ChromeImporter::ChromeImporter() {
Expand Down Expand Up @@ -147,15 +168,16 @@ void ChromeImporter::StartImport(const importer::SourceProfile& source_profile,
}

void ChromeImporter::ImportHistory() {
base::FilePath history_path =
source_path_.Append(
base::FilePath history_path = source_path_.Append(
base::FilePath::StringType(FILE_PATH_LITERAL("History")));
if (!base::PathExists(history_path))
return;

CreateCopyFile copy_history_file(history_path);
sql::Database db;
if (!db.Open(history_path))
if (!db.Open(copy_history_file.copied_file_path())) {
return;
}

const char query[] =
"SELECT u.url, u.title, v.visit_time, u.typed_count, u.visit_count "
Expand Down Expand Up @@ -196,7 +218,9 @@ void ChromeImporter::ImportBookmarks() {
base::FilePath bookmarks_path =
source_path_.Append(
base::FilePath::StringType(FILE_PATH_LITERAL("Bookmarks")));
base::ReadFileToString(bookmarks_path, &bookmarks_content);
CreateCopyFile copy_bookmark_file(bookmarks_path);
base::ReadFileToString(copy_bookmark_file.copied_file_path(),
&bookmarks_content);
base::Optional<base::Value> bookmarks_json =
base::JSONReader::Read(bookmarks_content);
const base::DictionaryValue* bookmark_dict;
Expand Down Expand Up @@ -240,8 +264,10 @@ void ChromeImporter::ImportBookmarks() {
if (!base::PathExists(favicons_path))
return;

CreateCopyFile copy_favicon_file(favicons_path);

sql::Database db;
if (!db.Open(favicons_path))
if (!db.Open(copy_favicon_file.copied_file_path()))
return;

FaviconMap favicon_map;
Expand Down Expand Up @@ -385,8 +411,10 @@ void ChromeImporter::ImportPasswords() {
if (!base::PathExists(passwords_path))
return;

CreateCopyFile copy_password_file(passwords_path);
password_manager::LoginDatabase database(
passwords_path, password_manager::IsAccountStore(false));
copy_password_file.copied_file_path(),
password_manager::IsAccountStore(false));
if (!database.Init()) {
LOG(ERROR) << "LoginDatabase Init() failed";
return;
Expand Down

0 comments on commit 13c0db1

Please sign in to comment.