Disable view source for Developer Tools.
[chromium-blink-merge.git] / chrome / browser / bookmarks / bookmark_utils.h
blobfa5086dc8d36df2c5fba606fbbe4a392f39b9574
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_
8 #include <string>
9 #include <vector>
11 #include "base/strings/string16.h"
12 #include "chrome/browser/bookmarks/bookmark_node_data.h"
14 class BookmarkModel;
15 class BookmarkNode;
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 // Fields to use when finding matching bookmarks.
26 struct QueryFields {
27 QueryFields();
28 ~QueryFields();
30 scoped_ptr<base::string16> word_phrase_query;
31 scoped_ptr<base::string16> url;
32 scoped_ptr<base::string16> title;
35 // Clones bookmark node, adding newly created nodes to |parent| starting at
36 // |index_to_add_at|. If |reset_node_times| is true cloned bookmarks and
37 // folders will receive new creation times and folder modification times
38 // instead of using the values stored in |elements|.
39 void CloneBookmarkNode(BookmarkModel* model,
40 const std::vector<BookmarkNodeData::Element>& elements,
41 const BookmarkNode* parent,
42 int index_to_add_at,
43 bool reset_node_times);
45 // Copies nodes onto the clipboard. If |remove_nodes| is true the nodes are
46 // removed after copied to the clipboard. The nodes are copied in such a way
47 // that if pasted again copies are made.
48 void CopyToClipboard(BookmarkModel* model,
49 const std::vector<const BookmarkNode*>& nodes,
50 bool remove_nodes);
52 // Pastes from the clipboard. The new nodes are added to |parent|, unless
53 // |parent| is null in which case this does nothing. The nodes are inserted
54 // at |index|. If |index| is -1 the nodes are added to the end.
55 void PasteFromClipboard(BookmarkModel* model,
56 const BookmarkNode* parent,
57 int index);
59 // Returns true if the user can copy from the pasteboard.
60 bool CanPasteFromClipboard(const BookmarkNode* node);
62 // Returns a vector containing up to |max_count| of the most recently modified
63 // folders. This never returns an empty vector.
64 std::vector<const BookmarkNode*> GetMostRecentlyModifiedFolders(
65 BookmarkModel* model, size_t max_count);
67 // Returns the most recently added bookmarks. This does not return folders,
68 // only nodes of type url.
69 void GetMostRecentlyAddedEntries(BookmarkModel* model,
70 size_t count,
71 std::vector<const BookmarkNode*>* nodes);
73 // Returns true if |n1| was added more recently than |n2|.
74 bool MoreRecentlyAdded(const BookmarkNode* n1, const BookmarkNode* n2);
76 // Returns up to |max_count| bookmarks from |model| whose url or title contain
77 // the text |query.word_phrase_query| and exactly match |query.url| and
78 // |query.title|, for all of the preceding fields that are not NULL.
79 // |languages| is user's accept-language setting to decode IDN.
80 void GetBookmarksMatchingProperties(BookmarkModel* model,
81 const QueryFields& query,
82 size_t max_count,
83 const std::string& languages,
84 std::vector<const BookmarkNode*>* nodes);
86 // Register user preferences for Bookmarks Bar.
87 void RegisterProfilePrefs(user_prefs::PrefRegistrySyncable* registry);
89 // Returns the parent for newly created folders/bookmarks. If |selection| has
90 // one element and it is a folder, |selection[0]| is returned, otherwise
91 // |parent| is returned. If |index| is non-null it is set to the index newly
92 // added nodes should be added at.
93 const BookmarkNode* GetParentForNewNodes(
94 const BookmarkNode* parent,
95 const std::vector<const BookmarkNode*>& selection,
96 int* index);
98 // Deletes the bookmark folders for the given list of |ids|.
99 void DeleteBookmarkFolders(BookmarkModel* model, const std::vector<int64>& ids);
101 // If there are no bookmarks for url, a bookmark is created.
102 void AddIfNotBookmarked(BookmarkModel* model,
103 const GURL& url,
104 const base::string16& title);
106 // Removes all bookmarks for the given |url|.
107 void RemoveAllBookmarks(BookmarkModel* model, const GURL& url);
109 } // namespace bookmark_utils
111 #endif // CHROME_BROWSER_BOOKMARKS_BOOKMARK_UTILS_H_