1 // Copyright (c) 2012 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
5 #ifndef CHROME_BROWSER_BOOKMARKS_BOOKMARK_UTILS_H_
6 #define CHROME_BROWSER_BOOKMARKS_BOOKMARK_UTILS_H_
11 #include "base/strings/string16.h"
12 #include "chrome/browser/bookmarks/bookmark_node_data.h"
18 namespace user_prefs {
19 class PrefRegistrySyncable;
22 // A collection of bookmark utility functions used by various parts of the UI
23 // that show bookmarks: bookmark manager, bookmark bar view ...
24 namespace bookmark_utils {
26 // Fields to use when finding matching bookmarks.
31 scoped_ptr<base::string16> word_phrase_query;
32 scoped_ptr<base::string16> url;
33 scoped_ptr<base::string16> title;
36 // Clones bookmark node, adding newly created nodes to |parent| starting at
37 // |index_to_add_at|. If |reset_node_times| is true cloned bookmarks and
38 // folders will receive new creation times and folder modification times
39 // instead of using the values stored in |elements|.
40 void CloneBookmarkNode(BookmarkModel* model,
41 const std::vector<BookmarkNodeData::Element>& elements,
42 const BookmarkNode* parent,
44 bool reset_node_times);
46 // Copies nodes onto the clipboard. If |remove_nodes| is true the nodes are
47 // removed after copied to the clipboard. The nodes are copied in such a way
48 // that if pasted again copies are made.
49 void CopyToClipboard(BookmarkModel* model,
50 const std::vector<const BookmarkNode*>& nodes,
53 // Pastes from the clipboard. The new nodes are added to |parent|, unless
54 // |parent| is null in which case this does nothing. The nodes are inserted
55 // at |index|. If |index| is -1 the nodes are added to the end.
56 void PasteFromClipboard(BookmarkModel* model,
57 const BookmarkNode* parent,
60 // Returns true if the user can copy from the pasteboard.
61 bool CanPasteFromClipboard(const BookmarkNode* node);
63 // Returns a vector containing up to |max_count| of the most recently modified
64 // folders. This never returns an empty vector.
65 std::vector<const BookmarkNode*> GetMostRecentlyModifiedFolders(
66 BookmarkModel* model, size_t max_count);
68 // Returns the most recently added bookmarks. This does not return folders,
69 // only nodes of type url.
70 void GetMostRecentlyAddedEntries(BookmarkModel* model,
72 std::vector<const BookmarkNode*>* nodes);
74 // Returns true if |n1| was added more recently than |n2|.
75 bool MoreRecentlyAdded(const BookmarkNode* n1, const BookmarkNode* n2);
77 // Returns up to |max_count| bookmarks from |model| whose url or title contain
78 // the text |query.word_phrase_query| and exactly match |query.url| and
79 // |query.title|, for all of the preceding fields that are not NULL.
80 // |languages| is user's accept-language setting to decode IDN.
81 void GetBookmarksMatchingProperties(BookmarkModel* model,
82 const QueryFields& query,
84 const std::string& languages,
85 std::vector<const BookmarkNode*>* nodes);
87 // Register user preferences for Bookmarks Bar.
88 void RegisterProfilePrefs(user_prefs::PrefRegistrySyncable* registry);
90 // Returns the parent for newly created folders/bookmarks. If |selection| has
91 // one element and it is a folder, |selection[0]| is returned, otherwise
92 // |parent| is returned. If |index| is non-null it is set to the index newly
93 // added nodes should be added at.
94 const BookmarkNode* GetParentForNewNodes(
95 const BookmarkNode* parent,
96 const std::vector<const BookmarkNode*>& selection,
99 // Deletes the bookmark folders for the given list of |ids|.
100 void DeleteBookmarkFolders(BookmarkModel* model, const std::vector<int64>& ids);
102 // If there are no bookmarks for url, a bookmark is created.
103 void AddIfNotBookmarked(BookmarkModel* model,
105 const base::string16& title);
107 // Removes all bookmarks for the given |url|.
108 void RemoveAllBookmarks(BookmarkModel* model, const GURL& url);
110 } // namespace bookmark_utils
112 #endif // CHROME_BROWSER_BOOKMARKS_BOOKMARK_UTILS_H_