Skip to content

Commit

Permalink
Merge pull request #4404 from brave/restore-other-bookmarks
Browse files Browse the repository at this point in the history
Restore other bookmarks
  • Loading branch information
darkdh authored Feb 20, 2020
2 parents 1fe6b3e + e0d275c commit fad9849
Show file tree
Hide file tree
Showing 37 changed files with 849 additions and 388 deletions.
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"
#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);
#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) {
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

0 comments on commit fad9849

Please sign in to comment.