Skip to content

Commit

Permalink
TEMPORARY: bookmarks workaround. #2010 Pending.
Browse files Browse the repository at this point in the history
  • Loading branch information
mkarolin committed Aug 20, 2019
1 parent 1c54c41 commit 55fd350
Show file tree
Hide file tree
Showing 6 changed files with 71 additions and 66 deletions.
9 changes: 5 additions & 4 deletions browser/bookmarks/brave_bookmark_client.cc
Original file line number Diff line number Diff line change
Expand Up @@ -22,12 +22,13 @@ BraveBookmarkClient::BraveBookmarkClient(
managed_bookmark_service,
bookmark_sync_service) {}

bookmarks::LoadExtraCallback BraveBookmarkClient::GetLoadExtraNodesCallback() {
bookmarks::LoadManagedNodeCallback
BraveBookmarkClient::GetLoadManagedNodeCallback() {
#if BUILDFLAG(ENABLE_BRAVE_SYNC)
return base::BindOnce(&brave_sync::LoadExtraNodes,
ChromeBookmarkClient::GetLoadExtraNodesCallback());
return base::BindOnce(&brave_sync::LoadManagedNode,
ChromeBookmarkClient::GetLoadManagedNodeCallback());
#endif
return ChromeBookmarkClient::GetLoadExtraNodesCallback();
return ChromeBookmarkClient::GetLoadManagedNodeCallback();
}

bool BraveBookmarkClient::IsPermanentNodeVisible(
Expand Down
2 changes: 1 addition & 1 deletion browser/bookmarks/brave_bookmark_client.h
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ class BraveBookmarkClient : public ChromeBookmarkClient {
bookmarks::ManagedBookmarkService* managed_bookmark_service,
sync_bookmarks::BookmarkSyncService* bookmark_sync_service);

bookmarks::LoadExtraCallback GetLoadExtraNodesCallback() override;
bookmarks::LoadManagedNodeCallback GetLoadManagedNodeCallback() override;
bool IsPermanentNodeVisible(
const bookmarks::BookmarkPermanentNode* node) override;

Expand Down
5 changes: 3 additions & 2 deletions components/brave_sync/brave_sync_service.h
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,9 @@ class BraveSyncServiceObserver;
class Settings;
class SyncDevices;

bookmarks::BookmarkPermanentNodeList
LoadExtraNodes(bookmarks::LoadExtraCallback callback, int64_t* next_node_id);
std::unique_ptr<bookmarks::BookmarkPermanentNode> LoadManagedNode(
bookmarks::LoadManagedNodeCallback callback,
int64_t* next_node_id);
bool IsSyncManagedNode(const bookmarks::BookmarkPermanentNode* node);

class BraveSyncService : public KeyedService {
Expand Down
79 changes: 41 additions & 38 deletions components/brave_sync/client/bookmark_change_processor.cc
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@

#include "base/strings/string_number_conversions.h"
#include "base/strings/utf_string_conversions.h"
#include "brave/components/brave_sync/brave_sync_service.h"
#include "brave/components/brave_sync/bookmark_order_util.h"
#include "brave/components/brave_sync/client/bookmark_node.h"
#include "brave/components/brave_sync/jslib_const.h"
Expand Down Expand Up @@ -80,21 +81,13 @@ bool IsSyncManagedNode(const bookmarks::BookmarkPermanentNode* node) {
return IsSyncManagedNodeDeleted(node) || IsSyncManagedNodePending(node);
}

bookmarks::BookmarkPermanentNodeList
LoadExtraNodes(bookmarks::LoadExtraCallback callback,
std::unique_ptr<bookmarks::BookmarkPermanentNode> LoadManagedNode(
bookmarks::LoadManagedNodeCallback callback,
int64_t* next_node_id) {
// TODO(bridiver) - deleted node should not be visible
bookmarks::BookmarkPermanentNodeList extra_nodes;
if (callback)
extra_nodes = std::move(callback).Run(next_node_id);

auto deleted_node = MakePermanentNode(kDeletedBookmarksTitle, next_node_id);
extra_nodes.push_back(std::move(deleted_node));

auto pending_node = MakePermanentNode(kPendingBookmarksTitle, next_node_id);
extra_nodes.push_back(std::move(pending_node));

return extra_nodes;
return std::move(callback).Run(next_node_id);
return nullptr;
}

namespace {
Expand Down Expand Up @@ -797,38 +790,48 @@ void BookmarkChangeProcessor::GetAllSyncData(

bookmarks::BookmarkNode* BookmarkChangeProcessor::GetDeletedNodeRoot() {
if (!deleted_node_root_) {
ui::TreeNodeIterator<const bookmarks::BookmarkNode>
iterator(bookmark_model_->root_node());
while (iterator.has_next()) {
const bookmarks::BookmarkNode* node = iterator.Next();
if (node->is_permanent_node() &&
IsSyncManagedNodeDeleted(
static_cast<const bookmarks::BookmarkPermanentNode*>(node))) {
deleted_node_root_ = const_cast<bookmarks::BookmarkNode*>(node);
return deleted_node_root_;
}
}
int64_t next_node_id = bookmark_model_->next_node_id();
deleted_node_root_ =
MakePermanentNode(kDeletedBookmarksTitle, &next_node_id);
bookmark_model_->Move(deleted_node_root_.get(),
bookmark_model_->root_node(), 0);
//ui::TreeNodeIterator<const bookmarks::BookmarkNode>
// iterator(bookmark_model_->root_node());
//while (iterator.has_next()) {
// const bookmarks::BookmarkNode* node = iterator.Next();
// if (node->is_permanent_node() &&
// IsSyncManagedNodeDeleted(
// static_cast<const bookmarks::BookmarkPermanentNode*>(node))) {
// deleted_node_root_ = const_cast<bookmarks::BookmarkNode*>(node);
// return deleted_node_root_;
// }
//}
}
DCHECK(deleted_node_root_);
return deleted_node_root_;
DCHECK(deleted_node_root_.get());
return deleted_node_root_.get();
}

bookmarks::BookmarkNode* BookmarkChangeProcessor::GetPendingNodeRoot() {
if (!pending_node_root_) {
ui::TreeNodeIterator<const bookmarks::BookmarkNode>
iterator(bookmark_model_->root_node());
while (iterator.has_next()) {
const bookmarks::BookmarkNode* node = iterator.Next();
if (node->is_permanent_node() &&
IsSyncManagedNodePending(
static_cast<const bookmarks::BookmarkPermanentNode*>(node))) {
pending_node_root_ = const_cast<bookmarks::BookmarkNode*>(node);
return pending_node_root_;
}
}
int64_t next_node_id = bookmark_model_->next_node_id();
pending_node_root_ =
MakePermanentNode(kPendingBookmarksTitle, &next_node_id);
bookmark_model_->Move(pending_node_root_.get(),
bookmark_model_->root_node(), 0);
// ui::TreeNodeIterator<const bookmarks::BookmarkNode>
// iterator(bookmark_model_->root_node());
//while (iterator.has_next()) {
// const bookmarks::BookmarkNode* node = iterator.Next();
// if (node->is_permanent_node() &&
// IsSyncManagedNodePending(
// static_cast<const bookmarks::BookmarkPermanentNode*>(node))) {
// pending_node_root_ = const_cast<bookmarks::BookmarkNode*>(node);
// return pending_node_root_;
// }
//}
}
DCHECK(pending_node_root_);
return pending_node_root_;
DCHECK(pending_node_root_.get());
return pending_node_root_.get();
}

int BookmarkChangeProcessor::FindMigrateSubOrderLength(
Expand Down
4 changes: 2 additions & 2 deletions components/brave_sync/client/bookmark_change_processor.h
Original file line number Diff line number Diff line change
Expand Up @@ -136,8 +136,8 @@ class BookmarkChangeProcessor : public ChangeProcessor,
Profile* profile_; // not owned
bookmarks::BookmarkModel* bookmark_model_; // not owned

bookmarks::BookmarkNode* deleted_node_root_;
bookmarks::BookmarkNode* pending_node_root_;
std::unique_ptr<bookmarks::BookmarkNode> deleted_node_root_;
std::unique_ptr<bookmarks::BookmarkNode> pending_node_root_;

DISALLOW_COPY_AND_ASSIGN(BookmarkChangeProcessor);
};
Expand Down
38 changes: 19 additions & 19 deletions components/brave_sync/test_util.cc
Original file line number Diff line number Diff line change
Expand Up @@ -18,20 +18,20 @@
#include "components/sync_preferences/pref_service_mock_factory.h"
#include "components/sync_preferences/testing_pref_service_syncable.h"

namespace {

using namespace bookmarks;

void AddPermanentNode(BookmarkPermanentNodeList* extra_nodes, int64_t id,
const std::string& title) {
auto node = std::make_unique<brave_sync::BraveBookmarkPermanentNode>(id);
node->set_type(bookmarks::BookmarkNode::FOLDER);
node->set_visible(false);
node->SetTitle(base::UTF8ToUTF16(title));
extra_nodes->push_back(std::move(node));
}

} // namespace
//namespace {
//
//using namespace bookmarks;
//
//void AddPermanentNode(BookmarkPermanentNodeList* extra_nodes, int64_t id,
// const std::string& title) {
// auto node = std::make_unique<brave_sync::BraveBookmarkPermanentNode>(id);
// node->set_type(bookmarks::BookmarkNode::FOLDER);
// node->set_visible(false);
// node->SetTitle(base::UTF8ToUTF16(title));
// extra_nodes->push_back(std::move(node));
//}
//
//} // namespace

namespace brave_sync {

Expand Down Expand Up @@ -59,13 +59,13 @@ std::unique_ptr<KeyedService> BuildFakeBookmarkModelForTests(
// Don't need context, unless we have more than one profile
using namespace bookmarks;
std::unique_ptr<TestBookmarkClient> client(new TestBookmarkClient());
BookmarkPermanentNodeList extra_nodes;
//BookmarkPermanentNodeList extra_nodes;

// These hard-coded titles cannot be changed
AddPermanentNode(&extra_nodes, 0xDE1E7ED40DE, "Deleted Bookmarks");
AddPermanentNode(&extra_nodes, 0x9E7D17640DE, "Pending Bookmarks");
//// These hard-coded titles cannot be changed
//AddPermanentNode(&extra_nodes, 0xDE1E7ED40DE, "Deleted Bookmarks");
//AddPermanentNode(&extra_nodes, 0x9E7D17640DE, "Pending Bookmarks");

client->SetExtraNodesToLoad(std::move(extra_nodes));
//client->SetExtraNodesToLoad(std::move(extra_nodes));
std::unique_ptr<BookmarkModel> model(
TestBookmarkClient::CreateModelWithClient(std::move(client)));
return model;
Expand Down

0 comments on commit 55fd350

Please sign in to comment.