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

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

Issue 7012005: Revert "Revert 84829 - Initial implementation of "Synced Bookmarks" folder." (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Fix linux test failure Created 9 years, 7 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) 2011 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2011 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_MODEL_H_ 5 #ifndef CHROME_BROWSER_BOOKMARKS_BOOKMARK_MODEL_H_
6 #define CHROME_BROWSER_BOOKMARKS_BOOKMARK_MODEL_H_ 6 #define CHROME_BROWSER_BOOKMARKS_BOOKMARK_MODEL_H_
7 #pragma once 7 #pragma once
8 8
9 #include "build/build_config.h" 9 #include "build/build_config.h"
10 10
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after
43 // star id and type. BookmarkNodes are returned from a BookmarkModel. 43 // star id and type. BookmarkNodes are returned from a BookmarkModel.
44 // 44 //
45 class BookmarkNode : public ui::TreeNode<BookmarkNode> { 45 class BookmarkNode : public ui::TreeNode<BookmarkNode> {
46 friend class BookmarkModel; 46 friend class BookmarkModel;
47 47
48 public: 48 public:
49 enum Type { 49 enum Type {
50 URL, 50 URL,
51 FOLDER, 51 FOLDER,
52 BOOKMARK_BAR, 52 BOOKMARK_BAR,
53 OTHER_NODE 53 OTHER_NODE,
54 SYNCED
54 }; 55 };
55 // Creates a new node with the specified url and id of 0 56 // Creates a new node with the specified url and id of 0
56 explicit BookmarkNode(const GURL& url); 57 explicit BookmarkNode(const GURL& url);
57 // Creates a new node with the specified url and id. 58 // Creates a new node with the specified url and id.
58 BookmarkNode(int64 id, const GURL& url); 59 BookmarkNode(int64 id, const GURL& url);
59 virtual ~BookmarkNode(); 60 virtual ~BookmarkNode();
60 61
61 // Returns the URL. 62 // Returns the URL.
62 const GURL& GetURL() const { return url_; } 63 const GURL& GetURL() const { return url_; }
63 // Sets the URL to the given value. 64 // Sets the URL to the given value.
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after
102 // this does not. 103 // this does not.
103 const SkBitmap& favicon() const { return favicon_; } 104 const SkBitmap& favicon() const { return favicon_; }
104 void set_favicon(const SkBitmap& icon) { favicon_ = icon; } 105 void set_favicon(const SkBitmap& icon) { favicon_ = icon; }
105 106
106 // The following methods are used by the bookmark model, and are not 107 // The following methods are used by the bookmark model, and are not
107 // really useful outside of it. 108 // really useful outside of it.
108 109
109 bool is_favicon_loaded() const { return loaded_favicon_; } 110 bool is_favicon_loaded() const { return loaded_favicon_; }
110 void set_favicon_loaded(bool value) { loaded_favicon_ = value; } 111 void set_favicon_loaded(bool value) { loaded_favicon_ = value; }
111 112
113 // Accessor method for controlling the visibility of a bookmark node/sub-tree.
114 // Note that visibility is not propagated down the tree hierarchy so if a
115 // parent node is marked as invisible, a child node may return "Visible". This
116 // function is primarily useful when traversing the model to generate a UI
117 // representation but we may want to suppress some nodes.
118 bool IsVisible() const;
sky 2011/05/17 15:59:08 Can you add a TODO to remove this when synced is n
Yaron 2011/05/17 19:17:33 Done.
119
112 HistoryService::Handle favicon_load_handle() const { 120 HistoryService::Handle favicon_load_handle() const {
113 return favicon_load_handle_; 121 return favicon_load_handle_;
114 } 122 }
115 void set_favicon_load_handle(HistoryService::Handle handle) { 123 void set_favicon_load_handle(HistoryService::Handle handle) {
116 favicon_load_handle_ = handle; 124 favicon_load_handle_ = handle;
117 } 125 }
118 126
119 // Called when the favicon becomes invalid. 127 // Called when the favicon becomes invalid.
120 void InvalidateFavicon(); 128 void InvalidateFavicon();
121 129
(...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after
186 // Returns the root node. The bookmark bar node and other node are children of 194 // Returns the root node. The bookmark bar node and other node are children of
187 // the root node. 195 // the root node.
188 const BookmarkNode* root_node() { return &root_; } 196 const BookmarkNode* root_node() { return &root_; }
189 197
190 // Returns the bookmark bar node. This is NULL until loaded. 198 // Returns the bookmark bar node. This is NULL until loaded.
191 const BookmarkNode* GetBookmarkBarNode() { return bookmark_bar_node_; } 199 const BookmarkNode* GetBookmarkBarNode() { return bookmark_bar_node_; }
192 200
193 // Returns the 'other' node. This is NULL until loaded. 201 // Returns the 'other' node. This is NULL until loaded.
194 const BookmarkNode* other_node() { return other_node_; } 202 const BookmarkNode* other_node() { return other_node_; }
195 203
204 // Returns the 'synced' node. This is NULL until loaded.
205 const BookmarkNode* synced_node() { return synced_node_; }
206
196 // Returns the parent the last node was added to. This never returns NULL 207 // Returns the parent the last node was added to. This never returns NULL
197 // (as long as the model is loaded). 208 // (as long as the model is loaded).
198 const BookmarkNode* GetParentForNewNodes(); 209 const BookmarkNode* GetParentForNewNodes();
199 210
200 void AddObserver(BookmarkModelObserver* observer) { 211 void AddObserver(BookmarkModelObserver* observer) {
201 observers_.AddObserver(observer); 212 observers_.AddObserver(observer);
202 } 213 }
203 214
204 void RemoveObserver(BookmarkModelObserver* observer) { 215 void RemoveObserver(BookmarkModelObserver* observer) {
205 observers_.RemoveObserver(observer); 216 observers_.RemoveObserver(observer);
(...skipping 98 matching lines...) Expand 10 before | Expand all | Expand 10 after
304 const string16& text, 315 const string16& text,
305 size_t max_count, 316 size_t max_count,
306 std::vector<bookmark_utils::TitleMatch>* matches); 317 std::vector<bookmark_utils::TitleMatch>* matches);
307 318
308 Profile* profile() const { return profile_; } 319 Profile* profile() const { return profile_; }
309 320
310 bool is_root(const BookmarkNode* node) const { return node == &root_; } 321 bool is_root(const BookmarkNode* node) const { return node == &root_; }
311 bool is_bookmark_bar_node(const BookmarkNode* node) const { 322 bool is_bookmark_bar_node(const BookmarkNode* node) const {
312 return node == bookmark_bar_node_; 323 return node == bookmark_bar_node_;
313 } 324 }
325 bool is_synced_bookmarks_node(const BookmarkNode* node) const {
326 return node == synced_node_;
327 }
314 bool is_other_bookmarks_node(const BookmarkNode* node) const { 328 bool is_other_bookmarks_node(const BookmarkNode* node) const {
315 return node == other_node_; 329 return node == other_node_;
316 } 330 }
317 // Returns whether the given node is one of the permanent nodes - root node, 331 // Returns whether the given node is one of the permanent nodes - root node,
318 // bookmark bar node or other bookmarks node. 332 // bookmark bar node or other bookmarks node.
319 bool is_permanent_node(const BookmarkNode* node) const { 333 bool is_permanent_node(const BookmarkNode* node) const {
320 return is_root(node) || 334 return is_root(node) ||
321 is_bookmark_bar_node(node) || 335 is_bookmark_bar_node(node) ||
322 is_other_bookmarks_node(node); 336 is_other_bookmarks_node(node) ||
337 is_synced_bookmarks_node(node);
323 } 338 }
324 339
325 // Sets the store to NULL, making it so the BookmarkModel does not persist 340 // Sets the store to NULL, making it so the BookmarkModel does not persist
326 // any changes to disk. This is only useful during testing to speed up 341 // any changes to disk. This is only useful during testing to speed up
327 // testing. 342 // testing.
328 void ClearStore(); 343 void ClearStore();
329 344
330 // Returns whether the bookmarks file changed externally. 345 // Returns whether the bookmarks file changed externally.
331 bool file_changed() const { return file_changed_; } 346 bool file_changed() const { return file_changed_; }
332 347
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after
373 int index, 388 int index,
374 BookmarkNode* node, 389 BookmarkNode* node,
375 bool was_bookmarked); 390 bool was_bookmarked);
376 391
377 // Implementation of GetNodeByID. 392 // Implementation of GetNodeByID.
378 const BookmarkNode* GetNodeByID(const BookmarkNode* node, int64 id); 393 const BookmarkNode* GetNodeByID(const BookmarkNode* node, int64 id);
379 394
380 // Returns true if the parent and index are valid. 395 // Returns true if the parent and index are valid.
381 bool IsValidIndex(const BookmarkNode* parent, int index, bool allow_end); 396 bool IsValidIndex(const BookmarkNode* parent, int index, bool allow_end);
382 397
383 // Creates the bookmark bar/other nodes. These call into 398 // Creates the bookmark bar/synced/other nodes. These call into
384 // CreateRootNodeFromStarredEntry. 399 // CreateRootNodeFromStarredEntry.
385 BookmarkNode* CreateBookmarkNode(); 400 BookmarkNode* CreateBookmarkNode();
386 BookmarkNode* CreateOtherBookmarksNode(); 401 BookmarkNode* CreateOtherBookmarksNode();
402 BookmarkNode* CreateSyncedBookmarksNode();
387 403
388 // Creates a root node (either the bookmark bar node or other node) from the 404 // Creates a root node (either the bookmark bar node or other node) from the
389 // specified starred entry. 405 // specified starred entry.
390 BookmarkNode* CreateRootNodeFromStarredEntry( 406 BookmarkNode* CreateRootNodeFromStarredEntry(
391 const history::StarredEntry& entry); 407 const history::StarredEntry& entry);
392 408
393 // Notification that a favicon has finished loading. If we can decode the 409 // Notification that a favicon has finished loading. If we can decode the
394 // favicon, FaviconLoaded is invoked. 410 // favicon, FaviconLoaded is invoked.
395 void OnFaviconDataAvailable(FaviconService::Handle handle, 411 void OnFaviconDataAvailable(FaviconService::Handle handle,
396 history::FaviconData favicon); 412 history::FaviconData favicon);
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after
432 // Whether the bookmarks file was changed externally. This is set after 448 // Whether the bookmarks file was changed externally. This is set after
433 // loading is complete and once set the value never changes. 449 // loading is complete and once set the value never changes.
434 bool file_changed_; 450 bool file_changed_;
435 451
436 // The root node. This contains the bookmark bar node and the 'other' node as 452 // The root node. This contains the bookmark bar node and the 'other' node as
437 // children. 453 // children.
438 BookmarkNode root_; 454 BookmarkNode root_;
439 455
440 BookmarkNode* bookmark_bar_node_; 456 BookmarkNode* bookmark_bar_node_;
441 BookmarkNode* other_node_; 457 BookmarkNode* other_node_;
458 BookmarkNode* synced_node_;
442 459
443 // The maximum ID assigned to the bookmark nodes in the model. 460 // The maximum ID assigned to the bookmark nodes in the model.
444 int64 next_node_id_; 461 int64 next_node_id_;
445 462
446 // The observers. 463 // The observers.
447 ObserverList<BookmarkModelObserver> observers_; 464 ObserverList<BookmarkModelObserver> observers_;
448 465
449 // Set of nodes ordered by URL. This is not a map to avoid copying the 466 // Set of nodes ordered by URL. This is not a map to avoid copying the
450 // urls. 467 // urls.
451 // WARNING: nodes_ordered_by_url_set_ is accessed on multiple threads. As 468 // WARNING: nodes_ordered_by_url_set_ is accessed on multiple threads. As
452 // such, be sure and wrap all usage of it around url_lock_. 469 // such, be sure and wrap all usage of it around url_lock_.
453 typedef std::multiset<BookmarkNode*, NodeURLComparator> NodesOrderedByURLSet; 470 typedef std::multiset<BookmarkNode*, NodeURLComparator> NodesOrderedByURLSet;
454 NodesOrderedByURLSet nodes_ordered_by_url_set_; 471 NodesOrderedByURLSet nodes_ordered_by_url_set_;
455 base::Lock url_lock_; 472 base::Lock url_lock_;
456 473
457 // Used for loading favicons and the empty history request. 474 // Used for loading favicons and the empty history request.
458 CancelableRequestConsumerTSimple<BookmarkNode*> load_consumer_; 475 CancelableRequestConsumerTSimple<BookmarkNode*> load_consumer_;
459 476
460 // Reads/writes bookmarks to disk. 477 // Reads/writes bookmarks to disk.
461 scoped_refptr<BookmarkStorage> store_; 478 scoped_refptr<BookmarkStorage> store_;
462 479
463 scoped_ptr<BookmarkIndex> index_; 480 scoped_ptr<BookmarkIndex> index_;
464 481
465 base::WaitableEvent loaded_signal_; 482 base::WaitableEvent loaded_signal_;
466 483
467 DISALLOW_COPY_AND_ASSIGN(BookmarkModel); 484 DISALLOW_COPY_AND_ASSIGN(BookmarkModel);
468 }; 485 };
469 486
470 #endif // CHROME_BROWSER_BOOKMARKS_BOOKMARK_MODEL_H_ 487 #endif // CHROME_BROWSER_BOOKMARKS_BOOKMARK_MODEL_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698