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"
17 namespace user_prefs {
18 class PrefRegistrySyncable;
21 // A collection of bookmark utility functions used by various parts of the UI
22 // that show bookmarks: bookmark manager, bookmark bar view ...
23 namespace bookmark_utils {
25 // Clones bookmark node, adding newly created nodes to |parent| starting at
26 // |index_to_add_at|. If |reset_node_times| is true cloned bookmarks and
27 // folders will receive new creation times and folder modification times
28 // instead of using the values stored in |elements|.
29 void CloneBookmarkNode(BookmarkModel* model,
30 const std::vector<BookmarkNodeData::Element>& elements,
31 const BookmarkNode* parent,
33 bool reset_node_times);
35 // Copies nodes onto the clipboard. If |remove_nodes| is true the nodes are
36 // removed after copied to the clipboard. The nodes are copied in such a way
37 // that if pasted again copies are made.
38 void CopyToClipboard(BookmarkModel* model,
39 const std::vector<const BookmarkNode*>& nodes,
42 // Pastes from the clipboard. The new nodes are added to |parent|, unless
43 // |parent| is null in which case this does nothing. The nodes are inserted
44 // at |index|. If |index| is -1 the nodes are added to the end.
45 void PasteFromClipboard(BookmarkModel* model,
46 const BookmarkNode* parent,
49 // Returns true if the user can copy from the pasteboard.
50 bool CanPasteFromClipboard(const BookmarkNode* node);
52 // Returns a vector containing up to |max_count| of the most recently modified
53 // folders. This never returns an empty vector.
54 std::vector<const BookmarkNode*> GetMostRecentlyModifiedFolders(
55 BookmarkModel* model, size_t max_count);
57 // Returns the most recently added bookmarks. This does not return folders,
58 // only nodes of type url.
59 void GetMostRecentlyAddedEntries(BookmarkModel* model,
61 std::vector<const BookmarkNode*>* nodes);
63 // Returns true if |n1| was added more recently than |n2|.
64 bool MoreRecentlyAdded(const BookmarkNode* n1, const BookmarkNode* n2);
66 // Returns up to |max_count| bookmarks from |model| whose url or title contains
67 // the text |text|. |languages| is user's accept-language setting to decode
69 void GetBookmarksContainingText(BookmarkModel* model,
72 const std::string& languages,
73 std::vector<const BookmarkNode*>* nodes);
75 // Register user preferences for Bookmarks Bar.
76 void RegisterProfilePrefs(user_prefs::PrefRegistrySyncable* registry);
78 // Returns the parent for newly created folders/bookmarks. If |selection| has
79 // one element and it is a folder, |selection[0]| is returned, otherwise
80 // |parent| is returned. If |index| is non-null it is set to the index newly
81 // added nodes should be added at.
82 const BookmarkNode* GetParentForNewNodes(
83 const BookmarkNode* parent,
84 const std::vector<const BookmarkNode*>& selection,
87 // Deletes the bookmark folders for the given list of |ids|.
88 void DeleteBookmarkFolders(BookmarkModel* model, const std::vector<int64>& ids);
90 // If there are no bookmarks for url, a bookmark is created.
91 void AddIfNotBookmarked(BookmarkModel* model,
93 const string16& title);
95 // Removes all bookmarks for the given |url|.
96 void RemoveAllBookmarks(BookmarkModel* model, const GURL& url);
98 } // namespace bookmark_utils
100 #endif // CHROME_BROWSER_BOOKMARKS_BOOKMARK_UTILS_H_