-
Notifications
You must be signed in to change notification settings - Fork 892
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
Restore other bookmarks #4404
Changes from all commits
aa5daa2
eaf5dd9
bee58c5
4a7b0eb
9a24d39
bb803e2
e530aef
1e700d1
43e450f
eb12743
769c336
87a0a38
fbf40d4
b5e896a
e0d275c
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
This file was deleted.
This file was deleted.
This file was deleted.
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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) | ||
|
@@ -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); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. nit: it's a little confusing to put this in the There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 |
||
#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); | ||
} |
This file was deleted.
This file was deleted.
This file was deleted.
This file was deleted.
This file was deleted.
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
fixed in 07e019e