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|. 27 void CloneBookmarkNode(BookmarkModel* model, 28 const std::vector<BookmarkNodeData::Element>& elements, 29 const BookmarkNode* parent, 30 int index_to_add_at); 31 32 // Copies nodes onto the clipboard. If |remove_nodes| is true the nodes are 33 // removed after copied to the clipboard. The nodes are copied in such a way 34 // that if pasted again copies are made. 35 void CopyToClipboard(BookmarkModel* model, 36 const std::vector<const BookmarkNode*>& nodes, 37 bool remove_nodes); 38 39 // Pastes from the clipboard. The new nodes are added to |parent|, unless 40 // |parent| is null in which case this does nothing. The nodes are inserted 41 // at |index|. If |index| is -1 the nodes are added to the end. 42 void PasteFromClipboard(BookmarkModel* model, 43 const BookmarkNode* parent, 44 int index); 45 46 // Returns true if the user can copy from the pasteboard. 47 bool CanPasteFromClipboard(const BookmarkNode* node); 48 49 // Returns a vector containing up to |max_count| of the most recently modified 50 // folders. This never returns an empty vector. 51 std::vector<const BookmarkNode*> GetMostRecentlyModifiedFolders( 52 BookmarkModel* model, size_t max_count); 53 54 // Returns the most recently added bookmarks. This does not return folders, 55 // only nodes of type url. 56 void GetMostRecentlyAddedEntries(BookmarkModel* model, 57 size_t count, 58 std::vector<const BookmarkNode*>* nodes); 59 60 // Returns true if |n1| was added more recently than |n2|. 61 bool MoreRecentlyAdded(const BookmarkNode* n1, const BookmarkNode* n2); 62 63 // Returns up to |max_count| bookmarks from |model| whose url or title contains 64 // the text |text|. |languages| is user's accept-language setting to decode 65 // IDN. 66 void GetBookmarksContainingText(BookmarkModel* model, 67 const string16& text, 68 size_t max_count, 69 const std::string& languages, 70 std::vector<const BookmarkNode*>* nodes); 71 72 // Returns true if |node|'s url or title contains the string |text|. 73 // |languages| is user's accept-language setting to decode IDN. 74 bool DoesBookmarkContainText(const BookmarkNode* node, 75 const string16& text, 76 const std::string& languages); 77 78 // Register user preferences for Bookmarks Bar. 79 void RegisterProfilePrefs(user_prefs::PrefRegistrySyncable* registry); 80 81 // Returns the parent for newly created folders/bookmarks. If |selection| has 82 // one element and it is a folder, |selection[0]| is returned, otherwise 83 // |parent| is returned. If |index| is non-null it is set to the index newly 84 // added nodes should be added at. 85 const BookmarkNode* GetParentForNewNodes( 86 const BookmarkNode* parent, 87 const std::vector<const BookmarkNode*>& selection, 88 int* index); 89 90 // Deletes the bookmark folders for the given list of |ids|. 91 void DeleteBookmarkFolders(BookmarkModel* model, const std::vector<int64>& ids); 92 93 // If there are no bookmarks for url, a bookmark is created. 94 void AddIfNotBookmarked(BookmarkModel* model, 95 const GURL& url, 96 const string16& title); 97 98 // Removes all bookmarks for the given |url|. 99 void RemoveAllBookmarks(BookmarkModel* model, const GURL& url); 100 101 // This enum is used for the Bookmarks.EntryPoint histogram. 102 enum BookmarkEntryPoint { 103 ENTRY_POINT_ACCELERATOR, 104 ENTRY_POINT_STAR_GESTURE, 105 ENTRY_POINT_STAR_KEY, 106 ENTRY_POINT_STAR_MOUSE, 107 108 ENTRY_POINT_LIMIT // Keep this last. 109 }; 110 111 // This enum is used for the Bookmarks.LaunchLocation histogram. 112 enum BookmarkLaunchLocation { 113 LAUNCH_NONE, 114 LAUNCH_ATTACHED_BAR = 0, 115 LAUNCH_DETACHED_BAR, 116 // These two are kind of sub-categories of the bookmark bar. Generally 117 // a launch from a context menu or subfolder could be classified in one of 118 // the other two bar buckets, but doing so is difficult because the menus 119 // don't know of their greater place in Chrome. 120 LAUNCH_BAR_SUBFOLDER, 121 LAUNCH_CONTEXT_MENU, 122 123 // Bookmarks menu within wrench menu. 124 LAUNCH_WRENCH_MENU, 125 // Bookmark manager. 126 LAUNCH_MANAGER, 127 // Autocomplete suggestion. 128 LAUNCH_OMNIBOX, 129 130 LAUNCH_LIMIT // Keep this last. 131 }; 132 133 // Records the launch of a bookmark for UMA purposes. 134 void RecordBookmarkLaunch(BookmarkLaunchLocation location); 135 136 // Records the user opening a folder of bookmarks for UMA purposes. 137 void RecordBookmarkFolderOpen(BookmarkLaunchLocation location); 138 139 // Records the user opening the apps page for UMA purposes. 140 void RecordAppsPageOpen(BookmarkLaunchLocation location); 141 142 } // namespace bookmark_utils 143 144 #endif // CHROME_BROWSER_BOOKMARKS_BOOKMARK_UTILS_H_ 145