#include "components/bookmarks/browser/bookmark_utils.h"
#include <stdint.h>
#include <memory>
#include <unordered_set>
#include <utility>
#include "base/containers/contains.h"
#include "base/files/file_path.h"
#include "base/functional/bind.h"
#include "base/i18n/case_conversion.h"
#include "base/i18n/string_search.h"
#include "base/memory/raw_ptr.h"
#include "base/metrics/user_metrics.h"
#include "base/metrics/user_metrics_action.h"
#include "base/ranges/algorithm.h"
#include "base/strings/string_util.h"
#include "base/strings/stringprintf.h"
#include "base/strings/utf_string_conversions.h"
#include "base/time/time.h"
#include "base/uuid.h"
#include "build/build_config.h"
#include "components/bookmarks/browser/bookmark_client.h"
#include "components/bookmarks/browser/bookmark_model.h"
#include "components/bookmarks/browser/scoped_group_bookmark_actions.h"
#include "components/bookmarks/common/bookmark_pref_names.h"
#include "components/pref_registry/pref_registry_syncable.h"
#include "components/prefs/pref_service.h"
#include "components/query_parser/query_parser.h"
#include "components/url_formatter/url_formatter.h"
#include "ui/base/clipboard/clipboard.h"
#include "ui/base/data_transfer_policy/data_transfer_endpoint.h"
#include "ui/base/models/tree_node_iterator.h"
#include "url/gurl.h"
Time;
namespace bookmarks {
namespace {
const size_t kCleanedUpUrlMaxLength = …;
const size_t kCleanedUpTitleMaxLength = …;
void CloneBookmarkNodeImpl(BookmarkModel* model,
const BookmarkNodeData::Element& element,
const BookmarkNode* parent,
size_t index_to_add_at,
bool reset_node_times) { … }
bool MoreRecentlyModified(const BookmarkNode* n1, const BookmarkNode* n2) { … }
bool DoesBookmarkTextContainWords(const std::u16string& text,
const std::vector<std::u16string>& words) { … }
bool PruneInvisibleFolders(const BookmarkNode* node) { … }
bool HasSelectedAncestor(
BookmarkModel* model,
const std::vector<raw_ptr<const BookmarkNode, VectorExperimental>>&
selected_nodes,
const BookmarkNode* node) { … }
template <typename Predicate>
const BookmarkNode* FindNode(const BookmarkNode* node, Predicate pred) { … }
std::string TruncateUrl(const std::string& url) { … }
GURL GetUrlFromClipboard(bool notify_if_restricted) { … }
template <class type>
std::vector<const BookmarkNode*> GetBookmarksMatchingPropertiesImpl(
type& iterator,
BookmarkModel* model,
const QueryFields& query,
const std::vector<std::u16string>& query_words,
size_t max_count) { … }
template <class Comparator>
void GetMostRecentEntries(
BookmarkModel* model,
size_t limit,
std::multiset<const BookmarkNode*, Comparator>* nodes_set) { … }
#if BUILDFLAG(IS_ANDROID)
bool HasUserCreatedBookmarks(BookmarkModel* model) {
const BookmarkNode* root_node = model->root_node();
return base::ranges::any_of(root_node->children(), [](const auto& node) {
return !node->children().empty();
});
}
#endif
}
QueryFields::QueryFields() { … }
QueryFields::~QueryFields() { … }
VectorIterator::VectorIterator(
std::vector<raw_ptr<const BookmarkNode, VectorExperimental>>* nodes)
: … { … }
VectorIterator::~VectorIterator() = default;
bool VectorIterator::has_next() { … }
const BookmarkNode* VectorIterator::Next() { … }
void CloneBookmarkNode(BookmarkModel* model,
const std::vector<BookmarkNodeData::Element>& elements,
const BookmarkNode* parent,
size_t index_to_add_at,
bool reset_node_times) { … }
void CopyToClipboard(
BookmarkModel* model,
const std::vector<raw_ptr<const BookmarkNode, VectorExperimental>>& nodes,
bool remove_nodes,
metrics::BookmarkEditSource source,
bool is_off_the_record) { … }
void MakeTitleUnique(const BookmarkModel* model,
const BookmarkNode* parent,
const GURL& url,
std::u16string* title) { … }
void PasteFromClipboard(BookmarkModel* model,
const BookmarkNode* parent,
size_t index) { … }
bool CanPasteFromClipboard(BookmarkModel* model, const BookmarkNode* node) { … }
std::vector<const BookmarkNode*> GetMostRecentlyModifiedUserFolders(
BookmarkModel* model,
size_t max_count) { … }
void GetMostRecentlyAddedEntries(BookmarkModel* model,
size_t count,
std::vector<const BookmarkNode*>* nodes) { … }
bool MoreRecentlyAdded(const BookmarkNode* n1, const BookmarkNode* n2) { … }
void GetMostRecentlyUsedEntries(BookmarkModel* model,
size_t count,
std::vector<const BookmarkNode*>* nodes) { … }
std::vector<const BookmarkNode*> GetBookmarksMatchingProperties(
BookmarkModel* model,
const QueryFields& query,
size_t max_count) { … }
std::vector<std::u16string> ParseBookmarkQuery(
const bookmarks::QueryFields& query) { … }
bool DoesBookmarkContainWords(const std::u16string& title,
const GURL& url,
const std::vector<std::u16string>& words) { … }
void RegisterProfilePrefs(user_prefs::PrefRegistrySyncable* registry) { … }
void RegisterManagedBookmarksPrefs(PrefRegistrySimple* registry) { … }
const BookmarkNode* GetParentForNewNodes(
const BookmarkNode* parent,
const std::vector<raw_ptr<const BookmarkNode, VectorExperimental>>&
selection,
size_t* index) { … }
void DeleteBookmarkFolders(BookmarkModel* model,
const std::vector<int64_t>& ids,
const base::Location& location) { … }
const BookmarkNode* AddIfNotBookmarked(BookmarkModel* model,
const GURL& url,
const std::u16string& title,
const BookmarkNode* parent) { … }
void RemoveAllBookmarks(BookmarkModel* model,
const GURL& url,
const base::Location& location) { … }
std::u16string CleanUpUrlForMatching(
const GURL& gurl,
base::OffsetAdjuster::Adjustments* adjustments) { … }
std::u16string CleanUpTitleForMatching(const std::u16string& title) { … }
bool CanAllBeEditedByUser(
BookmarkClient* client,
const std::vector<raw_ptr<const BookmarkNode, VectorExperimental>>& nodes) { … }
bool IsBookmarkedByUser(BookmarkModel* model, const GURL& url) { … }
const BookmarkNode* GetBookmarkNodeByID(const BookmarkModel* model,
int64_t id) { … }
bool IsDescendantOf(const BookmarkNode* node, const BookmarkNode* root) { … }
bool HasDescendantsOf(
const std::vector<raw_ptr<const BookmarkNode, VectorExperimental>>& list,
const BookmarkNode* root) { … }
const BookmarkNode* GetParentForNewNodes(BookmarkModel* model,
const GURL& url) { … }
}