Upstream version 7.35.144.0
[platform/framework/web/crosswalk.git] / src / chrome / browser / bookmarks / bookmark_utils.h
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 class Profile;
17
18 namespace user_prefs {
19 class PrefRegistrySyncable;
20 }
21
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 {
25
26 // Fields to use when finding matching bookmarks.
27 struct QueryFields {
28   QueryFields();
29   ~QueryFields();
30
31   scoped_ptr<base::string16> word_phrase_query;
32   scoped_ptr<base::string16> url;
33   scoped_ptr<base::string16> title;
34 };
35
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,
43                        int index_to_add_at,
44                        bool reset_node_times);
45
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,
51                      bool remove_nodes);
52
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,
58                         int index);
59
60 // Returns true if the user can copy from the pasteboard.
61 bool CanPasteFromClipboard(const BookmarkNode* node);
62
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);
67
68 // Returns the most recently added bookmarks. This does not return folders,
69 // only nodes of type url.
70 void GetMostRecentlyAddedEntries(BookmarkModel* model,
71                                  size_t count,
72                                  std::vector<const BookmarkNode*>* nodes);
73
74 // Returns true if |n1| was added more recently than |n2|.
75 bool MoreRecentlyAdded(const BookmarkNode* n1, const BookmarkNode* n2);
76
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,
83                                     size_t max_count,
84                                     const std::string& languages,
85                                     std::vector<const BookmarkNode*>* nodes);
86
87 // Register user preferences for Bookmarks Bar.
88 void RegisterProfilePrefs(user_prefs::PrefRegistrySyncable* registry);
89
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,
97     int* index);
98
99 // Deletes the bookmark folders for the given list of |ids|.
100 void DeleteBookmarkFolders(BookmarkModel* model, const std::vector<int64>& ids);
101
102 // If there are no bookmarks for url, a bookmark is created.
103 void AddIfNotBookmarked(BookmarkModel* model,
104                         const GURL& url,
105                         const base::string16& title);
106
107 // Removes all bookmarks for the given |url|.
108 void RemoveAllBookmarks(BookmarkModel* model, const GURL& url);
109
110 }  // namespace bookmark_utils
111
112 #endif  // CHROME_BROWSER_BOOKMARKS_BOOKMARK_UTILS_H_