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. 4 5 #ifndef CHROME_BROWSER_BOOKMARKS_BOOKMARK_UTILS_H_ 6 #define CHROME_BROWSER_BOOKMARKS_BOOKMARK_UTILS_H_ 7 8 #include <string> 9 #include <vector> 10 11 #include "base/strings/string16.h" 12 #include "chrome/browser/bookmarks/bookmark_node_data.h" 13 14 class BookmarkModel; 15 class BookmarkNode; 16 17 namespace user_prefs { 18 class PrefRegistrySyncable; 19 } 20 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 { 24 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, 32 int index_to_add_at, 33 bool reset_node_times); 34 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, 40 bool remove_nodes); 41 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, 47 int index); 48 49 // Returns true if the user can copy from the pasteboard. 50 bool CanPasteFromClipboard(const BookmarkNode* node); 51 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); 56 57 // Returns the most recently added bookmarks. This does not return folders, 58 // only nodes of type url. 59 void GetMostRecentlyAddedEntries(BookmarkModel* model, 60 size_t count, 61 std::vector<const BookmarkNode*>* nodes); 62 63 // Returns true if |n1| was added more recently than |n2|. 64 bool MoreRecentlyAdded(const BookmarkNode* n1, const BookmarkNode* n2); 65 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 68 // IDN. 69 void GetBookmarksContainingText(BookmarkModel* model, 70 const base::string16& text, 71 size_t max_count, 72 const std::string& languages, 73 std::vector<const BookmarkNode*>* nodes); 74 75 // Register user preferences for Bookmarks Bar. 76 void RegisterProfilePrefs(user_prefs::PrefRegistrySyncable* registry); 77 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, 85 int* index); 86 87 // Deletes the bookmark folders for the given list of |ids|. 88 void DeleteBookmarkFolders(BookmarkModel* model, const std::vector<int64>& ids); 89 90 // If there are no bookmarks for url, a bookmark is created. 91 void AddIfNotBookmarked(BookmarkModel* model, 92 const GURL& url, 93 const base::string16& title); 94 95 // Removes all bookmarks for the given |url|. 96 void RemoveAllBookmarks(BookmarkModel* model, const GURL& url); 97 98 } // namespace bookmark_utils 99 100 #endif // CHROME_BROWSER_BOOKMARKS_BOOKMARK_UTILS_H_ 101