Skip to content

Commit 41d5257

Browse files
committed
Destroy observer on ImportEnded
1 parent 094d0ec commit 41d5257

File tree

6 files changed

+30
-10
lines changed

6 files changed

+30
-10
lines changed

browser/ui/webui/settings/brave_import_data_handler.cc

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,12 +6,14 @@
66
#include "brave/browser/ui/webui/settings/brave_import_data_handler.h"
77

88
#include <memory>
9+
#include <string>
910
#include <unordered_map>
1011

1112
#include "brave/browser/ui/webui/settings/import_feature.h"
1213
#include "chrome/browser/importer/external_process_importer_host.h"
1314
#include "chrome/browser/importer/profile_writer.h"
1415
#include "chrome/browser/profiles/profile.h"
16+
#include "content/public/browser/browser_task_traits.h"
1517

1618
#if BUILDFLAG(IS_MAC)
1719
#include "base/files/file_path.h"
@@ -99,8 +101,21 @@ void BraveImportDataHandler::StartImportImpl(
99101
new ProfileWriter(profile));
100102
}
101103

102-
void BraveImportDataHandler::NotifyImportProgress(const base::Value& info) {
104+
void BraveImportDataHandler::NotifyImportProgress(
105+
const importer::SourceProfile& source_profile,
106+
const base::Value& info) {
103107
FireWebUIListener("brave-import-data-status-changed", info);
108+
const std::string* event = info.FindStringKey("event");
109+
if (event && *event == "ImportEnded") {
110+
content::GetUIThreadTaskRunner({})->PostTask(
111+
FROM_HERE,
112+
base::BindOnce(&BraveImportDataHandler::OnImportEnded,
113+
weak_factory_.GetWeakPtr(), source_profile.source_path));
114+
}
115+
}
116+
117+
void BraveImportDataHandler::OnImportEnded(const base::FilePath& source_path) {
118+
import_observers_.erase(source_path);
104119
}
105120

106121
#if BUILDFLAG(IS_MAC)

browser/ui/webui/settings/brave_import_data_handler.h

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,9 @@ class BraveImportDataHandler : public ImportDataHandler,
4545

4646
void StartImportImpl(const importer::SourceProfile& source_profile,
4747
uint16_t imported_items);
48-
void NotifyImportProgress(const base::Value& info);
48+
void NotifyImportProgress(const importer::SourceProfile& source_profile,
49+
const base::Value& info);
50+
void OnImportEnded(const base::FilePath& source_path);
4951
#if BUILDFLAG(IS_MAC)
5052
void CheckDiskAccess(const importer::SourceProfile& source_profile,
5153
uint16_t imported_items);

browser/ui/webui/settings/brave_importer_observer.cc

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ void BraveImporterObserver::ImportStarted() {
3838
data.Set("importer_type", source_profile_.importer_type);
3939
data.Set("items_to_import", imported_items_);
4040
data.Set("event", "ImportStarted");
41-
callback_.Run(base::Value(std::move(data)));
41+
callback_.Run(source_profile_, base::Value(std::move(data)));
4242
}
4343

4444
void BraveImporterObserver::ImportItemStarted(importer::ImportItem item) {
@@ -48,7 +48,7 @@ void BraveImporterObserver::ImportItemStarted(importer::ImportItem item) {
4848
data.Set("items_to_import", imported_items_);
4949
data.Set("event", "ImportItemStarted");
5050
data.Set("item", item);
51-
callback_.Run(base::Value(std::move(data)));
51+
callback_.Run(source_profile_, base::Value(std::move(data)));
5252
}
5353

5454
void BraveImporterObserver::ImportItemEnded(importer::ImportItem item) {
@@ -58,7 +58,7 @@ void BraveImporterObserver::ImportItemEnded(importer::ImportItem item) {
5858
data.Set("items_to_import", imported_items_);
5959
data.Set("event", "ImportItemEnded");
6060
data.Set("item", item);
61-
callback_.Run(base::Value(std::move(data)));
61+
callback_.Run(source_profile_, base::Value(std::move(data)));
6262
}
6363

6464
void BraveImporterObserver::ImportEnded() {
@@ -67,12 +67,14 @@ void BraveImporterObserver::ImportEnded() {
6767
data.Set("importer_type", source_profile_.importer_type);
6868
data.Set("items_to_import", imported_items_);
6969
data.Set("event", "ImportEnded");
70-
callback_.Run(base::Value(std::move(data)));
70+
7171
DCHECK(importer_host_);
7272
if (importer_host_)
7373
importer_host_->set_observer(nullptr);
7474

7575
importer_host_ = nullptr;
76+
77+
callback_.Run(source_profile_, base::Value(std::move(data)));
7678
}
7779

7880
ExternalProcessImporterHost*

browser/ui/webui/settings/brave_importer_observer.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,8 @@ class ExternalProcessImporterHost;
1515

1616
class BraveImporterObserver : public importer::ImporterProgressObserver {
1717
public:
18-
using ReportProgressCallback =
19-
base::RepeatingCallback<void(const base::Value&)>;
18+
using ReportProgressCallback = base::RepeatingCallback<
19+
void(const importer::SourceProfile& source_profile, const base::Value&)>;
2020

2121
explicit BraveImporterObserver(ExternalProcessImporterHost* host,
2222
const importer::SourceProfile& source_profile,

browser/ui/webui/settings/brave_importer_observer_unittest.cc

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,8 @@ class BraveImporterObserverUnitTest : public testing::Test {
2222
void SetExpectedInfo(base::Value value) { expected_info_ = std::move(value); }
2323
void SetExpectedCalls(int value) { expected_calls_ = value; }
2424
int GetExpectedCalls() { return expected_calls_; }
25-
void NotifyImportProgress(const base::Value& info) {
25+
void NotifyImportProgress(const importer::SourceProfile& source_profile,
26+
const base::Value& info) {
2627
EXPECT_EQ(expected_info_, info);
2728
expected_calls_++;
2829
}

browser/ui/webui/settings/import_feature.cc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
namespace settings {
1212

1313
const base::Feature kParallelImports{"ParallelImports",
14-
base::FEATURE_DISABLED_BY_DEFAULT};
14+
base::FEATURE_ENABLED_BY_DEFAULT};
1515

1616
// Temporary flag to keep old way until
1717
// https://github.com/brave/brave-core/pull/15637 landed.

0 commit comments

Comments
 (0)