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

Restore other bookmarks #4404

Merged
merged 15 commits into from
Feb 20, 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
2 changes: 0 additions & 2 deletions browser/BUILD.gn
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,6 @@ source_set("browser_process") {
"autocomplete/brave_autocomplete_provider_client.h",
"autocomplete/brave_autocomplete_scheme_classifier.cc",
"autocomplete/brave_autocomplete_scheme_classifier.h",
"bookmarks/brave_bookmark_client.cc",
"bookmarks/brave_bookmark_client.h",
"brave_rewards/rewards_tab_helper.cc",
"brave_rewards/rewards_tab_helper.h",
"brave_shields/ad_block_pref_service_factory.cc",
Expand Down
23 changes: 0 additions & 23 deletions browser/bookmarks/brave_bookmark_client.cc

This file was deleted.

26 changes: 0 additions & 26 deletions browser/bookmarks/brave_bookmark_client.h

This file was deleted.

28 changes: 0 additions & 28 deletions browser/bookmarks/brave_bookmark_client_browsertest.cc

This file was deleted.

3 changes: 3 additions & 0 deletions browser/brave_profile_prefs.cc
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,9 @@ void RegisterProfilePrefsForMigration(
#if BUILDFLAG(BRAVE_WALLET_ENABLED)
brave_wallet::RegisterBraveWalletProfilePrefsForMigration(registry);
#endif

// Restore "Other Bookmarks" migration
registry->RegisterBooleanPref(kOtherBookmarksMigrated, false);
}

void RegisterProfilePrefs(user_prefs::PrefRegistrySyncable* registry) {
Expand Down
1 change: 1 addition & 0 deletions browser/profiles/BUILD.gn
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ source_set("profiles") {
"//brave/browser/gcm_driver",
"//brave/browser/tor",
"//brave/browser/translate/buildflags",
"//brave/common:pref_names",
"//brave/common/tor",
"//brave/components/brave_ads/browser",
"//brave/components/brave_rewards/browser",
Expand Down
19 changes: 13 additions & 6 deletions browser/profiles/brave_bookmark_model_loaded_observer.cc
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,11 @@

#include "brave/browser/profiles/brave_bookmark_model_loaded_observer.h"

#include "brave/common/pref_names.h"
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

do any deps need to be added for these?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

fixed in 07e019e

#include "chrome/browser/profiles/profile.h"
#include "chrome/browser/sync/profile_sync_service_factory.h"
#include "components/bookmarks/browser/bookmark_model.h"
#include "components/prefs/pref_service.h"

#include "brave/components/brave_sync/buildflags/buildflags.h"
#if BUILDFLAG(ENABLE_BRAVE_SYNC)
Expand All @@ -23,16 +26,20 @@ BraveBookmarkModelLoadedObserver::BraveBookmarkModelLoadedObserver(
void BraveBookmarkModelLoadedObserver::BookmarkModelLoaded(
BookmarkModel* model,
bool ids_reassigned) {
if (!profile_->GetPrefs()->GetBoolean(kOtherBookmarksMigrated)) {
#if BUILDFLAG(ENABLE_BRAVE_SYNC)
BraveProfileSyncServiceImpl* brave_profile_service =
BraveProfileSyncServiceImpl* brave_profile_service =
static_cast<BraveProfileSyncServiceImpl*>(
ProfileSyncServiceFactory::GetForProfile(profile_));
// When sync is enabled, we need to send migration records to other devices so
// it is handled in BraveProfileSyncServiceImpl::OnSyncReady
if (brave_profile_service && !brave_profile_service->IsBraveSyncEnabled())
BraveMigrateOtherNode(model);
// When sync is enabled, we need to send migration records to other devices
// so it is handled in BraveProfileSyncServiceImpl::OnSyncReady
if (!brave_profile_service ||
(brave_profile_service && !brave_profile_service->IsBraveSyncEnabled()))
BraveMigrateOtherNodeFolder(model);
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: it's a little confusing to put this in the #if and #else

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is for when sync is running, we don't migrate right away. It is guarded by ENABLE_BRAVE_SYNC, if it is false, we don't have access to BraveProfileSyncServiceImpl.
I don't see how confusing it is.

#else
BraveMigrateOtherNode(model);
BraveMigrateOtherNodeFolder(model);
#endif
profile_->GetPrefs()->SetBoolean(kOtherBookmarksMigrated, true);
}
BookmarkModelLoadedObserver::BookmarkModelLoaded(model, ids_reassigned);
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
/* Copyright (c) 2020 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 "brave/common/pref_names.h"
#include "chrome/browser/bookmarks/bookmark_model_factory.h"
#include "chrome/browser/profiles/profile.h"
#include "chrome/browser/ui/browser.h"
#include "chrome/test/base/in_process_browser_test.h"
#include "components/bookmarks/browser/bookmark_model.h"
#include "components/prefs/pref_service.h"

using BraveBookmarkModelLoadedObserverBrowserTest = InProcessBrowserTest;

// This test to mainly testing kOtherBookmarksMigrated, granular testing for
// migration is in BookmarkModelTest::BraveMigrateOtherNodeFolder

namespace {

void CreateOtherBookmarksFolder(bookmarks::BookmarkModel* model) {
const bookmarks::BookmarkNode* other_node_folder = model->AddFolder(
model->bookmark_bar_node(), model->bookmark_bar_node()->children().size(),
model->other_node()->GetTitledUrlNodeTitle());
model->AddFolder(other_node_folder, 0, base::ASCIIToUTF16("A"));
}

} // namespace

IN_PROC_BROWSER_TEST_F(BraveBookmarkModelLoadedObserverBrowserTest,
PRE_OtherBookmarksMigration) {
AlexeyBarabash marked this conversation as resolved.
Show resolved Hide resolved
Profile* profile = browser()->profile();

profile->GetPrefs()->SetBoolean(kOtherBookmarksMigrated, false);

bookmarks::BookmarkModel* bookmark_model =
BookmarkModelFactory::GetForBrowserContext(profile);
CreateOtherBookmarksFolder(bookmark_model);
}

IN_PROC_BROWSER_TEST_F(BraveBookmarkModelLoadedObserverBrowserTest,
OtherBookmarksMigration) {
Profile* profile = browser()->profile();
EXPECT_TRUE(profile->GetPrefs()->GetBoolean(kOtherBookmarksMigrated));

bookmarks::BookmarkModel* bookmark_model =
BookmarkModelFactory::GetForBrowserContext(profile);

ASSERT_EQ(bookmark_model->other_node()->children().size(), 1u);
ASSERT_EQ(bookmark_model->bookmark_bar_node()->children().size(), 0u);
}

IN_PROC_BROWSER_TEST_F(BraveBookmarkModelLoadedObserverBrowserTest,
PRE_NoOtherBookmarksMigration) {
Profile* profile = browser()->profile();

profile->GetPrefs()->SetBoolean(kOtherBookmarksMigrated, true);

bookmarks::BookmarkModel* bookmark_model =
BookmarkModelFactory::GetForBrowserContext(profile);

CreateOtherBookmarksFolder(bookmark_model);
}

IN_PROC_BROWSER_TEST_F(BraveBookmarkModelLoadedObserverBrowserTest,
NoOtherBookmarksMigration) {
Profile* profile = browser()->profile();
EXPECT_TRUE(profile->GetPrefs()->GetBoolean(kOtherBookmarksMigrated));

bookmarks::BookmarkModel* bookmark_model =
BookmarkModelFactory::GetForBrowserContext(profile);

ASSERT_EQ(bookmark_model->other_node()->children().size(), 0u);
ASSERT_EQ(bookmark_model->bookmark_bar_node()->children().size(), 1u);
}
2 changes: 0 additions & 2 deletions browser/ui/BUILD.gn
Original file line number Diff line number Diff line change
Expand Up @@ -57,8 +57,6 @@ source_set("ui") {
"bookmark/bookmark_prefs_service.h",
"bookmark/bookmark_prefs_service_factory.cc",
"bookmark/bookmark_prefs_service_factory.h",
"bookmark/recently_used_folders_combo_model.cc",
"bookmark/recently_used_folders_combo_model.h",
"brave_browser_command_controller.cc",
"brave_browser_command_controller.h",
"brave_browser_content_setting_bubble_model_delegate.cc",
Expand Down
17 changes: 0 additions & 17 deletions browser/ui/bookmark/recently_used_folders_combo_model.cc

This file was deleted.

22 changes: 0 additions & 22 deletions browser/ui/bookmark/recently_used_folders_combo_model.h

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,4 @@

#define GetBrowserContextRedirectedInIncognito \
GetBrowserContextRedirectedInIncognitoOverride
#define ChromeBookmarkClient BraveBookmarkClient
#include "../../../../../chrome/browser/bookmarks/bookmark_model_factory.cc"
#undef ChromeBookmarkClient

This file was deleted.

This file was deleted.

This file was deleted.

Loading