Just warning if browser detect chrome is running while importing

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.
This commit is contained in:
Simon Hong
2020-05-12 11:35:47 +09:00
parent 490f0f04e9
commit c26d326491
5 changed files with 47 additions and 23 deletions
+4 -1
View File
@@ -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
@@ -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))
@@ -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);
@@ -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"
@@ -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);
+34 -6
View File
@@ -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() {
@@ -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 "
@@ -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;
@@ -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;
@@ -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;