Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(140)

Side by Side Diff: chrome/browser/bookmarks/bookmark_tag_model.h

Issue 26894002: Experimental bookmark model based on tags. (Closed) Base URL: http://git.chromium.org/chromium/src.git@master
Patch Set: s/tab/tag Created 7 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
(Empty)
1 // Copyright (c) 2013 The Chromium Authors. All rights reserved.
lpromero-g 2013/10/14 09:18:17 nit: No (c). Here and in every new file (also chec
noyau (Ping after 24h) 2013/10/14 23:59:39 Done.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4 #ifndef CHROME_BROWSER_BOOKMARKS_BOOKMARK_TAG_MODEL_H_
sky 2013/10/11 21:57:41 nit: newline between 3/4.
noyau (Ping after 24h) 2013/10/14 23:59:39 Done.
5 #define CHROME_BROWSER_BOOKMARKS_BOOKMARK_TAG_MODEL_H_
6
7 #include "chrome/browser/bookmarks/bookmark_model.h"
8 #include "chrome/browser/bookmarks/bookmark_model_observer.h"
9
10 class BookmarkTagModelObserver;
11
12 typedef string16 BookmarkTag;
13
14 // BookmarTagModel provides a way to access and manipulate bookmarks in a non
sky 2013/10/11 21:57:41 nit: non-hierarchical
noyau (Ping after 24h) 2013/10/14 23:59:39 Done.
15 // hierarchical way. It converts on demand the data from an existing
16 // BookmarkModel to its warped view of the world. It also uses the BookmarkModel
sky 2013/10/11 21:57:41 HAH! Please document better what 'warped view of t
noyau (Ping after 24h) 2013/10/14 23:59:39 Done.
17 // for storage.
18 //
19 // BookmarkTagModel view the bookmarks as a flat list, and each one can be
20 // marked with a collection of tags.
21 //
22 // An observer may be attached to a BookmarkTagModel to observe relevant events.
23 //
24 class BookmarkTagModel : public BookmarkModelObserver {
25 public:
26
27 // Used to sort bookmarks.
28 enum BookmarkOrdering {
sky 2013/10/11 21:57:41 Name enums as document in component: "enum values
noyau (Ping after 24h) 2013/10/14 23:59:39 Done.
29 UNSORTED_BOOKMARK_ORDERING, // No sort applied.
30 TITLE_BOOKMARK_ORDERING, // Sort by title.
31 URL_BOOKMARK_ORDERING, // Sort by URL.
32 CREATION_TIME_BOOKMARK_ORDERING, // Sort by creation time.
33 };
sky 2013/10/11 21:57:41 Is there a reason you baked sorting into these fun
noyau (Ping after 24h) 2013/10/14 23:59:39 I've removed the ordering for everything, includin
34
35 // Used to sort tags.
36 enum TagOrdering {
37 UNSORTED_TAG_ORDERING, // No sort applied.
38 MOST_USED_TAG_ORDERING, // Order by count of tagged bookmarks.
39 ALPHABETICAL_TAG_ORDERING, // Alphabetical order.
40 };
41
42 explicit BookmarkTagModel(BookmarkModel* bookmark_model);
43 virtual ~BookmarkTagModel();
44
45 // Returns true if the model finished loading.
46 bool loaded() const { return loaded_; }
47
48 // Add and remove observers on this object.
49 void AddObserver(BookmarkTagModelObserver* observer);
50 void RemoveObserver(BookmarkTagModelObserver* observer);
51
52 // Notifies the observers that an extensive set of changes is about to happen,
53 // such as during import or sync, so they can delay any expensive UI updates
54 // until it's finished.
55 void BeginExtensiveChanges();
sky 2013/10/11 21:57:41 Can you hide these behind a scoper object that is
noyau (Ping after 24h) 2013/10/14 23:59:39 Done.
56 void EndExtensiveChanges();
57
58 // Returns true if this bookmark model is currently in a mode where extensive
59 // changes might happen, such as for import and sync. This is helpful for
60 // observers that are created after the mode has started, and want to check
61 // state during their own initializer.
62 bool IsDoingExtensiveChanges() const;
63
64 // Removes the given |BookmarkNode|. Observers are notified immediately.
65 void Remove(const BookmarkNode* bookmark);
66
67 // Removes all the bookmark nodes. Observers are only notified when all nodes
68 // have been removed. There is no notification for individual node removals.
69 void RemoveAll();
70
71 // Returns the favicon for |node|. If the favicon has not yet been
72 // loaded it is loaded and the observer of the model notified when done.
73 const gfx::Image& GetFavicon(const BookmarkNode* bookmark);
74
75 // Sets the title of |node|.
76 void SetTitle(const BookmarkNode* bookmark, const string16& title);
77
78 // Sets the URL of |node|.
79 void SetURL(const BookmarkNode* bookmark, const GURL& url);
80
81 // Sets the date added time of |node|.
82 void SetDateAdded(const BookmarkNode* bookmark, base::Time date_added);
83
84 // Returns the most recently added bookmark for the |url|. Returns NULL if
85 // |url| is not bookmarked.
86 const BookmarkNode* GetMostRecentlyAddedBookmarkForURL(const GURL& url);
87
88 // Creates a new bookmark.
89 const BookmarkNode* AddURL(const string16& title,
90 const GURL& url,
91 const std::set<BookmarkTag>& tags);
92
93 // Adds the |tags| to the tag list of the |bookmark|.
94 void AddTagsToBookmark(const std::set<BookmarkTag>& tags,
95 const BookmarkNode* bookmark);
96
97 // Same but to a whole collection of |bookmarks|.
98 void AddTagsToBookmarks(const std::set<BookmarkTag>& tags,
99 const std::set<const BookmarkNode*>& bookmarks);
100
101 // Remove the |tags| from the tag list of the |bookmark|. If the bookmark
102 // is not tagged with one or more of the tags, these are ignored.
103 void RemoveTagsFromBookmark(const std::set<BookmarkTag>& tags,
104 const BookmarkNode* bookmark);
105
106 // Same but to a whole collection of |bookmarks|.
107 void RemoveTagsFromBookmarks(const std::set<BookmarkTag>& tags,
108 const std::set<const BookmarkNode*>& bookmarks);
109
110 // Returns all the tags set on a specific |bookmark|.
111 std::set<BookmarkTag> AllTagsForBookmark(const BookmarkNode* bookmark);
sky 2013/10/11 21:57:41 GetTagsForBookmark?
noyau (Ping after 24h) 2013/10/14 23:59:39 Done.
112
113 // Returns the bookmarks marked with all the given |tags| sorted with the
114 // specified |ordering|.
115 std::vector<const BookmarkNode*> BookmarksForTags(
116 const std::set<BookmarkTag>& tags, BookmarkOrdering ordering);
sky 2013/10/11 21:57:41 nit: when you wrap, one line per param.
117
118 // Returns the bookmarks marked with the given |tag| sorted with the specified
119 // |ordering|.
120 std::vector<const BookmarkNode*> BookmarksForTag(const BookmarkTag& tag,
121 BookmarkOrdering ordering);
122
123 // Returns all tags related to the parent |tag|. If |tag| is null this method
124 // will returns and sort all tags in the system. A related tag is a tag used
125 // on one or more of the bookmarks tagged with |tag|.
126 std::vector<BookmarkTag> TagsRelatedToTag(const BookmarkTag& tag,
127 TagOrdering ordering);
128
129 // All the BookmarkModelObserver methods. See there for details.
130 virtual void Loaded(BookmarkModel* model, bool ids_reassigned) OVERRIDE;
131 virtual void BookmarkModelBeingDeleted(BookmarkModel* model) OVERRIDE;
132 virtual void BookmarkNodeMoved(BookmarkModel* model,
133 const BookmarkNode* old_parent,
134 int old_index,
135 const BookmarkNode* new_parent,
136 int new_index) OVERRIDE;
137 virtual void BookmarkNodeAdded(BookmarkModel* model,
138 const BookmarkNode* parent,
139 int index) OVERRIDE;
140 virtual void OnWillRemoveBookmarks(BookmarkModel* model,
141 const BookmarkNode* parent,
142 int old_index,
143 const BookmarkNode* node) OVERRIDE;
144 virtual void BookmarkNodeRemoved(BookmarkModel* model,
145 const BookmarkNode* parent,
146 int old_index,
147 const BookmarkNode* node) OVERRIDE;
148 virtual void OnWillChangeBookmarkNode(BookmarkModel* model,
149 const BookmarkNode* node) OVERRIDE;
150 virtual void BookmarkNodeChanged(BookmarkModel* model,
151 const BookmarkNode* node) OVERRIDE;
152 virtual void OnWillChangeBookmarkMetaInfo(BookmarkModel* model,
153 const BookmarkNode* node) OVERRIDE;
154 virtual void BookmarkMetaInfoChanged(BookmarkModel* model,
155 const BookmarkNode* node) OVERRIDE;
156 virtual void BookmarkNodeFaviconChanged(BookmarkModel* model,
157 const BookmarkNode* node) OVERRIDE;
158 virtual void OnWillReorderBookmarkNode(BookmarkModel* model,
159 const BookmarkNode* node) OVERRIDE;
160 virtual void BookmarkNodeChildrenReordered(BookmarkModel* model,
161 const BookmarkNode* node) OVERRIDE;
162 virtual void ExtensiveBookmarkChangesBeginning(BookmarkModel* model) OVERRIDE;
163 virtual void ExtensiveBookmarkChangesEnded(BookmarkModel* model) OVERRIDE;
164 virtual void OnWillRemoveAllBookmarks(BookmarkModel* model) OVERRIDE;
165 virtual void BookmarkAllNodesRemoved(BookmarkModel* model) OVERRIDE;
166
167 private:
168 // The tags are currently stored in the BookmarkNode's metaInfo in JSON
169 // format. This method extracts the info from there and returns it in
170 // digestible format.
171 // If the Bookmark was never tagged before it is implicitely tagged with the
172 // title of all its ancestors in the BookmarkModel.
173 std::set<BookmarkTag> ExtractTagsFromBookmark(const BookmarkNode *bookmark);
174
175 // Encode the tags in a format suitable for the BookmarkNode's metaInfo and
176 // set or replace the value.
177 void ReplaceTagsOnBookmark(const std::set<BookmarkTag>& tags,
sky 2013/10/11 21:57:41 nit: SetTagsOnBookmark ?
noyau (Ping after 24h) 2013/10/14 23:59:39 Done.
178 const BookmarkNode* bookmark);
179
180 // Build the caches of tag to bookmarks and bookmarks to tag for faster
181 // access to the data. Load() is called from the constructor if possible, or
182 // as soon as possible after that.
183 void Load();
184
185 // Clear the local cache of all mentions of |bookmark|.
186 void RemoveBookmark(const BookmarkNode* bookmark);
187
188 // Extract the tags from |bookmark| and insert it in the local cache.
189 void LoadBookmark(const BookmarkNode* bookmark);
190
191 // The model from where the data is permanently stored.
192 BookmarkModel *bookmark_model_;
193
194 // True if the model is fully loaded.
195 bool loaded_;
196
197 // The observers.
198 ObserverList<BookmarkTagModelObserver> observers_;
199
200 // Local cache for quick access.
201 std::map<const BookmarkTag, std::set<const BookmarkNode*> > tag_to_bookmarks_;
202 std::map<const BookmarkNode*, std::set<BookmarkTag> > bookmark_to_tags_;
203
204 // Set to true during the creation of a new bookmark in order to send only the
205 // proper notification.
206 bool inhibit_change_notifications_;
207 };
sky 2013/10/11 21:57:41 DISALLOW...
noyau (Ping after 24h) 2013/10/14 23:59:39 Done.
208
209 #endif // CHROME_BROWSER_BOOKMARKS_BOOKMARK_TAG_MODEL_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698