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

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

Issue 1912: Renames BoomarkBarModel to BookmarkModel. (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: '' Created 12 years, 3 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 | Annotate | Revision Log
OLDNEW
1 // Copyright (c) 2006-2008 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2006-2008 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #ifndef CHROME_BROWSER_BOOKMARKS_BOOKMARK_BAR_MODEL_H_ 5 #ifndef CHROME_BROWSER_BOOKMARKS_BOOKMARK_BAR_MODEL_H_
6 #define CHROME_BROWSER_BOOKMARKS_BOOKMARK_BAR_MODEL_H_ 6 #define CHROME_BROWSER_BOOKMARKS_BOOKMARK_BAR_MODEL_H_
7 7
8 #include "base/lock.h" 8 #include "base/lock.h"
9 #include "base/observer_list.h" 9 #include "base/observer_list.h"
10 #include "base/scoped_handle.h" 10 #include "base/scoped_handle.h"
11 #include "chrome/browser/bookmarks/bookmark_service.h" 11 #include "chrome/browser/bookmarks/bookmark_service.h"
12 #include "chrome/browser/bookmarks/bookmark_storage.h" 12 #include "chrome/browser/bookmarks/bookmark_storage.h"
13 #include "chrome/browser/cancelable_request.h" 13 #include "chrome/browser/cancelable_request.h"
14 #include "chrome/browser/history/history.h" 14 #include "chrome/browser/history/history.h"
15 #include "chrome/browser/history/history_types.h" 15 #include "chrome/browser/history/history_types.h"
16 #include "chrome/common/notification_service.h" 16 #include "chrome/common/notification_service.h"
17 #include "chrome/views/tree_node_model.h" 17 #include "chrome/views/tree_node_model.h"
18 #include "googleurl/src/gurl.h" 18 #include "googleurl/src/gurl.h"
19 #include "skia/include/SkBitmap.h" 19 #include "skia/include/SkBitmap.h"
20 20
21 class BookmarkBarModel; 21 class BookmarkModel;
22 class BookmarkCodec; 22 class BookmarkCodec;
23 class Profile; 23 class Profile;
24 24
25 namespace history { 25 namespace history {
26 class StarredURLDatabase; 26 class StarredURLDatabase;
27 } 27 }
28 28
29 // BookmarkBarNode ------------------------------------------------------------ 29 // BookmarkNode ---------------------------------------------------------------
30 30
31 // BookmarkBarNode contains information about a starred entry: title, URL, 31 // BookmarkNode contains information about a starred entry: title, URL, favicon,
32 // favicon, star id and type. BookmarkBarNodes are returned from a 32 // star id and type. BookmarkNodes are returned from a BookmarkModel.
33 // BookmarkBarModel.
34 // 33 //
35 class BookmarkBarNode : public ChromeViews::TreeNode<BookmarkBarNode> { 34 class BookmarkNode : public ChromeViews::TreeNode<BookmarkNode> {
36 friend class BookmarkBarModel; 35 friend class BookmarkModel;
37 friend class BookmarkCodec; 36 friend class BookmarkCodec;
38 friend class history::StarredURLDatabase; 37 friend class history::StarredURLDatabase;
39 FRIEND_TEST(BookmarkBarModelTest, MostRecentlyAddedEntries); 38 FRIEND_TEST(BookmarkModelTest, MostRecentlyAddedEntries);
40 39
41 public: 40 public:
42 BookmarkBarNode(BookmarkBarModel* model, const GURL& url); 41 BookmarkNode(BookmarkModel* model, const GURL& url);
43 virtual ~BookmarkBarNode() {} 42 virtual ~BookmarkNode() {}
44 43
45 // Returns the favicon for the this node. If the favicon has not yet been 44 // Returns the favicon for the this node. If the favicon has not yet been
46 // loaded it is loaded and the observer of the model notified when done. 45 // loaded it is loaded and the observer of the model notified when done.
47 const SkBitmap& GetFavIcon(); 46 const SkBitmap& GetFavIcon();
48 47
49 // Returns the URL. 48 // Returns the URL.
50 const GURL& GetURL() const { return url_; } 49 const GURL& GetURL() const { return url_; }
51 50
52 // Returns a unique id for this node. 51 // Returns a unique id for this node.
53 // 52 //
(...skipping 25 matching lines...) Expand all
79 bool is_url() const { return type_ == history::StarredEntry::URL; } 78 bool is_url() const { return type_ == history::StarredEntry::URL; }
80 79
81 // TODO(sky): Consider adding last visit time here, it'll greatly simplify 80 // TODO(sky): Consider adding last visit time here, it'll greatly simplify
82 // HistoryContentsProvider. 81 // HistoryContentsProvider.
83 82
84 private: 83 private:
85 // Resets the properties of the node from the supplied entry. 84 // Resets the properties of the node from the supplied entry.
86 void Reset(const history::StarredEntry& entry); 85 void Reset(const history::StarredEntry& entry);
87 86
88 // The model. This is NULL when created by StarredURLDatabase for migration. 87 // The model. This is NULL when created by StarredURLDatabase for migration.
89 BookmarkBarModel* model_; 88 BookmarkModel* model_;
90 89
91 // Unique identifier for this node. 90 // Unique identifier for this node.
92 const int id_; 91 const int id_;
93 92
94 // Whether the favicon has been loaded. 93 // Whether the favicon has been loaded.
95 bool loaded_favicon_; 94 bool loaded_favicon_;
96 95
97 // The favicon. 96 // The favicon.
98 SkBitmap favicon_; 97 SkBitmap favicon_;
99 98
100 // If non-zero, it indicates we're loading the favicon and this is the handle 99 // If non-zero, it indicates we're loading the favicon and this is the handle
101 // from the HistoryService. 100 // from the HistoryService.
102 HistoryService::Handle favicon_load_handle_; 101 HistoryService::Handle favicon_load_handle_;
103 102
104 // The URL. BookmarkBarModel maintains maps off this URL, it is important that 103 // The URL. BookmarkModel maintains maps off this URL, it is important that
105 // it not change once the node has been created. 104 // it not change once the node has been created.
106 const GURL url_; 105 const GURL url_;
107 106
108 // Type of node. 107 // Type of node.
109 // TODO(sky): bug 1256202, convert this into a type defined here. 108 // TODO(sky): bug 1256202, convert this into a type defined here.
110 history::StarredEntry::Type type_; 109 history::StarredEntry::Type type_;
111 110
112 // Date we were created. 111 // Date we were created.
113 Time date_added_; 112 Time date_added_;
114 113
115 // Time last modified. Only used for groups. 114 // Time last modified. Only used for groups.
116 Time date_group_modified_; 115 Time date_group_modified_;
117 116
118 DISALLOW_EVIL_CONSTRUCTORS(BookmarkBarNode); 117 DISALLOW_EVIL_CONSTRUCTORS(BookmarkNode);
119 }; 118 };
120 119
120 // BookmarkModelObserver ------------------------------------------------------
121 121
122 // BookmarkBarModelObserver --------------------------------------------------- 122 // Observer for the BookmarkModel.
123
124 // Observer for the BookmarkBarModel.
125 // 123 //
126 class BookmarkBarModelObserver { 124 class BookmarkModelObserver {
127 public: 125 public:
128 // Invoked when the model has finished loading. 126 // Invoked when the model has finished loading.
129 virtual void Loaded(BookmarkBarModel* model) = 0; 127 virtual void Loaded(BookmarkModel* model) = 0;
130 128
131 // Invoked from the destructor of the BookmarkBarModel. 129 // Invoked from the destructor of the BookmarkModel.
132 virtual void BookmarkModelBeingDeleted(BookmarkBarModel* model) { } 130 virtual void BookmarkModelBeingDeleted(BookmarkModel* model) { }
133 131
134 // Invoked when a node has moved. 132 // Invoked when a node has moved.
135 virtual void BookmarkNodeMoved(BookmarkBarModel* model, 133 virtual void BookmarkNodeMoved(BookmarkModel* model,
136 BookmarkBarNode* old_parent, 134 BookmarkNode* old_parent,
137 int old_index, 135 int old_index,
138 BookmarkBarNode* new_parent, 136 BookmarkNode* new_parent,
139 int new_index) = 0; 137 int new_index) = 0;
140 138
141 // Invoked when a node has been added. 139 // Invoked when a node has been added.
142 virtual void BookmarkNodeAdded(BookmarkBarModel* model, 140 virtual void BookmarkNodeAdded(BookmarkModel* model,
143 BookmarkBarNode* parent, 141 BookmarkNode* parent,
144 int index) = 0; 142 int index) = 0;
145 143
146 // Invoked when a node has been removed, the item may still be starred though. 144 // Invoked when a node has been removed, the item may still be starred though.
147 virtual void BookmarkNodeRemoved(BookmarkBarModel* model, 145 virtual void BookmarkNodeRemoved(BookmarkModel* model,
148 BookmarkBarNode* parent, 146 BookmarkNode* parent,
149 int index) = 0; 147 int index) = 0;
150 148
151 // Invoked when the title or favicon of a node has changed. 149 // Invoked when the title or favicon of a node has changed.
152 virtual void BookmarkNodeChanged(BookmarkBarModel* model, 150 virtual void BookmarkNodeChanged(BookmarkModel* model,
153 BookmarkBarNode* node) = 0; 151 BookmarkNode* node) = 0;
154 152
155 // Invoked when a favicon has finished loading. 153 // Invoked when a favicon has finished loading.
156 virtual void BookmarkNodeFavIconLoaded(BookmarkBarModel* model, 154 virtual void BookmarkNodeFavIconLoaded(BookmarkModel* model,
157 BookmarkBarNode* node) = 0; 155 BookmarkNode* node) = 0;
158 }; 156 };
159 157
160 // BookmarkBarModel ----------------------------------------------------------- 158 // BookmarkModel --------------------------------------------------------------
161 159
162 // BookmarkBarModel provides a directed acyclic graph of the starred entries 160 // BookmarkModel provides a directed acyclic graph of the starred entries
163 // and groups. Two graphs are provided for the two entry points: those on 161 // and groups. Two graphs are provided for the two entry points: those on
164 // the bookmark bar, and those in the other folder. 162 // the bookmark bar, and those in the other folder.
165 // 163 //
166 // The methods of BookmarkBarModel update the internal structure immediately 164 // The methods of BookmarkModel update the internal structure immediately
167 // and update the backend in the background. 165 // and update the backend in the background.
168 // 166 //
169 // An observer may be attached to observer relevant events. 167 // An observer may be attached to observer relevant events.
170 // 168 //
171 // You should NOT directly create a BookmarkBarModel, instead go through the 169 // You should NOT directly create a BookmarkModel, instead go through the
172 // Profile. 170 // Profile.
173 171
174 // TODO(sky): rename to BookmarkModel. 172 // TODO(sky): rename to BookmarkModel.
175 class BookmarkBarModel : public NotificationObserver, public BookmarkService { 173 class BookmarkModel : public NotificationObserver, public BookmarkService {
176 friend class BookmarkBarNode; 174 friend class BookmarkNode;
177 friend class BookmarkBarModelTest; 175 friend class BookmarkModelTest;
178 friend class BookmarkStorage; 176 friend class BookmarkStorage;
179 177
180 public: 178 public:
181 explicit BookmarkBarModel(Profile* profile); 179 explicit BookmarkModel(Profile* profile);
182 virtual ~BookmarkBarModel(); 180 virtual ~BookmarkModel();
183 181
184 // Loads the bookmarks. This is called by Profile upon creation of the 182 // Loads the bookmarks. This is called by Profile upon creation of the
185 // BookmarkBarModel. You need not invoke this directly. 183 // BookmarkModel. You need not invoke this directly.
186 void Load(); 184 void Load();
187 185
188 // Returns the root node. The bookmark bar node and other node are children of 186 // Returns the root node. The bookmark bar node and other node are children of
189 // the root node. 187 // the root node.
190 BookmarkBarNode* root_node() { return &root_; } 188 BookmarkNode* root_node() { return &root_; }
191 189
192 // Returns the bookmark bar node. 190 // Returns the bookmark bar node.
193 BookmarkBarNode* GetBookmarkBarNode() { return bookmark_bar_node_; } 191 BookmarkNode* GetBookmarkBarNode() { return bookmark_bar_node_; }
194 192
195 // Returns the 'other' node. 193 // Returns the 'other' node.
196 BookmarkBarNode* other_node() { return other_node_; } 194 BookmarkNode* other_node() { return other_node_; }
197 195
198 // Returns the parent the last node was added to. This never returns NULL 196 // Returns the parent the last node was added to. This never returns NULL
199 // (as long as the model is loaded). 197 // (as long as the model is loaded).
200 BookmarkBarNode* GetParentForNewNodes(); 198 BookmarkNode* GetParentForNewNodes();
201 199
202 // Returns a vector containing up to |max_count| of the most recently 200 // Returns a vector containing up to |max_count| of the most recently
203 // modified groups. This never returns an empty vector. 201 // modified groups. This never returns an empty vector.
204 std::vector<BookmarkBarNode*> GetMostRecentlyModifiedGroups(size_t max_count); 202 std::vector<BookmarkNode*> GetMostRecentlyModifiedGroups(size_t max_count);
205 203
206 // Returns the most recently added bookmarks. 204 // Returns the most recently added bookmarks.
207 void GetMostRecentlyAddedEntries(size_t count, 205 void GetMostRecentlyAddedEntries(size_t count,
208 std::vector<BookmarkBarNode*>* nodes); 206 std::vector<BookmarkNode*>* nodes);
209 207
210 // Used by GetBookmarksMatchingText to return a matching node and the location 208 // Used by GetBookmarksMatchingText to return a matching node and the location
211 // of the match in the title. 209 // of the match in the title.
212 struct TitleMatch { 210 struct TitleMatch {
213 BookmarkBarNode* node; 211 BookmarkNode* node;
214 212
215 // Location of the matching words in the title of the node. 213 // Location of the matching words in the title of the node.
216 Snippet::MatchPositions match_positions; 214 Snippet::MatchPositions match_positions;
217 }; 215 };
218 216
219 // Returns the bookmarks whose title contains text. At most |max_count| 217 // Returns the bookmarks whose title contains text. At most |max_count|
220 // matches are returned in |matches|. 218 // matches are returned in |matches|.
221 void GetBookmarksMatchingText(const std::wstring& text, 219 void GetBookmarksMatchingText(const std::wstring& text,
222 size_t max_count, 220 size_t max_count,
223 std::vector<TitleMatch>* matches); 221 std::vector<TitleMatch>* matches);
224 222
225 void AddObserver(BookmarkBarModelObserver* observer) { 223 void AddObserver(BookmarkModelObserver* observer) {
226 observers_.AddObserver(observer); 224 observers_.AddObserver(observer);
227 } 225 }
228 226
229 void RemoveObserver(BookmarkBarModelObserver* observer) { 227 void RemoveObserver(BookmarkModelObserver* observer) {
230 observers_.RemoveObserver(observer); 228 observers_.RemoveObserver(observer);
231 } 229 }
232 230
233 // Unstars or deletes the specified entry. Removing a group entry recursively 231 // Unstars or deletes the specified entry. Removing a group entry recursively
234 // unstars all nodes. Observers are notified immediately. 232 // unstars all nodes. Observers are notified immediately.
235 void Remove(BookmarkBarNode* parent, int index); 233 void Remove(BookmarkNode* parent, int index);
236 234
237 // Moves the specified entry to a new location. 235 // Moves the specified entry to a new location.
238 void Move(BookmarkBarNode* node, BookmarkBarNode* new_parent, int index); 236 void Move(BookmarkNode* node, BookmarkNode* new_parent, int index);
239 237
240 // Sets the title of the specified node. 238 // Sets the title of the specified node.
241 void SetTitle(BookmarkBarNode* node, const std::wstring& title); 239 void SetTitle(BookmarkNode* node, const std::wstring& title);
242 240
243 // Returns true if the model finished loading. 241 // Returns true if the model finished loading.
244 bool IsLoaded() { return loaded_; } 242 bool IsLoaded() { return loaded_; }
245 243
246 // Returns the node with the specified URL, or NULL if there is no node with 244 // Returns the node with the specified URL, or NULL if there is no node with
247 // the specified URL. This method is thread safe. 245 // the specified URL. This method is thread safe.
248 BookmarkBarNode* GetNodeByURL(const GURL& url); 246 BookmarkNode* GetNodeByURL(const GURL& url);
249 247
250 // Returns all the bookmarked urls. This method is thread safe. 248 // Returns all the bookmarked urls. This method is thread safe.
251 virtual void GetBookmarks(std::vector<GURL>* urls); 249 virtual void GetBookmarks(std::vector<GURL>* urls);
252 250
253 // Returns true if there is a bookmark for the specified URL. This method is 251 // Returns true if there is a bookmark for the specified URL. This method is
254 // thread safe. See BookmarkService for more details on this. 252 // thread safe. See BookmarkService for more details on this.
255 virtual bool IsBookmarked(const GURL& url) { 253 virtual bool IsBookmarked(const GURL& url) {
256 return GetNodeByURL(url) != NULL; 254 return GetNodeByURL(url) != NULL;
257 } 255 }
258 256
259 // Blocks until loaded; this is NOT invoked on the main thread. See 257 // Blocks until loaded; this is NOT invoked on the main thread. See
260 // BookmarkService for more details on this. 258 // BookmarkService for more details on this.
261 virtual void BlockTillLoaded(); 259 virtual void BlockTillLoaded();
262 260
263 // Returns the node with the specified id, or NULL if there is no node with 261 // Returns the node with the specified id, or NULL if there is no node with
264 // the specified id. 262 // the specified id.
265 BookmarkBarNode* GetNodeByID(int id); 263 BookmarkNode* GetNodeByID(int id);
266 264
267 // Adds a new group node at the specified position. 265 // Adds a new group node at the specified position.
268 BookmarkBarNode* AddGroup(BookmarkBarNode* parent, 266 BookmarkNode* AddGroup(BookmarkNode* parent,
269 int index, 267 int index,
270 const std::wstring& title); 268 const std::wstring& title);
271 269
272 // Adds a url at the specified position. If there is already a node with the 270 // Adds a url at the specified position. If there is already a node with the
273 // specified URL, it is moved to the new position. 271 // specified URL, it is moved to the new position.
274 BookmarkBarNode* AddURL(BookmarkBarNode* parent, 272 BookmarkNode* AddURL(BookmarkNode* parent,
275 int index, 273 int index,
276 const std::wstring& title, 274 const std::wstring& title,
277 const GURL& url); 275 const GURL& url);
278 276
279 // Adds a url with a specific creation date. 277 // Adds a url with a specific creation date.
280 BookmarkBarNode* AddURLWithCreationTime(BookmarkBarNode* parent, 278 BookmarkNode* AddURLWithCreationTime(BookmarkNode* parent,
281 int index, 279 int index,
282 const std::wstring& title, 280 const std::wstring& title,
283 const GURL& url, 281 const GURL& url,
284 const Time& creation_time); 282 const Time& creation_time);
285 283
286 // This is the convenience that makes sure the url is starred or not 284 // This is the convenience that makes sure the url is starred or not
287 // starred. If the URL is not currently starred, it is added to the 285 // starred. If the URL is not currently starred, it is added to the
288 // most recent parent. 286 // most recent parent.
289 void SetURLStarred(const GURL& url, 287 void SetURLStarred(const GURL& url,
290 const std::wstring& title, 288 const std::wstring& title,
291 bool is_starred); 289 bool is_starred);
292 290
293 // Resets the 'date modified' time of the node to 0. This is used during 291 // Resets the 'date modified' time of the node to 0. This is used during
294 // importing to exclude the newly created groups from showing up in the 292 // importing to exclude the newly created groups from showing up in the
295 // combobox of most recently modified groups. 293 // combobox of most recently modified groups.
296 void ResetDateGroupModified(BookmarkBarNode* node); 294 void ResetDateGroupModified(BookmarkNode* node);
297 295
298 private: 296 private:
299 // Used to order BookmarkBarNodes by URL. 297 // Used to order BookmarkNodes by URL.
300 class NodeURLComparator { 298 class NodeURLComparator {
301 public: 299 public:
302 bool operator()(BookmarkBarNode* n1, BookmarkBarNode* n2) const { 300 bool operator()(BookmarkNode* n1, BookmarkNode* n2) const {
303 return n1->GetURL() < n2->GetURL(); 301 return n1->GetURL() < n2->GetURL();
304 } 302 }
305 }; 303 };
306 304
307 // Overriden to notify the observer the favicon has been loaded. 305 // Overriden to notify the observer the favicon has been loaded.
308 void FavIconLoaded(BookmarkBarNode* node); 306 void FavIconLoaded(BookmarkNode* node);
309 307
310 // Removes the node from internal maps and recurces through all children. If 308 // Removes the node from internal maps and recurces through all children. If
311 // the node is a url, its url is added to removed_urls. 309 // the node is a url, its url is added to removed_urls.
312 // 310 //
313 // This does NOT delete the node. 311 // This does NOT delete the node.
314 void RemoveNode(BookmarkBarNode* node, std::set<GURL>* removed_urls); 312 void RemoveNode(BookmarkNode* node, std::set<GURL>* removed_urls);
315 313
316 // Callback from BookmarkStorage that it has finished loading. This method 314 // Callback from BookmarkStorage that it has finished loading. This method
317 // may be hit twice. In particular, on construction BookmarkBarModel asks 315 // may be hit twice. In particular, on construction BookmarkModel asks
318 // BookmarkStorage to load the bookmarks. BookmarkStorage invokes this method 316 // BookmarkStorage to load the bookmarks. BookmarkStorage invokes this method
319 // with loaded_from_history false and file_exists indicating whether the 317 // with loaded_from_history false and file_exists indicating whether the
320 // bookmarks file exists. If the file doesn't exist, we query history. When 318 // bookmarks file exists. If the file doesn't exist, we query history. When
321 // history calls us back (OnHistoryDone) we then ask BookmarkStorage to load 319 // history calls us back (OnHistoryDone) we then ask BookmarkStorage to load
322 // from the migration file. BookmarkStorage again invokes this method, but 320 // from the migration file. BookmarkStorage again invokes this method, but
323 // with |loaded_from_history| true. 321 // with |loaded_from_history| true.
324 void OnBookmarkStorageLoadedBookmarks(bool file_exists, 322 void OnBookmarkStorageLoadedBookmarks(bool file_exists,
325 bool loaded_from_history); 323 bool loaded_from_history);
326 324
327 // Used for migrating bookmarks from history to standalone file. 325 // Used for migrating bookmarks from history to standalone file.
328 // 326 //
329 // Callback from history that it is done with an empty request. This is used 327 // Callback from history that it is done with an empty request. This is used
330 // if there is no bookmarks file. Once done, we attempt to load from the 328 // if there is no bookmarks file. Once done, we attempt to load from the
331 // temporary file creating during migration. 329 // temporary file creating during migration.
332 void OnHistoryDone(); 330 void OnHistoryDone();
333 331
334 // Invoked when loading is finished. Sets loaded_ and notifies observers. 332 // Invoked when loading is finished. Sets loaded_ and notifies observers.
335 void DoneLoading(); 333 void DoneLoading();
336 334
337 // Populates nodes_ordered_by_url_set_ from root. 335 // Populates nodes_ordered_by_url_set_ from root.
338 void PopulateNodesByURL(BookmarkBarNode* node); 336 void PopulateNodesByURL(BookmarkNode* node);
339 337
340 // Removes the node from its parent, sends notification, and deletes it. 338 // Removes the node from its parent, sends notification, and deletes it.
341 // type specifies how the node should be removed. 339 // type specifies how the node should be removed.
342 void RemoveAndDeleteNode(BookmarkBarNode* delete_me); 340 void RemoveAndDeleteNode(BookmarkNode* delete_me);
343 341
344 // Adds the node at the specified position, and sends notification. 342 // Adds the node at the specified position, and sends notification.
345 BookmarkBarNode* AddNode(BookmarkBarNode* parent, 343 BookmarkNode* AddNode(BookmarkNode* parent,
346 int index, 344 int index,
347 BookmarkBarNode* node); 345 BookmarkNode* node);
348 346
349 // Implementation of GetNodeByID. 347 // Implementation of GetNodeByID.
350 BookmarkBarNode* GetNodeByID(BookmarkBarNode* node, int id); 348 BookmarkNode* GetNodeByID(BookmarkNode* node, int id);
351 349
352 // Returns true if the parent and index are valid. 350 // Returns true if the parent and index are valid.
353 bool IsValidIndex(BookmarkBarNode* parent, int index, bool allow_end); 351 bool IsValidIndex(BookmarkNode* parent, int index, bool allow_end);
354 352
355 // Sets the date modified time of the specified node. 353 // Sets the date modified time of the specified node.
356 void SetDateGroupModified(BookmarkBarNode* parent, const Time time); 354 void SetDateGroupModified(BookmarkNode* parent, const Time time);
357 355
358 // Creates the bookmark bar/other nodes. These call into 356 // Creates the bookmark bar/other nodes. These call into
359 // CreateRootNodeFromStarredEntry. 357 // CreateRootNodeFromStarredEntry.
360 void CreateBookmarkBarNode(); 358 void CreateBookmarkNode();
361 void CreateOtherBookmarksNode(); 359 void CreateOtherBookmarksNode();
362 360
363 // Creates a root node (either the bookmark bar node or other node) from the 361 // Creates a root node (either the bookmark bar node or other node) from the
364 // specified starred entry. 362 // specified starred entry.
365 BookmarkBarNode* CreateRootNodeFromStarredEntry( 363 BookmarkNode* CreateRootNodeFromStarredEntry(
366 const history::StarredEntry& entry); 364 const history::StarredEntry& entry);
367 365
368 // Notification that a favicon has finished loading. If we can decode the 366 // Notification that a favicon has finished loading. If we can decode the
369 // favicon, FaviconLoaded is invoked. 367 // favicon, FaviconLoaded is invoked.
370 void OnFavIconDataAvailable( 368 void OnFavIconDataAvailable(
371 HistoryService::Handle handle, 369 HistoryService::Handle handle,
372 bool know_favicon, 370 bool know_favicon,
373 scoped_refptr<RefCountedBytes> data, 371 scoped_refptr<RefCountedBytes> data,
374 bool expired, 372 bool expired,
375 GURL icon_url); 373 GURL icon_url);
376 374
377 // Invoked from the node to load the favicon. Requests the favicon from the 375 // Invoked from the node to load the favicon. Requests the favicon from the
378 // history service. 376 // history service.
379 void LoadFavIcon(BookmarkBarNode* node); 377 void LoadFavIcon(BookmarkNode* node);
380 378
381 // If we're waiting on a favicon for node, the load request is canceled. 379 // If we're waiting on a favicon for node, the load request is canceled.
382 void CancelPendingFavIconLoadRequests(BookmarkBarNode* node); 380 void CancelPendingFavIconLoadRequests(BookmarkNode* node);
383 381
384 // Returns up to count of the most recently modified groups. This may not 382 // Returns up to count of the most recently modified groups. This may not
385 // add anything. 383 // add anything.
386 void GetMostRecentlyModifiedGroupNodes(BookmarkBarNode* parent, 384 void GetMostRecentlyModifiedGroupNodes(BookmarkNode* parent,
387 size_t count, 385 size_t count,
388 std::vector<BookmarkBarNode*>* nodes); 386 std::vector<BookmarkNode*>* nodes);
389 387
390 // NotificationObserver. 388 // NotificationObserver.
391 virtual void Observe(NotificationType type, 389 virtual void Observe(NotificationType type,
392 const NotificationSource& source, 390 const NotificationSource& source,
393 const NotificationDetails& details); 391 const NotificationDetails& details);
394 392
395 Profile* profile_; 393 Profile* profile_;
396 394
397 // Whether the initial set of data has been loaded. 395 // Whether the initial set of data has been loaded.
398 bool loaded_; 396 bool loaded_;
399 397
400 // The root node. This contains the bookmark bar node and the 'other' node as 398 // The root node. This contains the bookmark bar node and the 'other' node as
401 // children. 399 // children.
402 BookmarkBarNode root_; 400 BookmarkNode root_;
403 401
404 BookmarkBarNode* bookmark_bar_node_; 402 BookmarkNode* bookmark_bar_node_;
405 BookmarkBarNode* other_node_; 403 BookmarkNode* other_node_;
406 404
407 // The observers. 405 // The observers.
408 ObserverList<BookmarkBarModelObserver> observers_; 406 ObserverList<BookmarkModelObserver> observers_;
409 407
410 // Set of nodes ordered by URL. This is not a map to avoid copying the 408 // Set of nodes ordered by URL. This is not a map to avoid copying the
411 // urls. 409 // urls.
412 // WARNING: nodes_ordered_by_url_set_ is accessed on multiple threads. As 410 // WARNING: nodes_ordered_by_url_set_ is accessed on multiple threads. As
413 // such, be sure and wrap all usage of it around url_lock_. 411 // such, be sure and wrap all usage of it around url_lock_.
414 typedef std::set<BookmarkBarNode*,NodeURLComparator> NodesOrderedByURLSet; 412 typedef std::set<BookmarkNode*,NodeURLComparator> NodesOrderedByURLSet;
415 NodesOrderedByURLSet nodes_ordered_by_url_set_; 413 NodesOrderedByURLSet nodes_ordered_by_url_set_;
416 Lock url_lock_; 414 Lock url_lock_;
417 415
418 // Used for loading favicons and the empty history request. 416 // Used for loading favicons and the empty history request.
419 CancelableRequestConsumerT<BookmarkBarNode*, NULL> load_consumer_; 417 CancelableRequestConsumerT<BookmarkNode*, NULL> load_consumer_;
420 418
421 // Reads/writes bookmarks to disk. 419 // Reads/writes bookmarks to disk.
422 scoped_refptr<BookmarkStorage> store_; 420 scoped_refptr<BookmarkStorage> store_;
423 421
424 // Have we installed a listener on the NotificationService for 422 // Have we installed a listener on the NotificationService for
425 // NOTIFY_HISTORY_LOADED? A listener is installed if the bookmarks file 423 // NOTIFY_HISTORY_LOADED? A listener is installed if the bookmarks file
426 // doesn't exist and the history service hasn't finished loading. 424 // doesn't exist and the history service hasn't finished loading.
427 bool waiting_for_history_load_; 425 bool waiting_for_history_load_;
428 426
429 // Handle to event signaled when loading is done. 427 // Handle to event signaled when loading is done.
430 ScopedHandle loaded_signal_; 428 ScopedHandle loaded_signal_;
431 429
432 DISALLOW_COPY_AND_ASSIGN(BookmarkBarModel); 430 DISALLOW_COPY_AND_ASSIGN(BookmarkModel);
433 }; 431 };
434 432
435 #endif // CHROME_BROWSER_BOOKMARKS_BOOKMARK_BAR_MODEL_H_ 433 #endif // CHROME_BROWSER_BOOKMARKS_BOOKMARK_BAR_MODEL_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698